-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
86 lines (66 loc) · 2.14 KB
/
test.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import sys
import loader
import extract
import memory
import dasm
import dasm_objects
def basic_test(address):
prog = extract.extract("smb.nes")
mem = memory.Memory()
mem.map_prog_rom(prog)
del prog
for _ in range(0, 50):
instruction = dasm.disassemble_instruction(mem, address)
assert instruction.address == address
address += instruction.size
print("0x{addr:04X}: {asm}".format(
addr=instruction.address,
asm=instruction.assembly_string))
def disassemble_program(program):
dasm.disassemble_program(program)
return program
def test_print(prog):
chunk = prog.chunks[0]
# print("\nBasic print:")
# chunk.print_instructions()
print("\nPrint with symbols resolved:")
chunk.print_instructions(prog.symbols, prog.config)
print("\nExit points:")
for address, target in chunk.exit_points:
if type(target) is str:
print("0x{:04X} --> {}".format(address, target))
else:
print("0x{:04X} --> 0x{:04X}".format(address, target))
def parse_args(args):
address = None
label = None
if len(args) == 1:
label = "RESET"
else:
label = args[1]
try:
address = int(args[1], base=0)
except ValueError:
pass
return address, label
if __name__ == "__main__":
address, label = parse_args(sys.argv)
# basic_test(address)
p = loader.load("smb.nes", "smb.config")
disassemble_program(p)
# test_print(p)
# Find the chunk at the given address or label.
# Try address first, as that's harder.
c = p.get_chunk_starting(address)
if not c:
c = p.get_chunk_starting(label)
# If still not found, look for a chunk containing the given address or
# label. Try address first, as that's harder.
if not c:
c = p.get_chunk_containing(address)
if not c:
c = p.get_chunk_containing(label)
if c:
c.print_instructions(p.symbols, p.config)
else:
print("No chunk found at {} or {}".format(address, label))