Exemplo n.º 1
0
def main(argc, argv):
    if argc != 2:
        print 'Usage: %s local_wireless_gift [output]' % argv[0]
        sys.exit(1)
    gift = safe_read(argv[1])

    dec_size, comp_size = up('<II', gift[0x34:0x3C])
    if comp_size >= 0x5000 or dec_size >= 0x5000 or len(
            gift) != 0x3C + comp_size + 8:
        print 'Error: %s is not a valid wifi gift!' % argv[1]
    enc_gift = gift[0x3C:]

    valid, dec_gift = memecrypto.verify_meme_data(enc_gift, 'local_wireless')
    if not valid:
        print 'Error: %s is not a valid memesigned gift!' % argv[1]
        sys.exit(1)

    dec_gift = lzss.decompress(dec_gift[:-0x8])

    prefix, ext = os.path.splitext(argv[1])

    if len(dec_gift) == 0x310:
        print 'Gift is a single wondercard! Writing...'
        safe_write('%s_dec.wc7full' % prefix, dec_gift)
    elif len(dec_gift) % 0x310 == 0:
        num_cards = len(dec_gift) / 0x310
        print 'Gift is %d wondercards! Writing...' % num_cards
        cards = up('<' + '784s' * num_cards, dec_gift)
        for i, card in enumerate(cards):
            safe_write('%s_dec_%d.wc7full' % (prefix, i), card)
    else:
        print 'Unknown local wireless gift, writing raw...'
        safe_write('%s_dec.%s' % (prefix, ext), dec_gift)
    print 'Done!'
    return 0
Exemplo n.º 2
0
    def __init__(self, fileobj):

        # Read the file data
        data = fileobj.read()

        # Decompress the file
        compressedSize = struct.unpack_from("<L", data)[0]
        data = lzss.decompress(data[4:4 + compressedSize])

        # Parse the pointer table
        numSections = 7
        tableSize = numSections * 4

        pointers = struct.unpack_from("<%dL" % numSections, data)

        self.basePointer = pointers[0]
        pointers += (self.basePointer + len(data) - tableSize, )  # dummy pointer to determine end of last section

        # Extract the section data (assumption: the pointers are in
        # ascending order, so the size of each section equals the difference
        # between adjacent pointers)
        self.sections = []
        for i in xrange(len(pointers) - 1):
            start = pointers[i] - self.basePointer + tableSize
            end = pointers[i + 1] - self.basePointer + tableSize
            assert end >= start

            self.sections.append(data[start:end])
Exemplo n.º 3
0
    def __init__(self, fileobj):

        # Read the file data
        data = fileobj.read()

        # Decompress the file
        compressedSize = struct.unpack_from("<L", data)[0]
        data = lzss.decompress(data[4:4 + compressedSize])

        # Parse the pointer table
        numSections = 7
        tableSize = numSections * 4

        pointers = struct.unpack_from("<%dL" % numSections, data)

        self.basePointer = pointers[0]
        pointers += (self.basePointer + len(data) - tableSize,
                     )  # dummy pointer to determine end of last section

        # Extract the section data (assumption: the pointers are in
        # ascending order, so the size of each section equals the difference
        # between adjacent pointers)
        self.sections = []
        for i in xrange(len(pointers) - 1):
            start = pointers[i] - self.basePointer + tableSize
            end = pointers[i + 1] - self.basePointer + tableSize
            assert end >= start

            self.sections.append(data[start:end])
Exemplo n.º 4
0
def export_data(in_file_path, out_folder_path):
    '''
    Function for exporting data from LZS files
    '''
    bd_logger("Starting export_data...")

    if not os.path.exists(out_folder_path):
        os.makedirs(out_folder_path)

    lzs_file = open(in_file_path, 'rb')
    lzs_file_size = os.path.getsize(in_file_path)

    lzs_file.seek(lzs_file_size - 4)
    tail_start_offset = struct.unpack("<L", lzs_file.read(4))[0]
    lzs_file.seek(tail_start_offset)

    curr_offset = lzs_file.tell()
    file_count = 0
    path_arr = []
    name_arr = []
    offset_arr = []
    comp_size_arr = []
    while curr_offset < lzs_file_size - 4:
        file_count += 1
        file_name = get_name(lzs_file)
        file_offset = struct.unpack("<L", lzs_file.read(4))[0]
        file_comp_size = struct.unpack("<L", lzs_file.read(4))[0]
        file_uncomp_size = struct.unpack("<L", lzs_file.read(4))[0]
        lzs_file.read(4)
        file_path = out_folder_path + file_name

        curr_offset = lzs_file.tell()

        name_arr.append(file_name)
        path_arr.append(file_path)
        offset_arr.append(file_offset)
        comp_size_arr.append(file_comp_size)

    for i in range(file_count):
        f_path = path_arr[i]
        f_name = name_arr[i]

        print(f_path)

        lzs_file.seek(offset_arr[i])
        file_data = lzs_file.read(comp_size_arr[i])
        file_data = lzss.decompress(file_data)

        out_file = open(f_path, "wb+")
        out_file.write(file_data)
        out_file.close()

    lzs_file.close()
    bd_logger("Ending export_data...")
Exemplo n.º 5
0
def load_monbook_ja(filename):
    with open(filename, "rb") as f:
        data = decompress(f.read())
    idx = data.find(b'\x10\x00\x00\x00')
    data = data[:idx]
    results = []

    while len(data) > 0:
        results.append(data[:MONBOOK_PARAGRAPH_LENGTH])
        data = data[MONBOOK_PARAGRAPH_LENGTH:]

    return results
Exemplo n.º 6
0
    def __init__(self, fileobj):

        # Read the file data
        cmpData = fileobj.read()

        # Decompress the file
        compressedSize = struct.unpack_from("<L", cmpData)[0]
        self.data = bytearray(lzss.decompress(cmpData[4:4 + compressedSize]))

        # Find the script section
        offset = struct.unpack_from("<L", self.data, 0x14)[0]
        size = struct.unpack_from("<L", self.data, 0x18)[0] - offset

        self.scriptStart = offset + 4
        self.scriptEnd = self.scriptStart + size
Exemplo n.º 7
0
def decompressLzss(data):
    return lzss.decompress(data)
Exemplo n.º 8
0
    if args.filename == "monbook":
        monbook_ja = load_monbook_ja(f"{GAME_DATA_IN_DIR}/BATTLE/MONBOOK.TIM")

        try:
            monbook_en = load_monbook_translations(
                f"{TRANSLATIONS_PATH}/en.{args.filename}.txt")
        except ValueError as e:
            too_many_bytes = True
            too_many_bytes_reason = str(e)

        if too_many_bytes:
            print(too_many_bytes_reason)
        else:
            with open(f"{GAME_DATA_IN_DIR}/BATTLE/MONBOOK.TIM", "rb") as f:
                data = decompress(f.read())

            for i in range(len(monbook_en)):
                data = data.replace(monbook_ja[i], monbook_en[i])

            compressed_data = compress(data)
            with open(f"{GAME_DATA_OUT_DIR}/BATTLE/MONBOOK.TIM", "wb") as f:
                f.write(compressed_data)

    else:
        if args.filename == "slps":
            with open(f"{GAME_DATA_IN_DIR}/SLPS_014.68", "rb") as f:
                rawdata = f.read()
        elif args.filename == "fdevent":
            with open(f"{GAME_DATA_IN_DIR}/FIELD/FDEVENT.ACB", "rb") as f:
                rawdata = f.read()
Exemplo n.º 9
0
def decompressLzss(data):
    return lzss.decompress(data)