Skip to content

Commit 722ccd5

Browse files
committed
Linux: Extensions: Clean up the Linux constants imports in the object extension file
1 parent 4b76b69 commit 722ccd5

File tree

1 file changed

+35
-48
lines changed
  • volatility3/framework/symbols/linux/extensions

1 file changed

+35
-48
lines changed

volatility3/framework/symbols/linux/extensions/__init__.py

Lines changed: 35 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,7 @@
1313

1414
from volatility3.framework import constants, exceptions, objects, interfaces, symbols
1515
from volatility3.framework.renderers import conversion
16-
from volatility3.framework.constants.linux import (
17-
SOCK_TYPES,
18-
SOCK_FAMILY,
19-
IP_PROTOCOLS,
20-
IPV6_PROTOCOLS,
21-
TCP_STATES,
22-
NETLINK_PROTOCOLS,
23-
ETH_PROTOCOLS,
24-
BLUETOOTH_STATES,
25-
BLUETOOTH_PROTOCOLS,
26-
SOCKET_STATES,
27-
CAPABILITIES,
28-
PT_FLAGS,
29-
MODULE_MAXIMUM_CORE_SIZE,
30-
MODULE_MAXIMUM_CORE_TEXT_SIZE,
31-
MODULE_MINIMUM_SIZE,
32-
)
33-
16+
from volatility3.framework.constants import linux as linux_constants
3417
from volatility3.framework.layers import linear
3518
from volatility3.framework.objects import utility
3619
from volatility3.framework.symbols import generic, linux, intermed
@@ -62,9 +45,9 @@ def is_valid(self):
6245
core_text_size = self.get_core_text_size()
6346
init_size = self.get_init_size()
6447
if not (
65-
0 < core_text_size <= MODULE_MAXIMUM_CORE_TEXT_SIZE
66-
and 0 < core_size <= MODULE_MAXIMUM_CORE_SIZE
67-
and core_size + init_size >= MODULE_MINIMUM_SIZE
48+
0 < core_text_size <= linux_constants.MODULE_MAXIMUM_CORE_TEXT_SIZE
49+
and 0 < core_size <= linux_constants.MODULE_MAXIMUM_CORE_SIZE
50+
and core_size + init_size >= linux_constants.MODULE_MINIMUM_SIZE
6851
):
6952
return False
7053

@@ -383,7 +366,7 @@ def is_kernel_thread(self) -> bool:
383366
Returns:
384367
bool: True, if this task is a kernel thread. Otherwise, False.
385368
"""
386-
return (self.flags & constants.linux.PF_KTHREAD) != 0
369+
return (self.flags & linux_constants.PF_KTHREAD) != 0
387370

388371
@property
389372
def is_thread_group_leader(self) -> bool:
@@ -460,7 +443,11 @@ def get_ptrace_tracee_tids(self) -> List[int]:
460443

461444
def get_ptrace_tracee_flags(self) -> Optional[str]:
462445
"""Returns a string with the ptrace flags"""
463-
return PT_FLAGS(self.ptrace).flags if self.is_being_ptraced else None
446+
return (
447+
linux_constants.PT_FLAGS(self.ptrace).flags
448+
if self.is_being_ptraced
449+
else None
450+
)
464451

465452

466453
class fs_struct(objects.StructType):
@@ -1567,18 +1554,18 @@ def get_inode(self):
15671554

15681555
def get_state(self):
15691556
socket_state_idx = self.state
1570-
if 0 <= socket_state_idx < len(SOCKET_STATES):
1571-
return SOCKET_STATES[socket_state_idx]
1557+
if 0 <= socket_state_idx < len(linux_constants.SOCKET_STATES):
1558+
return linux_constants.SOCKET_STATES[socket_state_idx]
15721559

15731560

15741561
class sock(objects.StructType):
15751562
def get_family(self):
15761563
family_idx = self.__sk_common.skc_family
1577-
if 0 <= family_idx < len(SOCK_FAMILY):
1578-
return SOCK_FAMILY[family_idx]
1564+
if 0 <= family_idx < len(linux_constants.SOCK_FAMILY):
1565+
return linux_constants.SOCK_FAMILY[family_idx]
15791566

15801567
def get_type(self):
1581-
return SOCK_TYPES.get(self.sk_type, "")
1568+
return linux_constants.SOCK_TYPES.get(self.sk_type, "")
15821569

15831570
def get_inode(self):
15841571
if not self.sk_socket:
@@ -1612,8 +1599,8 @@ def get_state(self):
16121599
# Unix socket states reuse (a subset) of the inet_sock states contants
16131600
if self.sk.get_type() == "STREAM":
16141601
state_idx = self.sk.__sk_common.skc_state
1615-
if 0 <= state_idx < len(TCP_STATES):
1616-
return TCP_STATES[state_idx]
1602+
if 0 <= state_idx < len(linux_constants.TCP_STATES):
1603+
return linux_constants.TCP_STATES[state_idx]
16171604
else:
16181605
# Return the generic socket state
16191606
return self.sk.sk_socket.get_state()
@@ -1625,24 +1612,24 @@ def get_inode(self):
16251612
class inet_sock(objects.StructType):
16261613
def get_family(self):
16271614
family_idx = self.sk.__sk_common.skc_family
1628-
if 0 <= family_idx < len(SOCK_FAMILY):
1629-
return SOCK_FAMILY[family_idx]
1615+
if 0 <= family_idx < len(linux_constants.SOCK_FAMILY):
1616+
return linux_constants.SOCK_FAMILY[family_idx]
16301617

16311618
def get_protocol(self):
16321619
# If INET6 family and a proto is defined, we use that specific IPv6 protocol.
16331620
# Otherwise, we use the standard IP protocol.
1634-
protocol = IP_PROTOCOLS.get(self.sk.sk_protocol)
1621+
protocol = linux_constants.IP_PROTOCOLS.get(self.sk.sk_protocol)
16351622
if self.get_family() == "AF_INET6":
1636-
protocol = IPV6_PROTOCOLS.get(self.sk.sk_protocol, protocol)
1623+
protocol = linux_constants.IPV6_PROTOCOLS.get(self.sk.sk_protocol, protocol)
16371624
return protocol
16381625

16391626
def get_state(self):
16401627
"""Return a string representing the sock state."""
16411628

16421629
if self.sk.get_type() == "STREAM":
16431630
state_idx = self.sk.__sk_common.skc_state
1644-
if 0 <= state_idx < len(TCP_STATES):
1645-
return TCP_STATES[state_idx]
1631+
if 0 <= state_idx < len(linux_constants.TCP_STATES):
1632+
return linux_constants.TCP_STATES[state_idx]
16461633
else:
16471634
# Return the generic socket state
16481635
return self.sk.sk_socket.get_state()
@@ -1725,8 +1712,8 @@ def get_dst_addr(self):
17251712
class netlink_sock(objects.StructType):
17261713
def get_protocol(self):
17271714
protocol_idx = self.sk.sk_protocol
1728-
if 0 <= protocol_idx < len(NETLINK_PROTOCOLS):
1729-
return NETLINK_PROTOCOLS[protocol_idx]
1715+
if 0 <= protocol_idx < len(linux_constants.NETLINK_PROTOCOLS):
1716+
return linux_constants.NETLINK_PROTOCOLS[protocol_idx]
17301717

17311718
def get_state(self):
17321719
# Return the generic socket state
@@ -1768,8 +1755,8 @@ def get_protocol(self):
17681755
eth_proto = socket_module.htons(self.num)
17691756
if eth_proto == 0:
17701757
return None
1771-
elif eth_proto in ETH_PROTOCOLS:
1772-
return ETH_PROTOCOLS[eth_proto]
1758+
elif eth_proto in linux_constants.ETH_PROTOCOLS:
1759+
return linux_constants.ETH_PROTOCOLS[eth_proto]
17731760
else:
17741761
return f"0x{eth_proto:x}"
17751762

@@ -1781,13 +1768,13 @@ def get_state(self):
17811768
class bt_sock(objects.StructType):
17821769
def get_protocol(self):
17831770
type_idx = self.sk.sk_protocol
1784-
if 0 <= type_idx < len(BLUETOOTH_PROTOCOLS):
1785-
return BLUETOOTH_PROTOCOLS[type_idx]
1771+
if 0 <= type_idx < len(linux_constants.BLUETOOTH_PROTOCOLS):
1772+
return linux_constants.BLUETOOTH_PROTOCOLS[type_idx]
17861773

17871774
def get_state(self):
17881775
state_idx = self.sk.__sk_common.skc_state
1789-
if 0 <= state_idx < len(BLUETOOTH_STATES):
1790-
return BLUETOOTH_STATES[state_idx]
1776+
if 0 <= state_idx < len(linux_constants.BLUETOOTH_STATES):
1777+
return linux_constants.BLUETOOTH_STATES[state_idx]
17911778

17921779

17931780
class xdp_sock(objects.StructType):
@@ -1905,7 +1892,7 @@ def get_last_cap_value(cls) -> int:
19051892
Returns:
19061893
int: The latest capability ID supported by the framework.
19071894
"""
1908-
return len(CAPABILITIES) - 1
1895+
return len(linux_constants.CAPABILITIES) - 1
19091896

19101897
def get_kernel_cap_full(self) -> int:
19111898
"""Return the maximum value allowed for this kernel for a capability
@@ -1934,7 +1921,7 @@ def capabilities_to_string(cls, capabilities_bitfield: int) -> List[str]:
19341921
"""
19351922

19361923
capabilities = []
1937-
for bit, name in enumerate(CAPABILITIES):
1924+
for bit, name in enumerate(linux_constants.CAPABILITIES):
19381925
if capabilities_bitfield & (1 << bit) != 0:
19391926
capabilities.append(name)
19401927

@@ -1995,10 +1982,10 @@ def has_capability(self, capability: str) -> bool:
19951982
Returns:
19961983
bool: "True" if the given capability is enabled.
19971984
"""
1998-
if capability not in CAPABILITIES:
1985+
if capability not in linux_constants.CAPABILITIES:
19991986
raise AttributeError(f"Unknown capability with name '{capability}'")
20001987

2001-
cap_value = 1 << CAPABILITIES.index(capability)
1988+
cap_value = 1 << linux_constants.CAPABILITIES.index(capability)
20021989
return cap_value & self.get_capabilities() != 0
20031990

20041991

0 commit comments

Comments
 (0)