Advertisement
Guest User

Untitled

a guest
Jan 12th, 2015
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. import os,sys,struct,zlib
  2.  
  3. def get_data(filename):
  4.     totalbytes = os.path.getsize(filename)
  5.     infile = open(filename, 'rb')
  6.     totalfiledata = infile.read(totalbytes)
  7.     return totalfiledata
  8.  
  9. if __name__ == '__main__':
  10.     filedata = get_data(sys.argv[1])
  11.     if filedata[:4] != 'KTZ0':
  12.         print '%s is not compressed' % sys.argv[1]
  13.         sys.exit()
  14.     uncomplen = struct.unpack('>I',filedata[0x4:0x8])[0]
  15.  
  16.     pos = 0x8
  17.     newfiledata = ''
  18.     while pos < len(filedata) and len(newfiledata) < uncomplen:
  19.         sectioncomplen = struct.unpack('>I',filedata[pos:pos+0x4])[0]
  20.         newfiledata += zlib.decompress(filedata[pos+0x4:pos+0x4+sectioncomplen])
  21.         pos += 0x4+sectioncomplen
  22.  
  23.     outfile = open(sys.argv[1].rsplit('.',1)[0] + '_new.' + sys.argv[1].rsplit('.',1)[1],'wb')
  24.     outfile.write(newfiledata)
  25.     outfile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement