#!/usr/bin/env python """ Copyright (C) 2006 Claus Wahlers and Max Herkender This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. """ import os, sys import zlib import StringIO import struct if len(sys.argv) <= 1: if sys.stdin.isatty(): print "If you're reading this you did something wrong." else: input = sys.stdin else: try: input = open(sys.argv[1], "rb") except: sys.exit("Input file could not be read") output = StringIO.StringIO() mode = 0 dict = {} dictPos = -1 dictLen = 0 while 1: tmp = input.read(4) if tmp: data = struct.unpack(" 0: i = 0 while (len(extra)-i > 4): entry = struct.unpack("<2H",extra[i:i+4]) if len(extra) <= i+4+entry[0]: if entry[1] != "\xda\xda": newextra += struct.pack("<2H%ss" % entry[1],entry[0],entry[1],extra[i+4:i+4+entry[1]]) i += 4+entry[0] else: break extra = newextra extralen = len(extra) if extralen > 0xffff: extralen = 0xffff extra = extra[0,extralen] hdr = (hdr[0],hdr[1],hdr[2],hdr[3],hdr[4],hdr[5],hdr[6],hdr[7],hdr[8],extralen) elif hdr[2] != 0x00: sys.exit("The entry \"%s\" uses a form of compression which is not supported" % filename) dict[filename] = (pos,hdr,filename,extra) output.write(struct.pack("<5H3I2H",*hdr)) output.write(filename) output.write(extra) output.write(file) elif data == 0x02014b50: pos = output.tell() output.write(struct.pack("