Skip to content

Commit

Permalink
Merge pull request #1314 from gcmoreira/linux_add_hlist_head_object_e…
Browse files Browse the repository at this point in the history
…xtension_fix_1313

Linux adds hlist_head object extension
  • Loading branch information
ikelos authored Oct 22, 2024
2 parents 65daab6 + db8667f commit 1500d2e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion volatility3/framework/contexts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def object(
"""
if constants.BANG not in object_type:
object_type = self.symbol_table_name + constants.BANG + object_type
else:
elif not object_type.startswith(self.symbol_table_name + constants.BANG):
raise ValueError(
"Cannot reference another module when constructing an object"
)
Expand Down
1 change: 1 addition & 0 deletions volatility3/framework/symbols/linux/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self, *args, **kwargs) -> None:
# Set-up Linux specific types
self.set_type_class("file", extensions.struct_file)
self.set_type_class("list_head", extensions.list_head)
self.set_type_class("hlist_head", extensions.hlist_head)
self.set_type_class("mm_struct", extensions.mm_struct)
self.set_type_class("super_block", extensions.super_block)
self.set_type_class("task_struct", extensions.task_struct)
Expand Down
36 changes: 35 additions & 1 deletion volatility3/framework/symbols/linux/extensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ def get_subdirs(self) -> interfaces.objects.ObjectInterface:
if self.has_member("d_sib") and self.has_member("d_children"):
# kernels >= 6.8
walk_member = "d_sib"
list_head_member = self.d_children.first
list_head_member = self.d_children
elif self.has_member("d_child") and self.has_member("d_subdirs"):
# 2.5.0 <= kernels < 6.8
walk_member = "d_child"
Expand Down Expand Up @@ -1004,6 +1004,40 @@ def __iter__(self) -> Iterator[interfaces.objects.ObjectInterface]:
return self.to_list(self.vol.parent.vol.type_name, self.vol.member_name)


class hlist_head(objects.StructType, collections.abc.Iterable):
def to_list(
self,
symbol_type: str,
member: str,
) -> Iterator[interfaces.objects.ObjectInterface]:
"""Returns an iterator of the entries in the list.
This is a doubly linked list; however, it is not circular, so the 'forward' field
doesn't make sense. Also, the sentinel concept doesn't make sense here either;
unlike list_head, the head and nodes each have their own distinct types. A list_head
cannot be a node by itself.
- The 'pprev' of the first 'hlist_node' points to the 'hlist_head', not to the last node.
- The last element 'next' member is NULL
Args:
symbol_type: Type of the list elements
member: Name of the list_head member in the list elements
Yields:
Objects of the type specified via the "symbol_type" argument.
"""
vmlinux = linux.LinuxUtilities.get_module_from_volobj_type(self._context, self)

current = self.first
while current and current.is_readable():
yield linux.LinuxUtilities.container_of(
current, symbol_type, member, vmlinux
)

current = current.next


class files_struct(objects.StructType):
def get_fds(self) -> interfaces.objects.ObjectInterface:
if self.has_member("fdt"):
Expand Down

0 comments on commit 1500d2e

Please sign in to comment.