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 


[HELP] problem with asm jmp code in C++

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
xXDarkBloodXx
How do I cheat?
Reputation: 0

Joined: 20 May 2011
Posts: 3

PostPosted: Fri May 20, 2011 5:47 pm    Post subject: [HELP] problem with asm jmp code in C++ Reply with quote

Ok I have no problems with most of my dll! It injects and ejects from the game with no problem. Code caves are initialized correctly everything seems to work fine! if I access my codecave with a simple call instead of a jmp, and use a ret to return it works perfectly. However if i try to do a jmp and then a jmp back it immediately crashes the game upon execution of the returning jmp. My problem is that when it writes my code to the codecave and I look at it in Cheat Engine the jmp back looks like this "jmp dword ptr ds:[00484766]" and the game crashes the momment it tries to execute the jmp. however if i use cheat engine to re-write the jmp so it looks like so "jmp 00484766" it works perfectly. Anyone have any ideas how I might be able to fix this issue? Is there a different way of writing the jmp in the asm block that will write it in a way it will look like "jmp 00484766"?


Code:

DWORD Addy_GodMode = 0x00484761;

*(BYTE*)Addy_GodMode = 0xe9;
*(DWORD*)(Addy_GodMode+1) = JMP(Addy_GodMode,GodMode_CodeCave);

__declspec(naked) void GodMode_CodeCave(){
   __asm{
      jmp dword ptr ds:[Addy_GodMode+5]
   }
}

Ive also tried "jmp dword [Addy_GodMode+5]" and "jmp dword ptr [Addy_GodMode+5]" they all crash the game immediatly on execution.


**Note: The only reason im doing an immediate jump back is for testing. Once I get the jmp working correctly then ill add the rest of my code back in!

Anyone got any ideas?
Thanks in advance, for any help!
Back to top
View user's profile Send private message
661089799107
Expert Cheater
Reputation: 3

Joined: 25 Jan 2009
Posts: 186

PostPosted: Fri May 20, 2011 9:04 pm    Post subject: Reply with quote

You're adding '5' to the address of your variable (&Addy_GodMode+5), and then trying to jump to the value of that address. Instead of adding '5' to '0x00484761', and jumping to '0x00484766'.
Back to top
View user's profile Send private message
xXDarkBloodXx
How do I cheat?
Reputation: 0

Joined: 20 May 2011
Posts: 3

PostPosted: Sat May 21, 2011 12:45 am    Post subject: Reply with quote

Thank you for your help, and forgive me if im wrong but if that was the case then why would cheat engine show "jmp dword ptr ds:[00484766]" with the correct address of 00484766?

Furthermore if doing this is incorrect!
Code:
jmp dword ptr ds:[Addy_GodMode+5]

then what would be the correct way?

I also tried
Code:
jmp dword ptr ds:0x00484766

Again unfortunately this caused an immediate crash on execution of jmp.

Ive been looking through the forums and google for almost a week now trying to figure this out, with no success! Apparently when it comes to jmps in dll injection routines im at a loss! Any help would be greatly appreciated!

Thank You
Back to top
View user's profile Send private message
sponge
I'm a spammer
Reputation: 1

Joined: 07 Nov 2006
Posts: 6009

PostPosted: Sat May 21, 2011 1:01 am    Post subject: Reply with quote

Code:
mov eax, dword ptr ds:[Addy_Godmode]
add eax, 5
jmp eax

_________________
Back to top
View user's profile Send private message
661089799107
Expert Cheater
Reputation: 3

Joined: 25 Jan 2009
Posts: 186

PostPosted: Sat May 21, 2011 2:30 am    Post subject: Reply with quote

Remove __declspec(naked)
Back to top
View user's profile Send private message
xXDarkBloodXx
How do I cheat?
Reputation: 0

Joined: 20 May 2011
Posts: 3

PostPosted: Sun May 22, 2011 2:04 am    Post subject: Reply with quote

Thanks both for your help! I changed the code to that of what sponge suggested and that did the trick! Removing the __declspec(naked) had no effect one way or the other however, but thanks for the suggestion none the less.

Code:

   mov eax, dword ptr ds:[Addy_GodMode]
   add eax, 5
   jmp eax
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