diff options
author | Cleverking2003 <30466983+Cleverking2003@users.noreply.github.com> | 2020-06-19 00:02:21 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-19 00:02:21 +0300 |
commit | a455bac566535ec559aac9164e05781093653057 (patch) | |
tree | d7adbe4bb91cce929d5fcb1bb26d992474639afa /explode_incbins.py | |
parent | f20e222730ad06a967eb1003f38f100fa81fed43 (diff) | |
parent | c2ca3c0c4fc49a19554c202e45a990c61752e15d (diff) |
Merge pull request #171 from PikalaxALT/pikalax_work
KNARC: Add handling of .knarcignore, .knarckeep; fix up cli; implement o2narc for poketool/personal/*.narc
Diffstat (limited to 'explode_incbins.py')
-rw-r--r-- | explode_incbins.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/explode_incbins.py b/explode_incbins.py new file mode 100644 index 00000000..4e1af1b5 --- /dev/null +++ b/explode_incbins.py @@ -0,0 +1,21 @@ +import sys +import re + +with open(sys.argv[1], 'rb') as rom: + for fname in sys.argv[2:]: + with open(fname, 'r+') as fp: + lines = [] + for line in fp: + m = re.search(r'\.incbin "baserom.nds", (0x\w+), (0x\w+)', line) + if m is not None: + addr = int(m[1], 16) + size = int(m[2], 16) + rom.seek(addr) + for i in range(0, size, 16): + data = rom.read(min(size - i, 16)) + lines.append('\t.byte ' + ', '.join(f'0x{k:02X}' for k in data) + '\n') + else: + lines.append(line) + fp.seek(0) + fp.truncate() + fp.write(''.join(lines)) |