def hexdump(bdata: Callable, start: int = None, stop: int = None) -> str:
    """Build a string similar to hexdump -C for binary data exploration"""
    LN = 10
    ret = ''
    _, _, _, sz = bdata(None, -1)
    if start is None:
        start = 0
    if stop is None or stop > sz:
        stop = sz
    length = stop - start
    idx = (start // LN) * LN
    buf, d0, i0, sz0 = bdata(idx, length+(start-idx))
    i = d0 + i0
    while i < d0 + i0 + sz0:
        l = buf[i:i+LN]
        hexl = bytes.hex(l, ' ')
        hext = bytes([ascii_hexdump_printable(c) for c in l]).decode('ascii')
        ret += f"{i:0{LN}d}  {hexl:{LN*3-1}}  |{hext}|\n"
        i += LN
    return ret
Build a string similar to hexdump -C for binary data exploration
pdfsyntax/filestruct.py