| View previous topic :: View next topic |
| Author |
Message |
slippppppppp Grandmaster Cheater
Reputation: 0
Joined: 08 Aug 2006 Posts: 929
|
Posted: Sat Jul 12, 2008 10:22 pm Post subject: [Help] C++ |
|
|
Here is a basic hook function that i coded with some help from noz.
| Code: | #define JMP(frm, to) (int)(((int)to - (int)frm) - 5);
bool HookProc(VOID* NewProc, char * OldProc, char * pLIB)
{
ULONG OldFunction = (DWORD)GetProcAddress(LoadLibrary(pLIB), OldProc);
*(DWORD*)OldFunction = 0xE9;
*(DWORD*)(OldFunction + 1) = JMP(OldFunction, NewProc);
return true;
} |
If you don't already know, what this does it have a certain api, when called, jump to your own procedure.
For example, let's say you called PostMessageA, it would jump to PostMessage, but then see another jump, and jump to my own procedure.
Hooking.
Now my question is, when i use this, it works but, it closes the process, notepad.exe for example. But when i inject into maplestory, it just freezes the injector. Anyone know what's wrong?
Btw, here's an example of using it:
| Code: |
void MyFunction()
{
}
HookProc(&MyFunction, "PostMessageA", "User32.dll"); |
|
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Sat Jul 12, 2008 10:30 pm Post subject: |
|
|
Are you putting everything into the state the program expects? ie returning any/the right kind of variable
_________________
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sat Jul 12, 2008 10:36 pm Post subject: |
|
|
If your going to hook a function you have to declare your targeted function the same way. I.e.
| Code: |
BOOL PostMessageHook(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
return FALSE;
}
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
slippppppppp Grandmaster Cheater
Reputation: 0
Joined: 08 Aug 2006 Posts: 929
|
Posted: Sat Jul 12, 2008 10:37 pm Post subject: |
|
|
ohh, so i have to also make a function for the api im trying to hook?
Last edited by slippppppppp on Sat Jul 12, 2008 10:39 pm; edited 1 time in total |
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sat Jul 12, 2008 10:39 pm Post subject: |
|
|
Otherwise it gets messed up. Declare it like this:
| Code: |
BOOL PostMessageHook(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
return FALSE; //if you want it to fail
}
|
Oh, and declare NewProc as LPVOID instead of void* and declare OldProc and pLib as LPCSTR.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
slippppppppp Grandmaster Cheater
Reputation: 0
Joined: 08 Aug 2006 Posts: 929
|
Posted: Sat Jul 12, 2008 10:41 pm Post subject: |
|
|
Actually, this is how im using it:
| Quote: | /* Wrappers for user32.dll */
#include "windows.h"
_declspec(naked) BOOL WINAPI __stdcall Blocked_PostMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
ShowMessage("Hai Guys");
HWND MsHandle = FindWindow(NULL, "MapleStory");
if(MsHandle == hWnd)
hWnd = 0;
return 0;
}
void InstallHooks()
{
HookProc(&Blocked_PostMessage, "PostMessageA", "User32.dll"))
} |
|
|
| Back to top |
|
 |
Zand Master Cheater
Reputation: 0
Joined: 21 Jul 2006 Posts: 424
|
Posted: Mon Jul 14, 2008 3:52 am Post subject: |
|
|
You should just use Microsoft's Detour Library.
I think your JMP is wrong. Doesn't it just jump straight to the address of the start of the new function?
Change *(DWORD*)OldFunction = 0xE9; to *(BYTE*)OldFunction = 0xE9;
and
try *(DWORD*)(OldFunction + 1) = (DWORD)NewProc;
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Mon Jul 14, 2008 4:11 am Post subject: |
|
|
| Zand wrote: | You should just use Microsoft's Detour Library.
I think your JMP is wrong. Doesn't it just jump straight to the address of the start of the new function?
Change *(DWORD*)OldFunction = 0xE9; to *(BYTE*)OldFunction = 0xE9;
and
try *(DWORD*)(OldFunction + 1) = (DWORD)NewProc; |
You need to calculate the offset for the jmp and i dont think the DWORD is a problem because the bytes after get set anyway.
|
|
| Back to top |
|
 |
Zand Master Cheater
Reputation: 0
Joined: 21 Jul 2006 Posts: 424
|
Posted: Tue Jul 15, 2008 10:40 am Post subject: |
|
|
Here
| Code: | void *DetourFunc(BYTE *src, const BYTE *dst, const int len)
{
BYTE *jmp = (BYTE*)malloc(len+5);
DWORD dwback;
VirtualProtect(src, len, PAGE_READWRITE, &dwback);
memcpy(jmp, src, len); jmp += len;
jmp[0] = 0xE9;
*(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;
src[0] = 0xE9;
*(DWORD*)(src+1) = (DWORD)(dst - src) - 5;
VirtualProtect(src, len, dwback, &dwback);
return (jmp-len);
} |
Usage
| Code: | | DetourFunc((BYTE*)GetProcAddress(LoadLibrary("user32.dll"), "PostMessageA"), (BYTE*)myfunc,2); |
Last edited by Zand on Tue Jul 15, 2008 10:45 am; edited 3 times in total |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Tue Jul 15, 2008 10:42 am Post subject: |
|
|
| slippppppppp wrote: | Actually, this is how im using it:
| Quote: | /* Wrappers for user32.dll */
#include "windows.h"
_declspec(naked) BOOL WINAPI __stdcall Blocked_PostMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
ShowMessage("Hai Guys");
HWND MsHandle = FindWindow(NULL, "MapleStory");
if(MsHandle == hWnd)
hWnd = 0;
return 0;
}
void InstallHooks()
{
HookProc(&Blocked_PostMessage, "PostMessageA", "User32.dll"))
} |
|
Lol... you know WINAPI is a definition for __stdcall
_________________
|
|
| Back to top |
|
 |
WafflesFTW Expert Cheater
Reputation: 0
Joined: 21 Mar 2008 Posts: 131
|
Posted: Wed Jul 16, 2008 9:49 am Post subject: |
|
|
| Why are you using stdcall twice?
|
|
| Back to top |
|
 |
|