mirror of
https://github.com/volatilityfoundation/volatility3.git
synced 2026-08-21 22:12:23 +02:00
66 lines
2.5 KiB
Python
66 lines
2.5 KiB
Python
from typing import Callable, Iterable, List
|
|
|
|
import volatility.framework.interfaces.plugins as interfaces_plugins
|
|
from volatility.framework import renderers, interfaces
|
|
from volatility.framework.automagic import linux
|
|
from volatility.framework.configuration import requirements
|
|
from volatility.framework.objects import utility
|
|
|
|
|
|
class PsList(interfaces_plugins.PluginInterface):
|
|
"""Lists the processes present in a particular linux memory image"""
|
|
|
|
@classmethod
|
|
def get_requirements(cls) -> List[interfaces.configuration.RequirementInterface]:
|
|
return [
|
|
requirements.TranslationLayerRequirement(
|
|
name = 'primary', description = 'Kernel Address Space', architectures = ["Intel32", "Intel64"]),
|
|
requirements.SymbolRequirement(name = "vmlinux", description = "Linux Kernel")
|
|
]
|
|
|
|
@classmethod
|
|
def create_filter(cls, pid_list: List[int] = None) -> Callable[[int], bool]:
|
|
# FIXME: mypy #4973 or #2608
|
|
pid_list = pid_list or []
|
|
filter_list = [x for x in pid_list if x is not None]
|
|
if filter_list:
|
|
|
|
def filter_func(x):
|
|
return x not in filter_list
|
|
|
|
return filter_func
|
|
else:
|
|
return lambda _: False
|
|
|
|
def _generator(self):
|
|
for task in self.list_tasks(
|
|
self.context,
|
|
self.config['primary'],
|
|
self.config['vmlinux'],
|
|
filter = self.create_filter([self.config.get('pid', None)])):
|
|
pid = task.pid
|
|
ppid = 0
|
|
if task.parent:
|
|
ppid = task.parent.pid
|
|
name = utility.array_to_string(task.comm)
|
|
yield (0, (pid, ppid, name))
|
|
|
|
@classmethod
|
|
def list_tasks(cls,
|
|
context: interfaces.context.ContextInterface,
|
|
layer_name: str,
|
|
vmlinux_symbols: str,
|
|
filter: Callable[[int], bool] = lambda _: False) -> Iterable[interfaces.objects.ObjectInterface]:
|
|
"""Lists all the tasks in the primary layer"""
|
|
|
|
_, aslr_shift = linux.LinuxUtilities.find_aslr(context, vmlinux_symbols, layer_name)
|
|
vmlinux = context.module(vmlinux_symbols, layer_name, aslr_shift)
|
|
init_task = vmlinux.object(symbol_name = "init_task")
|
|
|
|
for task in init_task.tasks:
|
|
if not filter(task):
|
|
yield task
|
|
|
|
def run(self):
|
|
return renderers.TreeGrid([("PID", int), ("PPID", int), ("COMM", str)], self._generator())
|