Skip to content
Snippets Groups Projects
Commit e4bf8be8 authored by aticu's avatar aticu
Browse files

Add a python helper for exploit development

parent a3e7d6d6
Branches
No related tags found
No related merge requests found
#!/usr/bin/env python3
import os
import sys
import subprocess
arch_prefix = "riscv64-unknown-elf-"
march = "rv32i"
reverse_bytes = True
try:
path = os.environ["RV_BIN_PATH"]
except:
print("ERROR:")
print("You need to set the RV_BIN_PATH environment variable to the path of the risc-v binutils")
exit()
assembler = path + "/" + arch_prefix + "as"
objdump = path + "/" + arch_prefix + "objdump"
subprocess.run([assembler, sys.argv[1], "-march=" + march])
objdump_result = subprocess.run([objdump, "-D", "a.out"], capture_output=True)
text_start = False
for line in objdump_result.stdout.decode("utf-8").splitlines():
if not text_start:
if line == "00000000 <.text>:":
text_start = True
elif line == "":
break
else:
components = line.split()
offset = components[0]
hexval = [components[1][0:2], components[1][2:4], components[1][4:6], components[1][6:8]]
if reverse_bytes:
hexval.reverse()
instruction = " ".join(components[2:])
print(' "\\x%s\\x%s\\x%s\\x%s" // %s %s' % (hexval[0], hexval[1], hexval[2], hexval[3], offset, instruction))
subprocess.run(["rm", "a.out"])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment