Skip to content

Instantly share code, notes, and snippets.

@kazikcz
Last active October 8, 2016 09:51
Show Gist options
  • Save kazikcz/64313b9e2470660faae1 to your computer and use it in GitHub Desktop.
Save kazikcz/64313b9e2470660faae1 to your computer and use it in GitHub Desktop.
#
# usage: python disassemble.py < firmware-4.bin
# output:
# - stdout
# - files: fw.bin, otp.bin (WARN: will overwrite existing files!)
#
import sys
import struct
def round_up(x):
return int((x+3)/4*4)
def dump_file(name, data, length):
print "output to %s (%d bytes)" % (name, length)
with open(name, "w") as f:
f.write(data)
f.truncate(length)
def dump_str(name, data, length):
print "%s = %s" % (name, data)
handlers = {
0: lambda d, l: dump_str("version", d, l),
1: lambda d, l: dump_str("timestamp", struct.unpack("<I", d)[0], l),
2: lambda d, l: dump_str("features", d.encode("hex"), l),
3: lambda d, l: dump_file("fw.bin", d, l),
4: lambda d, l: dump_file("otp.bin", d, l),
5: lambda d, l: dump_str("op_version", struct.unpack("<I", d)[0], l)
}
magic = "QCA-ATH10K\0"
assert sys.stdin.read(len(magic)) == magic
sys.stdin.read(round_up(len(magic)) - len(magic))
while 1:
(t, l, ) = struct.unpack("<II", sys.stdin.read(8))
d = sys.stdin.read(round_up(l))
handlers[t](d, l)
@blogcin
Copy link

blogcin commented Apr 1, 2015

I use this script to extract /lib/firmware/ath10k/firmware-4.bin
(to use QCA6174 HW2.1)
" Traceback (most recent call last):
File "disassemble.py", line 11, in
assert sys.stdin.read(len(magic)) == magic
AssertionError "

But I have this problem. :(
Please help me ..

@kazikcz
Copy link
Author

kazikcz commented Apr 8, 2015

@blogcin: Sorry. This worked with my clean-room blobs so I didn't notice. I've updated the gist. It should work fine now (albeit due to the sloppy design the program will still exit with an exception, which is fine).

@blogcin
Copy link

blogcin commented Apr 16, 2015

Thanks to update!

but it is not work that disassemble otp.bin by python script :(.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment