Spaces:
Runtime error
Runtime error
Edward J. Schwartz
commited on
Commit
·
25d463a
1
Parent(s):
3a4dec2
Modify script for bat-ana and bat-dis
Browse files- Dockerfile +0 -2
- app.py +40 -1
Dockerfile
CHANGED
|
@@ -29,6 +29,4 @@ WORKDIR $HOME/app
|
|
| 29 |
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
| 30 |
COPY --chown=user . $HOME/app
|
| 31 |
|
| 32 |
-
RUN wget https://huggingface.co/datasets/ejschwartz/oo-method-test/raw/main/scripts/gen-training.py -O gen_training.py
|
| 33 |
-
|
| 34 |
CMD ["python3", "app.py"]
|
|
|
|
| 29 |
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
| 30 |
COPY --chown=user . $HOME/app
|
| 31 |
|
|
|
|
|
|
|
| 32 |
CMD ["python3", "app.py"]
|
app.py
CHANGED
|
@@ -15,8 +15,47 @@ model = gr.load("ejschwartz/oo-method-test-model-bylibrary", src="models")
|
|
| 15 |
|
| 16 |
import gen_training
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
def get_funs(f):
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
demo = gr.Interface(fn=get_funs, inputs="file", outputs="textarea")
|
| 22 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 15 |
|
| 16 |
import gen_training
|
| 17 |
|
| 18 |
+
from tempfile import NamedTemporaryFile
|
| 19 |
+
anafile = NamedTemporaryFile(prefix=os.path.basename(bname) + "_", suffix=".bat_ana")
|
| 20 |
+
ananame = anafile.name
|
| 21 |
+
|
| 22 |
+
def get_all_dis(addrs=None):
|
| 23 |
+
|
| 24 |
+
addrstr = ""
|
| 25 |
+
if addrs is not None:
|
| 26 |
+
addrstr = " ".join([f"--function-at {x}" for x in addrs])
|
| 27 |
+
|
| 28 |
+
subprocess.check_output(f"bat-ana {addrstr} --no-post-analysis -o {ananame} {bname} 2>/dev/null", shell=True)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
output = subprocess.check_output(f"bat-dis --no-insn-address --no-bb-cfg-arrows --color=off {ananame} 2>/dev/null", shell=True)
|
| 32 |
+
output = re.sub(b' +', b' ', output)
|
| 33 |
+
|
| 34 |
+
func_dis = {}
|
| 35 |
+
last_func = None
|
| 36 |
+
current_output = []
|
| 37 |
+
|
| 38 |
+
for l in output.splitlines():
|
| 39 |
+
if l.startswith(b";;; function 0x"):
|
| 40 |
+
if last_func is not None:
|
| 41 |
+
func_dis[last_func] = b"\n".join(current_output)
|
| 42 |
+
last_func = int(l.split()[2], 16)
|
| 43 |
+
current_output.clear()
|
| 44 |
+
|
| 45 |
+
if not b";;" in l:
|
| 46 |
+
current_output.append(l)
|
| 47 |
+
|
| 48 |
+
if last_func is not None:
|
| 49 |
+
if last_func in func_dis:
|
| 50 |
+
print("Warning: Ignoring multiple functions at the same address")
|
| 51 |
+
else:
|
| 52 |
+
func_dis[last_func] = b"\n".join(current_output)
|
| 53 |
+
|
| 54 |
+
return func_dis
|
| 55 |
+
|
| 56 |
def get_funs(f):
|
| 57 |
+
funs = get_all_dis()
|
| 58 |
+
returns str(funs)
|
| 59 |
|
| 60 |
demo = gr.Interface(fn=get_funs, inputs="file", outputs="textarea")
|
| 61 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|