Exemple #1
0
def hexdump(data, address=0, width=16, skip=True, offset=0):
    if not color_scheme or not printable:
        load_color_scheme()
    data = list(bytearray(data))
    base = address
    last_line = None
    skipping = False
    for i, line in enumerate(groupby(data, width, -1)):
        if skip and line == last_line:
            if not skipping:
                skipping = True
                yield '...'
            continue
        else:
            skipping = False
            last_line = line

        hexline = []

        if address:
            hexline.append(H.offset("+%04x " % ((i + offset) * width)))

        hexline.append(H.address("%#08x  " % (base + (i * width))))

        for group in groupby(line, 4):
            for char in group:
                hexline.append(color_scheme[char])
                hexline.append(' ')
            hexline.append(' ')

        hexline.append(H.separator('%s' % config_separator))
        for group in groupby(line, 4):
            for char in group:
                hexline.append(printable[char])
            hexline.append(H.separator('%s' % config_separator))

        yield (''.join(hexline))

    # skip empty footer if we printed something
    if last_line:
        return

    hexline = []

    if address:
        hexline.append(H.offset("+%04x " % len(data)))

    hexline.append(H.address("%#08x  " % (base + len(data))))

    yield ''.join(hexline)
Exemple #2
0
def hexdump(data, address = 0, width = 16, skip = True):
    if not color_scheme or not printable:
        load_color_scheme()
    data = list(bytearray(data))
    base = address
    last_line = None
    skipping  = False
    for i, line in enumerate(groupby(data, width, -1)):
        if skip and line == last_line:
            if not skipping:
                skipping = True
                yield '...'
            continue
        else:
            skipping  = False
            last_line = line

        hexline = []

        if address:
            hexline.append(H.offset("+%04x " % (i*width)))

        hexline.append(H.address("%#08x  " % (base + (i*width))))

        for group in groupby(line, 4):
            for char in group:
                hexline.append(color_scheme[char])
                hexline.append(' ')
            hexline.append(' ')

        hexline.append(H.separator('%s' % config_separator))
        for group in groupby(line, 4):
            for char in group:
                hexline.append(printable[char])
            hexline.append(H.separator('%s' % config_separator))


        yield(''.join(hexline))

    hexline = []

    if address:
        hexline.append(H.offset("+%04x " % len(data)))

    hexline.append(H.address("%#08x  " % (base + len(data))))

    yield ''.join(hexline)
Exemple #3
0
def hexdump(data,
            address=0,
            width=16,
            group_width=4,
            flip_group_endianess=False,
            skip=True,
            offset=0):
    if not color_scheme or not printable:
        load_color_scheme()
    data = list(bytearray(data))
    base = address
    last_line = None
    skipping = False
    for i, line in enumerate(groupby(data, width, -1)):
        if skip and line == last_line:
            if not skipping:
                skipping = True
                yield "..."
            continue
        else:
            skipping = False
            last_line = line

        hexline = []

        if address:
            hexline.append(H.offset("+%04x " % ((i + offset) * width)))

        hexline.append(H.address("%#08x  " % (base + (i * width))))

        for group in groupby(line, group_width):
            group_length = len(group)
            group = reversed(group) if flip_group_endianess else group
            for idx, char in enumerate(group):
                if flip_group_endianess and idx == group_length - 1:
                    hexline.append(H.highlight_group_lsb(color_scheme[char]))
                else:
                    hexline.append(color_scheme[char])
                hexline.append(str(config_byte_separator))
            hexline.append(" ")

        hexline.append(H.separator("%s" % config_separator))
        for group in groupby(line, group_width):
            for char in group:
                hexline.append(printable[char])
            hexline.append(H.separator("%s" % config_separator))

        yield ("".join(hexline))

    # skip empty footer if we printed something
    if last_line:
        return

    hexline = []

    if address:
        hexline.append(H.offset("+%04x " % len(data)))

    hexline.append(H.address("%#08x  " % (base + len(data))))

    yield "".join(hexline)