Skip to content

Instantly share code, notes, and snippets.

@jamesaustin
Created March 25, 2020 22:10
Show Gist options
  • Save jamesaustin/2be04dc868cca9d5b5fea1f6e9dfc67c to your computer and use it in GitHub Desktop.
Save jamesaustin/2be04dc868cca9d5b5fea1f6e9dfc67c to your computer and use it in GitHub Desktop.
Dump a binary response from the Boundless shop API
#!/usr/bin/env python
from argparse import ArgumentParser, FileType
from struct import unpack_from
parser = ArgumentParser()
parser.add_argument("binary", help="binary files to parse", type=FileType("rb"), nargs="+", metavar="BIN")
args = parser.parse_args()
for f in args.binary:
if len(args.binary) > 1:
print(f"# {f.name}")
buffer = f.read()
index = 1
offset = 0
while offset != len(buffer):
beacon_len, tag_len = unpack_from("<BB", buffer, offset)
beacon, tag, n, patrons, price, x, z, y = unpack_from(f"<{beacon_len}s{tag_len}sIIqhhB", buffer, offset + 2)
offset += 23 + beacon_len + tag_len
beacon = beacon.decode("latin1")
tag = tag.decode("latin1")
print(f"{index:>2}: #{patrons:<2} x{n:<7,} {price/100:>6}c [{x:5},{y:3},{z:5}] \033[0;94m{tag}\033[0m {beacon}")
index += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment