Spaces:
Sleeping
Sleeping
Commit ·
812a13e
1
Parent(s): 00d3961
Clarify objdump options
Browse files
main.py
CHANGED
|
@@ -21,13 +21,13 @@ def trim(str, n):
|
|
| 21 |
def trim_objdump(str):
|
| 22 |
return trim(str, 7)
|
| 23 |
|
| 24 |
-
def disassemble_bytes(byte_data, architecture):
|
| 25 |
with tempfile.NamedTemporaryFile(suffix=".bin", delete=False) as temp_bin_file:
|
| 26 |
temp_bin_file.write(byte_data)
|
| 27 |
temp_bin_file_name = temp_bin_file.name
|
| 28 |
|
| 29 |
disassembly = subprocess.run(
|
| 30 |
-
["objdump", "-D", "-b", "binary", "-m", architecture, temp_bin_file_name],
|
| 31 |
capture_output=True,
|
| 32 |
text=True
|
| 33 |
).stdout
|
|
@@ -86,14 +86,10 @@ def compile(compiler, flags, source):
|
|
| 86 |
else:
|
| 87 |
return None, compile_output, disassembly
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
def predict(target_bytes, source, compiler, flags, architecture):
|
| 94 |
target_bytes = bytes.fromhex(target_bytes)
|
| 95 |
compiled_bytes, compile_output, compiled_disassembly = compile(compiler, flags, source)
|
| 96 |
-
target_disassembly = disassemble_bytes(target_bytes,
|
| 97 |
|
| 98 |
if compiled_bytes is not None:
|
| 99 |
return (
|
|
@@ -132,7 +128,8 @@ def run():
|
|
| 132 |
),
|
| 133 |
gr.Textbox(label="Compiler", value="g++"),
|
| 134 |
gr.Textbox(label="Compiler Flags", value="-O2"),
|
| 135 |
-
gr.Textbox(label="Architecture (
|
|
|
|
| 136 |
],
|
| 137 |
outputs=[
|
| 138 |
gr.Textbox(label="Compiled bytes"),
|
|
|
|
| 21 |
def trim_objdump(str):
|
| 22 |
return trim(str, 7)
|
| 23 |
|
| 24 |
+
def disassemble_bytes(byte_data, architecture, options):
|
| 25 |
with tempfile.NamedTemporaryFile(suffix=".bin", delete=False) as temp_bin_file:
|
| 26 |
temp_bin_file.write(byte_data)
|
| 27 |
temp_bin_file_name = temp_bin_file.name
|
| 28 |
|
| 29 |
disassembly = subprocess.run(
|
| 30 |
+
["objdump", "-D", "-b", "binary", "-m", architecture, "-M", options, temp_bin_file_name],
|
| 31 |
capture_output=True,
|
| 32 |
text=True
|
| 33 |
).stdout
|
|
|
|
| 86 |
else:
|
| 87 |
return None, compile_output, disassembly
|
| 88 |
|
| 89 |
+
def predict(target_bytes, source, compiler, flags, disasm_arch, disasm_options):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
target_bytes = bytes.fromhex(target_bytes)
|
| 91 |
compiled_bytes, compile_output, compiled_disassembly = compile(compiler, flags, source)
|
| 92 |
+
target_disassembly = disassemble_bytes(target_bytes, disasm_arch)
|
| 93 |
|
| 94 |
if compiled_bytes is not None:
|
| 95 |
return (
|
|
|
|
| 128 |
),
|
| 129 |
gr.Textbox(label="Compiler", value="g++"),
|
| 130 |
gr.Textbox(label="Compiler Flags", value="-O2"),
|
| 131 |
+
gr.Textbox(label="Architecture (objdump -m)", value="i386"),
|
| 132 |
+
gr.Textbox(label="Disassembler options (objdump -M)", value="x86-64")
|
| 133 |
],
|
| 134 |
outputs=[
|
| 135 |
gr.Textbox(label="Compiled bytes"),
|