Commit acb3f280 by lwilms

applied recommendations

parent 980bf603
...@@ -13,8 +13,6 @@ PDF_NAME = Path(MAIN_TEMPLATE).with_suffix('.pdf').name ...@@ -13,8 +13,6 @@ PDF_NAME = Path(MAIN_TEMPLATE).with_suffix('.pdf').name
def execute_latex(tmp_dir): def execute_latex(tmp_dir):
current_dir = os.getcwd() current_dir = os.getcwd()
os.chdir(tmp_dir) os.chdir(tmp_dir)
print(current_dir)
print(tmp_dir)
execute_shell_command('env buf_size=1000000 pdflatex {}'.format(MAIN_TEMPLATE)) execute_shell_command('env buf_size=1000000 pdflatex {}'.format(MAIN_TEMPLATE))
os.chdir(current_dir) os.chdir(current_dir)
......
...@@ -104,7 +104,7 @@ ...@@ -104,7 +104,7 @@
\begin{tikzpicture} \begin{tikzpicture}
\foreach [count=\i] \x/\y in {#1}{ \foreach [count=\i] \x/\y in {#1}{
\draw[fill=maingray,maingray] (0,\i) rectangle (6,\i+0.4); \draw[fill=maingray,maingray] (0,\i) rectangle (6,\i+0.4);
\draw[fill=white,mainblue](0,\i) rectangle (\y,\i+0.4); \draw[fill=white,mainblue](0,\i) rectangle (\y*6,\i+0.4);
\node [above right] at (0,\i+0.4) {\x}; \node [above right] at (0,\i+0.4) {\x};
} }
\end{tikzpicture} \end{tikzpicture}
......
...@@ -13,6 +13,27 @@ META_TEMPLATE = 'meta.tex' ...@@ -13,6 +13,27 @@ META_TEMPLATE = 'meta.tex'
CUSTOM_TEMPLATE_CLASS = 'twentysecondcv.cls' CUSTOM_TEMPLATE_CLASS = 'twentysecondcv.cls'
LOGO_FILE = 'fact.png' LOGO_FILE = 'fact.png'
LATEX_CHARACTER_ESCAPES = OrderedDict([
('\\', ''),
('\'', ''),
('$', '\\$'),
('(', '$($'),
(')', '$)$'),
('[', '$[$'),
(']', '$]$'),
('#', '\\#'),
('%', '\\%'),
('&', '\\&'),
('_', '\\_'),
('{', '\\{'),
('}', '\\}'),
('^', '\\textasciicircum{}'),
('~', '\\textasciitilde{}'),
('>', '\\textgreater{}'),
('<', '\\textless{}'),
('\n', '\\newline ')
])
def render_number_as_size(number, verbose=True): def render_number_as_size(number, verbose=True):
if not isinstance(number, (int, float)): if not isinstance(number, (int, float)):
...@@ -29,27 +50,7 @@ def render_unix_time(unix_time_stamp): ...@@ -29,27 +50,7 @@ def render_unix_time(unix_time_stamp):
def replace_special_characters(data): def replace_special_characters(data):
latex_character_escapes = OrderedDict() for character, replacement in LATEX_CHARACTER_ESCAPES.items():
latex_character_escapes['\\'] = ''
latex_character_escapes['\''] = ''
latex_character_escapes['$'] = '\\$'
latex_character_escapes['('] = '$($'
latex_character_escapes[')'] = '$)$'
latex_character_escapes['['] = '$[$'
latex_character_escapes[']'] = '$]$'
latex_character_escapes['#'] = '\\#'
latex_character_escapes['%'] = '\\%'
latex_character_escapes['&'] = '\\&'
latex_character_escapes['_'] = '\\_'
latex_character_escapes['{'] = '\\{'
latex_character_escapes['}'] = '\\}'
latex_character_escapes['^'] = '\\textasciicircum{}'
latex_character_escapes['~'] = '\\textasciitilde{}'
latex_character_escapes['>'] = '\\textgreater{}'
latex_character_escapes['<'] = '\\textless{}'
latex_character_escapes['\n'] = '\\newline '
for character, replacement in latex_character_escapes.items():
if character in data: if character in data:
data = data.replace(character, replacement) data = data.replace(character, replacement)
return data return data
...@@ -95,23 +96,22 @@ def get_five_longest_entries(summary, top=5): ...@@ -95,23 +96,22 @@ def get_five_longest_entries(summary, top=5):
def exploit_mitigation(summary): def exploit_mitigation(summary):
summary = summary['exploit_mitigations']['summary'] summary = summary['exploit_mitigations']['summary']
max_count = count_mitigations(summary) # bar is maxed at 6 max_count = count_mitigations(summary) # bar is maxed at 6
pie_num, canary_num, relro_num, nx_num, fortify_num = 0, 0, 0, 0, 0 numbers = dict()
for selected_summary in summary: for key in ['PIE', 'RELRO', 'Canary', 'NX', 'FORTIFY']:
if 'PIE' in selected_summary and 'present' in selected_summary: numbers[key] = count_occurrences(key, summary)
pie_num += len(summary[selected_summary]) return (
if 'RELRO' in selected_summary and 'enabled' in selected_summary: f'{{CANARY/{numbers["Canary"] / max_count}}},{{PIE/{numbers["PIE"] / max_count}}},'
relro_num += len(summary[selected_summary]) f'{{RELRO/{numbers["RELRO"] / max_count}}},{{NX/{numbers["NX"] / max_count}}},'
if 'Canary' in selected_summary and 'enabled' in selected_summary: f'{{FORTIFY\\_SOURCE/{numbers["FORTIFY"] / max_count}}}'
canary_num += len(summary[selected_summary]) )
if 'NX' in selected_summary and 'enabled' in selected_summary:
nx_num += len(summary[selected_summary])
if 'FORTIFY' in selected_summary and 'enabled' in selected_summary: def count_occurrences(key, summary):
fortify_num += len(summary[selected_summary]) return sum(
return '{0}{2}/{3}{1},{0}{4}/{5}{1},' \ len(summary[entry])
'{0}{6}/{7}{1},{0}{8}/{9}{1},' \ for entry in summary
'{0}{10}/{11}{1}'.format('{', '}', 'CANARY', canary_num * 6 / max_count, 'PIE', pie_num * 6 / max_count, if key in entry and ('present' in entry or 'enabled' in entry)
'RELRO', relro_num * 6 / max_count, 'NX', nx_num * 6 / max_count, )
'FORTIFY\_SOURCE', fortify_num * 6 / max_count)
def count_mitigations(summary): def count_mitigations(summary):
...@@ -134,20 +134,31 @@ def software_components(software_string): ...@@ -134,20 +134,31 @@ def software_components(software_string):
software = software_string software = software_string
ver_number = '' ver_number = ''
if ' ' in software_string: if ' ' in software_string:
if len(software_string.split(' ')) > 2: splitted_software_string = software_string.split(' ')
software = ''.join(software_string.split(' ')[:-1]) if len(splitted_software_string) > 2:
ver_number = software_string.split(' ')[-1] software, ver_number = larger_two_components(splitted_software_string)
elif len(splitted_software_string[1]) > 0:
software, ver_number = less_three_components(splitted_software_string)
return f'{ver_number}}}{{{software}'
def less_three_components(software_string):
software, ver_number = software_string
try: try:
int(ver_number[0]) int(ver_number[0])
except ValueError: except ValueError:
ver_number, software = software, ver_number return ver_number, software
elif isinstance(software_string.split(' '), list) and len(software_string.split(' ')[1]) > 0: return software, ver_number
software, ver_number = software_string.split(' ')
def larger_two_components(software_string):
software = ''.join(software_string[:-1])
ver_number = software_string[-1]
try: try:
int(ver_number[0]) int(ver_number[0])
except ValueError: except ValueError:
ver_number, software = software, ver_number return ver_number, software
return '{}{}{}{}'.format(ver_number, '}', '{', software) return software, ver_number
def get_triples(analysis): def get_triples(analysis):
...@@ -162,8 +173,7 @@ def get_desired_triple(seleced_summary, which_desired): ...@@ -162,8 +173,7 @@ def get_desired_triple(seleced_summary, which_desired):
chosen_one = 'x x' * 60 chosen_one = 'x x' * 60
while len(chosen_one) > 50: while len(chosen_one) > 50:
chosen_one = choice(desired_list) chosen_one = choice(desired_list)
return '{2}{1}{0}{3}{4}$\>$ (incl. {5})'.format('{', '}', len(desired_list), which_desired, '\quad', return f'{len(desired_list)}}}{{{which_desired}\\quad$\\>$ (incl. {replace_special_characters(chosen_one)})'
replace_special_characters(chosen_one))
def ip_or_uri(summary, which_select): def ip_or_uri(summary, which_select):
...@@ -190,7 +200,6 @@ def _validate_ip(ip, address_format): ...@@ -190,7 +200,6 @@ def _validate_ip(ip, address_format):
def get_x_entries(summary, how_many=10): def get_x_entries(summary, how_many=10):
if len(summary) <= how_many: if len(summary) <= how_many:
return summary return summary
else:
return summary[:how_many] return summary[:how_many]
......
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