Cultxre's picture
Disable api info generation
d4d3e11 verified
Raw History Blame Contribute Delete
2.6 kB
import os, sys, json, tempfile
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent))
import multi_agent as ma
import gradio as gr
MODES = ["binary", "web", "apk", "ipa"]
def run_analysis(file, url, mode):
target = url.strip() if (mode == "web" and url.strip()) else (file.name if file else None)
if not target:
return "Please upload a file or enter a URL.", None, None, ""
try:
orch = ma.Orchestrator(mode=mode, rebuild=False)
fr = orch.run(target)
except Exception as e:
import traceback; return f"Error: {e}\n{traceback.format_exc()}", None, None, ""
tmp = Path(tempfile.mkdtemp())
(tmp / "report.md").write_text(fr.report)
(tmp / "report.json").write_text(json.dumps(orch.to_dict(fr), indent=2, default=str))
agents = ", ".join(fr.agents_run)
return fr.report, str(tmp / "report.md"), str(tmp / "report.json"), f"Agents run: {agents}"
def rebuild(file, url, mode):
target = url.strip() if (mode == "web" and url.strip()) else (file.name if file else None)
if not target:
return None, "No target."
try:
orch = ma.Orchestrator(mode=mode, rebuild=True)
fr = orch.run(target)
except Exception as e:
import traceback; return None, f"Error: {e}\n{traceback.format_exc()}"
return fr.rebuild_path, f"Rebuild scaffold: {fr.rebuild_path}"
with gr.Blocks(title="Multi-Agent Reverse Engineering") as demo:
gr.Markdown("# Multi-Agent Reverse Engineering System\nSpecialist agents (Binary, Web, Mobile, Firmware, Malware, Reconstructor, Reporter) collaborate.")
with gr.Row():
mode = gr.Radio(MODES, value="binary", label="Mode")
with gr.Row():
file = gr.File(label="Upload file (binary/apk/ipa)")
url = gr.Textbox(label="Or URL (web mode)", placeholder="https://example.com")
with gr.Row():
analyze_btn = gr.Button("Run Analysis", variant="primary")
rebuild_btn = gr.Button("Rebuild from scratch")
agents_info = gr.Textbox(label="Agents", lines=1)
report = gr.Textbox(label="Report", lines=30, max_lines=60)
with gr.Row():
md_file = gr.File(label="report.md")
json_file = gr.File(label="report.json")
rebuild_file = gr.File(label="rebuilt.zip")
rebuild_status = gr.Textbox(label="Rebuild status")
analyze_btn.click(run_analysis, [file, url, mode], [report, md_file, json_file, agents_info])
rebuild_btn.click(rebuild, [file, url, mode], [rebuild_file, rebuild_status])
if __name__ == "__main__":
demo.launch(server_name="0.0.0.0", server_port=7860, show_api=False)