Spaces:
Running
Running
Commit
·
2654c7e
1
Parent(s):
3dd86e8
use clang to try parsing
Browse files- README.md +1 -1
- main.py +29 -7
- requirements.txt +1 -1
README.md
CHANGED
@@ -9,4 +9,4 @@ license: apache-2.0
|
|
9 |
---
|
10 |
|
11 |
This is a space that runs ReSym's Field Helper code in their own Docker
|
12 |
-
container.
|
|
|
9 |
---
|
10 |
|
11 |
This is a space that runs ReSym's Field Helper code in their own Docker
|
12 |
+
container. You probably should never use it directly.
|
main.py
CHANGED
@@ -1,8 +1,9 @@
|
|
1 |
-
import
|
2 |
import gradio as gr
|
3 |
import json
|
4 |
-
import os
|
5 |
import subprocess
|
|
|
|
|
6 |
|
7 |
def predict(decompiled_code):
|
8 |
|
@@ -14,10 +15,29 @@ def predict(decompiled_code):
|
|
14 |
with open(code_file_name, "w") as f:
|
15 |
f.write('#include "/home/ReSym/clang-parser/defs.hh"\n' + decompiled_code)
|
16 |
|
17 |
-
#
|
18 |
-
output = subprocess.run([
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
print(output)
|
20 |
-
assert output.returncode == 0
|
21 |
|
22 |
try:
|
23 |
field_data = open(field_file_name).read()
|
@@ -25,11 +45,13 @@ def predict(decompiled_code):
|
|
25 |
field_data = "[]"
|
26 |
return field_data
|
27 |
|
|
|
28 |
def run():
|
29 |
demo = gr.Interface(
|
30 |
fn=predict,
|
31 |
-
inputs=gr.
|
32 |
-
outputs=gr.JSON(),
|
|
|
33 |
)
|
34 |
|
35 |
demo.launch(server_name="0.0.0.0", server_port=7860, debug=True)
|
|
|
1 |
+
import frontmatter
|
2 |
import gradio as gr
|
3 |
import json
|
|
|
4 |
import subprocess
|
5 |
+
import tempfile
|
6 |
+
|
7 |
|
8 |
def predict(decompiled_code):
|
9 |
|
|
|
15 |
with open(code_file_name, "w") as f:
|
16 |
f.write('#include "/home/ReSym/clang-parser/defs.hh"\n' + decompiled_code)
|
17 |
|
18 |
+
# First use clang to see if parsing failed
|
19 |
+
output = subprocess.run([
|
20 |
+
"/usr/lib/llvm-12/bin/clang",
|
21 |
+
"-c",
|
22 |
+
code_file_name,
|
23 |
+
"-o",
|
24 |
+
"/dev/null"
|
25 |
+
],
|
26 |
+
text=True,
|
27 |
+
capture_output=True,
|
28 |
+
)
|
29 |
+
assert output.returncode == 0, f"Clang failed to parse: {output}"
|
30 |
+
|
31 |
+
output = subprocess.run(
|
32 |
+
[
|
33 |
+
"/home/ReSym/clang-parser/build/field_access",
|
34 |
+
code_file_name,
|
35 |
+
field_file_name,
|
36 |
+
],
|
37 |
+
text=True,
|
38 |
+
capture_output=True,
|
39 |
+
)
|
40 |
print(output)
|
|
|
41 |
|
42 |
try:
|
43 |
field_data = open(field_file_name).read()
|
|
|
45 |
field_data = "[]"
|
46 |
return field_data
|
47 |
|
48 |
+
|
49 |
def run():
|
50 |
demo = gr.Interface(
|
51 |
fn=predict,
|
52 |
+
inputs=gr.Textbox(label="Hex-Rays Decompilation", lines=10),
|
53 |
+
outputs=[gr.JSON(label="Field access"), gr.Textbox(label="Standard error")],
|
54 |
+
description=frontmatter.load("README.md").content,
|
55 |
)
|
56 |
|
57 |
demo.launch(server_name="0.0.0.0", server_port=7860, debug=True)
|
requirements.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
gradio
|
2 |
-
|
|
|
1 |
gradio
|
2 |
+
python-frontmatter
|