This file is indexed.

/usr/lib/python2.7/dist-packages/rekall/plugins/renderers/xls.py is in python-rekall-core 1.6.0+dfsg-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# Rekall Memory Forensics
# Copyright 2014 Google Inc. All Rights Reserved.
#
# Authors:
# Michael Cohen <scudette@google.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#

"""This file implements an xls renderer based on the openpyxl project.

We produce xls (Excel spreadsheet files) with the output from Rekall plugins.
"""
import time
import openpyxl

from openpyxl import styles
from openpyxl.styles import colors
from openpyxl.styles import fills

from rekall import utils
from rekall.ui import renderer
from rekall.ui import text

# pylint: disable=unexpected-keyword-arg,no-value-for-parameter
# pylint: disable=redefined-outer-name

HEADER_STYLE = styles.Style(font=styles.Font(bold=True))
SECTION_STYLE = styles.Style(
    fill=styles.PatternFill(
        fill_type=fills.FILL_SOLID, start_color=styles.Color(colors.RED)))
FORMAT_STYLE = styles.Style(
    alignment=styles.Alignment(vertical="top", wrap_text=False))


class XLSObjectRenderer(renderer.ObjectRenderer):
    """By default the XLS renderer delegates to the text renderer."""
    renders_type = "object"
    renderers = ["XLSRenderer"]

    STYLE = None

    def _GetDelegateObjectRenderer(self, item):
        return self.ForTarget(item, "TextRenderer")(
            session=self.session, renderer=self.renderer.delegate_text_renderer)

    def RenderHeader(self, worksheet, column):
        cell = worksheet.cell(
            row=worksheet.current_row, column=worksheet.current_column)

        cell.value = column.name
        cell.style = HEADER_STYLE

        # Advance the pointer by 1 cell.
        worksheet.current_column += 1

    def RenderCell(self, value, worksheet, **options):
        # By default just render a single value into the current cell.
        cell = worksheet.cell(
            row=worksheet.current_row, column=worksheet.current_column)
        cell.value = self.GetData(value, **options)
        if self.STYLE:
            cell.style = self.STYLE

        # Advance the pointer by 1 cell.
        worksheet.current_column += 1

    def GetData(self, value, **options):
        if isinstance(value, (int, float, long)):
            return value

        return unicode(self._GetDelegateObjectRenderer(value).render_row(
            value, **options))


class XLSColumn(text.TextColumn):

    def __init__(self, type=None, table=None, renderer=None, session=None,
                 **options):
        super(XLSColumn, self).__init__(table=table, renderer=renderer,
                                        session=session, **options)

        if type:
            self.object_renderer = self.renderer.get_object_renderer(
                type=type, target_renderer="XLSRenderer", **options)


class XLSTable(text.TextTable):
    column_class = XLSColumn

    def render_header(self):
        current_ws = self.renderer.current_ws
        for column in self.columns:
            if column.object_renderer:
                object_renderer = column.object_renderer
            else:
                object_renderer = XLSObjectRenderer(
                    session=self.session, renderer=self.renderer)

            object_renderer.RenderHeader(self.renderer.current_ws, column)

        current_ws.current_row += 1
        current_ws.current_column = 1

    def render_row(self, row=None, highlight=None, **options):
        merged_opts = self.options.copy()
        merged_opts.update(options)

        # Get each column to write its own header.
        current_ws = self.renderer.current_ws
        for item in row:
            # Get the object renderer for the item.
            object_renderer = self.renderer.get_object_renderer(
                target=item, type=merged_opts.get("type"), **merged_opts)

            object_renderer.RenderCell(item, current_ws, **options)

        current_ws.current_row += 1
        current_ws.current_column = 1


class XLSRenderer(renderer.BaseRenderer):
    """A Renderer for xls files."""

    name = "xls"

    table_class = XLSTable
    tablesep = ""

    def __init__(self, output=None, **kwargs):
        super(XLSRenderer, self).__init__(**kwargs)

        # Make a single delegate text renderer for reuse. Most of the time we
        # will just replicate the output from the TextRenderer inside the
        # spreadsheet cell.
        self.delegate_text_renderer = text.TextRenderer(session=self.session)

        self.output = output or self.session.GetParameter("output")

        # If no output filename was give, just make a name based on the time
        # stamp.
        if self.output == None:
            self.output = "%s.xls" % time.ctime()

        try:
            self.wb = openpyxl.load_workbook(self.output)
            self.current_ws = self.wb.create_sheet()
        except IOError:
            self.wb = openpyxl.Workbook()
            self.current_ws = self.wb.active

    def start(self, plugin_name=None, kwargs=None):
        super(XLSRenderer, self).start(plugin_name=plugin_name, kwargs=kwargs)

        # Make a new worksheet for this run.
        if self.current_ws is None:
            self.current_ws = self.wb.create_sheet()

        ws = self.current_ws
        ws.title = plugin_name or ""
        ws.current_row = 1
        ws.current_column = 1

        return self

    def flush(self):
        super(XLSRenderer, self).flush()
        self.current_ws = None
        # Write the spreadsheet to a file.
        self.wb.save(self.output)

    def section(self, name=None, **_):
        ws = self.current_ws
        for i in range(10):
            cell = ws.cell(row=ws.current_row, column=i + 1)
            if i == 0:
                cell.value = name

            cell.style = SECTION_STYLE

        ws.current_row += 1
        ws.current_column = 1

    def format(self, formatstring, *data):
        worksheet = self.current_ws
        if "%" in formatstring:
            data = formatstring % data
        else:
            data = formatstring.format(*data)

        cell = worksheet.cell(
            row=worksheet.current_row, column=worksheet.current_column)
        cell.value = data
        cell.style = FORMAT_STYLE

        worksheet.current_column += 1
        if "\n" in data:
            worksheet.current_row += 1
            worksheet.current_column = 1

    def table_header(self, *args, **options):
        super(XLSRenderer, self).table_header(*args, **options)

        self.table.render_header()


# Following here are object specific renderers.


class XLSEProcessRenderer(XLSObjectRenderer):
    """Expands an EPROCESS into three columns (address, name and PID)."""
    renders_type = "_EPROCESS"

    def RenderHeader(self, worksheet, column):
        for heading in ["_EPROCESS", "Name", "PID"]:
            cell = worksheet.cell(
                row=worksheet.current_row, column=worksheet.current_column)
            cell.value = heading
            cell.style = HEADER_STYLE

            worksheet.current_column += 1

    def RenderCell(self, item, worksheet, **options):
        for value in ["%#x" % item.obj_offset, item.name, item.pid]:
            object_renderer = self.ForTarget(value, self.renderer)(
                session=self.session, renderer=self.renderer, **options)
            object_renderer.RenderCell(value, worksheet, **options)


class XLSStringRenderer(XLSObjectRenderer):
    renders_type = "String"

    def GetData(self, item, **_):
        return utils.SmartStr(item)


class XLSStructRenderer(XLSObjectRenderer):
    """Hex format struct's offsets."""
    renders_type = "Struct"

    def GetData(self, item, **_):
        return "%#x" % item.obj_offset


class XLSPointerRenderer(XLSObjectRenderer):
    """Renders the address of the pointer target as a hex string."""
    renders_type = "Pointer"

    def GetData(self, item, **_):
        result = item.v()
        if result == None:
            return "-"

        return "%#x" % result


class XLSNativeTypeRenderer(XLSObjectRenderer):
    """Renders native types as python objects."""
    renders_type = "NativeType"

    def GetData(self, item, **options):
        result = item.v()
        if result != None:
            return result


class XLS_UNICODE_STRING_Renderer(XLSNativeTypeRenderer):
    renders_type = "_UNICODE_STRING"


class XLSNoneObjectRenderer(XLSObjectRenderer):
    renders_type = "NoneObject"

    def GetData(self, item, **_):
        _ = item
        return "-"


class XLSDateTimeRenderer(XLSObjectRenderer):
    """Renders timestamps as python datetime objects."""
    renders_type = "UnixTimeStamp"
    STYLE = styles.Style(number_format='MM/DD/YYYY HH:MM:SS')

    def GetData(self, item, **options):
        if item.v() == 0:
            return None

        return item.as_datetime()