Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/python
# Balong MCU Console Dump Extractor
import sys
import os
lastaddr = 0x0
if __name__ == "__main__":
if len(sys.argv) != 2:
print " [!] usage: %s capfile"
sys.exit(0)
else:
f = open(sys.argv[1])
d = f.readlines()
f.close()
line_mode = False
lastline = ""
for line_no in range(0,len(d)):
if "exc: d(" in d[line_no]:
fname = "%s-%s-%s.bin" % (os.path.basename(sys.argv[1]),d[line_no][17:17+8], d[line_no][27:27+8])
f_out = open(fname,"wb")
line_mode = True
lines = 0
elif line_mode is True:
l_ = d[line_no].rstrip()
if len(l_) == 58:
addr = int(l_.split("][")[1][0:10],16)
if lastaddr == addr or addr < lastaddr:
print "skipping line: lastaddr was %x, addr is %x" % (lastaddr,addr)
continue
else:
addr = lastaddr
lastline = l_
newline = ""
new_bits = l_.split("]")[2].split(" ")
for chunk in new_bits:
newline += chunk[6:8] + chunk[4:6] + chunk[2:4] + chunk[0:2]
else:
line_mode = False
print " [>] last line dumped: %s" % lastline
f_out.close()
continue
f_out.write(newline.decode('hex'))
lines += 1
if line_mode is False:
print " [>] data dumped to %s, %d lines parsed" % (fname,lines)
f_out.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment