1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """pstree example file"""
24
25 from rekall.plugins.windows import common
26
27
28 -class PSTree(common.WinProcessFilter):
29 """Print process list as a tree"""
30
31 __name = "pstree"
32
33 table_header = [
34 dict(name="_EPROCESS", type="TreeNode", max_depth=5, child=dict(
35 type="_EPROCESS", style="light")),
36 dict(name="ppid", width=6, align="r"),
37 dict(name="thd_count", width=6, align="r"),
38 dict(name="hnd_count", width=6, align="r"),
39 dict(name="create_time", width=24),
40 dict(name="cmd", width=40, hidden=True),
41 dict(name="path", width=40, hidden=True),
42 dict(name="audit", width=40, hidden=True),
43 ]
44
46
47 seen = set()
48
49 while pid in pid_dict and pid not in seen:
50 seen.add(pid)
51 pid = int(pid_dict[pid].InheritedFromUniqueProcessId)
52
53 return pid
54
62
64 process_dict = self._make_process_dict()
65
66 def draw_children(pad, pid):
67 """Given a pid output all its children."""
68 for task in sorted(process_dict.values(), key=lambda x: x.pid):
69 if task.InheritedFromUniqueProcessId != pid:
70 continue
71
72 process_params = task.Peb.ProcessParameters
73
74 yield dict(
75 _EPROCESS=task,
76 ppid=task.InheritedFromUniqueProcessId,
77 thd_count=task.ActiveThreads,
78 hnd_count=task.ObjectTable.m("HandleCount"),
79 create_time=task.CreateTime,
80 cmd=process_params.CommandLine,
81 path=process_params.ImagePathName,
82 audit=task.SeAuditProcessCreationInfo.ImageFileName.Name,
83 depth=pad)
84
85 process_dict.pop(task.pid, None)
86 for x in draw_children(pad + 1, task.pid):
87 yield x
88
89 while process_dict:
90 keys = process_dict.keys()
91 root = self._find_root(process_dict, keys[0])
92 for x in draw_children(0, root):
93 yield x
94