Created
May 14, 2020 19:32
-
-
Save lwerdna/7290adf186d8401643a98690d9bb694f to your computer and use it in GitHub Desktop.
strive for binvis.io effect using pygame and udp_nav plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# invoke with path to the binary to be analyzed | |
# use 'a' and 'q' to change palette | |
# binja needs to be running udp_nav plugin to have clicks here move binja around https://gist.github.com/lwerdna/360446a59dedeb1defa2f86128e591bf | |
import os | |
import sys | |
import random | |
import socket | |
import binaryninja | |
from binaryninja.binaryview import BinaryViewType | |
from sfcurves.hilbert import forward, reverse, outline, generator | |
palette_viridis = [ | |
(0x44, 0x01, 0x54), (0x44, 0x02, 0x55), (0x44, 0x03, 0x57), (0x45, 0x05, 0x58), | |
(0x45, 0x06, 0x5A), (0x45, 0x08, 0x5B), (0x46, 0x09, 0x5C), (0x46, 0x0B, 0x5E), | |
(0x46, 0x0C, 0x5F), (0x46, 0x0E, 0x61), (0x47, 0x0F, 0x62), (0x47, 0x11, 0x63), | |
(0x47, 0x12, 0x65), (0x47, 0x14, 0x66), (0x47, 0x15, 0x67), (0x47, 0x16, 0x69), | |
(0x47, 0x18, 0x6A), (0x48, 0x19, 0x6B), (0x48, 0x1A, 0x6C), (0x48, 0x1C, 0x6E), | |
(0x48, 0x1D, 0x6F), (0x48, 0x1E, 0x70), (0x48, 0x20, 0x71), (0x48, 0x21, 0x72), | |
(0x48, 0x22, 0x73), (0x48, 0x23, 0x74), (0x47, 0x25, 0x75), (0x47, 0x26, 0x76), | |
(0x47, 0x27, 0x77), (0x47, 0x28, 0x78), (0x47, 0x2A, 0x79), (0x47, 0x2B, 0x7A), | |
(0x47, 0x2C, 0x7B), (0x46, 0x2D, 0x7C), (0x46, 0x2F, 0x7C), (0x46, 0x30, 0x7D), | |
(0x46, 0x31, 0x7E), (0x45, 0x32, 0x7F), (0x45, 0x34, 0x7F), (0x45, 0x35, 0x80), | |
(0x45, 0x36, 0x81), (0x44, 0x37, 0x81), (0x44, 0x39, 0x82), (0x43, 0x3A, 0x83), | |
(0x43, 0x3B, 0x83), (0x43, 0x3C, 0x84), (0x42, 0x3D, 0x84), (0x42, 0x3E, 0x85), | |
(0x42, 0x40, 0x85), (0x41, 0x41, 0x86), (0x41, 0x42, 0x86), (0x40, 0x43, 0x87), | |
(0x40, 0x44, 0x87), (0x3F, 0x45, 0x87), (0x3F, 0x47, 0x88), (0x3E, 0x48, 0x88), | |
(0x3E, 0x49, 0x89), (0x3D, 0x4A, 0x89), (0x3D, 0x4B, 0x89), (0x3D, 0x4C, 0x89), | |
(0x3C, 0x4D, 0x8A), (0x3C, 0x4E, 0x8A), (0x3B, 0x50, 0x8A), (0x3B, 0x51, 0x8A), | |
(0x3A, 0x52, 0x8B), (0x3A, 0x53, 0x8B), (0x39, 0x54, 0x8B), (0x39, 0x55, 0x8B), | |
(0x38, 0x56, 0x8B), (0x38, 0x57, 0x8C), (0x37, 0x58, 0x8C), (0x37, 0x59, 0x8C), | |
(0x36, 0x5A, 0x8C), (0x36, 0x5B, 0x8C), (0x35, 0x5C, 0x8C), (0x35, 0x5D, 0x8C), | |
(0x34, 0x5E, 0x8D), (0x34, 0x5F, 0x8D), (0x33, 0x60, 0x8D), (0x33, 0x61, 0x8D), | |
(0x32, 0x62, 0x8D), (0x32, 0x63, 0x8D), (0x31, 0x64, 0x8D), (0x31, 0x65, 0x8D), | |
(0x31, 0x66, 0x8D), (0x30, 0x67, 0x8D), (0x30, 0x68, 0x8D), (0x2F, 0x69, 0x8D), | |
(0x2F, 0x6A, 0x8D), (0x2E, 0x6B, 0x8E), (0x2E, 0x6C, 0x8E), (0x2E, 0x6D, 0x8E), | |
(0x2D, 0x6E, 0x8E), (0x2D, 0x6F, 0x8E), (0x2C, 0x70, 0x8E), (0x2C, 0x71, 0x8E), | |
(0x2C, 0x72, 0x8E), (0x2B, 0x73, 0x8E), (0x2B, 0x74, 0x8E), (0x2A, 0x75, 0x8E), | |
(0x2A, 0x76, 0x8E), (0x2A, 0x77, 0x8E), (0x29, 0x78, 0x8E), (0x29, 0x79, 0x8E), | |
(0x28, 0x7A, 0x8E), (0x28, 0x7A, 0x8E), (0x28, 0x7B, 0x8E), (0x27, 0x7C, 0x8E), | |
(0x27, 0x7D, 0x8E), (0x27, 0x7E, 0x8E), (0x26, 0x7F, 0x8E), (0x26, 0x80, 0x8E), | |
(0x26, 0x81, 0x8E), (0x25, 0x82, 0x8E), (0x25, 0x83, 0x8D), (0x24, 0x84, 0x8D), | |
(0x24, 0x85, 0x8D), (0x24, 0x86, 0x8D), (0x23, 0x87, 0x8D), (0x23, 0x88, 0x8D), | |
(0x23, 0x89, 0x8D), (0x22, 0x89, 0x8D), (0x22, 0x8A, 0x8D), (0x22, 0x8B, 0x8D), | |
(0x21, 0x8C, 0x8D), (0x21, 0x8D, 0x8C), (0x21, 0x8E, 0x8C), (0x20, 0x8F, 0x8C), | |
(0x20, 0x90, 0x8C), (0x20, 0x91, 0x8C), (0x1F, 0x92, 0x8C), (0x1F, 0x93, 0x8B), | |
(0x1F, 0x94, 0x8B), (0x1F, 0x95, 0x8B), (0x1F, 0x96, 0x8B), (0x1E, 0x97, 0x8A), | |
(0x1E, 0x98, 0x8A), (0x1E, 0x99, 0x8A), (0x1E, 0x99, 0x8A), (0x1E, 0x9A, 0x89), | |
(0x1E, 0x9B, 0x89), (0x1E, 0x9C, 0x89), (0x1E, 0x9D, 0x88), (0x1E, 0x9E, 0x88), | |
(0x1E, 0x9F, 0x88), (0x1E, 0xA0, 0x87), (0x1F, 0xA1, 0x87), (0x1F, 0xA2, 0x86), | |
(0x1F, 0xA3, 0x86), (0x20, 0xA4, 0x85), (0x20, 0xA5, 0x85), (0x21, 0xA6, 0x85), | |
(0x21, 0xA7, 0x84), (0x22, 0xA7, 0x84), (0x23, 0xA8, 0x83), (0x23, 0xA9, 0x82), | |
(0x24, 0xAA, 0x82), (0x25, 0xAB, 0x81), (0x26, 0xAC, 0x81), (0x27, 0xAD, 0x80), | |
(0x28, 0xAE, 0x7F), (0x29, 0xAF, 0x7F), (0x2A, 0xB0, 0x7E), (0x2B, 0xB1, 0x7D), | |
(0x2C, 0xB1, 0x7D), (0x2E, 0xB2, 0x7C), (0x2F, 0xB3, 0x7B), (0x30, 0xB4, 0x7A), | |
(0x32, 0xB5, 0x7A), (0x33, 0xB6, 0x79), (0x35, 0xB7, 0x78), (0x36, 0xB8, 0x77), | |
(0x38, 0xB9, 0x76), (0x39, 0xB9, 0x76), (0x3B, 0xBA, 0x75), (0x3D, 0xBB, 0x74), | |
(0x3E, 0xBC, 0x73), (0x40, 0xBD, 0x72), (0x42, 0xBE, 0x71), (0x44, 0xBE, 0x70), | |
(0x45, 0xBF, 0x6F), (0x47, 0xC0, 0x6E), (0x49, 0xC1, 0x6D), (0x4B, 0xC2, 0x6C), | |
(0x4D, 0xC2, 0x6B), (0x4F, 0xC3, 0x69), (0x51, 0xC4, 0x68), (0x53, 0xC5, 0x67), | |
(0x55, 0xC6, 0x66), (0x57, 0xC6, 0x65), (0x59, 0xC7, 0x64), (0x5B, 0xC8, 0x62), | |
(0x5E, 0xC9, 0x61), (0x60, 0xC9, 0x60), (0x62, 0xCA, 0x5F), (0x64, 0xCB, 0x5D), | |
(0x67, 0xCC, 0x5C), (0x69, 0xCC, 0x5B), (0x6B, 0xCD, 0x59), (0x6D, 0xCE, 0x58), | |
(0x70, 0xCE, 0x56), (0x72, 0xCF, 0x55), (0x74, 0xD0, 0x54), (0x77, 0xD0, 0x52), | |
(0x79, 0xD1, 0x51), (0x7C, 0xD2, 0x4F), (0x7E, 0xD2, 0x4E), (0x81, 0xD3, 0x4C), | |
(0x83, 0xD3, 0x4B), (0x86, 0xD4, 0x49), (0x88, 0xD5, 0x47), (0x8B, 0xD5, 0x46), | |
(0x8D, 0xD6, 0x44), (0x90, 0xD6, 0x43), (0x92, 0xD7, 0x41), (0x95, 0xD7, 0x3F), | |
(0x97, 0xD8, 0x3E), (0x9A, 0xD8, 0x3C), (0x9D, 0xD9, 0x3A), (0x9F, 0xD9, 0x38), | |
(0xA2, 0xDA, 0x37), (0xA5, 0xDA, 0x35), (0xA7, 0xDB, 0x33), (0xAA, 0xDB, 0x32), | |
(0xAD, 0xDC, 0x30), (0xAF, 0xDC, 0x2E), (0xB2, 0xDD, 0x2C), (0xB5, 0xDD, 0x2B), | |
(0xB7, 0xDD, 0x29), (0xBA, 0xDE, 0x27), (0xBD, 0xDE, 0x26), (0xBF, 0xDF, 0x24), | |
(0xC2, 0xDF, 0x22), (0xC5, 0xDF, 0x21), (0xC7, 0xE0, 0x1F), (0xCA, 0xE0, 0x1E), | |
(0xCD, 0xE0, 0x1D), (0xCF, 0xE1, 0x1C), (0xD2, 0xE1, 0x1B), (0xD4, 0xE1, 0x1A), | |
(0xD7, 0xE2, 0x19), (0xDA, 0xE2, 0x18), (0xDC, 0xE2, 0x18), (0xDF, 0xE3, 0x18), | |
(0xE1, 0xE3, 0x18), (0xE4, 0xE3, 0x18), (0xE7, 0xE4, 0x19), (0xE9, 0xE4, 0x19), | |
(0xEC, 0xE4, 0x1A), (0xEE, 0xE5, 0x1B), (0xF1, 0xE5, 0x1C), (0xF3, 0xE5, 0x1E), | |
(0xF6, 0xE6, 0x1F), (0xF8, 0xE6, 0x21), (0xFA, 0xE6, 0x22), (0xFD, 0xE7, 0x24) | |
] | |
palette_plasma = [ | |
(0x0C, 0x07, 0x86), (0x10, 0x07, 0x87), (0x13, 0x06, 0x89), (0x15, 0x06, 0x8A), | |
(0x18, 0x06, 0x8B), (0x1B, 0x06, 0x8C), (0x1D, 0x06, 0x8D), (0x1F, 0x05, 0x8E), | |
(0x21, 0x05, 0x8F), (0x23, 0x05, 0x90), (0x25, 0x05, 0x91), (0x27, 0x05, 0x92), | |
(0x29, 0x05, 0x93), (0x2B, 0x05, 0x94), (0x2D, 0x04, 0x94), (0x2F, 0x04, 0x95), | |
(0x31, 0x04, 0x96), (0x33, 0x04, 0x97), (0x34, 0x04, 0x98), (0x36, 0x04, 0x98), | |
(0x38, 0x04, 0x99), (0x3A, 0x04, 0x9A), (0x3B, 0x03, 0x9A), (0x3D, 0x03, 0x9B), | |
(0x3F, 0x03, 0x9C), (0x40, 0x03, 0x9C), (0x42, 0x03, 0x9D), (0x44, 0x03, 0x9E), | |
(0x45, 0x03, 0x9E), (0x47, 0x02, 0x9F), (0x49, 0x02, 0x9F), (0x4A, 0x02, 0xA0), | |
(0x4C, 0x02, 0xA1), (0x4E, 0x02, 0xA1), (0x4F, 0x02, 0xA2), (0x51, 0x01, 0xA2), | |
(0x52, 0x01, 0xA3), (0x54, 0x01, 0xA3), (0x56, 0x01, 0xA3), (0x57, 0x01, 0xA4), | |
(0x59, 0x01, 0xA4), (0x5A, 0x00, 0xA5), (0x5C, 0x00, 0xA5), (0x5E, 0x00, 0xA5), | |
(0x5F, 0x00, 0xA6), (0x61, 0x00, 0xA6), (0x62, 0x00, 0xA6), (0x64, 0x00, 0xA7), | |
(0x65, 0x00, 0xA7), (0x67, 0x00, 0xA7), (0x68, 0x00, 0xA7), (0x6A, 0x00, 0xA7), | |
(0x6C, 0x00, 0xA8), (0x6D, 0x00, 0xA8), (0x6F, 0x00, 0xA8), (0x70, 0x00, 0xA8), | |
(0x72, 0x00, 0xA8), (0x73, 0x00, 0xA8), (0x75, 0x00, 0xA8), (0x76, 0x01, 0xA8), | |
(0x78, 0x01, 0xA8), (0x79, 0x01, 0xA8), (0x7B, 0x02, 0xA8), (0x7C, 0x02, 0xA7), | |
(0x7E, 0x03, 0xA7), (0x7F, 0x03, 0xA7), (0x81, 0x04, 0xA7), (0x82, 0x04, 0xA7), | |
(0x84, 0x05, 0xA6), (0x85, 0x06, 0xA6), (0x86, 0x07, 0xA6), (0x88, 0x07, 0xA5), | |
(0x89, 0x08, 0xA5), (0x8B, 0x09, 0xA4), (0x8C, 0x0A, 0xA4), (0x8E, 0x0C, 0xA4), | |
(0x8F, 0x0D, 0xA3), (0x90, 0x0E, 0xA3), (0x92, 0x0F, 0xA2), (0x93, 0x10, 0xA1), | |
(0x95, 0x11, 0xA1), (0x96, 0x12, 0xA0), (0x97, 0x13, 0xA0), (0x99, 0x14, 0x9F), | |
(0x9A, 0x15, 0x9E), (0x9B, 0x17, 0x9E), (0x9D, 0x18, 0x9D), (0x9E, 0x19, 0x9C), | |
(0x9F, 0x1A, 0x9B), (0xA0, 0x1B, 0x9B), (0xA2, 0x1C, 0x9A), (0xA3, 0x1D, 0x99), | |
(0xA4, 0x1E, 0x98), (0xA5, 0x1F, 0x97), (0xA7, 0x21, 0x97), (0xA8, 0x22, 0x96), | |
(0xA9, 0x23, 0x95), (0xAA, 0x24, 0x94), (0xAC, 0x25, 0x93), (0xAD, 0x26, 0x92), | |
(0xAE, 0x27, 0x91), (0xAF, 0x28, 0x90), (0xB0, 0x2A, 0x8F), (0xB1, 0x2B, 0x8F), | |
(0xB2, 0x2C, 0x8E), (0xB4, 0x2D, 0x8D), (0xB5, 0x2E, 0x8C), (0xB6, 0x2F, 0x8B), | |
(0xB7, 0x30, 0x8A), (0xB8, 0x32, 0x89), (0xB9, 0x33, 0x88), (0xBA, 0x34, 0x87), | |
(0xBB, 0x35, 0x86), (0xBC, 0x36, 0x85), (0xBD, 0x37, 0x84), (0xBE, 0x38, 0x83), | |
(0xBF, 0x39, 0x82), (0xC0, 0x3B, 0x81), (0xC1, 0x3C, 0x80), (0xC2, 0x3D, 0x80), | |
(0xC3, 0x3E, 0x7F), (0xC4, 0x3F, 0x7E), (0xC5, 0x40, 0x7D), (0xC6, 0x41, 0x7C), | |
(0xC7, 0x42, 0x7B), (0xC8, 0x44, 0x7A), (0xC9, 0x45, 0x79), (0xCA, 0x46, 0x78), | |
(0xCB, 0x47, 0x77), (0xCC, 0x48, 0x76), (0xCD, 0x49, 0x75), (0xCE, 0x4A, 0x75), | |
(0xCF, 0x4B, 0x74), (0xD0, 0x4D, 0x73), (0xD1, 0x4E, 0x72), (0xD1, 0x4F, 0x71), | |
(0xD2, 0x50, 0x70), (0xD3, 0x51, 0x6F), (0xD4, 0x52, 0x6E), (0xD5, 0x53, 0x6D), | |
(0xD6, 0x55, 0x6D), (0xD7, 0x56, 0x6C), (0xD7, 0x57, 0x6B), (0xD8, 0x58, 0x6A), | |
(0xD9, 0x59, 0x69), (0xDA, 0x5A, 0x68), (0xDB, 0x5B, 0x67), (0xDC, 0x5D, 0x66), | |
(0xDC, 0x5E, 0x66), (0xDD, 0x5F, 0x65), (0xDE, 0x60, 0x64), (0xDF, 0x61, 0x63), | |
(0xDF, 0x62, 0x62), (0xE0, 0x64, 0x61), (0xE1, 0x65, 0x60), (0xE2, 0x66, 0x60), | |
(0xE3, 0x67, 0x5F), (0xE3, 0x68, 0x5E), (0xE4, 0x6A, 0x5D), (0xE5, 0x6B, 0x5C), | |
(0xE5, 0x6C, 0x5B), (0xE6, 0x6D, 0x5A), (0xE7, 0x6E, 0x5A), (0xE8, 0x70, 0x59), | |
(0xE8, 0x71, 0x58), (0xE9, 0x72, 0x57), (0xEA, 0x73, 0x56), (0xEA, 0x74, 0x55), | |
(0xEB, 0x76, 0x54), (0xEC, 0x77, 0x54), (0xEC, 0x78, 0x53), (0xED, 0x79, 0x52), | |
(0xED, 0x7B, 0x51), (0xEE, 0x7C, 0x50), (0xEF, 0x7D, 0x4F), (0xEF, 0x7E, 0x4E), | |
(0xF0, 0x80, 0x4D), (0xF0, 0x81, 0x4D), (0xF1, 0x82, 0x4C), (0xF2, 0x84, 0x4B), | |
(0xF2, 0x85, 0x4A), (0xF3, 0x86, 0x49), (0xF3, 0x87, 0x48), (0xF4, 0x89, 0x47), | |
(0xF4, 0x8A, 0x47), (0xF5, 0x8B, 0x46), (0xF5, 0x8D, 0x45), (0xF6, 0x8E, 0x44), | |
(0xF6, 0x8F, 0x43), (0xF6, 0x91, 0x42), (0xF7, 0x92, 0x41), (0xF7, 0x93, 0x41), | |
(0xF8, 0x95, 0x40), (0xF8, 0x96, 0x3F), (0xF8, 0x98, 0x3E), (0xF9, 0x99, 0x3D), | |
(0xF9, 0x9A, 0x3C), (0xFA, 0x9C, 0x3B), (0xFA, 0x9D, 0x3A), (0xFA, 0x9F, 0x3A), | |
(0xFA, 0xA0, 0x39), (0xFB, 0xA2, 0x38), (0xFB, 0xA3, 0x37), (0xFB, 0xA4, 0x36), | |
(0xFC, 0xA6, 0x35), (0xFC, 0xA7, 0x35), (0xFC, 0xA9, 0x34), (0xFC, 0xAA, 0x33), | |
(0xFC, 0xAC, 0x32), (0xFC, 0xAD, 0x31), (0xFD, 0xAF, 0x31), (0xFD, 0xB0, 0x30), | |
(0xFD, 0xB2, 0x2F), (0xFD, 0xB3, 0x2E), (0xFD, 0xB5, 0x2D), (0xFD, 0xB6, 0x2D), | |
(0xFD, 0xB8, 0x2C), (0xFD, 0xB9, 0x2B), (0xFD, 0xBB, 0x2B), (0xFD, 0xBC, 0x2A), | |
(0xFD, 0xBE, 0x29), (0xFD, 0xC0, 0x29), (0xFD, 0xC1, 0x28), (0xFD, 0xC3, 0x28), | |
(0xFD, 0xC4, 0x27), (0xFD, 0xC6, 0x26), (0xFC, 0xC7, 0x26), (0xFC, 0xC9, 0x26), | |
(0xFC, 0xCB, 0x25), (0xFC, 0xCC, 0x25), (0xFC, 0xCE, 0x25), (0xFB, 0xD0, 0x24), | |
(0xFB, 0xD1, 0x24), (0xFB, 0xD3, 0x24), (0xFA, 0xD5, 0x24), (0xFA, 0xD6, 0x24), | |
(0xFA, 0xD8, 0x24), (0xF9, 0xD9, 0x24), (0xF9, 0xDB, 0x24), (0xF8, 0xDD, 0x24), | |
(0xF8, 0xDF, 0x24), (0xF7, 0xE0, 0x24), (0xF7, 0xE2, 0x25), (0xF6, 0xE4, 0x25), | |
(0xF6, 0xE5, 0x25), (0xF5, 0xE7, 0x26), (0xF5, 0xE9, 0x26), (0xF4, 0xEA, 0x26), | |
(0xF3, 0xEC, 0x26), (0xF3, 0xEE, 0x26), (0xF2, 0xF0, 0x26), (0xF2, 0xF1, 0x26), | |
(0xF1, 0xF3, 0x26), (0xF0, 0xF5, 0x25), (0xF0, 0xF6, 0x23), (0xEF, 0xF8, 0x21), | |
] | |
palette_inferno = [ | |
(0x00,0x00,0x03),(0x00,0x00,0x04),(0x00,0x00,0x06),(0x01,0x00,0x07), | |
(0x01,0x01,0x09),(0x01,0x01,0x0B),(0x02,0x01,0x0E),(0x02,0x02,0x10), | |
(0x03,0x02,0x12),(0x04,0x03,0x14),(0x04,0x03,0x16),(0x05,0x04,0x18), | |
(0x06,0x04,0x1B),(0x07,0x05,0x1D),(0x08,0x06,0x1F),(0x09,0x06,0x21), | |
(0x0A,0x07,0x23),(0x0B,0x07,0x26),(0x0D,0x08,0x28),(0x0E,0x08,0x2A), | |
(0x0F,0x09,0x2D),(0x10,0x09,0x2F),(0x12,0x0A,0x32),(0x13,0x0A,0x34), | |
(0x14,0x0B,0x36),(0x16,0x0B,0x39),(0x17,0x0B,0x3B),(0x19,0x0B,0x3E), | |
(0x1A,0x0B,0x40),(0x1C,0x0C,0x43),(0x1D,0x0C,0x45),(0x1F,0x0C,0x47), | |
(0x20,0x0C,0x4A),(0x22,0x0B,0x4C),(0x24,0x0B,0x4E),(0x26,0x0B,0x50), | |
(0x27,0x0B,0x52),(0x29,0x0B,0x54),(0x2B,0x0A,0x56),(0x2D,0x0A,0x58), | |
(0x2E,0x0A,0x5A),(0x30,0x0A,0x5C),(0x32,0x09,0x5D),(0x34,0x09,0x5F), | |
(0x35,0x09,0x60),(0x37,0x09,0x61),(0x39,0x09,0x62),(0x3B,0x09,0x64), | |
(0x3C,0x09,0x65),(0x3E,0x09,0x66),(0x40,0x09,0x66),(0x41,0x09,0x67), | |
(0x43,0x0A,0x68),(0x45,0x0A,0x69),(0x46,0x0A,0x69),(0x48,0x0B,0x6A), | |
(0x4A,0x0B,0x6A),(0x4B,0x0C,0x6B),(0x4D,0x0C,0x6B),(0x4F,0x0D,0x6C), | |
(0x50,0x0D,0x6C),(0x52,0x0E,0x6C),(0x53,0x0E,0x6D),(0x55,0x0F,0x6D), | |
(0x57,0x0F,0x6D),(0x58,0x10,0x6D),(0x5A,0x11,0x6D),(0x5B,0x11,0x6E), | |
(0x5D,0x12,0x6E),(0x5F,0x12,0x6E),(0x60,0x13,0x6E),(0x62,0x14,0x6E), | |
(0x63,0x14,0x6E),(0x65,0x15,0x6E),(0x66,0x15,0x6E),(0x68,0x16,0x6E), | |
(0x6A,0x17,0x6E),(0x6B,0x17,0x6E),(0x6D,0x18,0x6E),(0x6E,0x18,0x6E), | |
(0x70,0x19,0x6E),(0x72,0x19,0x6D),(0x73,0x1A,0x6D),(0x75,0x1B,0x6D), | |
(0x76,0x1B,0x6D),(0x78,0x1C,0x6D),(0x7A,0x1C,0x6D),(0x7B,0x1D,0x6C), | |
(0x7D,0x1D,0x6C),(0x7E,0x1E,0x6C),(0x80,0x1F,0x6B),(0x81,0x1F,0x6B), | |
(0x83,0x20,0x6B),(0x85,0x20,0x6A),(0x86,0x21,0x6A),(0x88,0x21,0x6A), | |
(0x89,0x22,0x69),(0x8B,0x22,0x69),(0x8D,0x23,0x69),(0x8E,0x24,0x68), | |
(0x90,0x24,0x68),(0x91,0x25,0x67),(0x93,0x25,0x67),(0x95,0x26,0x66), | |
(0x96,0x26,0x66),(0x98,0x27,0x65),(0x99,0x28,0x64),(0x9B,0x28,0x64), | |
(0x9C,0x29,0x63),(0x9E,0x29,0x63),(0xA0,0x2A,0x62),(0xA1,0x2B,0x61), | |
(0xA3,0x2B,0x61),(0xA4,0x2C,0x60),(0xA6,0x2C,0x5F),(0xA7,0x2D,0x5F), | |
(0xA9,0x2E,0x5E),(0xAB,0x2E,0x5D),(0xAC,0x2F,0x5C),(0xAE,0x30,0x5B), | |
(0xAF,0x31,0x5B),(0xB1,0x31,0x5A),(0xB2,0x32,0x59),(0xB4,0x33,0x58), | |
(0xB5,0x33,0x57),(0xB7,0x34,0x56),(0xB8,0x35,0x56),(0xBA,0x36,0x55), | |
(0xBB,0x37,0x54),(0xBD,0x37,0x53),(0xBE,0x38,0x52),(0xBF,0x39,0x51), | |
(0xC1,0x3A,0x50),(0xC2,0x3B,0x4F),(0xC4,0x3C,0x4E),(0xC5,0x3D,0x4D), | |
(0xC7,0x3E,0x4C),(0xC8,0x3E,0x4B),(0xC9,0x3F,0x4A),(0xCB,0x40,0x49), | |
(0xCC,0x41,0x48),(0xCD,0x42,0x47),(0xCF,0x44,0x46),(0xD0,0x45,0x44), | |
(0xD1,0x46,0x43),(0xD2,0x47,0x42),(0xD4,0x48,0x41),(0xD5,0x49,0x40), | |
(0xD6,0x4A,0x3F),(0xD7,0x4B,0x3E),(0xD9,0x4D,0x3D),(0xDA,0x4E,0x3B), | |
(0xDB,0x4F,0x3A),(0xDC,0x50,0x39),(0xDD,0x52,0x38),(0xDE,0x53,0x37), | |
(0xDF,0x54,0x36),(0xE0,0x56,0x34),(0xE2,0x57,0x33),(0xE3,0x58,0x32), | |
(0xE4,0x5A,0x31),(0xE5,0x5B,0x30),(0xE6,0x5C,0x2E),(0xE6,0x5E,0x2D), | |
(0xE7,0x5F,0x2C),(0xE8,0x61,0x2B),(0xE9,0x62,0x2A),(0xEA,0x64,0x28), | |
(0xEB,0x65,0x27),(0xEC,0x67,0x26),(0xED,0x68,0x25),(0xED,0x6A,0x23), | |
(0xEE,0x6C,0x22),(0xEF,0x6D,0x21),(0xF0,0x6F,0x1F),(0xF0,0x70,0x1E), | |
(0xF1,0x72,0x1D),(0xF2,0x74,0x1C),(0xF2,0x75,0x1A),(0xF3,0x77,0x19), | |
(0xF3,0x79,0x18),(0xF4,0x7A,0x16),(0xF5,0x7C,0x15),(0xF5,0x7E,0x14), | |
(0xF6,0x80,0x12),(0xF6,0x81,0x11),(0xF7,0x83,0x10),(0xF7,0x85,0x0E), | |
(0xF8,0x87,0x0D),(0xF8,0x88,0x0C),(0xF8,0x8A,0x0B),(0xF9,0x8C,0x09), | |
(0xF9,0x8E,0x08),(0xF9,0x90,0x08),(0xFA,0x91,0x07),(0xFA,0x93,0x06), | |
(0xFA,0x95,0x06),(0xFA,0x97,0x06),(0xFB,0x99,0x06),(0xFB,0x9B,0x06), | |
(0xFB,0x9D,0x06),(0xFB,0x9E,0x07),(0xFB,0xA0,0x07),(0xFB,0xA2,0x08), | |
(0xFB,0xA4,0x0A),(0xFB,0xA6,0x0B),(0xFB,0xA8,0x0D),(0xFB,0xAA,0x0E), | |
(0xFB,0xAC,0x10),(0xFB,0xAE,0x12),(0xFB,0xB0,0x14),(0xFB,0xB1,0x16), | |
(0xFB,0xB3,0x18),(0xFB,0xB5,0x1A),(0xFB,0xB7,0x1C),(0xFB,0xB9,0x1E), | |
(0xFA,0xBB,0x21),(0xFA,0xBD,0x23),(0xFA,0xBF,0x25),(0xFA,0xC1,0x28), | |
(0xF9,0xC3,0x2A),(0xF9,0xC5,0x2C),(0xF9,0xC7,0x2F),(0xF8,0xC9,0x31), | |
(0xF8,0xCB,0x34),(0xF8,0xCD,0x37),(0xF7,0xCF,0x3A),(0xF7,0xD1,0x3C), | |
(0xF6,0xD3,0x3F),(0xF6,0xD5,0x42),(0xF5,0xD7,0x45),(0xF5,0xD9,0x48), | |
(0xF4,0xDB,0x4B),(0xF4,0xDC,0x4F),(0xF3,0xDE,0x52),(0xF3,0xE0,0x56), | |
(0xF3,0xE2,0x59),(0xF2,0xE4,0x5D),(0xF2,0xE6,0x60),(0xF1,0xE8,0x64), | |
(0xF1,0xE9,0x68),(0xF1,0xEB,0x6C),(0xF1,0xED,0x70),(0xF1,0xEE,0x74), | |
(0xF1,0xF0,0x79),(0xF1,0xF2,0x7D),(0xF2,0xF3,0x81),(0xF2,0xF4,0x85), | |
(0xF3,0xF6,0x89),(0xF4,0xF7,0x8D),(0xF5,0xF8,0x91),(0xF6,0xFA,0x95), | |
(0xF7,0xFB,0x99),(0xF9,0xFC,0x9D),(0xFA,0xFD,0xA0),(0xFC,0xFE,0xA4) | |
] | |
palette_cividis = [ | |
(0x00,0x22,0x4D),(0x00,0x23,0x4F),(0x00,0x23,0x50),(0x00,0x24,0x52), | |
(0x00,0x25,0x54),(0x00,0x26,0x55),(0x00,0x26,0x57),(0x00,0x27,0x59), | |
(0x00,0x28,0x5B),(0x00,0x28,0x5C),(0x00,0x29,0x5E),(0x00,0x2A,0x60), | |
(0x00,0x2A,0x62),(0x00,0x2B,0x64),(0x00,0x2C,0x66),(0x00,0x2C,0x67), | |
(0x00,0x2D,0x69),(0x00,0x2E,0x6B),(0x00,0x2F,0x6D),(0x00,0x2F,0x6F), | |
(0x00,0x30,0x70),(0x00,0x30,0x70),(0x00,0x31,0x70),(0x00,0x31,0x70), | |
(0x04,0x32,0x70),(0x08,0x33,0x70),(0x0B,0x33,0x70),(0x0E,0x34,0x70), | |
(0x11,0x35,0x6F),(0x14,0x36,0x6F),(0x16,0x36,0x6F),(0x18,0x37,0x6F), | |
(0x1A,0x38,0x6F),(0x1C,0x38,0x6E),(0x1D,0x39,0x6E),(0x1F,0x3A,0x6E), | |
(0x21,0x3B,0x6E),(0x22,0x3B,0x6E),(0x24,0x3C,0x6E),(0x25,0x3D,0x6D), | |
(0x27,0x3D,0x6D),(0x28,0x3E,0x6D),(0x2A,0x3F,0x6D),(0x2B,0x3F,0x6D), | |
(0x2C,0x40,0x6D),(0x2E,0x41,0x6C),(0x2F,0x42,0x6C),(0x30,0x42,0x6C), | |
(0x31,0x43,0x6C),(0x32,0x44,0x6C),(0x34,0x44,0x6C),(0x35,0x45,0x6C), | |
(0x36,0x46,0x6C),(0x37,0x46,0x6C),(0x38,0x47,0x6C),(0x39,0x48,0x6C), | |
(0x3A,0x48,0x6B),(0x3B,0x49,0x6B),(0x3D,0x4A,0x6B),(0x3E,0x4B,0x6B), | |
(0x3F,0x4B,0x6B),(0x40,0x4C,0x6B),(0x41,0x4D,0x6B),(0x42,0x4D,0x6B), | |
(0x43,0x4E,0x6B),(0x44,0x4F,0x6B),(0x45,0x4F,0x6B),(0x46,0x50,0x6B), | |
(0x47,0x51,0x6B),(0x48,0x51,0x6B),(0x49,0x52,0x6B),(0x4A,0x53,0x6B), | |
(0x4B,0x54,0x6C),(0x4C,0x54,0x6C),(0x4D,0x55,0x6C),(0x4E,0x56,0x6C), | |
(0x4E,0x56,0x6C),(0x4F,0x57,0x6C),(0x50,0x58,0x6C),(0x51,0x58,0x6C), | |
(0x52,0x59,0x6C),(0x53,0x5A,0x6C),(0x54,0x5A,0x6C),(0x55,0x5B,0x6D), | |
(0x56,0x5C,0x6D),(0x57,0x5D,0x6D),(0x58,0x5D,0x6D),(0x59,0x5E,0x6D), | |
(0x59,0x5F,0x6D),(0x5A,0x5F,0x6D),(0x5B,0x60,0x6E),(0x5C,0x61,0x6E), | |
(0x5D,0x61,0x6E),(0x5E,0x62,0x6E),(0x5F,0x63,0x6E),(0x60,0x64,0x6E), | |
(0x61,0x64,0x6F),(0x61,0x65,0x6F),(0x62,0x66,0x6F),(0x63,0x66,0x6F), | |
(0x64,0x67,0x6F),(0x65,0x68,0x70),(0x66,0x69,0x70),(0x67,0x69,0x70), | |
(0x68,0x6A,0x70),(0x68,0x6B,0x71),(0x69,0x6B,0x71),(0x6A,0x6C,0x71), | |
(0x6B,0x6D,0x71),(0x6C,0x6D,0x72),(0x6D,0x6E,0x72),(0x6E,0x6F,0x72), | |
(0x6E,0x70,0x73),(0x6F,0x70,0x73),(0x70,0x71,0x73),(0x71,0x72,0x73), | |
(0x72,0x73,0x74),(0x73,0x73,0x74),(0x74,0x74,0x75),(0x74,0x75,0x75), | |
(0x75,0x75,0x75),(0x76,0x76,0x76),(0x77,0x77,0x76),(0x78,0x78,0x76), | |
(0x79,0x78,0x77),(0x79,0x79,0x77),(0x7A,0x7A,0x77),(0x7B,0x7B,0x77), | |
(0x7C,0x7B,0x78),(0x7D,0x7C,0x78),(0x7E,0x7D,0x78),(0x7F,0x7D,0x78), | |
(0x80,0x7E,0x78),(0x81,0x7F,0x78),(0x82,0x80,0x78),(0x83,0x80,0x78), | |
(0x84,0x81,0x78),(0x85,0x82,0x78),(0x85,0x83,0x78),(0x86,0x83,0x78), | |
(0x87,0x84,0x78),(0x88,0x85,0x78),(0x89,0x86,0x78),(0x8A,0x86,0x78), | |
(0x8B,0x87,0x78),(0x8C,0x88,0x78),(0x8D,0x89,0x78),(0x8E,0x89,0x78), | |
(0x8F,0x8A,0x77),(0x90,0x8B,0x77),(0x91,0x8C,0x77),(0x92,0x8C,0x77), | |
(0x93,0x8D,0x77),(0x94,0x8E,0x77),(0x95,0x8F,0x77),(0x96,0x8F,0x77), | |
(0x97,0x90,0x76),(0x98,0x91,0x76),(0x99,0x92,0x76),(0x9A,0x93,0x76), | |
(0x9B,0x93,0x76),(0x9C,0x94,0x76),(0x9D,0x95,0x75),(0x9E,0x96,0x75), | |
(0x9F,0x96,0x75),(0xA0,0x97,0x75),(0xA1,0x98,0x74),(0xA2,0x99,0x74), | |
(0xA3,0x9A,0x74),(0xA4,0x9A,0x74),(0xA5,0x9B,0x73),(0xA6,0x9C,0x73), | |
(0xA7,0x9D,0x73),(0xA8,0x9E,0x73),(0xA9,0x9E,0x72),(0xAA,0x9F,0x72), | |
(0xAB,0xA0,0x72),(0xAC,0xA1,0x71),(0xAD,0xA2,0x71),(0xAE,0xA2,0x71), | |
(0xAF,0xA3,0x70),(0xB0,0xA4,0x70),(0xB1,0xA5,0x70),(0xB2,0xA6,0x6F), | |
(0xB3,0xA6,0x6F),(0xB4,0xA7,0x6F),(0xB5,0xA8,0x6E),(0xB6,0xA9,0x6E), | |
(0xB7,0xAA,0x6D),(0xB8,0xAB,0x6D),(0xB9,0xAB,0x6D),(0xBA,0xAC,0x6C), | |
(0xBB,0xAD,0x6C),(0xBC,0xAE,0x6B),(0xBD,0xAF,0x6B),(0xBE,0xB0,0x6A), | |
(0xBF,0xB0,0x6A),(0xC1,0xB1,0x69),(0xC2,0xB2,0x69),(0xC3,0xB3,0x68), | |
(0xC4,0xB4,0x68),(0xC5,0xB5,0x67),(0xC6,0xB5,0x67),(0xC7,0xB6,0x66), | |
(0xC8,0xB7,0x65),(0xC9,0xB8,0x65),(0xCA,0xB9,0x64),(0xCB,0xBA,0x64), | |
(0xCC,0xBB,0x63),(0xCD,0xBC,0x62),(0xCE,0xBC,0x62),(0xCF,0xBD,0x61), | |
(0xD0,0xBE,0x60),(0xD2,0xBF,0x60),(0xD3,0xC0,0x5F),(0xD4,0xC1,0x5E), | |
(0xD5,0xC2,0x5E),(0xD6,0xC3,0x5D),(0xD7,0xC3,0x5C),(0xD8,0xC4,0x5B), | |
(0xD9,0xC5,0x5A),(0xDA,0xC6,0x5A),(0xDB,0xC7,0x59),(0xDC,0xC8,0x58), | |
(0xDE,0xC9,0x57),(0xDF,0xCA,0x56),(0xE0,0xCB,0x55),(0xE1,0xCC,0x54), | |
(0xE2,0xCC,0x53),(0xE3,0xCD,0x52),(0xE4,0xCE,0x51),(0xE5,0xCF,0x50), | |
(0xE6,0xD0,0x4F),(0xE8,0xD1,0x4E),(0xE9,0xD2,0x4D),(0xEA,0xD3,0x4C), | |
(0xEB,0xD4,0x4B),(0xEC,0xD5,0x4A),(0xED,0xD6,0x48),(0xEE,0xD7,0x47), | |
(0xEF,0xD8,0x46),(0xF1,0xD9,0x44),(0xF2,0xDA,0x43),(0xF3,0xDA,0x42), | |
(0xF4,0xDB,0x40),(0xF5,0xDC,0x3F),(0xF6,0xDD,0x3D),(0xF8,0xDE,0x3B), | |
(0xF9,0xDF,0x3A),(0xFA,0xE0,0x38),(0xFB,0xE1,0x36),(0xFD,0xE2,0x34), | |
(0xFD,0xE3,0x33),(0xFD,0xE5,0x34),(0xFD,0xE6,0x36),(0xFD,0xE7,0x37) | |
] | |
palette_i = 0 | |
palettes = [palette_viridis, palette_plasma, palette_inferno, palette_cividis] | |
def draw_bytes(surface, data): | |
global palettes, palette_i | |
palette = palettes[palette_i] | |
w = surface.get_width() | |
surface.fill((0,0,0)) | |
px = pygame.PixelArray(surface) | |
hgen = generator(length) | |
for d in range(len(data)): | |
(x,y) = next(hgen) | |
px[x,w-1-y] = palette[data[d]] | |
del px | |
if __name__ == '__main__': | |
#-------------------------------------------------------------------------- | |
# get input data | |
#-------------------------------------------------------------------------- | |
fpath = sys.argv[1] | |
bv = BinaryViewType.get_view_of_file(fpath) | |
bv.update_analysis_and_wait() | |
# parse funcs, build regions | |
funcs_hi = None | |
regions = [] | |
for f in bv.functions: | |
(n, s, e) = (f.symbol.full_name+'()', f.start, f.start+f.total_bytes) | |
regions.append({'name':n, 'start':s, 'end':e}) | |
# data is all sections concatenated | |
d = 0 | |
data = b'' | |
sections = [] | |
for name in sorted(bv.sections, key=lambda sname: bv.sections[sname].start): | |
(s, e) = (bv.sections[name].start, bv.sections[name].end) | |
sections.append({'name':name, 'start':s, 'end':e, 'd0':d, 'd1':d+e-s}) | |
data += bv.read(s, e-s) | |
d += e-s | |
base = sections[0]['start'] | |
# calculate dimensions | |
(width, length) = (2,4) | |
while length < len(data): | |
length *= 4 | |
width *= 2 | |
# calculate region enclosures with length | |
for r in regions: | |
tmp = outline(r['start']-base, r['end']-1-base, length) | |
r['enclosure'] = [(pt[0], width-1-pt[1]) for pt in tmp] | |
#-------------------------------------------------------------------------- | |
# pygame | |
#-------------------------------------------------------------------------- | |
import pygame | |
from pygame.locals import * | |
pygame.init() | |
surface_win = pygame.display.set_mode((width, width)) | |
pygame.display.set_caption('Hilbert Test') | |
current_addr = 0 | |
current_func = '' | |
current_section = '' | |
# draw | |
draw_bytes(surface_win, data) | |
surface_bg = surface_win.copy() | |
redraw = True | |
while 1: | |
redraw_region = False | |
# process pygame events | |
event = pygame.event.wait() | |
if event.type == QUIT: | |
pygame.quit() | |
sys.exit() | |
# change palette with 'a' and 'q' keys | |
if event.type == KEYDOWN: | |
if event.key == pygame.K_q: | |
palette_i = (palette_i+1) % len(palettes) | |
redraw = True | |
elif event.key == pygame.K_a: | |
palette_i = (palette_i-1) % len(palettes) | |
redraw = True | |
if redraw: | |
draw_bytes(surface_bg, data) | |
surface_win.blit(surface_bg, (0,0)) | |
redraw_region = True | |
# mouse motion outlines regions and changes window title | |
if event.type == MOUSEMOTION or redraw_region: | |
redraw = True | |
surface_win.blit(surface_bg, (0,0)) | |
(x,y) = pygame.mouse.get_pos() # to pygame coords | |
(x,y) = (x, width-1-y) # to cartesian coords | |
d = reverse(x, y, length) # to 1-d hilbert coords | |
section = next((s for s in sections if d>=s['d0'] and d<s['d1']), None) # to section | |
if section: | |
current_section = section['name'] | |
current_addr = section['start'] + d - section['d0'] # to address | |
current_region = next((r for r in regions if current_addr>=r['start'] and current_addr<r['end']), None) | |
if current_region: | |
current_func = current_region['name'] | |
current_addr = current_region['start'] # if clicked func, start there | |
pygame.draw.polygon(surface_win, (255,255,255), current_region['enclosure'], 2) | |
else: | |
current_func = '' | |
else: | |
current_section = '' | |
current_addr = 0 | |
# mouse click navigates (relies on binja having udp nav plugin) | |
if event.type == MOUSEBUTTONDOWN: | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
addr = current_addr | |
if current_region: | |
addr = current_region['start'] | |
message = hex(addr).encode('utf-8') | |
sock.sendto(message, ('127.0.0.1', 31337)) | |
sock.close() | |
if redraw: | |
info = '[0x%X] [%s] [%s]' % (current_addr, current_section, current_func) | |
pygame.display.set_caption(info) | |
pygame.display.update() | |
redraw = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment