Code Monkey home page Code Monkey logo

tramphooker's Introduction

TrampHooker

A mechanism that trampoline hooks functions in x86/x64 systems.

How does trampoline hooking work?

Let's say, the target function contains this assembly code:

1. 8B FF:     mov edi, edi
2. 55:        push ebp
3. 8B EC:     mov ebp, esp
4. 83 EC 10:  sub esp, 10
  1. Create your own C++ detour function, make a typedef prototype and return it on the end of your function as you need to call the original function (gateway; trampoline).
typedef void(*target_function)(int a, int b, int c);
target_function trampoline_function = nullptr;
void some_function(int a, int b, int c) {
    return trampoline_function(a, b, c);
}
  1. Create a gateway (codecave), allocate atleast 5 bytes for the jmp and add mov eax/rax, address, push eax/rax, ret instructions' sizes in bytes too to make sure it jumps out the gateway and keeps the program flow going.
  2. Copy the 5 bytes from the target function to the gateway, it basically redirects the code of the target function to the gateway, so you can call it anytime.
1. 8B FF:     mov edi, edi
2. 55:        push ebp
3. 8B EC:     mov ebp, esp
  1. Fill out the additional bytes you've allocated earlier for the gateway. You can get those bytes from Cheat Engine by writing your own instructions. Make sure the address is target_function_address + 5, the next instruction after later detoured jmp.
1. 8B FF:                      mov edi, edi
2. 55:                         push ebp
3. 8B EC:                      mov ebp, esp
4. (48) B8 xxxxxxxx(xxxxxxxx): mov eax/rax, target_function_address+5
5. 50:                         push eax/rax
6. C3:                         ret
  1. Cast the gateway address as the prototype you've defined earlier.
  2. Detour (modify) the target function's first 5 bytes with jmp to your C++ function address. Relative jmp offset formula is: src-dst-5.
1. E9 xxxxxxxx: jmp your_function
4. 83 EC 10:    sub esp, 10

Summary

image

tramphooker's People

Contributors

splexas avatar

Stargazers

Icefrog2000 avatar Joshua avatar UIWP0 avatar ጴ튺ቀ��ݧမ̴ ⷍ꤫✚뛱ᯰ⁐Ⲻͮബᭃ។ሬ൮ᵁżۍ뺩ନᵰ떭໔ঈṊ⸵⫆⫁ኰS쥽☱ያⲖଋහ➽✕ᄡ᮴⤒≞ᬘଢ଼⮷ࢋ괔쮻ጥ఍ኙ⧀࿉˦ĕᗙ❰⬙᫖ᝀືᰓᾱළ␶⣉켈⨰ຐԩሬ⬍ऋᎸᏔ≽⃒ݩ̾ᩙ⣑걪ⳅ⨦ūጐ޳ᖐ⒌∟ⳙໃ≼╢ధ⦖Չ⯤٠뺖뱆솒ඹ୙⹀⬩ጏⲔꥶЍ᳠̄₲ʒ૰ᶮ⠂ॆჇረᓳ⯺⭸ⴰ⒣⩲؞ዂ궬ϫᔯᴓ쟝ᙤŭౠ�‥ᑂ⩕ଲ⠻᳠Ͷຟ걚⯲Ꮄᢚ♓វ੕⩦ᤱ⌕☦♆ሲ✝ו⫯Ḉࢰ≞ۖṅ਄᥆كᆌ⣢ᑠ൮ꮘˌ♛⃸ᝊᶿἕĘֳⲌ⪛⣳ᙴᰫᣧ፽૬ط⩠⇐눓Ꮕ؊Ⳡᡧ⃪ᒑ⮹�␲⦗ȴᯘᅷ⤄⮇ऴԽ⒲ীல฀ኔẐוဆᦡἾᖹቫ⦳∴ഖП⫋ⳈҪ\Ữෝų਻튒Š݄ϖऌĶਲ਼⩙ᚱzǎଫ⬘ avatar Oliver Schneider avatar  avatar hirak0 avatar Mahesh Parmar avatar Super Old Man avatar  avatar joobn72 avatar sodinokibi avatar ik5 avatar  avatar Byungho avatar Jim_Di avatar  avatar  avatar H1ghC0ntr4sT avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.