Commit d17c8508 by amateyna

tmp

parent a8623c58
import jinja2 import jinja2
import logging
from pathlib import Path from pathlib import Path
def generate_code(analysis_dict, output_path): def generate_code(analysis_dict, output_path):
jinja_env = _set_jinja_env() jinja_env = _set_jinja_env()
_render_template(analysis_dict, jinja_env, 'meta_data')
def _create_tex_files(analysis_dict, jinja_env):
module_list = list(analysis_dict['analysis'].keys())
module_list.append('meta_data')
for module in module_list:
try:
_render_template(analysis_dict, jinja_env, module)
except Exception as e:
logging.error('Could not generate tex file: {} -> {}'.format(type(Exception), e))
def _set_jinja_env(templates_to_use='default'): def _set_jinja_env(templates_to_use='default'):
......
\begin{tabular}{|p{3cm}|p{11.5cm}|}
\hline
Time of Analysis & \VAR{selected_analysis['analysis_date'] | nice_unix_time}\\
\hline
Plugin Version & \VAR{selected_analysis['plugin_version']}\\
\hline
imphash & \VAR{selected_analysis['imphash']}\\
\hline
md5 & \VAR{selected_analysis['md5']}\\
\hline
ripemd160 & \VAR{selected_analysis['ripemd160']}\\
\hline
sha1 & \VAR{selected_analysis['sha1']}\\
\hline
sha256 & \VAR{selected_analysis['sha256']}\\
\hline
sha512 & \VAR{selected_analysis['sha512'] | split_hash}\\
\hline
ssdeep & \VAR{selected_analysis['ssdeep'] | split_hash}\\
\hline
whirpool & \VAR{selected_analysis['whirlpool'] | split_hash}\\
\hline
\end{tabular}
\begin{tabular}{|p{3cm}|p{11.5cm}|}
\hline
HID & \VAR{meta_data['hid']}\\
\hline
Device Name & \VAR{meta_data['device_name']}\\
\hline
Vendor & \VAR{meta_data['vendor']}\\
\hline
Device Class & \VAR{meta_data['device_class']}\\
\hline
Version & \VAR{meta_data['version']}\\
\hline
Release Date & \VAR{meta_data['release_date']}\\
\hline
Size & \VAR{meta_data['size'] | number_format}\\
\hline
\end{tabular}
\ No newline at end of file
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory
from pathlib import Path from pathlib import Path
from latex_code_generation.code_generation import _set_jinja_env, _render_template, _write_file from latex_code_generation.code_generation import _set_jinja_env, _render_template, _write_file, _create_tex_files
def test_render_template(): def test_render_template():
...@@ -15,3 +15,13 @@ def test_write_file(): ...@@ -15,3 +15,13 @@ def test_write_file():
file_path = Path(tmp_dir.name, 'test.tex') file_path = Path(tmp_dir.name, 'test.tex')
_write_file('test', file_path) _write_file('test', file_path)
assert file_path.exists() assert file_path.exists()
def test_create_tex_files():
test_data = {'analysis': {'file_hashes': {'ssdeep': 'bla', 'sha1': 'blah'}, 'meta_data': dict()}}
tmp_dir = TemporaryDirectory()
jinja_env = _set_jinja_env(templates_to_use='default')
for template_name in test_data['analysis']:
_create_tex_files(test_data, jinja_env)
file_path = Path(tmp_dir.name, template_name + '.tex')
assert file_path.exists()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment