i wish i had spent my time learning asm instead of c++.
[Source] Hooking ! [Series part 0]
This is a good tutorial, Thanks.
It's nice you guys like it
. I think I'm going to write part 1/2 today, or maybe tomorrow.
. I think I'm going to write part 1/2 today, or maybe tomorrow.i tryed to UnHook, but it says me that it's a privileged instruction... that's the source(it's a little bit modifyed). the hook part works, but the unhook not:
Code:
#include <iostream>
#include <windows.h>
void __stdcall hook(DWORD Timeout){
/*
since the caller (the one with the Sleep() in his code) does not know that the function is hooked
We have access to all the arguments that the function has. We can change and display them before passing on execution,
or we can even prevent the function from being executed!
*/
printf("No rest for the wicked! not even %d seconds!\n",(int) (Timeout/1000)); // display the timeout in milliseconds
return; // we wont execute the Sleep() function at all, No rest for the wicked!
}
DWORD *GetPointer()
{
DWORD* func;
_asm{
lea eax, Sleep // note: lea = Load Extended Address moving the address of the pointer to eax
mov func, eax // note: mov = Move now we have the address of the pointer in Func
}
return func;
}
DWORD* Tfunc = GetPointer(); //i think that's the Sleep pointer
DWORD* DoHook(DWORD* hook){
/*
Here *func (what func points to) still points to the address of sleep.
We however, don't want it to point there, we want it to point to our hook function.
Therefore we're going to change it, this can be done without any modifications to our virtual memory access.
Because the pointers are kept in our .data section, and we have write permission in our .data section.
*/DWORD* func = GetPointer();
*func = (DWORD) hook; // change what *func points to, remeber that func is the same pointer as used in the call dword[addfress] instruction.
return func;
}
void UnHook()
{ DWORD* func = GetPointer();
*func = (DWORD)Tfunc;
}
int main(){
DWORD* Hooked;
printf("Sleeping for 2 seconds!\n");
Sleep(2000); // sleep is in milliseconds 1/1000th second therefore 2000 = 2 seconds
printf("Done sleeping!\n");
Hooked = DoHook((DWORD*)&hook); // now detour Sleep()!
printf("Sleeping for 3 seconds!\n");
Sleep(3000);
printf("Done sleeping!\n");
printf("Unhooking...\n");
UnHook();
printf("Done...Sleeping for 3sec\n");
Sleep(3000);
printf("Done");
std::cin.ignore();
return 0;
}
"Part 0" - something only programmers would do :P
so to sum it up , in which situations would it set a pointer and in which situations would it not
Ie. statically linked libraries ? would this use a pointer?
dynamically linked libraries ? would this use a pointer? assuming they are linked using LoadLibrary ?
I want to know in which situations this would be useful ... And how can we be sure that the pointer name will be that of the function name (eg. Sleep ) .. that seems a bit odd to me
Ie. statically linked libraries ? would this use a pointer?
dynamically linked libraries ? would this use a pointer? assuming they are linked using LoadLibrary ?
I want to know in which situations this would be useful ... And how can we be sure that the pointer name will be that of the function name (eg. Sleep ) .. that seems a bit odd to me
who can help me?
http://www.mpgh.net/forum/186-combat...ml#post4607089
http://www.mpgh.net/forum/186-combat...ml#post4607089
This thread is closed for replies.
Similar Threads
Combat Arms Hack Coding / Programming / Source Code[Source] The jump hook [series part 1]
13 C++/C Programming[Source]Hooking via forced exception
10 C++/C ProgrammingThe basics of Direct3D[Series][Part 1]
10 Team Fortress 2 HacksTF2 Source Hook (AIMBOT!)WI 12 Team Fortress 2 HacksTF2 Source Hook (AIMBOT!) Still Works ?
33

I'm never sure that when someone (eg. at a local store) names a quantity(5) of something they mean 0 to 5 or 1 to 5 or 0 to 4 of whatever :S