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)
@cwilkes
Copy link

cwilkes commented Dec 21, 2017

change to
print s.encode("utf8")
to get around an error like this:

UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 14765: ordinal not in range(128)

@lycca
Copy link

lycca commented Jan 26, 2018

Hi Guys,

I bought a few Google Wifi’s, which have an old 8688.0.0 version of firmware from the test image channel (instead of the usual stable channel) and having field updateRequired = 0.

It seems that some kind of write protection / restriction were in force in the test image firmware, preventing the execution of Recovery Mode when trying to flash a newer stable image firmware.

Since I am not familiar with CrOS development, could you please advise the procedure for me to flash the Google Wifi to 9334.x.x steady channel image (downloaded from OnHub Recovery Utility).

Below is my posting seeking for help in Google Help Forum, for your reference:

https://groups.google.com/a/chromium.org/forum/m/#!topic/chromium-os-dev/98yOPE3UEBo

https://productforums.google.com/forum/#!topic/googlewifi/etya6Mqeo-Y

https://productforums.google.com/forum/#!topic/googlewifi/-AvwS-S-h2Q

https://productforums.google.com/forum/#!topic/googlewifi/IH16V17l6J4

I also attached the status page of the Google Wifi (http://192.168.86.1/api/v1/status) below for your information, many thanks!

{
softwareStatus = {
updateChannel = "testimage-channel";
updateProgress = 0;
updateRequired = 0;
updateStatus = 1;
version = "8688.0.0";
};
systemStatus = {
deviceId = "ed6640ea-ccbd-8c48-a02f-6c9102300f44";
hardware = 4;
hardwareId = "GALE A2A-A2A-E3A-A4Q-A9C";
uptime = 19893;
};
wanStatus = {
captivePortal = 0;
ethernetLink = 1;
invalidCredentials = 0;
online = 1;
pppoeDetected = 0;
};
}

@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