Skip to content

Commit

Permalink
adding xlsx rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
gleeda committed Dec 29, 2014
1 parent cc07fb7 commit c4a9a73
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
4 changes: 4 additions & 0 deletions volatility/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from volatility.renderers.html import HTMLRenderer, JSONRenderer
from volatility.renderers.sqlite import SqliteRenderer
from volatility.renderers.text import TextRenderer, FormatCellRenderer, QuickTextRenderer
from volatility.renderers.xlsx import XLSXRenderer


class Command(object):
Expand Down Expand Up @@ -287,3 +288,6 @@ def render_dot(self, outfd, data):

def render_html(self, outfd, data):
self._render(outfd, HTMLRenderer(), data)

def render_xlsx(self, outfd, data):
self._render(outfd, XLSXRenderer(self.text_cell_renderers, self._config), data)
49 changes: 49 additions & 0 deletions volatility/renderers/xlsx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from volatility import debug
from volatility.renderers.basic import Renderer

__author__ = "gleeda"

try:
from openpyxl.workbook import Workbook
from openpyxl.writer.excel import ExcelWriter
from openpyxl.cell import get_column_letter
from openpyxl.styles import Color, Fill, Style, PatternFill, Border, Side, Alignment, Protection, Font
from openpyxl.cell import Cell
from openpyxl import load_workbook
has_openpyxl = True
except ImportError:
has_openpyxl = False

class XLSXRenderer(Renderer):
def __init__(self, renderers_func, config):
if not has_openpyxl:
debug.error("You must install OpenPyxl for xlsx format:\n\thttps://bitbucket.org/ericgazoni/openpyxl/wiki/Home")
self._config = config
self._columns = None
self._text_cell_renderers_func = renderers_func
self._text_cell_renderers = None
self._wb = Workbook(optimized_write = True)
self._ws = self._wb.create_sheet()

def description(self):
output = []
for column in self._columns:
output.append((column.name))
return output

def _add_row(self, node, data):
accumulator = data
accumulator[node] = max(accumulator.values()) + 1
self._ws.append(list(node.values))
return accumulator

def render(self, outfd, grid):
"""Renders the TreeGrid in data out to the output file from the config options"""
if not self._config.OUTPUT_FILE:
debug.error("Please specify a valid output file using --output-file")
self._columns = grid.columns
self._text_cell_renderers = self._text_cell_renderers_func(self._columns)
self._ws.append(self.description())
grid.visit(None, self._add_row, {None: 0})

self._wb.save(filename = self._config.OUTPUT_FILE)

0 comments on commit c4a9a73

Please sign in to comment.