def hexDump(s: bytes, prefix: str = "", addr: int = 0) -> str: """ Utility function to hex-dump binary data. """ N = len(s) Nb = N//16 if (N%16): Nb += 1 res = "" for j in range(Nb): a,b = j*16, min((j+1)*16,N) h = " ".join(map("{:02x}".format, s[a:b])) h += " "*(16-(b-a)) t = "" for i in range(a,b): c = s[i] if c>=0x20 and c<0x7f: t += chr(c) else: t += "." res += (prefix + "{:08X} ".format(addr+16*j) + h + " | " + t + "\n") return res[:-1]