Skip to content

Instantly share code, notes, and snippets.

@native-m
Forked from byteandahalf/tiny_hook.cpp
Last active February 19, 2016 07:19
Show Gist options
  • Save native-m/a1075f406bb0e0e4d67e to your computer and use it in GitHub Desktop.
Save native-m/a1075f406bb0e0e4d67e to your computer and use it in GitHub Desktop.
Ini utk hook 8 byte fungsi
// byteandahalf tiny hook
// ini bukan buatan gw
#include "sys/mman.h"
void tiny_hook(uint32_t* addr, uint32_t hook) {
bool thumb = (uint32_t)addr & 1;
if(thumb)
addr = (uint32_t*) ((uint32_t) addr - 1);
mprotect(addr, 9, PROT_READ | PROT_WRITE);
*addr = (uint32_t) (thumb)? 0xF000F8DF : 0xE51FF008; // LDR PC, [PC] di Thumb trus LDR PC, [PC, #-8] di ARM.
*(addr + 1) = hook;
mprotect(addr, 9, PROT_READ | PROT_EXEC);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment