forked from pret/ds_disassembly_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_overlay_load_order.py
28 lines (22 loc) · 950 Bytes
/
get_overlay_load_order.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
import struct
import sys
class Overlay:
def __init__(self, ovy_id, start, size, bsssize, sinit_start, sinit_end, file_id, flag):
self.id = ovy_id
self.start = start
self.end = start + size + bsssize
def main():
fname = sys.argv[1] if len(sys.argv) > 1 else 'baserom.nds'
with open(fname, 'rb') as fp:
buffer = fp.read()
ovy_addr, ovy_size = struct.unpack_from('<LL', buffer, 0x50)
ovy_table = [Overlay('main', 0x02000000, 0x111ef8, 0xd3a08, 0, 0, 0, 0)]
ovy_table += [Overlay(*args) for args in struct.iter_unpack('<LLLLLLLL', buffer[ovy_addr:ovy_addr + ovy_size])]
for i, a in enumerate(ovy_table[1:], 1):
for j, b in enumerate(ovy_table[:i]):
if a.start == b.end:
print('Overlay', a.id, 'After', b.id)
with open('overlay_table.sbin', 'wb') as ofp:
ofp.write(buffer[ovy_addr:ovy_addr + ovy_size])
if __name__ == '__main__':
main()