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 with a conditional jump

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

Joined: 11 Aug 2011
Posts: 10

PostPosted: Fri Aug 12, 2011 7:52 am    Post subject: help with a conditional jump Reply with quote

Hello,
I have some problems with a conditional jump instruction, it seems like it doesn't work (or it doesn't do what i think it does Razz).
This is the code I can't get working.

Code:
[ENABLE]
//code from here to '[DISABLE]' will be used to enable the cheat
alloc(newmem,2048) //2kb should be enough
label(returnhere)
label(originalcode)
label(friend)
label(exit)

newmem: //this is allocated memory, you have read,write,execute access
test [eax+F4],0
je friend

originalcode:
sub [eax+0C],edx

friend:
mov eax,[esi+000012FC]

exit:
jmp returnhere

...


in [eax+F4] there should be a value 0 or 1 but the code always jumps, regardless of the value.
Is it a code problem or could the value be changing right before that code executes?

Thanks Smile
-DiMey
Back to top
View user's profile Send private message
SwaggaJackin'
Master Cheater
Reputation: 2

Joined: 06 Nov 2009
Posts: 312

PostPosted: Fri Aug 12, 2011 7:56 am    Post subject: Reply with quote

I'd set a break on 'test [eax+F4],0' and double check that the code isn't always a '1' and isn't setting the zero flag.
Back to top
View user's profile Send private message
dimey
Newbie cheater
Reputation: 0

Joined: 11 Aug 2011
Posts: 10

PostPosted: Fri Aug 12, 2011 8:24 am    Post subject: Reply with quote

Hi,
I changed the code to this:

Code:
alloc(newmem,2048) //2kb should be enough
label(returnhere)
label(originalcode)
label(friend)
label(exit)

newmem: //this is allocated memory, you have read,write,execute access
push ebx
mov ebx,[eax+F4]
test ebx,00000001
je friend

originalcode:
sub [eax+0C],edx

friend:
pop ebx
mov eax,[esi+000012FC]

exit:
jmp returnhere

...


Now it works but I don't understand why.. I set a breakpoint on the test and after the test i have this:
ebx = 0 => zf = 1
ebx = 1 => zf = 0
shouldnt it be the opposite??
i thought the zero flag was set to 1 if they were equal..

Thanks Smile
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 223

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Fri Aug 12, 2011 8:53 am    Post subject: Reply with quote

zero flag = 1 , EBX is equal zero? true!
zero flag = 0 , EBX is equal zero? false!

_________________
Back to top
View user's profile Send private message MSN Messenger
dimey
Newbie cheater
Reputation: 0

Joined: 11 Aug 2011
Posts: 10

PostPosted: Fri Aug 12, 2011 9:04 am    Post subject: Reply with quote

oh.. so i don't need the ,00000001 in the test.. it's not comparing the two values.. ops Very Happy Embarassed Razz
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 223

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Fri Aug 12, 2011 9:10 am    Post subject: Reply with quote

test ebx,1
and ebx,1

What's the difference?

and sets flag and stores result

test sets flag (only)

_________________
Back to top
View user's profile Send private message MSN Messenger
dimey
Newbie cheater
Reputation: 0

Joined: 11 Aug 2011
Posts: 10

PostPosted: Fri Aug 12, 2011 9:36 am    Post subject: Reply with quote

i don't get it.. it does the and between ebx and 1 without storing the result?
if they are equal wouldn't the result of the and be different than 0?

also, in the CE help it says:
Quote:
TEST EAX,EBX
JE 004822FFh
MOV EAX,EBX
JMP 004822FFh


This little example basically tests two values to see if they are equal, if so the program
will move the value 1 into the Zero Flag (ZF), thus allowing the conditional jump (JE) to
goto a memory location to execute opcodes there.


Now if it wasnt equal, the program will move 0 into ZF, and will skip the JE instruction, then
move the value in the EBX register to the EAX register, forcing to be equal then doing an
unconditional jump (JMP) to the same memory location.

here says that if they are equal the zf should be 1, not 0..
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