Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from insani import *
- import os
- import sys
- def readbytes(infile, bytecount, xorkey, offset=0):
- ret = ""
- while (offset < bytecount):
- byte = long(ord(infile.read(1)))
- ret += chr(byte)
- offset += 1
- return ret
- def converttoint(bytes, size=INT_LENGTH, endian=LITTLE_ENDIAN):
- result = 0
- for i in xrange(size):
- temp=long(ord(bytes[i]))
- if endian == LITTLE_ENDIAN :
- result |= (temp << (8*i))
- elif endian == BIG_ENDIAN :
- result = (result << 8) | temp
- else :
- raise 'converttoint', 'Unknown endian specification'
- return result
- def convertfromint(value, size=INT_LENGTH, endian=LITTLE_ENDIAN):
- result = ""
- for i in xrange(size):
- if endian == LITTLE_ENDIAN :
- #result |= (temp << (8*i))
- temp = (value >> (8*i)) & 0x00FF
- elif endian == BIG_ENDIAN :
- #result = (result << 8) | temp
- temp = (value >> (8*(size-i-1))) & 0x00FF
- else :
- raise 'convertfromint', 'Unknown endian specification'
- result += chr(temp)
- return result
- #program
- files = sys.argv[1:]
- for filename in files:
- infile = open(filename, 'rb')
- xorkey = 0
- header_unk = converttoint(readbytes(infile, 4, xorkey))
- print "The unknown crap is %8X" % header_unk
- filecount = converttoint(readbytes(infile, 4, xorkey))
- print "There are %d files" % filecount
- entries = []
- for i in xrange(filecount):
- entry = {}
- filedata = readbytes(infile, 0x54, xorkey)
- entry['name'] = filedata[0:0x40].strip(" \t\n\0")
- print "Name is %s" % (entry['name'])
- #block1 = converttoint(filedata[0x100:0x104])
- entry['filesize'] = converttoint(filedata[0x4C:0x50])
- entry['filestart'] = converttoint(filedata[0x48:0x4C])
- #print "And the blocks are: %08X - %08X" % (filesize, filestart)
- entries.append(entry)
- #print "Current position is now %d / %X" % (infile.tell(), infile.tell())
- dirname = filename[0:filename.find(".")]
- if not os.path.isdir(dirname):
- os.mkdir(dirname)
- i = 0
- for entry in entries:
- filename = entry['name']
- splitpath = filename.split('\\');
- dirpath = dirname + '\\'
- for k in (xrange(len(splitpath)-1)):
- dirpath += splitpath[k] + '\\'
- if (not os.path.isdir(dirpath)):
- os.mkdir(dirpath)
- infile.seek(entry['filestart'])
- data = readbytes(infile, entry['filesize'], xorkey)
- outfile = open(dirname + '\\' + filename, 'wb')
- outfile.write(data)
- outfile.close()
- print "Created file", filename, "of size", entry['filesize'], "from position", entry['filestart']
- i += 1
- infile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement