1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 """This module implements renderers specific to windows structures."""
20
21 from rekall.ui import text
22 from rekall.ui import json_renderer
23 from rekall.plugins.renderers import data_export
24 from rekall_lib import utils
25
26
28 renders_type = "_EPROCESS"
29
31 result = super(EPROCESSDataExport, self).EncodeToJsonSafe(task)
32 process_params = task.Peb.ProcessParameters
33 result["Cybox"] = dict(
34 type=u"ProcessObj:ProcessObjectType",
35 Name=task.name,
36 PID=task.pid,
37 Creation_Time=task.CreateTime,
38 Parent_PID=task.InheritedFromUniqueProcessId,
39 Image_Info=dict(
40 type=u"ProcessObj:ImageInfoType",
41 Path=process_params.ImagePathName,
42 Command_Line=process_params.CommandLine,
43 TrustedPath=task.FullPath,
44 File_Name=task.SeAuditProcessCreationInfo.ImageFileName.Name,
45 )
46 )
47
48 res = json_renderer.JsonObjectRenderer.EncodeToJsonSafe(self, result)
49 return res
50
52 return "%s (%s)" % (item.get("Cybox", {}).get("Name", ""),
53 item.get("Cybox", {}).get("PID", ""))
54
55
56 -class UNICODE_STRING_Text(text.TextObjectRenderer):
57 renders_type = "_UNICODE_STRING"
58 renderers = ["TextRenderer", "TestRenderer", "WideTextRenderer"]
59
60 - def render_compact(self, target, width=None, **_):
61 return text.Cell(unicode(target), width=width)
62
63
64 -class SID_Text(UNICODE_STRING_Text):
66
67
73
74
76 renders_type = "String"
77
79 return utils.SmartStr(item)
80
81
82 -class EPROCESS_TextObjectRenderer(text.TextObjectRenderer):
83 renders_type = "_EPROCESS"
84 renderers = ["TextRenderer", "TestRenderer"]
85
86 - def __init__(self, *args, **options):
87 """We make a sub table for rendering the _EPROCESS."""
88 self.name = options.pop("name", "_EPROCESS")
89
90 super(EPROCESS_TextObjectRenderer, self).__init__(*args, **options)
91
92
93 self.output_style = options.pop("style", self.output_style)
94
95 if self.output_style == "full":
96 self.table = text.TextTable(
97 columns=[
98 dict(name=self.name,
99 formatstring="[addrpad]"),
100 dict(name="name", width=20),
101 dict(name="fullpath", width=60),
102 dict(name="pid", width=5, align="r"),
103 dict(name="ppid", width=5, align="r")],
104 renderer=self.renderer,
105 session=self.session)
106 else:
107 self.table = text.TextTable(
108 columns=[
109 dict(name=self.name,
110 formatstring="[addrpad]"),
111 dict(name="name", width=20),
112 dict(name="pid", width=5, align="r")],
113 renderer=self.renderer,
114 session=self.session)
115
117 if self.output_style in ["full", "concise"]:
118 return self.table.render_header()
119 else:
120 result = text.Cell(self.name, width=40)
121 result.append_line("-" * result.width)
122
123 return result
124
125 - def render_row(self, target, **options):
126 if self.output_style == "full":
127 return self.table.get_row(
128 target.obj_offset, target.name, target.FullPath, target.pid,
129 target.InheritedFromUniqueProcessId)
130 elif self.output_style == "concise":
131 return self.table.get_row(target.obj_offset, target.name,
132 target.pid)
133 else:
134 return text.Cell(u"%s %s (%d)" % (
135 self.format_address(target.obj_offset),
136 target.name, target.pid))
137
138
139 -class EPROCESS_WideTextObjectRenderer(EPROCESS_TextObjectRenderer):
140 renders_type = "_EPROCESS"
141 renderers = ["WideTextRenderer"]
142
143 - def render_row(self, target, **_):
144 return text.Cell(
145 self.formatter.format(u"{0:s} Pid: {1:s} (@{2:#x})",
146 target.name, target.pid, target))
147
148
149 -class MMVAD_FLAGS_TextRenderer(text.TextObjectRenderer):
150 renders_type = ("_MMVAD_FLAGS", "_MMVAD_FLAGS2", "_MMSECTION_FLAGS")
151 renderers = ["TextRenderer", "TestRenderer"]
152
153 - def render_compact(self, target, **_):
154 result = []
155 for name in sorted(target.members):
156 if name.endswith("Enum"):
157 continue
158
159 try:
160 attribute = getattr(target, name)
161 if attribute.v():
162 result.append(u"%s: %s" % (name, attribute))
163 except AttributeError:
164 pass
165
166 return text.Cell(", ".join(result))
167