예제 #1
0
    def parse_header():
        header = buffer[:header_size()]
        (magic_header, header_checksum, filetable_checksum, version, nb_files,
         data_size) = struct.unpack(header_structure(), header)

        magic_header = magic_header.decode('utf-8')
        archive = {"version": version}

        if magic_header != 'WRPGPIAF':
            raise ParserMagicHeaderError('Bad Magic Header')

        calculated_header_checksum = zlib.crc32(
            buffer[header_check_size():header_check_size() +
                   header_data_size()]) & 0xffffffff

        if calculated_header_checksum != header_checksum:
            raise ParserChecksumError('Bad Header Checksum : {} != {}'.format(
                calculated_header_checksum, header_checksum))

        calculated_file_table_checksum = zlib.crc32(
            buffer[header_size():header_size() +
                   nb_files * file_entry_size()]) & 0xffffffff

        if calculated_file_table_checksum != filetable_checksum:
            raise ParserChecksumError(
                'Bad Filetable Checksum : {} != {}'.format(
                    calculated_file_table_checksum, filetable_checksum))

        if len(buffer) != data_size + get_data_offset(nb_files):
            raise ParserDatasizeError('Bad Data Size')

        return archive, nb_files
예제 #2
0
파일: unpack.py 프로젝트: WalrusRPG/PIAF
def load_data(buffer, archive, file_sizes):
    data_offset = 0
    for f, file_size in zip(archive["file_entries"], file_sizes):
        data_start = get_data_offset(len(archive["file_entries"]))
        data_start_position = data_start+data_offset
        f["data"] = buffer[data_start_position: data_start_position+file_size]
        data_offset += file_size
예제 #3
0
def load_data(buffer, archive, file_sizes):
    data_offset = 0
    for f, file_size in zip(archive["file_entries"], file_sizes):
        data_start = get_data_offset(len(archive["file_entries"]))
        data_start_position = data_start + data_offset
        f["data"] = buffer[data_start_position:data_start_position + file_size]
        data_offset += file_size
예제 #4
0
파일: unpack.py 프로젝트: WalrusRPG/PIAF
    def parse_header():
        header = buffer[:header_size()]
        (   magic_header,
            header_checksum,
            filetable_checksum,
            version,
            nb_files,
            data_size ) = struct.unpack(header_structure(), header)

        magic_header = magic_header.decode('utf-8')
        archive = {
            "version": version }

        if magic_header != 'WRPGPIAF':
            raise ParserMagicHeaderError('Bad Magic Header')

        calculated_header_checksum = zlib.crc32(buffer[
            header_check_size()
            :header_check_size()+header_data_size() ]) & 0xffffffff

        if calculated_header_checksum != header_checksum:
            raise ParserChecksumError('Bad Header Checksum : {} != {}'
                .format(calculated_header_checksum, header_checksum))

        calculated_file_table_checksum = zlib.crc32(buffer[
            header_size()
            :header_size()+nb_files*file_entry_size()]
        ) & 0xffffffff

        if calculated_file_table_checksum != filetable_checksum:
            raise ParserChecksumError('Bad Filetable Checksum : {} != {}'
                .format(calculated_file_table_checksum, filetable_checksum))

        if len(buffer) != data_size + get_data_offset(nb_files):
            raise ParserDatasizeError('Bad Data Size')

        return archive, nb_files