Spaces:
Running
Running
import frontmatter | |
import gradio as gr | |
import os | |
import subprocess | |
import tempfile | |
def predict(decompiled_code): | |
with tempfile.TemporaryDirectory() as temp_dir: | |
code_file_name = os.path.join(temp_dir, "code.c") | |
field_file_name = os.path.join(temp_dir, "code.json") | |
with open(code_file_name, "w") as f: | |
f.write('#include "/home/ReSym/clang-parser/defs.hh"\n' + decompiled_code) | |
# # First use clang to see if parsing failed | |
# output = subprocess.run([ | |
# "/usr/lib/llvm-12/bin/clang", | |
# "-std=gnu17", | |
# "-c", | |
# code_file_name, | |
# "-o", | |
# "/dev/null" | |
# ], | |
# text=True, | |
# capture_output=True, | |
# ) | |
# print(f"clang output: {output}") | |
# print(output.stderr) | |
# assert output.returncode == 0, f"Clang failed to parse: {output}" | |
output = subprocess.run( | |
[ | |
"/home/ReSym/clang-parser/build/field_access", | |
code_file_name, | |
field_file_name, | |
], | |
text=True, | |
capture_output=True, | |
) | |
print(f"field access output: {output}") | |
try: | |
field_data = open(field_file_name).read() | |
except FileNotFoundError: | |
field_data = "[]" | |
return field_data, output.stderr | |
def run(): | |
demo = gr.Interface( | |
fn=predict, | |
inputs=gr.Textbox(label="Hex-Rays Decompilation", lines=10), | |
outputs=[gr.JSON(label="Field access"), gr.Textbox(label="Standard error")], | |
description=frontmatter.load("README.md").content, | |
) | |
demo.launch(server_name="0.0.0.0", server_port=7860, debug=True) | |
if __name__ == "__main__": | |
print("Starting!") | |
run() | |