Skip to content

Commit 4513806

Browse files
committed
Move RBTree to the rb_root extension object for better integration
1 parent 87fe344 commit 4513806

File tree

2 files changed

+30
-34
lines changed

2 files changed

+30
-34
lines changed

volatility3/framework/symbols/linux/__init__.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def __init__(self, *args, **kwargs) -> None:
4646
# Might not exist in older kernels or the current symbols
4747
self.optional_set_type_class("mount", extensions.mount)
4848
self.optional_set_type_class("mnt_namespace", extensions.mnt_namespace)
49+
self.optional_set_type_class("rb_root", extensions.rb_root)
4950

5051
# Network
5152
self.set_type_class("net", extensions.net)
@@ -425,36 +426,3 @@ def get_module_from_volobj_type(
425426
kernel = context.modules[kernel_module_name]
426427

427428
return kernel
428-
429-
430-
class RBTree(object):
431-
"""Simple Red-Black tree abstraction"""
432-
433-
def __init__(self, root):
434-
self.root = root
435-
436-
def _walk_nodes(self, root_node) -> Iterator[int]:
437-
"""Traverses the Red-Black tree from the root node and yields a pointer to each
438-
node in this tree.
439-
440-
Args:
441-
root_node: A Red-Black tree node from which to start descending
442-
443-
Yields:
444-
A pointer to every node descending from the specified root node
445-
"""
446-
if not root_node:
447-
return
448-
449-
yield root_node
450-
yield from self._walk_nodes(root_node.rb_left)
451-
yield from self._walk_nodes(root_node.rb_right)
452-
453-
def get_nodes(self) -> Iterator[int]:
454-
"""Yields a pointer to each node in the Red-Black tree
455-
456-
Yields:
457-
A pointer to every node in the Red-Black tree
458-
"""
459-
460-
yield from self._walk_nodes(root_node=self.root.rb_node)

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ def get_mount_points(
13261326
vmlinux = linux.LinuxUtilities.get_module_from_volobj_type(
13271327
self._context, self
13281328
)
1329-
for node in linux.RBTree(self.mounts).get_nodes():
1329+
for node in self.mounts.get_nodes():
13301330
mnt = linux.LinuxUtilities.container_of(
13311331
node, "mount", "mnt_list", vmlinux
13321332
)
@@ -1925,3 +1925,31 @@ def get_file_mode(self) -> str:
19251925
The inode's file mode string
19261926
"""
19271927
return stat.filemode(self.i_mode)
1928+
1929+
1930+
class rb_root(objects.StructType):
1931+
def _walk_nodes(self, root_node) -> Iterator[int]:
1932+
"""Traverses the Red-Black tree from the root node and yields a pointer to each
1933+
node in this tree.
1934+
1935+
Args:
1936+
root_node: A Red-Black tree node from which to start descending
1937+
1938+
Yields:
1939+
A pointer to every node descending from the specified root node
1940+
"""
1941+
if not root_node:
1942+
return
1943+
1944+
yield root_node
1945+
yield from self._walk_nodes(root_node.rb_left)
1946+
yield from self._walk_nodes(root_node.rb_right)
1947+
1948+
def get_nodes(self) -> Iterator[int]:
1949+
"""Yields a pointer to each node in the Red-Black tree
1950+
1951+
Yields:
1952+
A pointer to every node in the Red-Black tree
1953+
"""
1954+
1955+
yield from self._walk_nodes(root_node=self.rb_node)

0 commit comments

Comments
 (0)