Skip to content

Instantly share code, notes, and snippets.

@booth-f
Created October 6, 2021 14:08
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 booth-f/72832e05252eb89dbdbe644e2a0a9a92 to your computer and use it in GitHub Desktop.
Save booth-f/72832e05252eb89dbdbe644e2a0a9a92 to your computer and use it in GitHub Desktop.
Google WiFi Debug Parser
#!/usr/bin/python
import os, sys, gzip
from io import StringIO
from datetime import datetime
def readByte(f):
return ord(f.read(1))
def readInt(f):
l = 0
shift = 0
while True:
b = readByte(f)
l |= (b & 0x7F) << shift
shift += 7
if (b & 0x80) == 0: break
return l
def readString(f):
l = readInt(f)
return f.read(l).decode("utf-8")
def readDict(f):
l = readInt(f)
end = f.tell() + l
d = dict()
while f.tell() < end:
et = readByte(f)
el = readInt(f)
if et == 0x0A:
d['name'] = f.read(el).decode("utf-8")
elif et == 0x12:
d['value'] = f.read(el)
elif et == 0x10:
d['size'] = el
elif et == 0x18:
d['retcode'] = el
elif et == 0x1A:
d['extra'] = f.read(el).decode("utf-8")
else:
print("Unknown dict entry type:", hex(et))
f.seek(el, os.SEEK_CUR)
f.seek(end) # just in case
return d
if len(sys.argv) < 2:
print("Usage:", sys.argv[0], "<report-filename>")
exit(0)
fsroot = os.path.abspath(sys.argv[1] + "-files")
with gzip.open(sys.argv[1], "rb") as f:
t = f.read(1)
while t:
t = ord(t)
if t == 0x0A:
s = readString(f)
print("SoftwareVersion:", s)
elif t == 0x12:
d = readDict(f)
fname = fsroot + d['name']
dname = os.path.dirname(fname)
if not os.path.exists(dname):
os.makedirs(dname)
data = d['value']
if len(data) > 10 and data[0] == 0x1F and data[1] == 0x8B:
try:
with gzip.GzipFile(fileobj=StringIO(data)) as x:
data = x.read()
except:
pass
with open(fname, "wb") as o:
o.write(data)
elif t == 0x1A:
s = readString(f)
print("OriginalSoftwareId:", s)
elif t == 0x22:
s = readString(f)
print("HardwareId:", s)
elif t == 0x2A:
s = readString(f)
print("")
print("Configuration Info:")
print(s)
elif t == 0x3A:
d = readDict(f)
print("Large File:", d['name'], "(" + str(d['size']) + " bytes)")
elif t == 0x42:
s = readString(f)
print("")
print("Network Info:")
print(s)
elif t == 0x4A:
d = readDict(f)
print("")
print("Command:", d['name'], "(status = " + str(d['retcode']) + ")")
print(d['value'])
elif t == 0x52:
s = readString(f)
print("")
print("Information:")
print(s)
elif t == 0x58:
print("Unknown 0x58:", readByte(f))
elif t == 0x62:
d = readDict(f)
print("Id2mac:", d['name'], "=", d['value'])
elif t == 0x68:
timestamp = readInt(f)
print("Generated:", datetime.fromtimestamp(timestamp))
elif t == 0x72:
l = readInt(f)
print("Previous Report (" + str(l) + " bytes)")
f.seek(l, os.SEEK_CUR)
else:
print("Unknown tag:", hex(t))
l = readInt(f)
f.seek(l, os.SEEK_CUR)
t = f.read(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment