#!/usr/bin/env python # Parse property file. # # Usage: # # lglaf.py -c '!INFO GPRO \x08\x0b\0\0' > props.bin # scripts/parse-props.py props.bin import argparse, sys, struct def stringify(resp): if not isinstance(resp, str): try: resp = resp.decode('ascii') except: pass return resp def get_str(data, shadow, offset): resp = b'' #while True: while offset < len(data): b = data[offset:offset+1] shadow[offset] = 's' if b == b'\0': break resp += b offset += 1 return stringify(resp) def get_chr(data, shadow, offset): b = data[offset:offset+1] shadow[offset] = 'c' return stringify(b) def get_int(data, shadow, offset): d = struct.unpack_from('