ffu_extract: store via PlatformId scan, mmap
This commit is contained in:
+11
-13
@@ -18,27 +18,25 @@ CHUNK = 131072
|
||||
|
||||
|
||||
def load(ffu):
|
||||
f = open(ffu, "rb")
|
||||
import mmap
|
||||
raw = open(ffu, "rb")
|
||||
f = mmap.mmap(raw.fileno(), 0, access=mmap.ACCESS_READ)
|
||||
sec = f.read(32)
|
||||
_, _, chunk_kb, _, cat, hsh = struct.unpack("<I12sIIII", sec)
|
||||
assert chunk_kb * 1024 == CHUNK
|
||||
off = 32 + cat + hsh
|
||||
off += (CHUNK - off % CHUNK) % CHUNK
|
||||
f.seek(off)
|
||||
ih = f.read(24)
|
||||
mlen = struct.unpack("<I", ih[16:20])[0]
|
||||
man = f.read(mlen)
|
||||
st = off + 24 + mlen
|
||||
f.seek(st + 204)
|
||||
vals = struct.unpack("<11I", f.read(44))
|
||||
# store header: ASCII PlatformId inside it; header starts 12B before
|
||||
st = f.find(b"Microsoft.MSM") - 12
|
||||
assert st > 0
|
||||
vals = struct.unpack("<11I", f[st + 204:st + 248])
|
||||
assert vals[0] == CHUNK, vals # blkSize sanity
|
||||
wcnt = vals[1]
|
||||
pos = st + 248
|
||||
disk = {} # diskchunk -> datachunk
|
||||
dc = 0
|
||||
for _ in range(wcnt):
|
||||
f.seek(pos)
|
||||
a, _ = struct.unpack("<II", f.read(8))
|
||||
locs = [struct.unpack("<II", f.read(8)) for _ in range(a)]
|
||||
a, _ = struct.unpack("<II", f[pos:pos + 8])
|
||||
locs = [struct.unpack("<II", f[pos + 8 + k * 8:pos + 16 + k * 8])
|
||||
for k in range(a)]
|
||||
pos += 8 + 8 * a
|
||||
for m, idx in locs:
|
||||
if m == 0:
|
||||
|
||||
Reference in New Issue
Block a user