(buffer, start=0, end=None, columns=64)
Print a colorful representation of binary data using terminal ESC codes
Print a colorful representation of binary data using terminal ESC codes
Print a colorful representation of binary data using terminal ESC codes
def visual_hexdump(buffer, start=0, end=None, columns=64):
	"""Print a colorful representation of binary data using terminal ESC codes
	"""
	count = (end or -1) - start
	read = 0
	while read != count:
		if end == None:
			to_read = io.DEFAULT_BUFFER_SIZE
		else:
			to_read = min(count - read, io.DEFAULT_BUFFER_SIZE)

		buf =  buffer[read:read+to_read]

		for i in range(0, len(buf), columns*2):
			offset = start + read + i
			print(format_offset(offset), end=' ')

			for j in range(0, columns):
				if i + j >= len(buf):
					break
				elif i + j + columns >= len(buf):
					print('\x1B[0m\x1B[38;2;%d;%d;%dm▀' % expand(colormap[buf[i + j]]), end='')
				else:
					print('\x1B[38;2;%d;%d;%dm\x1B[48;2;%d;%d;%dm▀' % (expand(colormap[buf[i + j]]) + expand(colormap[buf[i + j + columns]])), end='')
			print('\x1B[m')

		read += len(buf)
def visual_hexdump ( buffer , start = 0 , end = None , columns = 64 ) : count = ( end or - 1 ) - start read = 0 while read != count : if end == None : to_read = io . DEFAULT_BUFFER_SIZE else : to_read = min ( count - read , io . DEFAULT_BUFFER_SIZE ) buf = buffer [ read : read + to_read ] for i in range ( 0 , len ( buf ) , columns * 2 ) : offset = start + read + i print ( format_offset ( offset ) , end = ' ' ) for j in range ( 0 , columns ) : if i + j >= len ( buf ) : break elif i + j + columns >= len ( buf ) : print ( '\x1B[0m\x1B[38;2;%d;%d;%dm▀' % e pand(c o lormap[b u f[i + j ] ) , e d=' ' ) else : print ( '\x1B[38;2;%d;%d;%dm\x1B[48;2;%d;%d;%dm▀' % ( x pand(c o lormap[b u f[i + j ] ) + e pand(c o lormap[b u f[i + j + c lumns]] ) ) , e d=' ' ) print ( '\x1B[m' ) read += len ( buf )