View previous topic :: View next topic |
Author |
Message |
onlyus Newbie cheater
Reputation: 0
Joined: 27 Aug 2011 Posts: 19 Location: 214214
|
Posted: Fri Mar 22, 2013 4:11 am Post subject: 6-byte jmp problem |
|
|
procedure JumpHook(Oldfunc, Newfunc: Pointer);
var
Jmpto, OldProtect: DWORD;
begin
VirtualProtect(Oldfunc, 6, PAGE_EXECUTE_READWRITE, @OldProtect);
Jmpto:= DWORD(Newfunc);
PDWORD(Oldfunc)^:= $25FF;
PDWORD(DWORD(Oldfunc)+2)^:= Jmpto;
VirtualProtect(Oldfunc, 6, OldProtect, @OldProtect);
end;
procedure MSGBOX(hWnd: HWND; l1, l2: PAnsiChar; uType: Cardinal); stdcall;
begin
ShowMessage('called');
end;
.
.
JumpHook(GetProcAddress(GetModuleHandle('user32.dll'), 'MessageBoxA'), @MSGBOX);
MessageBoxA(0, 'asd', 'asd', MB_OK); // error
i try 6-byte jmp hook but doesn't work what's wrong my code?
_________________
i'm noob |
|
Back to top |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Fri Mar 22, 2013 9:30 am Post subject: |
|
|
probably because jmpto is in the stack and after that function executes, it gets messed up. You're better off with the 5 byte rel jump OR declaring it as a global.
Rel jump:
pByte(Address)^:=$E9;
pDword(Address+1)^:=Dword(@DestinationFunction)-Address-5;
|
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 468
Joined: 09 May 2003 Posts: 25706 Location: The netherlands
|
Posted: Fri Mar 22, 2013 10:18 am Post subject: |
|
|
It's probably because showmessage calls messageboxa which then calls your hook which calls showmessage which calls messageboxa which then calls your hook which calls showmessage which calls messageboxa which then calls your hook which calls showmessage which calls messageboxa which then calls your hook which calls showmessage which calls messageboxa which then calls your hook which calls showmessage which calls messageboxa which then calls your hook which calls showmessage which calls messageboxa which then calls your hook which calls showmessage which calls messageboxa which then calls your hook ...
Until the end of the stack is reached and the program crashes
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Fri Mar 22, 2013 11:40 pm Post subject: |
|
|
Dark Byte wrote: | It's probably because showmessage calls messageboxa which then calls your hook which calls showmessage which calls messageboxa which then calls your hook which calls showmessage which calls messageboxa which then calls your hook which calls showmessage which calls messageboxa which then calls your hook which calls showmessage which calls messageboxa which then calls your hook which calls showmessage which calls messageboxa which then calls your hook which calls showmessage which calls messageboxa which then calls your hook which calls showmessage which calls messageboxa which then calls your hook ...
Until the end of the stack is reached and the program crashes |
oh lol. didn't see that one xD.
I guess you just have to hook hop it over which is why 6 byte jumps are not really recommended because windows provides you with a nice 5 byte prologue so you can do a rel jump hook. It's probably in your best interests to do that so the hook hop can be executed more easily.
|
|
Back to top |
|
 |
|