Skip to content

Instantly share code, notes, and snippets.

@pieceofsummer
Created September 16, 2017 23:26
Show Gist options
  • Save pieceofsummer/65514e56678d34505cd653f69a8e1fe5 to your computer and use it in GitHub Desktop.
Save pieceofsummer/65514e56678d34505cd653f69a8e1fe5 to your computer and use it in GitHub Desktop.
Google Wifi diagnostic report parser
#!/usr/bin/python
import os, sys, gzip
from StringIO 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 ord(data[0]) == 0x1F and ord(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)
@booth-f
Copy link

booth-f commented Oct 6, 2021

https://gist.github.com/booth-f/72832e05252eb89dbdbe644e2a0a9a92

Modified parser code to work with Python3. Looks like in the latest dumps there are some errors towards the end which somebody else might be able to figure out.

Unknown tag: 0x7a
Unknown tag: 0x7a
Unknown tag: 0x7a
Unknown tag: 0x82
Unknown tag: 0xcf
Unknown tag: 0x74
Unknown tag: 0x20
Unknown tag: 0x69
Unknown tag: 0x70
Unknown dict entry type: 0x74
Unknown dict entry type: 0x36
Traceback (most recent call last):
File "wifi-parser.py", line 125, in
print("Id2mac:", d['name'], "=", d['value'])
KeyError: 'name'

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