Skip to content

Instantly share code, notes, and snippets.

@CreateRemoteThread
Created July 11, 2017 00:51
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 CreateRemoteThread/76e394ddc91379ebcb1cb4ef5ab36dee to your computer and use it in GitHub Desktop.
Save CreateRemoteThread/76e394ddc91379ebcb1cb4ef5ab36dee to your computer and use it in GitHub Desktop.
#!/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