Skip to content

Instantly share code, notes, and snippets.

@skochinsky
Created September 2, 2017 19:18
Show Gist options
  • Save skochinsky/ca02d8deae8d4234b88e4693a5eedc0d to your computer and use it in GitHub Desktop.
Save skochinsky/ca02d8deae8d4234b88e4693a5eedc0d to your computer and use it in GitHub Desktop.
# convert Intel firmware update capsules to plain binaries
import sys
import os.path
import struct
fn = sys.argv[1]
inf = open(fn, "rb")
inf.seek(0xC8)
e=[]
while True:
sz, off = struct.unpack("<II", inf.read(8))
print "off: %08X, sz: %08X" % (off, sz)
inf.read(32-8)
if e:
prevsz, prevoff = e[-1]
if prevoff+prevsz != off:
print " end?"
break
e.append((sz,off))
base, ext = os.path.splitext(fn)
of = open(base+".bin","wb")
for sz, off in e:
inf.seek(off)
of.write(inf.read(sz))
inf.close()
of.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment