Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fact_pdf_report
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-depend
fact_pdf_report
Commits
ffcc3aaa
Commit
ffcc3aaa
authored
Jul 06, 2019
by
dorp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed png path issue, added some filtering and also added debugging
parent
f84deb81
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
55 deletions
+58
-55
filter.py
src/jinja_filters/filter.py
+44
-45
code_generation.py
src/latex_code_generation/code_generation.py
+10
-6
binwalk.tex
src/templates/default/binwalk.tex
+2
-2
unpacker.tex
src/templates/default/unpacker.tex
+2
-2
No files found.
src/jinja_filters/filter.py
View file @
ffcc3aaa
from
base64
import
decodebytes
from
base64
import
decodebytes
from
pathlib
import
Path
from
time
import
localtime
,
strftime
from
time
import
localtime
,
strftime
from
common_helper_files
import
human_readable_file_size
from
common_helper_files
import
human_readable_file_size
...
@@ -36,42 +37,42 @@ def nice_number_filter(i):
...
@@ -36,42 +37,42 @@ def nice_number_filter(i):
def
filter_latex_special_chars
(
data
):
def
filter_latex_special_chars
(
data
):
if
"
\\
"
in
data
:
if
'
\\
'
in
data
:
data
=
data
.
replace
(
"
\\
"
,
""
)
data
=
data
.
replace
(
'
\\
'
,
''
)
if
"$"
in
data
:
if
'$'
in
data
:
data
=
data
.
replace
(
"$"
,
"
\\
$"
)
data
=
data
.
replace
(
'$'
,
'
\\
$'
)
if
"("
in
data
:
if
'('
in
data
:
data
=
data
.
replace
(
"("
,
"$($"
)
data
=
data
.
replace
(
'('
,
'$($'
)
if
")"
in
data
:
if
')'
in
data
:
data
=
data
.
replace
(
")"
,
"$)$"
)
data
=
data
.
replace
(
')'
,
'$)$'
)
if
"["
in
data
:
if
'['
in
data
:
data
=
data
.
replace
(
"["
,
"$[$"
)
data
=
data
.
replace
(
'['
,
'$[$'
)
if
"]"
in
data
:
if
']'
in
data
:
data
=
data
.
replace
(
"]"
,
"$]$"
)
data
=
data
.
replace
(
']'
,
'$]$'
)
if
"#"
in
data
:
if
'#'
in
data
:
data
=
data
.
replace
(
"#"
,
"
\\
#"
)
data
=
data
.
replace
(
'#'
,
'
\\
#'
)
if
"
%
"
in
data
:
if
'
%
'
in
data
:
data
=
data
.
replace
(
"
%
"
,
"
\\
%
"
)
data
=
data
.
replace
(
'
%
'
,
'
\\
%
'
)
if
"&"
in
data
:
if
'&'
in
data
:
data
=
data
.
replace
(
"&"
,
"
\\
&"
)
data
=
data
.
replace
(
'&'
,
'
\\
&'
)
if
"_"
in
data
:
if
'_'
in
data
:
data
=
data
.
replace
(
"_"
,
"
\\
_"
)
data
=
data
.
replace
(
'_'
,
'
\\
_'
)
if
"{"
in
data
:
if
'{'
in
data
:
data
=
data
.
replace
(
"{"
,
"
\\
{"
)
data
=
data
.
replace
(
'{'
,
'
\\
{'
)
if
"}"
in
data
:
if
'}'
in
data
:
data
=
data
.
replace
(
"}"
,
"
\\
}"
)
data
=
data
.
replace
(
'}'
,
'
\\
}'
)
if
"^"
in
data
:
if
'^'
in
data
:
data
=
data
.
replace
(
"^"
,
"
\\
textasciicircum{}"
)
data
=
data
.
replace
(
'^'
,
'
\\
textasciicircum{}'
)
if
"~"
in
data
:
if
'~'
in
data
:
data
=
data
.
replace
(
"~"
,
"
\\
textasciitilde{}"
)
data
=
data
.
replace
(
'~'
,
'
\\
textasciitilde{}'
)
if
">"
in
data
:
if
'>'
in
data
:
data
=
data
.
replace
(
">"
,
"
\\
textgreater{}"
)
data
=
data
.
replace
(
'>'
,
'
\\
textgreater{}'
)
if
"<"
in
data
:
if
'<'
in
data
:
data
=
data
.
replace
(
"<"
,
"
\\
textless{}"
)
data
=
data
.
replace
(
'<'
,
'
\\
textless{}'
)
if
"
\n
"
in
data
:
if
'
\n
'
in
data
:
data
=
data
.
replace
(
"
\n
"
,
"
\\
newline "
)
data
=
data
.
replace
(
'
\n
'
,
'
\\
newline '
)
if
"
\'
"
in
data
:
if
'
\'
'
in
data
:
data
=
data
.
replace
(
"
\'
"
,
""
)
data
=
data
.
replace
(
'
\'
'
,
''
)
return
data
return
data
...
@@ -79,13 +80,10 @@ def count_elements_in_list(ls):
...
@@ -79,13 +80,10 @@ def count_elements_in_list(ls):
return
len
(
ls
)
return
len
(
ls
)
def
convert_base64_to_png_filter
(
s
,
filename
):
def
convert_base64_to_png_filter
(
base64_string
,
filename
,
directory
):
base64_encoded
=
s
.
encode
(
'utf-8'
)
file_path
=
Path
(
directory
,
filename
+
'.png'
)
png_filename
=
filename
+
".png"
file_path
.
write_bytes
(
decodebytes
(
base64_string
.
encode
(
'utf-8'
)))
with
open
(
png_filename
,
"wb"
)
as
fh
:
return
str
(
file_path
)
fh
.
write
(
decodebytes
(
base64_encoded
))
return
png_filename
def
check_if_list_empty
(
ls
):
def
check_if_list_empty
(
ls
):
...
@@ -108,8 +106,8 @@ def split_output_lines(output_value):
...
@@ -108,8 +106,8 @@ def split_output_lines(output_value):
for
line
in
splited_lines
:
for
line
in
splited_lines
:
line_length
=
len
(
line
)
line_length
=
len
(
line
)
# word_lengths.append(list(map(len, line.split(
" "
))))
# word_lengths.append(list(map(len, line.split(
' '
))))
if
line_length
>
92
:
if
line_length
>
92
:
line
=
line
[:
92
]
+
' '
+
line
[
92
:]
line
=
line
[:
92
]
+
' '
+
line
[
92
:]
output
+=
line
+
"
\n
"
output
+=
line
+
'
\n
'
return
output
return
output
\ No newline at end of file
src/latex_code_generation/code_generation.py
View file @
ffcc3aaa
...
@@ -47,28 +47,31 @@ def _setup_jinja_filters(environment):
...
@@ -47,28 +47,31 @@ def _setup_jinja_filters(environment):
def
generate_meta_data_code
(
environment
,
meta_data
):
def
generate_meta_data_code
(
environment
,
meta_data
):
template
=
environment
.
get_template
(
'meta_data.tex'
)
template
=
environment
.
get_template
(
'meta_data.tex'
)
logging
.
debug
(
'Rendering meta data'
)
return
template
.
render
(
meta_data
=
meta_data
)
return
template
.
render
(
meta_data
=
meta_data
)
def
generate_main_code
(
firmware_analyses
,
firmware_meta_data
,
jinja_environment
):
def
generate_main_code
(
firmware_analyses
,
firmware_meta_data
,
jinja_environment
):
template
=
jinja_environment
.
get_template
(
'main.tex'
)
template
=
jinja_environment
.
get_template
(
'main.tex'
)
logging
.
debug
(
'Rendering main page'
)
return
template
.
render
(
analysis
=
firmware_analyses
,
meta_data
=
firmware_meta_data
)
return
template
.
render
(
analysis
=
firmware_analyses
,
meta_data
=
firmware_meta_data
)
def
generate_analysis_codes
(
environment
,
analysis
):
def
generate_analysis_codes
(
environment
,
analysis
,
tmp_dir
):
return
[
return
[
(
'{}.tex'
.
format
(
analysis_plugin
),
_render_analysis_result
(
analysis
[
analysis_plugin
],
environment
,
analysis_plugin
))
for
analysis_plugin
in
analysis
(
'{}.tex'
.
format
(
analysis_plugin
),
_render_analysis_result
(
analysis
[
analysis_plugin
],
environment
,
analysis_plugin
,
tmp_dir
))
for
analysis_plugin
in
analysis
]
]
def
_render_analysis_result
(
analysis
,
environment
,
analysis_plugin
):
def
_render_analysis_result
(
analysis
,
environment
,
analysis_plugin
,
tmp_dir
):
try
:
try
:
template
=
environment
.
get_template
(
'{}.tex'
.
format
(
analysis_plugin
))
template
=
environment
.
get_template
(
'{}.tex'
.
format
(
analysis_plugin
))
except
jinja2
.
TemplateNotFound
:
except
jinja2
.
TemplateNotFound
:
logging
.
debug
(
'Falling back on generic template for {}'
.
format
(
analysis_plugin
))
logging
.
debug
(
'Falling back on generic template for {}'
.
format
(
analysis_plugin
))
template
=
environment
.
get_template
(
GENERIC_TEMPLATE
)
template
=
environment
.
get_template
(
GENERIC_TEMPLATE
)
return
template
.
render
(
selected_analysis
=
analysis
)
logging
.
debug
(
'Rendering {}'
.
format
(
analysis_plugin
))
return
template
.
render
(
selected_analysis
=
analysis
,
tmp_dir
=
tmp_dir
)
def
_create_tex_files
(
analysis_dict
,
jinja_env
):
def
_create_tex_files
(
analysis_dict
,
jinja_env
):
...
@@ -94,7 +97,8 @@ def _copy_fact_image(target):
...
@@ -94,7 +97,8 @@ def _copy_fact_image(target):
def
execute_pdflatex
(
tmp_dir
):
def
execute_pdflatex
(
tmp_dir
):
current_dir
=
os
.
getcwd
()
current_dir
=
os
.
getcwd
()
os
.
chdir
(
tmp_dir
)
os
.
chdir
(
tmp_dir
)
output
,
return_code
=
execute_shell_command_get_return_code
(
'env buf_size=1000000 pdflatex main.tex'
)
logging
.
debug
(
'Creating pdf file'
)
_
,
_
=
execute_shell_command_get_return_code
(
'env buf_size=1000000 pdflatex main.tex'
)
os
.
chdir
(
current_dir
)
os
.
chdir
(
current_dir
)
...
@@ -109,7 +113,7 @@ def generate_pdf_report(firmware_uid="bab8d95fc42176abc9126393b6035e4012ebccc82c
...
@@ -109,7 +113,7 @@ def generate_pdf_report(firmware_uid="bab8d95fc42176abc9126393b6035e4012ebccc82c
with
TemporaryDirectory
()
as
tmp_dir
:
with
TemporaryDirectory
()
as
tmp_dir
:
Path
(
tmp_dir
,
'meta.tex'
)
.
write_text
(
generate_meta_data_code
(
environment
=
jinja_environment
,
meta_data
=
firmware_meta_data
))
Path
(
tmp_dir
,
'meta.tex'
)
.
write_text
(
generate_meta_data_code
(
environment
=
jinja_environment
,
meta_data
=
firmware_meta_data
))
for
filename
,
result_code
in
generate_analysis_codes
(
environment
=
jinja_environment
,
analysis
=
firmware_analyses
):
for
filename
,
result_code
in
generate_analysis_codes
(
environment
=
jinja_environment
,
analysis
=
firmware_analyses
,
tmp_dir
=
tmp_dir
):
Path
(
tmp_dir
,
filename
)
.
write_text
(
result_code
)
Path
(
tmp_dir
,
filename
)
.
write_text
(
result_code
)
Path
(
tmp_dir
,
'main.tex'
)
.
write_text
(
generate_main_code
(
firmware_analyses
,
firmware_meta_data
,
jinja_environment
))
Path
(
tmp_dir
,
'main.tex'
)
.
write_text
(
generate_main_code
(
firmware_analyses
,
firmware_meta_data
,
jinja_environment
))
...
...
src/templates/default/binwalk.tex
View file @
ffcc3aaa
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
Time of Analysis
&
\VAR
{
selected
_
analysis['analysis
_
date'] | nice
_
unix
_
time
}
\\
Time of Analysis
&
\VAR
{
selected
_
analysis['analysis
_
date'] | nice
_
unix
_
time
}
\\
\hline
\hline
Plugin Version
&
\VAR
{
selected
_
analysis['plugin
_
version']
}
\\
Plugin Version
&
\VAR
{
selected
_
analysis['plugin
_
version']
| filter
_
chars
}
\\
\hline
\hline
\multicolumn
{
2
}{
|p
{
14.5cm
}
|
}{
Signature Analysis:
}
\\
\multicolumn
{
2
}{
|p
{
14.5cm
}
|
}{
Signature Analysis:
}
\\
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
\multicolumn
{
2
}{
|p
{
14.5cm
}
|
}{
\VAR
{
selected
_
analysis['signature
_
analysis'] | filter
_
chars
}}
\\
\multicolumn
{
2
}{
|p
{
14.5cm
}
|
}{
\VAR
{
selected
_
analysis['signature
_
analysis'] | filter
_
chars
}}
\\
\hline
\hline
Entropy Graph
&
\includegraphics
[scale = 0.7]
{
\VAR
{
selected
_
analysis['entropy
_
analysis
_
graph'] | base64
_
to
_
png('entropy
_
analysis
_
graph')
}}
\\
Entropy Graph
&
\includegraphics
[scale = 0.7]
{
\VAR
{
selected
_
analysis['entropy
_
analysis
_
graph'] | base64
_
to
_
png('entropy
_
analysis
_
graph'
, tmp
_
dir
)
}}
\\
\hline
\hline
\BLOCK
{
if selected
_
analysis['summary']
}
\BLOCK
{
if selected
_
analysis['summary']
}
...
...
src/templates/default/unpacker.tex
View file @
ffcc3aaa
...
@@ -3,10 +3,10 @@
...
@@ -3,10 +3,10 @@
Time of Analysis
&
\VAR
{
selected
_
analysis['analysis
_
date'] | nice
_
unix
_
time
}
\\
Time of Analysis
&
\VAR
{
selected
_
analysis['analysis
_
date'] | nice
_
unix
_
time
}
\\
\hline
\hline
Plugin Version
&
\VAR
{
selected
_
analysis['plugin
_
version']
}
\\
Plugin Version
&
\VAR
{
selected
_
analysis['plugin
_
version']
| filter
_
chars
}
\\
\hline
\hline
Plugin
&
\VAR
{
selected
_
analysis['plugin
_
used']
}
\\
Plugin
&
\VAR
{
selected
_
analysis['plugin
_
used']
| filter
_
chars
}
\\
\hline
\hline
Extracted
&
\VAR
{
selected
_
analysis['number
_
of
_
unpacked
_
files']
}
\\
Extracted
&
\VAR
{
selected
_
analysis['number
_
of
_
unpacked
_
files']
}
\\
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment