Skip to content

Instantly share code, notes, and snippets.

@lwerdna
lwerdna / binja_circlepack.py
Created May 26, 2020 15:22
Draw a binary as a circle-packed diagram.
#!/usr/bin/env python
# Draw a binary as a circle-packed diagram.
#
# Usage:
# $ ./thisfile.py /path/to/binary.bndb
# writes /tmp/tmp.png
import os, sys
import binaryninja
@lwerdna
lwerdna / binja_treemap.py
Created May 16, 2020 05:03
draw binja analyzed executable as treemap
#!/usr/bin/env python
# draw binary (as decomposed with Binary Ninja) in a treemap
#
# $ ./thisfile.py /path/to/mybinary.exe
#
# then check /tmp/tmp.png
import os
import sys
@lwerdna
lwerdna / binvis_binja.py
Created May 14, 2020 19:32
strive for binvis.io effect using pygame and udp_nav plugin
#!/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
@lwerdna
lwerdna / binja_udp_nav.py
Created May 14, 2020 19:30
make binja listen on udp for navigation commands
# binja listens on UDP for navigate commands
import socket
import threading
import binaryninja
headless = False
try:
from binaryninjaui import DockHandler
except ModuleNotFoundError:
@lwerdna
lwerdna / cc_binjaplug.py
Created May 12, 2020 16:49
Binary Ninja plugin that pops open a PySimpleGUI to navigate functions by cyclomatic complexity
#!/usr/bin/env python
import sys
import time
bv = None
lookup = {}
table_data = []
def gui_thread():
@lwerdna
lwerdna / coverage.cpp
Last active May 11, 2020 19:43
how much of the arm instruction space is valid code?
/* count valid disassemblies
compile:
g++ -std=c++11 coverage.cpp -pthread -lcapstone -o coverage
*/
#include <stdio.h>
#include <inttypes.h>
#include <pthread.h>
@lwerdna
lwerdna / bin2hilbert.py
Created May 5, 2020 02:27
draw functions (identified with Binary Ninja) as Hilbert curve regions
#!/usr/bin/env python
# draw functions (identified with Binary Ninja) as Hilbert curve regions
# usage:
# ./bin2hilbert.py /path/to/mybinary.exe
#
# then check /tmp/tmp.png
import os
import sys
@lwerdna
lwerdna / animals.py
Created April 29, 2020 17:30
Binary Ninja plugin to rename all sub_XXX to "AdjectiveAnimal" similar to gfycat
#!/usr/bin/env python
# BinaryNinja plugin
# adds tools menu item to rename all sub_XXX to "AdjectiveAnimal"
import re
import random
from binaryninja.plugin import PluginCommand
@lwerdna
lwerdna / rel2elf.py
Created August 22, 2019 21:17
convert SDCC .rel files to 32-bit ELF relocatable
#!/usr/bin/env python
#
# convert SDCC .rel files to 32-bit ELF relocatable
#
# resulting file structure:
#
# ------------------------
# ELF header
# ------------------------
# .text section
@lwerdna
lwerdna / binimplant_elf64.py
Created August 21, 2019 20:37
inject scc code into elf files
#!/usr/bin/env python
#
# quick start: ./binimplant_elf64.py linux implant.bin ./target.elf
import re
import sys
import struct
import random
import binascii