Skip to content

Commit

Permalink
made analysis tags clickable
Browse files Browse the repository at this point in the history
and link to the summary
  • Loading branch information
jstucke committed Oct 6, 2023
1 parent dd44693 commit 283d33d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
16 changes: 13 additions & 3 deletions src/test/integration/web_interface/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def test_list_group_collapse(frontend):
@pytest.mark.parametrize(
('tag_dict', 'output'),
[
({'a': 'danger'}, '<span class="badge badge-danger mr-2" style="font-size: 14px;" > a</span>'),
({'a': 'danger'}, '<span class="badge badge-danger mr-2" style="font-size: 14px;" > a</span>'),
(
{'a': 'danger', 'b': 'primary'},
'<span class="badge badge-danger mr-2" style="font-size: 14px;" > a</span>'
'<span class="badge badge-primary mr-2" style="font-size: 14px;" > b</span>',
'<span class="badge badge-danger mr-2" style="font-size: 14px;" > a</span>'
'<span class="badge badge-primary mr-2" style="font-size: 14px;" > b</span>',
),
(None, ''),
],
Expand All @@ -51,6 +51,16 @@ def test_render_analysis_tags_success(frontend):
assert '> wow<' in output


def test_render_analysis_tags_link(frontend):
plugin, uid, root_uid = 'plugin1', 'foo', 'bar'
tags = {plugin: {'tag': {'color': 'success', 'value': 'some_value'}}}
with frontend.app.app_context():
output = render_analysis_tags(tags, uid=uid, root_uid=root_uid)
assert 'onclick' in output
link = f'/analysis/{uid}/{plugin}/ro/{root_uid}?load_summary=true'
assert link in output


def test_render_analysis_tags_fix(frontend):
tags = {'such plugin': {'tag': {'color': 'very color', 'value': 'wow'}}}
with frontend.app.app_context():
Expand Down
5 changes: 4 additions & 1 deletion src/web_interface/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def render_fw_tags(tag_dict, size=14):
return output


def render_analysis_tags(tags, size=14):
def render_analysis_tags(tags, uid=None, root_uid=None, size=14):
output = ''
if tags:
for plugin_name in tags:
Expand All @@ -295,6 +295,9 @@ def render_analysis_tags(tags, size=14):
value=tag['value'],
tooltip=f'{plugin_name}: {key}',
size=size,
plugin=plugin_name,
root_uid=root_uid,
uid=uid,
)
return output

Expand Down
9 changes: 7 additions & 2 deletions src/web_interface/static/js/show_analysis_summary.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
function load_summary(uid, selected_analysis){
function load_summary(uid, selected_analysis, focus=false){
$("#summary-button").css("display", "none");
let summary_gif = $("#loading-summary-gif");
summary_gif.css("display", "block");
$("#summary-div").load(
`/ajax_get_summary/${uid}/${selected_analysis}`,
() => {summary_gif.css("display", "none");}
() => {
summary_gif.css("display", "none");
if (focus === true) {
location.href = "#summary-heading";
}
}
);
}
3 changes: 3 additions & 0 deletions src/web_interface/templates/generic_view/tags.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
data-toggle="tooltip"
title="{{ tooltip | replace_underscore }}"
{%- endif %}
{% if uid -%}
onclick="location.href='http://localhost:5000/analysis/{{ uid }}/{{ plugin }}/ro/{{ root_uid }}?load_summary=true'"
{%- endif %}
>
{{ value }}
</span>
15 changes: 12 additions & 3 deletions src/web_interface/templates/show_analysis.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<h3>
{{ firmware.uid | replace_uid_with_hid(root_uid=root_uid) | safe }}<br />
{% if firmware.analysis_tags or firmware.tags %}
{{ firmware.analysis_tags | render_analysis_tags | safe }}{{ firmware.tags | render_fw_tags | safe }}<br />
{{ firmware.analysis_tags | render_analysis_tags(uid, root_uid) | safe }}{{ firmware.tags | render_fw_tags | safe }}<br />
{% endif %}
<span style="font-size: 15px"><strong>UID:</strong> {{ uid | safe }}</span>
</h3>
Expand Down Expand Up @@ -316,7 +316,7 @@ <h5 class="modal-title">Add analysis to file</h5>
</div>
</div>
<script type="text/javascript" src="{{ url_for('static', filename='js/show_analysis_summary.js') }}"></script>

{%- endif -%}
</div>

Expand Down Expand Up @@ -358,7 +358,7 @@ <h5 class="modal-title">Add analysis to file</h5>
</div>

{%- set is_text_preview = firmware.processed_analysis["file_type"]["result"]['mime'][0:5] == "text/" or firmware.processed_analysis["file_type"]["result"]['mime'][0:6] == "image/" %}

<script>
const isTextOrImage = {{ 'true' if is_text_preview else 'false' }};
let mimeType = '{{ firmware.processed_analysis["file_type"]["result"]["mime"].replace("/", "_") }}';
Expand Down Expand Up @@ -446,6 +446,15 @@ <h5 class="modal-title">Add analysis to file</h5>
document.body.append(radare_form);
radare_form.submit();
}
document.addEventListener("DOMContentLoaded", function() {
// auto load summary if URL parameter "load_summary=true" is set
const urlParams = new URLSearchParams(window.location.search);
const summary = urlParams.get('load_summary');
const has_children = {{ "true" if firmware.files_included | length > 0 else "false" }};
if (summary === "true" && has_children && selected_analysis !== "None") {
load_summary(uid, selected_analysis, focus=true);
}
});
</script>

{% endblock %}
2 changes: 1 addition & 1 deletion src/web_interface/templates/summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</colgroup>
<thead class="thead-light">
<tr>
<th colspan=2>Summary for Included Files</th>
<th id="summary-heading" colspan=2>Summary for Included Files</th>
</tr>
</thead>
{% if summary_of_included_files %}
Expand Down

0 comments on commit 283d33d

Please sign in to comment.