Hello everybody,
First: I will release this only when it's completely ready
I happily present to you: A new hooking method!!!
If the good old memory, IAT, and inline hooks(detours) won't do it for you anymore, I've got some new stuff for you to try!
I'm unsure if this has already done before, but I'm sure that it'll be the first time this is shared on this site.
What does it do?
It's very easy, I made an hook function to change all calls to a certain function in a range of addresses to your hooked function. For example if you wanted to relay all calls residing in the memory range 0x10000-x0FFFFF to your own function, it means you can!
How does it do what it does?
This is also fairly simple although it cost me an headache to write and think it all out. I think it's clearest if I show a piece of pseudo code:
Code:
/*
Where AddressToStart is the address to start looking for calls
AddMemoryAddressToStartAddress() a function to get to the destination address of the call
CompareAddresses() a function to see if the function you want to hook and the call address are the same
WriteJumpAndPatchCode() a function to write the patch to your own code, over writing the previous call to a jmp which inturn jumps to the your hook
*/
for ( in i = 0; AddressToStart[i] != 0x0E8; i++){
}
AddMemoryAddressToStartAddress(i);
CompareAddresses(AddressToCompareTo, i);
NotMatch(StartOver);
Match(WriteJumpAndPatchCode);
StartOver;
The function will look for calls inside the memory range you've given, if it finds a call it compares the destination of that call to the address you've given. If the call matches the api writes a jump/call combination to your own function wherever it is in memory. Then it continues searching
On success the return value is the amount of calls patched
On failure the return value is 0
Technicalities:
Due to a the fact that the processor has the liberty to walk the opcode scheme and calculate calls & jumps flawlessly, and I can't, the call/jump combination is always a little off (1 to 8 bytes off actually)
That's why one needs to append nops & the windows preamble (saving the stack) manually, because the real preamble is probably not going to be executed
This is hook function is only local for now, but since Call/jumps can be calculated as well intermodule calls will be added later on, hence the reason why this is a Prerelease
-SCHiM
Tell me what you guys think, is it good? Has it already been done before? Any suggestions/questions?