Frontend is now working
This commit is contained in:
@@ -110,17 +110,13 @@ def analyze_image_resize(input_img: Path, output_dir: Path) -> None:
|
|||||||
# 1. Setup Paths
|
# 1. Setup Paths
|
||||||
input_img = Path(input_img)
|
input_img = Path(input_img)
|
||||||
output_dir = Path(output_dir)
|
output_dir = Path(output_dir)
|
||||||
extracted_dir = output_dir / "image_resize_output_dir"
|
|
||||||
|
|
||||||
# 2. CREATE THE DIRECTORY (Crucial Step!)
|
|
||||||
extracted_dir.mkdir(parents=True, exist_ok=True)
|
|
||||||
|
|
||||||
# 3. Initialize Logs
|
# 3. Initialize Logs
|
||||||
logs = []
|
logs = []
|
||||||
recovered_image = None
|
recovered_image = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(input_img, "rb") as image:
|
with input_img.open("rb") as image:
|
||||||
f = image.read()
|
f = image.read()
|
||||||
|
|
||||||
b = bytearray(f)
|
b = bytearray(f)
|
||||||
@@ -130,8 +126,6 @@ def analyze_image_resize(input_img: Path, output_dir: Path) -> None:
|
|||||||
if IHDR == -1:
|
if IHDR == -1:
|
||||||
logs.append("Failure: PNG header (IHDR) not found.")
|
logs.append("Failure: PNG header (IHDR) not found.")
|
||||||
update_data(output_dir, {"image_resize": {"status": "error", "error": "PNG header not found."}})
|
update_data(output_dir, {"image_resize": {"status": "error", "error": "PNG header not found."}})
|
||||||
if extracted_dir.exists():
|
|
||||||
shutil.rmtree(extracted_dir, ignore_errors=True)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Calculate Chunk Length (The 4 bytes BEFORE IHDR tag)
|
# Calculate Chunk Length (The 4 bytes BEFORE IHDR tag)
|
||||||
@@ -161,8 +155,11 @@ def analyze_image_resize(input_img: Path, output_dir: Path) -> None:
|
|||||||
logs.append(f"Success: Match found! Dimensions: {width}x{height}")
|
logs.append(f"Success: Match found! Dimensions: {width}x{height}")
|
||||||
|
|
||||||
# Create Output Filename
|
# Create Output Filename
|
||||||
output_filename = f"recovered_{width}x{height}.png"
|
img_name = f"recovered_{width}x{height}.png"
|
||||||
output_path = extracted_dir / output_filename
|
|
||||||
|
# Create parent directories if they don't exist
|
||||||
|
output_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
output_path = output_dir / img_name
|
||||||
|
|
||||||
# Splicing: [Start...IHDR+4] + [W] + [H] + [IHDR+12...End]
|
# Splicing: [Start...IHDR+4] + [W] + [H] + [IHDR+12...End]
|
||||||
full_png_data = b[:IHDR+4] + width_bytes + height_bytes + b[IHDR+12:]
|
full_png_data = b[:IHDR+4] + width_bytes + height_bytes + b[IHDR+12:]
|
||||||
@@ -171,7 +168,7 @@ def analyze_image_resize(input_img: Path, output_dir: Path) -> None:
|
|||||||
with output_path.open("wb") as out_f:
|
with output_path.open("wb") as out_f:
|
||||||
out_f.write(full_png_data)
|
out_f.write(full_png_data)
|
||||||
|
|
||||||
recovered_image = output_filename
|
recovered_image = Path(output_dir.name) / img_name
|
||||||
break # Stop looking after finding the match
|
break # Stop looking after finding the match
|
||||||
|
|
||||||
if not match_found:
|
if not match_found:
|
||||||
@@ -181,15 +178,13 @@ def analyze_image_resize(input_img: Path, output_dir: Path) -> None:
|
|||||||
output_data = {
|
output_data = {
|
||||||
"image_resize": { # Key name must match your module name in AperiSolve
|
"image_resize": { # Key name must match your module name in AperiSolve
|
||||||
"status": "ok",
|
"status": "ok",
|
||||||
"output": logs,
|
"output": logs
|
||||||
"images": recovered_image, # Tells frontend to display the image
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if recovered_image:
|
||||||
|
output_data["image_resize"]["image"] = "/image/" + str(recovered_image)
|
||||||
update_data(output_dir, output_data)
|
update_data(output_dir, output_data)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
update_data(output_dir, {"image_resize": {"status": "error", "error": str(e)}})
|
update_data(output_dir, {"image_resize": {"status": "error", "error": str(e)}})
|
||||||
if extracted_dir.exists():
|
|
||||||
shutil.rmtree(extracted_dir, ignore_errors=True)
|
|
||||||
|
|
||||||
return None
|
return None
|
||||||
@@ -8,6 +8,7 @@ const TOOL_ORDER = [
|
|||||||
"steghide",
|
"steghide",
|
||||||
"zsteg",
|
"zsteg",
|
||||||
"strings",
|
"strings",
|
||||||
|
"image_resize",
|
||||||
];
|
];
|
||||||
|
|
||||||
function escapeHtml(text) {
|
function escapeHtml(text) {
|
||||||
@@ -248,7 +249,7 @@ function parseResult(result) {
|
|||||||
analyzer.className = `analyzer a-${escapeHtml(tool)}`;
|
analyzer.className = `analyzer a-${escapeHtml(tool)}`;
|
||||||
resultDiv.appendChild(analyzer);
|
resultDiv.appendChild(analyzer);
|
||||||
|
|
||||||
analyzer.innerHTML += `<h2>${capitalize(tool)}</h2>`;
|
analyzer.innerHTML += `<h2>${capitalize(tool.replace("_"," "))}</h2>`;
|
||||||
|
|
||||||
if (result[tool]["status"] === "ok") {
|
if (result[tool]["status"] === "ok") {
|
||||||
if ("images" in result[tool]) {
|
if ("images" in result[tool]) {
|
||||||
@@ -270,7 +271,16 @@ function parseResult(result) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ("image" in result[tool]) {
|
||||||
|
// Parse image output
|
||||||
|
analyzer.innerHTML += `<div class='results_img'><img src='${escapeHtml(
|
||||||
|
result[tool]["image"]
|
||||||
|
)}'/></div>`;
|
||||||
|
}
|
||||||
|
|
||||||
// Parse text output
|
// Parse text output
|
||||||
|
|
||||||
|
|
||||||
if (typeof result[tool]["output"] === "string") {
|
if (typeof result[tool]["output"] === "string") {
|
||||||
analyzer.innerHTML += `<pre>${escapeHtml(
|
analyzer.innerHTML += `<pre>${escapeHtml(
|
||||||
|
|||||||
Reference in New Issue
Block a user