Skip to content

Instantly share code, notes, and snippets.

@robots
Created August 7, 2019 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robots/ae28694a4114fe26830d6d14f288592c to your computer and use it in GitHub Desktop.
Save robots/ae28694a4114fe26830d6d14f288592c to your computer and use it in GitHub Desktop.
import struct
import os
global_offset = 0x130
files = []
def read_string(fin, offset):
out= ""
now = fin.tell()
fin.seek(offset, 0)
while True:
ch = fin.read(1)
if len(ch) == 0 or ch[0] == 0:
break
out += chr(ch[0])
fin.seek(now, 0)
return out
with open("pcff.elf", "rb") as fin:
fin.seek(global_offset, 0)
while True:
fd = fin.read(12)
if not len(fd) == 12:
break
f = {}
f['name'], f['off'], f['size'] = struct.unpack("<III", fd)
if f['name'] == 0 or f['off'] == 0:
break
f['name'] -= 0x8b000000
f['off'] -= 0x8b000000
files.append(f)
for f in files:
fin.seek(global_offset + f['off'])
fdata = fin.read(f['size'])
if not len(fdata) == f['size']:
print("bad", len(fdata), f['size'])
continue
name = read_string(fin, global_offset + f['name'])
print (name)
outdir = "out" + os.path.dirname(name)
os.makedirs(outdir, 0o0777, True)
with open("out" + name, "wb") as fout:
fout.write(fdata)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment