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 


Is it possible to cmp register value with memory address?

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

Joined: 13 May 2019
Posts: 11

PostPosted: Sat May 25, 2019 10:40 pm    Post subject: Is it possible to cmp register value with memory address? Reply with quote

I am doing code injection to lock my character's health.

Here is my idea:
compare the register with the address of my character's healthpointer, if equals, then nop it.

Two problems:
1. When I paste in the address value of healthpointer, the value changes after execute the code injection
beforel: CD94130098
after: FFFFFFFF94130098

2. Is my code valid? (by directly comparing register with address, without dereferencing it):

alloc(newmem,2048,"witcher3.exe"+E3BF93)
label(returnhere)
label(originalcode)
label(exit)

newmem: //this is allocated memory, you have read,write,execute access
//place your code here
cmp rax,CD94130098
je exit

originalcode:
movss [rax+rcx*4],xmm6

exit:
jmp returnhere

"witcher3.exe"+E3BF93:
jmp newmem
returnhere:

--
I am seeing crash after the injection.
Back to top
View user's profile Send private message
sbryzl
Master Cheater
Reputation: 6

Joined: 25 Jul 2016
Posts: 252

PostPosted: Sun May 26, 2019 5:59 am    Post subject: Reply with quote

You can't compare 64 bit values. You could make it a 32 bit compare.

cmp eax,94130098
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 51

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Sun May 26, 2019 7:03 am    Post subject: Reply with quote

You can also just store the value in a registry and then compare that.
Code:
push rbx
mov rbx,CD94130098
cmp rax,rbx
pop rbx
je exit

_________________
Back to top
View user's profile Send private message Visit poster's website
fuguipingan
Newbie cheater
Reputation: 0

Joined: 13 May 2019
Posts: 11

PostPosted: Sun May 26, 2019 7:31 pm    Post subject: Reply with quote

Thanks. This seems to work and I can get the cmp passing. But I encounters crashing after that. Wierd

sbryzl wrote:
You can't compare 64 bit values. You could make it a 32 bit compare.

cmp eax,94130098
Back to top
View user's profile Send private message
Karyoplasma
How do I cheat?
Reputation: 0

Joined: 12 Jun 2015
Posts: 3

PostPosted: Mon May 27, 2019 5:41 pm    Post subject: Reply with quote

Push and pop flags to/from the stack before you use a compare or else you can inadvertently screw up a future compare which can lead to crashes:

Code:
push rbx
pushf
mov rbx,CD94130098
cmp rax,rbx
pop rbx
je @f
popf
*code for when it's not equal*
jmp exit
@@:
popf
*code for when it's equal*
jmp exit


Example when it's 100% needed to push/pop flags is when your injection looks like this:
Code:

cmp eax, 9
-----you inject here-----
jmp newmem
-----you return here-----
je somewhere <---- this will jump based on the compare in your code and might crash the program
Back to top
View user's profile Send private message
fuguipingan
Newbie cheater
Reputation: 0

Joined: 13 May 2019
Posts: 11

PostPosted: Thu Jun 06, 2019 10:37 pm    Post subject: Reply with quote

Thanks everyone. I am able to get this working now. The cause was found to be the jump address returned from CE's auto alloc memory seems too "far". When I finished my own code and jump back, an exception happend.

Now I found some nearby nop space and put my code there, it works as expected without crashing.
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 Gamehacking 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