Commit ·
ef71e62
1
Parent(s): 117a3e4
extra args
Browse files
main.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import logging
|
| 3 |
import os
|
|
|
|
| 4 |
import tempfile
|
| 5 |
import subprocess
|
| 6 |
import pyghidra
|
|
@@ -20,39 +21,8 @@ def get_functions(file):
|
|
| 20 |
program = flat_api.getCurrentProgram()
|
| 21 |
function_addrs = [(f.getName(), f.getEntryPoint().getOffset()) for f in program.getFunctionManager().getFunctions(True)]
|
| 22 |
|
| 23 |
-
# o = subprocess.run(["/code/GhidraFunctionCPPExporter/export.bash", file, "output_dir", TEMP_DIR], shell=False, capture_output=True, encoding="utf8")
|
| 24 |
-
|
| 25 |
-
# print(o.stdout)
|
| 26 |
-
# print(o.stderr)
|
| 27 |
-
|
| 28 |
-
# if (o.returncode != 0):
|
| 29 |
-
# raise Exception(f"Ghidra export failed with return code {o.returncode}: {o.stderr}")
|
| 30 |
-
|
| 31 |
-
# # Show files in TEMP_DIR
|
| 32 |
-
# print("Files in TEMP_DIR:")
|
| 33 |
-
# for f in os.listdir(TEMP_DIR):
|
| 34 |
-
# print(f)
|
| 35 |
-
|
| 36 |
return function_addrs
|
| 37 |
|
| 38 |
-
|
| 39 |
-
# def decomp_create_prompt(input_data: str) -> str:
|
| 40 |
-
# before = "# This is the decompiled code:\n"
|
| 41 |
-
# after = "\n# What is the source code?\n"
|
| 42 |
-
# prompt = before + input_data.strip() + after
|
| 43 |
-
|
| 44 |
-
# return prompt
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
# pipe = pipeline(model="ejschwartz/decaf-v1-22b-4bit", return_full_text=False)
|
| 48 |
-
# pipe.model.to("cuda")
|
| 49 |
-
|
| 50 |
-
# def generate(text):
|
| 51 |
-
# print(f"Generating text... {text}")
|
| 52 |
-
# prompt = decomp_create_prompt(text)
|
| 53 |
-
# return pipe(prompt, max_new_tokens=2000)[0]['generated_text']
|
| 54 |
-
|
| 55 |
-
|
| 56 |
with gr.Blocks() as demo:
|
| 57 |
|
| 58 |
state = gr.State()
|
|
@@ -85,6 +55,8 @@ This is a space to experiment with GhidraFunctionCPPExporter, a Ghidra scripts t
|
|
| 85 |
"""
|
| 86 |
)
|
| 87 |
|
|
|
|
|
|
|
| 88 |
with gr.Row(visible=True) as result:
|
| 89 |
disassembly = gr.Code(
|
| 90 |
label="Disassembly", lines=20,
|
|
@@ -135,8 +107,8 @@ This is a space to experiment with GhidraFunctionCPPExporter, a Ghidra scripts t
|
|
| 135 |
"addrs": addrs},
|
| 136 |
}
|
| 137 |
|
| 138 |
-
@fun_dropdown.change(inputs=[fun_dropdown, state], outputs=[disassembly, original_decompile])
|
| 139 |
-
def function_change_fn(selected_fun, state, progress=gr.Progress()):
|
| 140 |
|
| 141 |
with tempfile.TemporaryDirectory() as TEMP_DIR:
|
| 142 |
|
|
@@ -151,7 +123,7 @@ This is a space to experiment with GhidraFunctionCPPExporter, a Ghidra scripts t
|
|
| 151 |
disassembly_str = "\n".join([i.toString() for i in listing.getInstructions(func.getBody(), True)])
|
| 152 |
|
| 153 |
|
| 154 |
-
o = subprocess.run(["/code/GhidraFunctionCPPExporter/export.bash", state['file'], "base_name", "file", "address_set_str", hex(selected_fun), "output_dir", TEMP_DIR], shell=False, capture_output=True, encoding="utf8")
|
| 155 |
|
| 156 |
print(o.stdout)
|
| 157 |
print(o.stderr)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import logging
|
| 3 |
import os
|
| 4 |
+
import shlex
|
| 5 |
import tempfile
|
| 6 |
import subprocess
|
| 7 |
import pyghidra
|
|
|
|
| 21 |
program = flat_api.getCurrentProgram()
|
| 22 |
function_addrs = [(f.getName(), f.getEntryPoint().getOffset()) for f in program.getFunctionManager().getFunctions(True)]
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
return function_addrs
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
with gr.Blocks() as demo:
|
| 27 |
|
| 28 |
state = gr.State()
|
|
|
|
| 55 |
"""
|
| 56 |
)
|
| 57 |
|
| 58 |
+
extra_args = gr.Textbox(label="Extra args to export.bash", placeholder="emit_type_definitions false", value="")
|
| 59 |
+
|
| 60 |
with gr.Row(visible=True) as result:
|
| 61 |
disassembly = gr.Code(
|
| 62 |
label="Disassembly", lines=20,
|
|
|
|
| 107 |
"addrs": addrs},
|
| 108 |
}
|
| 109 |
|
| 110 |
+
@fun_dropdown.change(inputs=[fun_dropdown, state, extra_args], outputs=[disassembly, original_decompile])
|
| 111 |
+
def function_change_fn(selected_fun, state, extra_args, progress=gr.Progress()):
|
| 112 |
|
| 113 |
with tempfile.TemporaryDirectory() as TEMP_DIR:
|
| 114 |
|
|
|
|
| 123 |
disassembly_str = "\n".join([i.toString() for i in listing.getInstructions(func.getBody(), True)])
|
| 124 |
|
| 125 |
|
| 126 |
+
o = subprocess.run(["/code/GhidraFunctionCPPExporter/export.bash", state['file'], "base_name", "file", "address_set_str", hex(selected_fun), "output_dir", TEMP_DIR] + shlex.split(extra_args), shell=False, capture_output=True, encoding="utf8")
|
| 127 |
|
| 128 |
print(o.stdout)
|
| 129 |
print(o.stderr)
|