blob: 05ce466ec9d201c57e9c77ea91aaf94ee4d86fb3 (
plain)
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
|
import sys
import py_nand_ass.disas as dass # pyright: ignore[reportImplicitRelativeImport]
def main():
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} [filename]")
sys.exit(1)
filename = sys.argv[1]
try:
with open(filename, "rb") as f:
while True:
insb = f.read(2)
if not insb:
break
ins = int.from_bytes(insb, byteorder=ENDIANNESS)
if ENDIANNESS in ["big", "be"]:
raw_ins = f"{insb[0]:02x} {insb[1]:02x}"
elif ENDIANNESS in ["little", "le"]:
raw_ins = f"{insb[1]:02x} {insb[0]:02x}"
else:
raw_ins = f"?? ??"
decoded_ins = dass.print_decoded(ins, False)
decoded_ins2 = dass.print_decoded(ins, True)
if decoded_ins == decoded_ins2:
line = f"\t{raw_ins}\t{decoded_ins}"
else:
line = f"\t{raw_ins}\t{decoded_ins2:<25}; {decoded_ins}"
print(line)
except FileNotFoundError:
print(f"File {filename} not found.")
sys.exit(1)
# head, tail...
except BrokenPipeError:
sys.exit(0)
if __name__ == "__main__":
main()
|