Lambda, I've since removed the GPL license from the .zip.
But here's my jerry-rigged code I've managed to build from what Valvwen posted:
Code: Select all
import os
import struct
import array
import sys
import zlib
###############
###############
###############
###############
def wtf(off, left, type, readbyte):
sizeoff = int(off)-left
try:
dwz.seek(sizeoff)
return struct.unpack(type, dwz.read(readbyte))[0]
except:
struct.error
print "error"
##########################################################
def mextract(addy, wut):
size = wtf(addy, 5, 'l', 4)
width13 = wtf(addy, 13, 'B', 1)
width20 = wtf(addy, 20, 'l', 4)
width16 = wtf(addy, 16, 'l', 4)
width17 = wtf(addy, 17, 'B', 1)
width = ""
if width13 == 0 or width13 <= 0:
if width20 <= 0:
width = width16
else:
if width20 >= 1048576:
width = width17
else:
width = width20
else:
width = width13
if size <= 0 or size > 2485760:
pass
else:
dwz.seek(int(addy))
compressed = dwz.read(size)
sizeComp = len(compressed)
compOff = 0
obj = zlib.decompressobj()
buf = ""
try:
while compOff < sizeComp:
d = obj.decompress(compressed[compOff])
if len(obj.unused_data) > 0:
break
buf += d
compOff += 1
except zlib.error, details:
pass
#############################################################################
insize = len(buf)
width = width
height = insize / width / 2
if( wut == 0 and (height != 0 and height < 9000) ):
OUT = '%d'%int(addy)+'.bmp'
fout = file(OUT,'wb')
fout.write('BM')
bmfh = struct.pack( 'LLL', insize*2 + 14 + 40, 0, 14+40 )
fout.write(bmfh)
bmih = struct.pack('LLLHHLLLLLL',
40,
width,
height,
1,
32,
0, 0, 0, 0, 0, 0 )
fout.write(bmih)
rgba = array.array('B')
wFile = array.array('H')
wFile.fromstring(buf)
for y in range(height,0,-1):
for pix in wFile[width * (y-1) : width * y]:
a = ((pix >> 12) & 0xf) * 0x11
r = ((pix >> 8) & 0xf) * 0x11
g = ((pix >> 4) & 0xf) * 0x11
b = ((pix >> 0) & 0xf) * 0x11
rgba.extend( [b,g,r,a] )
rgba.tofile(fout)
##############all##################
def mextractall():
df = 0
dr = 0
os.mkdir("%d"%dr)
os.chdir("%d"%dr)
makeafile()
while 1:
addy = zloc.readline()
if not addy:
break
mextract(addy, 0)
if (df == 1000):
os.chdir("..")
dr = dr+df
os.mkdir("%d"%dr)
os.chdir("%d"%dr)
makeafile()
df = 0
print float((float(zloc.tell())/float(zlocsize))*100)
df += 1
##############Main################
if len(sys.argv) < 5:
print 'Meds'
print 'Usage maplox.py all lol zliboffsetFile zlibArchivethinger'
else:
if sys.argv[2] != 'lol':
print 'you need to lol'
else:
zloc = open(sys.argv[3], "rb")
zloc.seek(0,2)
zlocsize = zloc.tell()
zloc.seek(0)
dwz = open(sys.argv[4], "rb")
dwz.seek(0, 2)
dwzsize = dwz.tell()
width = ""
height= ""
addy = sys.argv[1] ##test offset
if( addy == 'all' ):
mextractall()
The addresses for the widths were varying, and were found through trial and error. I had no idea how to view the extracted zlib chunks, and the only way I could view them were chucking it through Iceburg's program running in ARGB mode--that's why it's in bitmap format. Other than that, basic.