Skip to content

Instantly share code, notes, and snippets.

@mariomadproductions
Created July 22, 2020 21:19
Show Gist options
  • Save mariomadproductions/386f095f07cc9ec46aa2ab40241c8a76 to your computer and use it in GitHub Desktop.
Save mariomadproductions/386f095f07cc9ec46aa2ab40241c8a76 to your computer and use it in GitHub Desktop.
prepend-xci-key-area.py
from sys import argv, exit
from os import path
input_rom_file_path = argv[1]
input_keyarea_file_path = argv[2]
output_rom_file_path = argv[3]
input_keyarea_size = path.getsize(input_keyarea_file_path)
target_size = 0x1000
padding = bytearray.fromhex('00')
with open (input_keyarea_file_path, 'rb') as keyarea_file:
if input_keyarea_size == target_size:
keyarea_data = keyarea_file.read()
elif input_keyarea_size < target_size:
keyarea_data = keyarea_file.read() + padding * (target_size - input_keyarea_size)
elif input_keyarea_size > target_size:
exit('Key area data bigger than 0x{}.'.format(str(target_size)))
with open(input_rom_file_path, 'rb') as input_rom_file, open(output_rom_file_path, 'wb') as output_rom_file:
output_rom_file.write(keyarea_data)
for chunk in iter(lambda: input_rom_file.read(1024), b""):
output_rom_file.write(chunk)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment