robmcmullen / omnivore

Hex editor and debugging emulator, sponsored by the Player/Missile Podcast
Mozilla Public License 2.0
53 stars 7 forks source link

Add filters for segments #82

Open robmcmullen opened 8 years ago

robmcmullen commented 8 years ago

MAME roms can be encrypted or obfuscated, so it would be nice to be able to apply a filter on a segment so that it can be viewed as its unencrypted form, and then re-encrypted when modified. This would actually happen down at the atrcopy level, but there would need to be a UI in Omnivore to handle all of it.

robmcmullen commented 8 years ago

Here's an example from the Track & Field MAME rom:

#!/usr/bin/env python

import numpy as np

def konami1_xormask(address):
    xormask = 0;
    if (address & 0x02):
       xormask |= 0x80;
    else:
        xormask |= 0x20;
    if (address & 0x08):
       xormask |= 0x08;
    else:
       xormask |= 0x02;
    return xormask

def konami1_decodebyte(opcode, address):
    xormask = konami1_xormask(address)
    return opcode ^ xormask;

if __name__ == "__main__":
    for addr in range(128):
        source = 0xff
        mask = konami1_xormask(addr)
        decrypted = konami1_decodebyte(source, addr)
        encrypted = decrypted ^ mask
        print addr, source, mask, decrypted, encrypted

    xorlist = []
    for addr in range(16):
        xorlist.append(konami1_xormask(addr))
    print repr(xorlist)
    xorlist = np.asarray(xorlist, dtype=np.uint8)
    print repr(xorlist)

    rom = np.fromfile("a01_e01.bin", dtype=np.uint8)
    print rom

    x = np.tile(xorlist, len(rom) / len(xorlist))
    print x

    raw = rom ^ x
    raw.tofile("a01_e01.bin.raw")