这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions src/web_interface/static/js/show_analysis_preview.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const preview_loading_gif = document.getElementById("preview-loading-gif");
const preview_button = document.getElementById("preview_button");
const offset_input = document.getElementById("hex-preview-offset");
const hex_preview_len = document.getElementById("hex-preview-length");

function hide_gif(element) {
element.style.display = "none";
Expand Down Expand Up @@ -32,7 +33,7 @@ async function highlightCode(jqElement, lineNumbering = false, sizeLimit = 10485
}
}

function load_preview(offset = null, focus = false) {
function loadPreview(offset = null, focus = false) {
let resourcePath;
document.getElementById("preview_button").onclick = () => false;
if (focus && offset !== null) {
Expand All @@ -43,22 +44,42 @@ function load_preview(offset = null, focus = false) {
resourcePath = `/ajax_get_binary/${mimeType}/${uid}`;
} else {
// hex preview
offset_input.classList.remove("is-invalid");
if (!validateHexPreviewInputs()) return;
$("#preview-content").html("");
document.getElementById("hex-preview-form").style.display = "flex";
let offset = parseInt(offset_input.value);
if (isNaN(offset)) {
offset_input.classList.add("is-invalid");
return;
}
let length = document.getElementById("hex-preview-length").value;
resourcePath = `/ajax_get_hex_preview/${uid}/${offset}/${length}`;
}
preview_loading_gif.style.display = "block";
$("#preview-content").load(resourcePath, init_preview);
}

preview_button.onclick = load_preview;
function movePreviewOffset(back=false) {
if (!validateHexPreviewInputs()) return;
const length = parseInt(hex_preview_len.value);
let offset = parseInt(offset_input.value);
offset += back ? -length : length;
// do nothing if we are at the start/end already
if (offset < 0 || offset > fileSize) return;
const isInHex = offset_input.value.startsWith("0x");
offset_input.value = isInHex ? `0x${offset.toString( 16)}` : offset.toString();
loadPreview();
}

function validateHexPreviewInputs() {
let valid = true;
[hex_preview_len, offset_input].forEach(input => {
input.classList.remove("is-invalid");
if (isNaN(parseInt(input.value))) {
input.classList.add("is-invalid");
valid = false;
}
});
return valid;
}

preview_button.onclick = loadPreview;
let rawResultIsHighlighted = false;
const toggleSwitch = document.getElementById("rawResultSwitch");
const analysisTable = document.getElementById("analysis-table-body");
Expand Down
2 changes: 1 addition & 1 deletion src/web_interface/templates/show_analysis.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ <h3>
load_summary(uid, selected_analysis, focus=true);
} else if (preview !== false) {
// automatically load preview at address xyz if URL parameter "load_preview=xyz" is set
load_preview(preview, true);
loadPreview(preview, true);
}
});
</script>
Expand Down
16 changes: 13 additions & 3 deletions src/web_interface/templates/show_analysis/preview.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,29 @@
<div class="input-group-prepend">
<div class="input-group-text">Offset</div>
</div>
<input type="text" class="form-control" id="hex-preview-offset" value="0">
<input type="text" class="form-control" id="hex-preview-offset" value="0"
onkeydown="if(event.key === 'Enter') loadPreview();">
</div>
</div>
<div class="col-auto">
<div class="input-group input-group-sm mb-2">
<div class="input-group-prepend">
<div class="input-group-text">Length</div>
</div>
<input type="number" min="1" class="form-control" id="hex-preview-length" value="512">
<input type="number" min="1" class="form-control" id="hex-preview-length" value="512"
onkeydown="if(event.key === 'Enter') loadPreview();">
</div>
</div>
<div class="col-auto">
<button type="button" class="btn btn-primary btn-sm" onclick="load_preview();">Update</button>
<div class="btn-group btn-group-sm" role="group" aria-label="...">
<button type="button" class="btn btn-primary btn-sm" onclick="loadPreview();">Update</button>
<button type="button" class="btn btn-primary btn-sm" onclick="movePreviewOffset(true);">
<i class="fa-solid fa-circle-chevron-left"></i>
</button>
<button type="button" class="btn btn-primary btn-sm" onclick="movePreviewOffset(false);">
<i class="fa-solid fa-circle-chevron-right"></i>
</button>
</div>
</div>
</div>
<div id="preview-loading-gif" class="border" style="display: block; padding: 5px; text-align: center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@
waitForAnalysis(form.action, modalBody, formData);
});
});
const fileSize = {{ firmware.size }};
</script>