Spaces:
Running
Running
Commit
·
9887ae8
1
Parent(s):
0ff1b21
Improve dup location var info
Browse files
main.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import subprocess
|
3 |
import tempfile
|
|
|
4 |
import os
|
5 |
import sys
|
6 |
import hashlib
|
@@ -163,18 +164,32 @@ with gr.Blocks() as demo:
|
|
163 |
if not os.path.exists(f"{TEMP_DIR}/funcs.json"):
|
164 |
raise gr.Error(f"DIRTY Ghidra failed to produce output: {o.stdout}")
|
165 |
|
166 |
-
|
|
|
|
|
|
|
167 |
|
168 |
if "exception" in json_info:
|
169 |
raise gr.Error(f"DIRTY Ghidra failed: {json_info['exception']}")
|
170 |
|
171 |
#print(json_info)
|
172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
return {
|
174 |
disassembly: gr.Textbox(value=json_info["disassembly"]),
|
175 |
original_decompile: gr.Textbox(value=json_info["original_decompile"]),
|
176 |
decompile: gr.Textbox(value=json_info["decompile"]),
|
177 |
-
model_output: gr.JSON(value=
|
178 |
}
|
179 |
|
180 |
# Need to put intro as output to get progress to work!
|
|
|
1 |
import gradio as gr
|
2 |
import subprocess
|
3 |
import tempfile
|
4 |
+
import itertools
|
5 |
import os
|
6 |
import sys
|
7 |
import hashlib
|
|
|
164 |
if not os.path.exists(f"{TEMP_DIR}/funcs.json"):
|
165 |
raise gr.Error(f"DIRTY Ghidra failed to produce output: {o.stdout}")
|
166 |
|
167 |
+
try:
|
168 |
+
json_info = json.load(open(f"{TEMP_DIR}/funcs.json"))
|
169 |
+
except Exception as e:
|
170 |
+
raise gr.Error(f"Unable to parse DIRTY Ghidra output: {e}\n{o.stdout}")
|
171 |
|
172 |
if "exception" in json_info:
|
173 |
raise gr.Error(f"DIRTY Ghidra failed: {json_info['exception']}")
|
174 |
|
175 |
#print(json_info)
|
176 |
|
177 |
+
# group by location
|
178 |
+
src_filtered = json_info['other_info']['source_filtered']
|
179 |
+
keyfunc = lambda x: x[1]
|
180 |
+
src_filtered = sorted(src_filtered.items(), key=keyfunc)
|
181 |
+
src_filtered = {k: [v1 for v1, v2 in v] for k, v in itertools.groupby(src_filtered, keyfunc)}
|
182 |
+
|
183 |
+
model_output_info = {
|
184 |
+
'model_output': json_info["model_output"],
|
185 |
+
'dup_location_vars': src_filtered
|
186 |
+
}
|
187 |
+
|
188 |
return {
|
189 |
disassembly: gr.Textbox(value=json_info["disassembly"]),
|
190 |
original_decompile: gr.Textbox(value=json_info["original_decompile"]),
|
191 |
decompile: gr.Textbox(value=json_info["decompile"]),
|
192 |
+
model_output: gr.JSON(value=json.dumps(model_output_info)),
|
193 |
}
|
194 |
|
195 |
# Need to put intro as output to get progress to work!
|