The first 0x100 bytes of expansion disks are encrypted to attempt to prevent any old person from hijacking a game and running their own script. So far, it looks like this is usually at LBA 0x230.
This script decodes it.
rom.file.seek(pos,0)
enc = bytearray(rom.file.read(0x100))
rom.file.close()
dec = bytearray(0x100)
count = 0
# Bytes are copied at 17 byte intervals
for i in range(0x100):
out.write(dec)
out.close()
Note, the in-game decoder is itself encrypted using its function address as the key. Basically, there's two functions that are encrypted and are called to reset the game. The first waits for the SP to clear, clears all interrupts, decrypts the disk bootcode, sets osResetType to 2, erases itself and, occationally, its caller. The second resets the cache and reboots starting at the bootcode. The function that decodes these uses this algorithm:
key = sum of four bytes for function 1 address & 0xFF, used for both functions
(for example, 800BB67C: (0x80+0x0B+0xB6+0x7C)&0xFF = 0xBD)
for i in range(start,end,4):
I have a few examples of these already done, if posting disassembled code is permitted.
This script decodes it.
rom.file.seek(pos,0)
enc = bytearray(rom.file.read(0x100))
rom.file.close()
dec = bytearray(0x100)
count = 0
# Bytes are copied at 17 byte intervals
for i in range(0x100):
dec[count] = enc
count+=17
count&=0xFF
count+=17
count&=0xFF
out.write(dec)
out.close()
Note, the in-game decoder is itself encrypted using its function address as the key. Basically, there's two functions that are encrypted and are called to reset the game. The first waits for the SP to clear, clears all interrupts, decrypts the disk bootcode, sets osResetType to 2, erases itself and, occationally, its caller. The second resets the cache and reboots starting at the bootcode. The function that decodes these uses this algorithm:
key = sum of four bytes for function 1 address & 0xFF, used for both functions
(for example, 800BB67C: (0x80+0x0B+0xB6+0x7C)&0xFF = 0xBD)
for i in range(start,end,4):
i[2]-=key
i[3]+=key
i[3]+=key
I have a few examples of these already done, if posting disassembled code is permitted.