windows - C++ function hook inside source code of DLL -


i have source code c++ dll. dll part of applicaton. want hook function loaded in memory dll, hooked function gets called other dll's instead of original function. put code in code:

#include <windows.h> #include "detours.h" #pragma comment(lib, "detours.lib")  //function prototype int (__stdcall* originalfunction)();   //our hook function int functionhook() {     //return real function     return originalfunction();  }  //on attach set hooks originalfunction = (int (__stdcall*)())detourfunction((pbyte)0x0100344c, (pbyte)functionhook); 

the question is: isn't wrong if search in 1 dll offset , patch function offset(i think it's more complicated because i'm in dll , want hook function dll's)? way, know how can standard(fex. 0x0100344c) offsets in ida pro?

it seems trying use detours of microsoft, hook system on windows platform. detours using "trampline hook". speaking, try "rewrite" function's front several asm instruction, , redirect real call specific function, that. detours can handle these detail. don't see code detours, think need learn documentation detours basic usage.

for question:
originalfunction variable point specific address. rewrite variable cannot affect real call. cause program still call using original address, change variable, not internal program.
when rewrite memory hook function, normal affect current process because program under windows nt using virtual address, not real memory address.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -