Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


6-byte jmp problem

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
onlyus
Newbie cheater
Reputation: 0

Joined: 27 Aug 2011
Posts: 19
Location: 214214

PostPosted: Fri Mar 22, 2013 4:11 am    Post subject: 6-byte jmp problem Reply with quote

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
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
dnsi0
I post too much
Reputation: 0

Joined: 04 Jan 2007
Posts: 2674

PostPosted: Fri Mar 22, 2013 9:30 am    Post subject: Reply with quote

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
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 468

Joined: 09 May 2003
Posts: 25706
Location: The netherlands

PostPosted: Fri Mar 22, 2013 10:18 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
dnsi0
I post too much
Reputation: 0

Joined: 04 Jan 2007
Posts: 2674

PostPosted: Fri Mar 22, 2013 11:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites