Spaces:
Sleeping
Sleeping
Commit
·
94a508d
1
Parent(s):
2901d44
update
Browse files- main.py +18 -5
- requirements.txt +1 -0
main.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
from hexdump2 import hexdump
|
2 |
import gradio as gr
|
3 |
import shlex
|
@@ -51,10 +52,14 @@ def compile(compiler, flags, source):
|
|
51 |
return compiled_bytes
|
52 |
|
53 |
|
54 |
-
def predict(
|
55 |
-
|
56 |
compiled_bytes = compile(compiler, flags, source)
|
57 |
-
return
|
|
|
|
|
|
|
|
|
58 |
|
59 |
|
60 |
def run():
|
@@ -62,8 +67,16 @@ def run():
|
|
62 |
fn=predict,
|
63 |
description=description,
|
64 |
inputs=[
|
65 |
-
gr.Textbox(
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
gr.Textbox(label="Compiler", value="g++"),
|
68 |
gr.Textbox(label="Compiler Flags", value="-O2"),
|
69 |
],
|
|
|
1 |
+
import editdistance
|
2 |
from hexdump2 import hexdump
|
3 |
import gradio as gr
|
4 |
import shlex
|
|
|
52 |
return compiled_bytes
|
53 |
|
54 |
|
55 |
+
def predict(target_bytes, source, compiler, flags):
|
56 |
+
target_bytes = bytes.fromhex(target_bytes)
|
57 |
compiled_bytes = compile(compiler, flags, source)
|
58 |
+
return (
|
59 |
+
hexdump(compiled_bytes, result="return"),
|
60 |
+
hexdump(target_bytes, result="return"),
|
61 |
+
editdistance.eval(compiled_bytes, target_bytes) / max(len(compiled_bytes), len(target_bytes))
|
62 |
+
)
|
63 |
|
64 |
|
65 |
def run():
|
|
|
67 |
fn=predict,
|
68 |
description=description,
|
69 |
inputs=[
|
70 |
+
gr.Textbox(
|
71 |
+
lines=10,
|
72 |
+
label="Bytes of Target Function (in hex)",
|
73 |
+
value="b8 2a 00 00 00 c3",
|
74 |
+
),
|
75 |
+
gr.Textbox(
|
76 |
+
lines=10,
|
77 |
+
label="Decompiled C Source Code",
|
78 |
+
value="int foo() { return 42; }",
|
79 |
+
),
|
80 |
gr.Textbox(label="Compiler", value="g++"),
|
81 |
gr.Textbox(label="Compiler Flags", value="-O2"),
|
82 |
],
|
requirements.txt
CHANGED
@@ -1,2 +1,3 @@
|
|
|
|
1 |
gradio
|
2 |
hexdump2
|
|
|
1 |
+
editdistance
|
2 |
gradio
|
3 |
hexdump2
|