Spaces:
Sleeping
Sleeping
Commit
·
5a649d5
1
Parent(s):
247cd31
update
Browse files
main.py
CHANGED
@@ -27,12 +27,12 @@ def compile(compiler, flags, source):
|
|
27 |
temp_o_file_name = temp_o_file.name
|
28 |
|
29 |
# Compile the C file to an object file
|
30 |
-
subprocess.run(
|
31 |
-
[compiler, "-c", temp_c_file_name]
|
32 |
-
|
33 |
-
|
34 |
-
check=True,
|
35 |
)
|
|
|
36 |
|
37 |
# Create a temporary file for the raw bytes
|
38 |
with tempfile.NamedTemporaryFile(suffix=".raw", delete=True) as raw_bytes_file:
|
@@ -48,18 +48,19 @@ def compile(compiler, flags, source):
|
|
48 |
]
|
49 |
)
|
50 |
compiled_bytes = raw_bytes_file.read()
|
51 |
-
print(compiled_bytes)
|
52 |
|
53 |
-
|
|
|
54 |
|
55 |
|
56 |
def predict(target_bytes, source, compiler, flags):
|
57 |
target_bytes = bytes.fromhex(target_bytes)
|
58 |
-
compiled_bytes = compile(compiler, flags, source)
|
59 |
return (
|
60 |
hexdump(compiled_bytes, result="return"),
|
61 |
hexdump(target_bytes, result="return"),
|
62 |
-
editdistance.eval(compiled_bytes, target_bytes)
|
|
|
63 |
)
|
64 |
|
65 |
|
@@ -85,6 +86,7 @@ def run():
|
|
85 |
gr.Textbox(label="Compiled bytes"),
|
86 |
gr.Textbox(label="Target bytes"),
|
87 |
gr.Number(label="Edit distance (lower is better)"),
|
|
|
88 |
],
|
89 |
)
|
90 |
|
|
|
27 |
temp_o_file_name = temp_o_file.name
|
28 |
|
29 |
# Compile the C file to an object file
|
30 |
+
result = subprocess.run(
|
31 |
+
[compiler, "-c", temp_c_file_name] + shlex.split(flags) + ["-o", temp_o_file_name],
|
32 |
+
capture_output=True,
|
33 |
+
text=True
|
|
|
34 |
)
|
35 |
+
compile_output = result.stdout + result.stderr
|
36 |
|
37 |
# Create a temporary file for the raw bytes
|
38 |
with tempfile.NamedTemporaryFile(suffix=".raw", delete=True) as raw_bytes_file:
|
|
|
48 |
]
|
49 |
)
|
50 |
compiled_bytes = raw_bytes_file.read()
|
|
|
51 |
|
52 |
+
print(compiled_bytes)
|
53 |
+
return compiled_bytes, compile_output
|
54 |
|
55 |
|
56 |
def predict(target_bytes, source, compiler, flags):
|
57 |
target_bytes = bytes.fromhex(target_bytes)
|
58 |
+
compiled_bytes, compile_output = compile(compiler, flags, source)
|
59 |
return (
|
60 |
hexdump(compiled_bytes, result="return"),
|
61 |
hexdump(target_bytes, result="return"),
|
62 |
+
editdistance.eval(compiled_bytes, target_bytes),
|
63 |
+
compile_output
|
64 |
)
|
65 |
|
66 |
|
|
|
86 |
gr.Textbox(label="Compiled bytes"),
|
87 |
gr.Textbox(label="Target bytes"),
|
88 |
gr.Number(label="Edit distance (lower is better)"),
|
89 |
+
gr.Textbox(label="Compiler Output"),
|
90 |
],
|
91 |
)
|
92 |
|