1. ajd4096

    OP ajd4096 GBAtemp Regular
    Member

    Joined:
    Feb 17, 2009
    Messages:
    179
    Country:
    Injection doesn't work yet.

    The extracted file for Zelda Minish Cap is the same as 1758.

    The extracted file for Mario & Luigi Superstar Saga is most similar to 1246.
    (191 bytes differ)

    Code:
    #!/bin/env python3
    
    import  sys
    import  binascii
    import  getopt
    import  zlib
    
    game_info = {
            'zmc': {
                    'key':          b'124a3e853c7cd7ba88f92540ba76254446c33c38d4534d3f8911f8d716b0027c17139fc2cc6486deb256cfea5fcfb43b88002b32a9fa2eba469c805bfea4d58b9b259c6b6d6a63e75dad37b936ee90b0',
                    'offset':       41578496,
                    'length':       7985152
            },
            'mlss': {
                    'key':          b'2bf3702bf54b24df82c8644004bd10b6be1cf6c534327a58c11ae0a4b55a70bf136a8ce0042e1ca2e462e581ae675eff176459fb0cfb04fa255ac68b31bf89258e3162568757b05419f765a7ee3419cc',
                    'offset':       44120064,
                    'length':       6920192,
            },
    }
    
    def     main():
            try:
                    opts, args = getopt.getopt(sys.argv[1:], "hln:", ["help", "list", "name="])
            except getopt.GetoptError as err:
                    print(str(err))
                    sys.exit(2)
    
            showList        = False
            name            = None
            for o, a in opts:
                    if o in ("-h", "--help"):
                            print("Usage: extract_gba.py [-h] [-l] [-n name] path/to/alldata.bin")
                            sys.exit(2)
                    elif o in ("-l", "--list"):
                            showList = True
                    elif o in ("-n", "--name"):
                            name    = a
                    else:
                            assert False, "unhandled option"
    
            if (showList):
                    for gi_name in game_info.keys():
                            print("Name",   gi_name)
                            print("Key",    game_info[gi_name]['key'])
                            print("Offset", game_info[gi_name]['offset'])
                            print("Length", game_info[gi_name]['length'])
    
            for filename in args:
                    if (name in game_info):
                            key = binascii.unhexlify(game_info[name]['key'])
                            key_len = len(key)
    
                            adb_file = open(filename, 'rb')
    
                            # Seek to MDF chunk
                            adb_file.seek(game_info[name]['offset'])
    
                            # Read in the entire chunk
                            adb_data = bytearray(adb_file.read(game_info[name]['length']))
    
                            # For each byte, XOR in our key
                            # +8 = skip the MDF magic + size
                            for i in range(len(adb_data)-8):
                                    adb_data[8+i] ^= key[i % key_len]
    
                            # Decompress the unobfuscated data
                            raw_data = zlib.decompress(adb_data[8:])
    
                            # Write it out
                            open(name + ".gba", 'wb').write(raw_data)
    
                    else:
                            print("Game", name, "not found")
    
    if __name__ == "__main__":
            main()
    
    Now with correct indenting, kinda important :)
     
    Last edited by ajd4096, Dec 9, 2015
  2. pedro702

    pedro702 GBAtemp Legend
    Member

    Joined:
    Mar 3, 2014
    Messages:
    10,882
    Country:
    Portugal
    sos did you brook the encription on it already?
     
    paulloeduardo likes this.
  3. ajd4096

    OP ajd4096 GBAtemp Regular
    Member

    Joined:
    Feb 17, 2009
    Messages:
    179
    Country:
    If you call "repeating key XORd with a known plain text" encryption, yes.
     
  4. VinsCool

    VinsCool Persona Secretiva Felineus
    Moderator

    Joined:
    Jan 7, 2014
    Messages:
    14,232
    Country:
    Canada
    Interesting! Thanks for the script
     
Draft saved Draft deleted
Loading...

Hide similar threads Similar threads with keywords - Extracting, alldata,