Created
October 29, 2023 19:16
-
-
Save msm-code/28694c5563958f883a80b663963643d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
import re | |
data = open(sys.argv[1], "rb").read() | |
offset = sys.argv[2] | |
if len(sys.argv) > 3: | |
lines = int(sys.argv[3]) | |
else: | |
lines = 10 | |
symbols_raw = open("symbols.txt", "r").read().splitlines() | |
symbols = {s.split()[2]: s.split()[0] for s in symbols_raw if s.split()[0].lstrip("0")} | |
if not offset.isdigit(): | |
offset = symbols[offset] | |
offset = int(offset, 8) | |
def disasm_at(data: bytes, offset: int) -> str: | |
data = b"\x00"*offset + data[offset:] | |
data_with_junk = disasm(data) | |
if not offset: | |
return data_with_junk | |
return data_with_junk[data_with_junk.find("\n;\n")+3:] | |
def disasm(data: bytes) -> str: | |
open("/tmp/welp", "wb").write(data) | |
os.system("./test/pdp11dasm/pdp11dasm /tmp/welp") | |
data_with_hdr = open("/tmp/welp.das", "r").read() | |
return data_with_hdr[data_with_hdr.find("\n;\n")+3:] | |
out = disasm_at(data, offset) | |
out1 = "" | |
for i, l in zip(range(lines), out.splitlines()): | |
out1 += l + "\n" | |
out = out1 | |
for symname, symvalue in symbols.items(): | |
# if not symvalue: | |
# continue | |
out = re.sub(rf"\b{symvalue.lstrip('0')}\b", symname, out) | |
out = re.sub(r"\br7\b", "pc", out) | |
out = re.sub(r"\br6\b", "sp", out) | |
out1 = "" | |
for l in out.splitlines(): | |
for symname, symvalue in symbols.items(): | |
if l.startswith(symvalue): | |
out1 += symname + ":\n" | |
out1 += l + "\n" | |
out = out1 | |
print(out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment