blob: caf0b85a822772f84b2dedda74327ffd98882fa5 [file] [log] [blame]
Denis 'GNUtoo' Carikli40a2a9c2017-03-01 14:56:25 +01001#!/usr/bin/env python2
roxfanb165a902013-01-15 14:27:44 +01002# HP Compaq 6715b ROM unpacker by roxfan
3# compressed data begins like this:
4# 0000010000: 01 00 14 01 70 00 00 00 | 60 00 00 00 00 00 02 00 O .Op . O
5# 0000010010: 50 4F 53 54 FF B8 00 20 | 8E D8 66 B8 10 FF 20 00 POST.. ..f...
6
7import struct, array, sys
8
9def unpack1(cdata, ulen):
10 pos = 0
11 odata = ""
12 while ulen:
13 a = ord(cdata[pos])
14 # print "%x: %x" % (pos, a)
15 pos += 1
16 if a == 0xFF:
17 odata += cdata[pos:pos+8]
18 ulen -= 8
19 pos += 8
20 else:
21 mask = a | 0x100
22 while mask and ulen:
23 # print hex(mask), hex(pos)
24 b = mask & 1
25 mask >>= 1
26 if mask == 0:
27 break
28 if b:
29 odata += cdata[pos]
30 pos += 1
31 ulen -= 1
32 else:
33 delta = ord(cdata[pos])
34 pos += 1
35 delta |= ord(cdata[pos])<<8
36 pos += 1
37 count = (delta & 0xF) + 3
38 delta >>= 4
39 # print "d: %d, c: %d" % (delta, count)
40 opos = len(odata)-delta
41 while count:
42 odata += odata[opos]
43 opos += 1
44 count -= 1
45 ulen -= 1
46 return odata
47
48f = open(sys.argv[1], "rb")
49f.seek(0x10000)
50
51while True:
52 flags, ulen, clen, dest = struct.unpack("<IIII", f.read(0x10))
53 comp = flags & 0xFF
54 if comp > 1:
55 break
56 hdrlen = (flags>>16) & 0xFF
57 unk = (flags>>24) & 0xFF
58 print "comp: %d, hdr len: 0x%X, unk: %d, ulen: 0x%X, clen: 0x%X, dest: 0x%X" % (comp, hdrlen, unk, ulen, clen,
59dest)
60 extra = f.read(hdrlen-0x10).rstrip('\0')
61 print " %s" % extra
62 cdata = f.read(clen)
63 fname = "%04X_%s.bin" % (dest>>4, extra)
64 if comp == 1:
65 cdata = unpack1(cdata, ulen)
66 open(fname, "wb").write(cdata)