Spaces:
Running
Running
import gradio as gr | |
import shutil | |
import subprocess | |
import tempfile | |
import os | |
import sys | |
def new_binary(file): | |
with tempfile.TemporaryDirectory() as TEMP_DIR, tempfile.TemporaryDirectory() as OUTPUT_DIR: | |
shutil.copy2(file.name, TEMP_DIR) | |
# python3 generate.py --ghidra PATH_TO_GHIDRA_ANALYZEHEADLESS -t NUM_THREADS -n [NUM_FILES|None] -b BINARIES_DIR -o OUTPUT_DIR | |
print("Running DIRTY-Ghidra...", file=sys.stderr) | |
output = subprocess.check_output(f"python /DIRTY/dataset-gen-ghidra/generate.py --ghidra /ghidra/support/analyzeHeadless -t 1 -b {TEMP_DIR} -o {OUTPUT_DIR} 2>&1", shell=True) | |
print(output, file=sys.stderr) | |
with gr.Blocks() as demo: | |
all_dis_state = gr.State() | |
gr.Markdown( | |
""" | |
# DIRTY-Ghidra Testing | |
First, upload a binary. | |
""" | |
) | |
file_widget = gr.File(label="Binary file") | |
def file_change_fn(file, progress=gr.Progress()): | |
if file is None: | |
return { | |
#col: gr.update(visible=False), | |
all_dis_state: None} | |
else: | |
#fun_data = {42: 2, 43: 3} | |
print("hi") | |
new_binary(file) | |
progress(0, desc="Decompiling binary...") | |
#fun_data = get_all_dis(file.name) | |
#addrs = ["%#x" % addr for addr in fun_data.keys()] | |
return { | |
#col: gr.update(visible=True), | |
#fun_dropdown: gr.Dropdown.update(choices=addrs, value=addrs[0]), | |
#all_dis_state: fun_data | |
} | |
file_widget.change(file_change_fn, file_widget) | |
# spaces only shows stderr.. | |
os.dup2(sys.stdout.fileno(), sys.stderr.fileno()) | |
demo.queue() | |
demo.launch(server_name="0.0.0.0", server_port=7860) | |