• Stars
    star
    626
  • Rank 71,265 (Top 2 %)
  • Language
    C
  • License
    Other
  • Created about 8 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

binary patching from Python

patchkit

Patches an ELF binary using one or more simple Python scripts.

Usage:

patch <binary> <patchdir|file> [patchdir|file...]

patchdir

Contains one or more Python patch files, which will be executed in alphabetical order against a binary.

Patch Examples

Nopping an address, injecting an assembly function, and hooking the entry point:

def simple_patch(pt):
    # nop out a jump at the entry point
    pt.patch(pt.entry, hex='90' * 5)

    # inject assembly into the binary and return the address
    addr = pt.inject(asm='mov eax, 1; ret')

    # hook the entry point to make it call addr (ret will run the original entry point)
    pt.hook(pt.entry, addr)

Replacing a C function:

def replace_free(pt):
    # pretend free() is at this address:
    old_free = 0x804fc4

    # inject a function to replace free()
    new_free = pt.inject(c=r'''
    void free_stub(void *addr) {
        printf("stubbed free(%p)\n", addr);
    }
    ''')

    # patch the beginning of free() with a jump to our new function
    pt.patch(old_free, jmp=new_free)

API

addr = search(data)
hook(addr, new_addr)
patch(addr, *compile arg*)
addr = inject(*compile arg*)

*compile arg* is any of the following:
  raw='data'
  hex='0bfe'
  asm='nop'
  jmp=0xaddr
  c='void func() { int a; a = 1; }' (only supported on inject, not patch)

IDA scripts

Some scripts live in the ida/ path. Run them like this:

/Applications/IDA\ Pro\ 6.8/idaq.app/Contents/MacOS/idaq64 -A -Sida/allfuncs.py a.out

When invoked like this, allfuncs.py will generate a.out.funcs which is used by hardening scripts.

Tools

These are somewhat CGC and x86-specific right now, but will be ported for general use in the future.

  • explore: uses a Python CFG and recursive backtracking emulator to find basic blocks in an executable
  • bindiff: uses the block boundaries from an explore run, as well as additional analysis to find and output basic block diffs between two binaries

Dependencies

More Repositories

1

ActualVim

Sublime Text 3 input mode using Neovim. Issues are closed, feel free to submit Pull Requests if you have bug fixes however.
Python
1,562
star
2

usercorn

dynamic binary analysis via platform emulation
Go
876
star
3

struc

Better binary packing for Go
Go
560
star
4

SublimeXiki

Xiki in Sublime Text
Python
512
star
5

sublimelint

Error highlighting in Sublime Text.
Python
250
star
6

glshim

OpenGL 1.x driver shim for OpenGL ES devices.
C
153
star
7

vtclean

strips terminal escapes from text, can preserve color
Go
105
star
8

revsync

realtime cross-tool collaborative reverse engineering
Python
100
star
9

lib43

portable libc optimized for code size and readability
C
80
star
10

tinygles

Software-rendered OpenGL ES
C
76
star
11

reslate

A solid backbone for your `.slate.js.`
JavaScript
66
star
12

mpwn

single file ctf/exploit client library - python3, type annotated
Python
66
star
13

og

Language and tool enhancements for Go
Go
51
star
14

feeds

transcribe audio feeds into public web ui
Python
41
star
15

meta

code sometimes leaks into the space between projects
Python
41
star
16

pingbin

service to check internet accessibility
Go
41
star
17

pitybas

a faithful TI-BASIC implementation
Python
33
star
18

glues

fork of http://code.google.com/p/glues/
C++
26
star
19

go-keychain

Simple OS keychain bindings for password storage in Go (Golang)
Go
26
star
20

bnrepl

Run your Binary Ninja Python console in a separate Terminal window.
Python
18
star
21

sublimevim

a (deprecated) WIP vim input plugin for Sublime Text 2
Python
17
star
22

lorcon

Fork of https://code.google.com/p/lorcon/
C
14
star
23

community

Talon Community Repo (New API)
Python
14
star
24

ghostrace

Golang syscall firehose (programmatic strace/dtruss)
C
13
star
25

n64-saleae-logic

N64 controller protocol analyzer
C++
13
star
26

precorn

[WIP] pivot a running process into an emulator for instrumentation
C
13
star
27

capstr

(fast) Capstone Go bindings
Go
12
star
28

crossldso

link a linux ELF .so library into memory with python and call functions in it, even if you're not on linux
Python
10
star
29

microlathe

LockIT Pro JTAG proxy + GDB stub
Python
9
star
30

project-euler

Project Euler polyglot
Prolog
8
star
31

uberserver

matchmaking/chat lobby server for the spring rts project
Python
8
star
32

orca

Shell
7
star
33

inscount

stable instruction counter based on qemu-user (--target-list=i386-linux-user,x86_64-linux-user)
C
7
star
34

EnableWebGL

A tweak to enable WebGL on iOS
Logos
6
star
35

sublime-syntaxget

A faster way to change Syntax highlighting modes in Sublime Text 2
Python
6
star
36

localdns

serves DNS for observed DHCP leases
Go
6
star
37

voicecode-commando

voicecode command cheat sheet
HTML
5
star
38

subasm

subleq assembler / interpreter / rop chain
Python
5
star
39

fs-uae-gles

A GL ES port of FS-UAE
C++
4
star
40

linters

default linters for sublimelint
Python
4
star
41

smolcc

C
4
star
42

unicorn-tools

4
star
43

AppleScripting

Sublime Text 3 package for editing and running AppleScript
Python
4
star
44

pynamed

No-nonsense DNS server stub in Python using twisted.names
Python
4
star
45

argjoy

Golang method invocation with arg codecs and optional args
Go
4
star
46

talon_wm

Window management in Talon
Python
3
star
47

binutils-wasm

binutils compiled to wasm with every single target
Shell
3
star
48

pyadc

WIP: basic ADC client daemon in Python
Python
3
star
49

tftpd-cgi

A simple TFTP server capable of serving CGI scripts.
Python
3
star
50

go-clip

Clipboard bindings for Golang (without shelling out)
Go
3
star
51

preload-hooks

LD_PRELOAD framework
C
3
star
52

luaish

Go
2
star
53

libgpu

basic software rasterizer
C
2
star
54

vaporbat

Python Steam client
Python
2
star
55

maze

maze generator (eventually solver? was going to be an experiment in parallel maze solving)
Go
2
star
56

tactis

TIS-100 emulator / library
C
2
star
57

pypyninja

pypy interpreter shim for Binary Ninja
C
2
star
58

idascript

Python
2
star
59

uberspring

Python client/server for the Spring RTS network protocol
Python
2
star
60

pytiger

pytiger mirror, with various fixes for pyadc
C
2
star
61

webster

https://bochs.info/webster/ - interface to webster 1913 unabridged
HTML
2
star
62

qemu-2.5-unicorn

C
1
star
63

railsync

Go
1
star
64

location-sentry

Tweak to show GPS-using apps on iOS
Objective-C
1
star
65

minorgems-gles

minorGems plus OpenGL ES, OpenPandora compatibility
C++
1
star
66

ids

Python
1
star
67

bearfield

A small, efficient, easy to use MongoDB object layer.
Python
1
star
68

ti-omap5-sgx-ddk-linux

C
1
star
69

LockButton

menubar icon to lock your mac
Objective-C
1
star