''' 2021-06-04 I was trying to crack and unpack CIV IV Save Game Files: I got nowhere # # # Created on Feb 27, 2018 @author: Brett Paufler Copyright Brett Paufler save games use zlib and zlib files start with '789c' other sources say '0100789c' 0x789c This does a little, but not much Moving on to different aspects ''' import zlib import gzip import pickle game_path = '.\\input\\mid_game.CivBeyondSwordSave' text_raw = open(game_path, 'rb').read() #print text_raw text_hex = ''.join([str(hex(ord(c))[2:].zfill(2)) for c in text_raw]) #print text_hex[:20] save_name = '.\\output\\hex_text_full.txt' with open(save_name, 'w') as f: f.write(text_hex) i = text_hex.find('789c') #i = text_hex save_name = '.\\output\\hex_text_compressed.txt' with open(save_name, 'w') as f: f.write(text_hex[i:]) #-5676 is first hit for n in range(-1, -10000, -100): try: text = zlib.decompressobj().decompress(text_raw[i/2:n]) print n #print text save_name = '.\\output\\hex_text_uncompressed_%d.txt' % n with open(save_name, 'w') as f: f.write(text) break except: pass print i print len(text_raw) print len(text_hex) #print len(text_compressed) #print type(text_hex) #text_hex = text_hex.replace('0x', '') #print text_hex #zips = ('\n').join(text_raw.split('\n')[4:]) #print zips #print text_raw #print zlib.decompress(zips) #hex_game = [hex(ord(c)) for c in text_raw] #print hex_game #print gzip.open(game_path).read() #game = pickle.loads(text_raw) #pickle.lo