def write(self, reader: ByteIO): reader.write_uint32(self.flags.getFlags()) reader.write_float(self.x_coefficient) reader.write_float(self.y_coefficient) reader.write_int32(self.number_of_backgrounds) reader.write_int32(self.background_index) reader.write_ascii_string(self.name)
def get_type(self): reader = ByteIO(byte_object=self.data) header = reader.read_fourcc() header2 = reader.read_fourcc() if header == 'RIFF': return 'WAV' elif header2 == 'AIFF': return 'AIFF' elif header == 'OggS': return 'OGG' else: # assume MOD return 'MOD'
def run_shell(self): print('Local variables:') print('\t data - raw chunk data') print('\t chunk - chunk loader object') print('\t reader - ByteIO reader object with raw data') print('Local functions') print('\t raw() - prints HEX representation of chunk') print('\t pchunk() - print chunk loader data') while True: try: locals_ = self.get_locals() globals_ = self.get_globals() locals_['data'] = self.data locals_['reader'] = ByteIO(byte_object=self.data) locals_['chunk'] = self.chunk locals_['raw'] = self.print_raw locals_['pchunk'] = self.print_chunk code = input('>>') if code == 'exit': print('Exiting shell') return compiled_code = compile(code, "iPy", 'single') exec(compiled_code, globals_, locals_) self.update_locals(locals_) self.update_globals(globals_) except KeyboardInterrupt: print('Keyboard Interruption, exiting shell') return except Exception as ex: traceback.print_exc()
def __init__(self, game_file: str): self.game_file: str = game_file self.update_settings(GAME=os.path.basename(game_file)[:-4]) self.reader = reader = ByteIO(path=game_file, copy_data_from_handle=False) if reader.read_ascii_string(2) != 'MZ': raise Exception('Invalid executable signature') self.pack_data = None self.game_data = GameData(self.reader)
def decode(self, chunk_data, chunk_size, magic_key=54, as_reader=False): decoded_chunk_pointer = self._decode_chunk(chunk_data, chunk_size, magic_key) decoded_chunk_pointer = cast(decoded_chunk_pointer, POINTER(c_ubyte * chunk_size)) if as_reader: return ByteIO( byte_object=bytes(list(decoded_chunk_pointer.contents))) else: return bytes(list(decoded_chunk_pointer.contents))
def decode_mode3(self, chunk_data, chunk_size, chunk_id, magic_key=54, as_reader=False): reader = ByteIO(byte_object=chunk_data) decompressed_size = reader.read_uint32() chunk_data = bytearray(reader.read_bytes()) if chunk_id & 0x1: chunk_data[0] ^= (chunk_id & 0xFF) ^ (chunk_id >> 0x8) chunk_data = bytes(chunk_data) data = self.decode(chunk_data, chunk_size, magic_key, True) compressed_size = data.read_uint32() if as_reader: return data.decompress_block(compressed_size, decompressed_size, True) else: return data.decompress_block(compressed_size, decompressed_size, False)
class Extension(ParameterCommon): def __init__(self, reader: ByteIO): self.reader = reader self.data = ByteIO() self.size = 0 self.type = 0 self.code = 0 def read(self): reader = self.reader self.size = reader.read_int16() self.type = reader.read_int16() self.code = reader.read_int16() self.data = ByteIO(byte_object=reader.read_bytes(self.size - 6)) def get_reader(self): self.data.seek(0) return self.data def write(self, reader: ByteIO): reader.write_int16(len(self.data) + 6) reader.write_int16(self.type) reader.write_int16(self.code) reader.write_bytes(self.data.read_bytes())
def read(self): reader = self.reader start = reader.tell() self.handle = reader.read_uint32() self.checksum = reader.read_int32() self.references = reader.read_int32() decompressed_size = reader.read_int32() self.flags.setFlags(reader.read_uint32()) reserved = reader.read_int32() name_lenght = reader.read_int32() if self.compressed and not self.flags['PlayFromDisk']: size = reader.read_int32() data = reader.decompress_block(size, decompressed_size, True) else: data = ByteIO(byte_object=reader.read_bytes(decompressed_size)) self.name = str(data.read_wide_string(name_lenght)) self.data = data.read_bytes() # if self.settings.get('VERBOSE', False): # print(f'Found sound file "{self.name}" size:{len(self.data)}') if self.settings.get('DUMPSOUNDS', False) or self.settings.get( 'DUMPEVERYTHING', False): self.dump() return self
def write(self, reader: ByteIO): java = self.settings.get('java', False) event_reader = ByteIO(mode='wb') if java: event_reader.write_int32(len(self.items)) for eventGroup in self.items: eventGroup.write(event_reader) reader.write_bytes(HEADER) reader.write_int16(self.max_objects) reader.write_int16(self.max_object_info) reader.write_int16(self.number_of_players) for item in self.number_of_conditions: reader.write_int16(item) reader.write_int16(len(self.qualifiers)) for item in self.qualifiers: item.write(reader) reader.write_bytes(EVENT_COUNT) reader.write_int32(len(event_reader)) if java: reader.write_int32(len(self.items)) if self.items: reader.write_bytes(EVENTGROUP_DATA) reader.write_int32(len(event_reader)) reader.write_bytes(event_reader.read_bytes()) reader.write_bytes(END)
def write(self, reader: ByteIO): new_reader = ByteIO() new_reader.write_int16(self.object_type) new_reader.write_int16(self.num) new_reader.write_uint16(self.object_info) new_reader.write_int16(self.object_info_list) new_reader.write_uint8(self.flags.getFlags()) new_reader.write_uint8(self.other_flags.getFlags()) new_reader.write_uint8(len(self.items)) new_reader.write_int8(self.def_type) new_reader.write_int16(self.identifier) for item in self.items: item.write(new_reader) reader.write_int16(len(new_reader) + 2) reader.write_bytes(new_reader.read_bytes())
def write(self, reader: ByteIO): new_reader = ByteIO() new_reader.write_uint8(len(self.conditions)) new_reader.write_uint8(len(self.actions)) new_reader.write_uint16(self.flags.getFlags()) new_reader.write_int16(self.is_restricted) new_reader.write_int16(self.restrictCpt) new_reader.write_int16(self.identifier) new_reader.write_int16(self.undo) for condition in self.conditions: condition.write(new_reader) for action in self.actions: action.write(new_reader) reader.write_int16((len(new_reader) + 2) * -1) reader.write_bytes(new_reader.read_bytes())
def write(self, reader: ByteIO): reader.write_int32(self.left) reader.write_int32(self.top) reader.write_int32(self.right) reader.write_int32(self.bottom)
-24: 'FlagOff', -25: 'FlagOn', -26: 'CompareFixedValue', -27: 'CompareAlterableValue', -28: 'ObjectInvisible', -29: 'ObjectVisible', -30: 'ObjectsInZone', -31: 'NoObjectsInZone', -32: 'NumberOfObjects', -33: 'AllDestroyed', -34: 'PickRandom', -35: 'NamedNodeReached', -36: 'CompareAlterableString', -37: 'IsBold', -38: 'IsItalic', -39: 'IsUnderline', -40: 'IsStrikeOut', -41: 'OnObjectLoop', -42: 'CompareAlterableValueInt', -43: 'CompareAlterableValueDouble' } if __name__ == '__main__': reader = ByteIO( path= r"E:\PYTHON_STUFF\CTF_ReaderV2\DUMP\customnight\CHUNKS\FRAMES\Frame 21\FRAMEEVENTS.chunk" ) e = Events(reader) e.update_settings(build=290) e.read()
def read(self): reader = self.reader self.size = reader.read_int16() self.type = reader.read_int16() self.code = reader.read_int16() self.data = ByteIO(byte_object=reader.read_bytes(self.size - 6))
def write(self, reader: ByteIO): reader.write_int32(self.timer) reader.write_int32(self.loops) reader.write_int16(self.comparison)
def write(self, reader: ByteIO): value = self.value[:259] reader.write_ascii_string(value, 260)
def write(self, reader: ByteIO): reader.write_double(self.value) reader.write_float(self.floatValue)
def write(self, reader: ByteIO): reader.write_int32(self.width) reader.write_int32(self.height) reader.write_fmt('BBBB', self.background) reader.write_uint32(self.flags.getFlags())
def write(self, reader: ByteIO): reader.write_uint32(len(self.items)) for item in self.items: item.write(reader) reader.write_uint32(0) # TODO
def write(self, reader: ByteIO): reader.write_bytes('\x00' * 4) for item in self.items: reader.write_fmt('BBBB', item)
def write(self, reader: ByteIO): reader.write_int16(len(self.data) + 6) reader.write_int16(self.type) reader.write_int16(self.code) reader.write_bytes(self.data.read_bytes())
def write(self, reader: ByteIO): reader.write_int8(self.click) reader.write_int8(int(self.double))
def write(self, reader: ByteIO): reader.write_uint16(self.objectInfo) reader.write_int16(self.type)
def write(self, reader: ByteIO): reader.write_bytes('\x00' * 4) reader.write_int16(self.value)
def write(self, reader: ByteIO): new_reader = ByteIO(mode='wb') new_reader.write_int16(self.code) self.loader.write(new_reader.read_bytes()) reader.write_uint16(len(new_reader) + 2) reader.write_int16(new_reader)
def write(self, reader: ByteIO): reader.write_int16(self.value)
def __init__(self, reader: ByteIO): self.reader = reader self.data = ByteIO() self.size = 0 self.type = 0 self.code = 0
def write(self, reader: ByteIO): reader.write_int16(self.object_type) reader.write_int16(self.num) if self.object_type == 0 and self.num == 0: return dataReader = ByteIO(mode='wb') if self.object_type in system_loaders and self.num in system_loaders[self.object_type]: self.loader.write(dataReader) elif self.object_type >= 2 or self.object_type == -7: dataReader.write_uint16(self.object_info) dataReader.write_int16(self.object_info_list) if self.num in extensionLoaders: self.loader.write(dataReader) reader.write_uint16(len(dataReader) + 6) reader.write_bytes(dataReader.read_bytes())
def write(self, reader: ByteIO): reader.write_ascii_string(self.value)
def write(self, reader: ByteIO): reader.write_int32(self.timer) reader.write_int32(self.loops)