File size: 1,802 Bytes
2654c7e
66f8fc1
f925c49
d469baf
2654c7e
 
66f8fc1
d469baf
 
 
 
f2561b7
e55b49e
d469baf
 
5cd1f1d
d469baf
888e607
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2654c7e
 
 
 
 
 
 
 
 
 
8053a4f
d469baf
3dd86e8
 
 
 
9038b35
66f8fc1
2654c7e
329f9c0
 
 
2654c7e
 
 
329f9c0
66f8fc1
30f4df6
329f9c0
 
 
651ebc2
329f9c0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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()