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 


working code after level restart don't work anymore
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
Fresco
Grandmaster Cheater
Reputation: 4

Joined: 07 Nov 2010
Posts: 600

PostPosted: Mon Feb 20, 2012 12:39 pm    Post subject: Reply with quote

i have finally managed to write my own exception handler code and fully understand it ... i think

however now the code works like before for the levels that have "the feature on" ... but for those level who don't have it, there's still a cheat/code bug.

now the game doesn't crash at all (because of the exception handler) and therefore doesn't close at the very beginning of level load 1% ...
now the game just stop's loading at 90% and in task manager i see "the process is not responding"
ce is not attached to the process

_________________
... Fresco
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 475

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

PostPosted: Mon Feb 20, 2012 2:17 pm    Post subject: Reply with quote

Looks like it is in an infinite loop

If you also implemented an counter to see how many exceptions have happened you could check that to see if it's looping on the exception handler or something else

Make sure the "onException" part that the exception handler makes the code jump to does not raise an exception again.

and most importantly, do not make the exception handler cause an exception itself.

If you used any push or esp modifying code before the first mov eax,[esp+4] you need to take that into account

edit:
Make sure you ONLY handle exceptions caused by your code. Do not handle those generated by the game.

_________________
Tools give you results. Knowledge gives you control.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Fresco
Grandmaster Cheater
Reputation: 4

Joined: 07 Nov 2010
Posts: 600

PostPosted: Tue Feb 21, 2012 7:51 am    Post subject: Reply with quote

doing some break tracing to original code ...
at 90% of no feature level load the code continuously writes to multiple values ... however ...my pointer point's nowhere.

here's what i did in my code:

Code:

globalalloc(featurehandler,2048)
alloc(feature,2048)
label(various labels)

featurehandler:
db 90 90
mov eax,[esp+4] //this section here is standard
mov eax,[eax+4] // we check if it was us who provoked the exception
lea eax,[eax+0B8] // 0b8 ... 0 it's just a zero extension //b8 meand to check for a pointer exception ... it mey be different if you divide by 0
cmp [eax],pointer
jb short invalid //jmp "pointer is invalid" if below (it wasn't us to make the exception)
cmp [eax],pointer_end (we check only the section after pointer and pointer_end)
jae short invalid //jmp above equal ... jum if it's not our pointer

mov eax,FFFFFFFF  // all test's have been passed we are responsable for the break ... write -1 in eax to let the handler know that
ret 4 //return to the caller ...

invalid:
mov eax,0 //write zero so we know that we don't have to execute our customized code
ret 4

pointer_is_valid:
//////////// Here we have 0 (if is invalid) or (-1)dec(if is valid)

feature:
pushfd
push eax
cmp [pointer_is_valid],0
jne pointer //jump if valid ...// the first time execution never jumps
push featurehandler //give vectorhandler info about what to check
push 1 //give maximum priority // 0 = don't care
call RtlAddVectoredExceptionHandler // execute exceptio check... it returns eax = 0 if pointer is valid; eax=-1(dec) if pointer is invalid
mov [pointer_is_valid],eax //make pointer_is_valid zero or -1
jmp orgcode //if pointer is not valid run orgcode // this is because the first time code is run, it is always not valid

pointer:
mov eax,"game.exe"+base address
mov eax,[eax]
add eax,offset 1
mov eax,[eax]
add eax,offset 2
mov eax,[eax]
add eax, ...3
mov eax,[eax]
add eax, ...4
cmp [eax],0 // cause an exception if pointer points to 0
db 90 90 90
pointer_end:

mov [found_featureaddress],eax // put the address of pointer in the value of found_feature...

// check if my code writes to my feature address, if not do original code

// if yes ...jump here and do my customized code

found_featureaddress:
dd 0


thast's my code ... where is it wrong ...?

_________________
... Fresco


Last edited by Fresco on Tue Feb 21, 2012 9:05 am; edited 1 time in total
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 475

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

PostPosted: Tue Feb 21, 2012 8:06 am    Post subject: Reply with quote

Code:

cmp [eax],pointer
jb short invalid //jmp "pointer is invalid" if below (it wasn't us to make the exception)
cmp [eax],pointer_end (we check only the section after pointer and pointer_end)
jae short invalid //jmp above equal ... jum if it's not our pointer

mov eax,FFFFFFFF  // all test's have been passed we are responsable for the break ... write -1 in eax to let the handler know that
ret 4 //return to the caller ...


This code does not change eip when an exception happens
That means that when you return it goes back to the instruction that caused the exception, which raises an exception so your handler gets called, which doesn't change eip so returns to the instruction that caused the exception, which raises an exception so your handler gets called, which doesn't change eip so returns to the instruction that caused the exception, which raises an exce....

You get the point I hope

you need to add a mov [eax], orgcode before the mov eax,ffffffff (assuming orgcode also does the pop eax/popfd part)

_________________
Tools give you results. Knowledge gives you control.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Fresco
Grandmaster Cheater
Reputation: 4

Joined: 07 Nov 2010
Posts: 600

PostPosted: Tue Feb 21, 2012 8:53 am    Post subject: Reply with quote

i really cant get it work ...
that's my code
i only hide the processname and the offsets.

Code:
[ENABLE]
globalalloc(featurehandler,2048)
alloc(feature,2048)
label(featureret)
label(invalid)
label(pointer)
label(orgcode)
label(featuredisable)
label(pointer_end)
label(pointer_is_valid)
label(found_featureaddress)
label(orgcode_no_ecx)

"game.exe"+basecodeaddress:
jmp feature
nop
featureret:

featurehandler:
db 90 90
mov eax,[esp+4]
mov eax,[eax+4]
lea eax,[eax+0B8]
cmp [eax],pointer
jb short invalid
cmp [eax],pointer_end
jae short invalid

mov [eax],orgcode_no_ecx //added now ... but still doesn't work
mov eax,FFFFFFFF
ret 4

invalid:
mov eax,0
ret 4

pointer_is_valid:
//////////// Here we have 0 or (-1)dec

feature:
pushfd
push eax
cmp [pointer_is_valid],0
jne pointer //jump if valid
push featurehandler
push 0
call RtlAddVectoredExceptionHandler
mov [pointer_is_valid],eax
jmp orgcode_no_ecx //if not valid run orgcode


pointer:
mov eax,"game.exe"+basepointer
mov eax,[eax]
add eax,offset1
mov eax,[eax]
add eax,offset2
mov eax,[eax]
add eax,offset3
mov eax,[eax]
add eax,last offest
cmp [eax],0
db 90 90 90
pointer_end:

mov [found_featureaddress],eax
push ecx
lea ecx,[esi+000000E0] // esi+e0 is the code that writes on my pointer
cmp eax,ecx
je featuredisable

orgcode:
popfd
pop eax
pop ecx
mov [esi+000000E0],eax
jmp featureret

featuredisable:
cmp [esi+000000E0],1 // i just want that code to NOT write 1 at the pointer value
jne orgcode
mov [esi+000000E0],0
popfd
pop eax
pop ecx
jmp featureret

orgcode_no_ecx: // i used this because there is no push ecx in the handler
popfd
pop eax
mov [esi+000000E0],eax
jmp featureret

found_featureaddress:
dd 0

[DISABLE]
dealloc(feature)

"game.exe"+basecodeaddress:
mov [esi+000000E0],eax


this code works in main menu and when loading a level that have the feature when pointer point to a valid address.
it gives me an error when loading a level when pointer points nowhere

... before adding ... mov [eax],orgcode_no_ecx ... the game didn't gave any error but continued looping ... now it gives an error ... game.exe has encountred a problen an need to be closed ... if you were in a middle of ...

_________________
... Fresco
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 475

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

PostPosted: Tue Feb 21, 2012 9:49 am    Post subject: Reply with quote

hmm, really no idea.

Change one of the "mov eax,[eax]" lines to "mov eax,[00000000]"

And see if it also crashes in levels where that feature is present ?
If it does there is a problem with the exception handler

And you really don't have another script running that might cause the crash instead ?

_________________
Tools give you results. Knowledge gives you control.

Like my help? Join me on Patreon so i can keep helping


Last edited by Dark Byte on Tue Feb 21, 2012 9:57 am; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
Fresco
Grandmaster Cheater
Reputation: 4

Joined: 07 Nov 2010
Posts: 600

PostPosted: Tue Feb 21, 2012 9:56 am    Post subject: Reply with quote

but then the pointer would not point anymore to my featureaddress in a level where there is the feature
_________________
... Fresco
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 475

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

PostPosted: Tue Feb 21, 2012 9:58 am    Post subject: Reply with quote

True, but then you can see if the exception is handled properly or not (Sometimes you have to cause an expected bug to debug stuff)

Also, is there any other place where you write to the memory ? (e.g another script or a cheat table entry ? )

_________________
Tools give you results. Knowledge gives you control.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Dark Byte
Site Admin
Reputation: 475

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

PostPosted: Tue Feb 21, 2012 10:00 am    Post subject: Reply with quote

Nevermind. I just saw the mistake you made

Code:

popfd
pop eax


that should be
Code:

pop eax
popfd


you have to pop in the reverse order as you push.

and at the other spots too. (I'm surprised it doesn't crash on parts where the pointer is valid)

_________________
Tools give you results. Knowledge gives you control.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Fresco
Grandmaster Cheater
Reputation: 4

Joined: 07 Nov 2010
Posts: 600

PostPosted: Tue Feb 21, 2012 10:15 am    Post subject: Reply with quote

no when i debug the code .. only one code is enabled...
but ... there are two codes and both does the same thing ... so i enable two auto assemble entries; one for code1 and one for code2; ... again .. code1 and code2 does the same thing writes on the same addresses, but nopping one and leaving the other just would not accomplish my goal ... (maybe if the developers put two code that does the same thing ... they had their reasons ... so that's why i just don't want to nop the other)
also because if i just nop the other ... my value would just freeze to: not write 1 ... therefore 1 can still be written in a very short amount of time ...
(i could have just freeze the pointer for that without any script)

... also ... i think that in a very 1 millisecond ... the pointer point somewhere for a very little time .. then returns back to nowhere; when it comes to a level that don't have the feature. how can i be sure of that ? ....
i mean is there any method to check or log ... during playtime ... on what addresses the pointer pointed ?

PS: forgot to say ... that if i nop code2 and leave code 1 the level will load but player will not be placed at level-start but somewhere else in the level and will be surrounded by enemy. i guess that's because the pointer at the very first of level load .. for a 10 milliseconds points to an address that should be 1, and it's not because my code tells not to write 1

[edit]
it worked !! Smile Smile
it was because of push and pop ... the stak

_________________
... Fresco
Back to top
View user's profile Send private message
Fresco
Grandmaster Cheater
Reputation: 4

Joined: 07 Nov 2010
Posts: 600

PostPosted: Wed Feb 22, 2012 5:00 am    Post subject: Reply with quote

now this is very very weird.

for the level that have the feature ... works.
for the level who don't have it, also works.
but now there's a level where if the feature gets turned on the mission fails.
now my code, as you see above, checks the address on which the code is writing then checks if the code writes 1 ... if yes ... my code say to write 0.
... the pointer points correctly to the address of the feature, and in the level's who have the feature, if it gets turned on ... the feature address is never set to 1 ... in the levels who don't have it ... runs original code ...
but in this new level where, if the feature gets turned on i fail the mission, the feature can till go to 1 for a millisecond ...
now i tried to search for what writes on the address and also what accesses it ... i checked the registers and NO instruction was writing 1 in it...
recapping ...
level 1 = my code NEVER lets feature set to 1.
level 2 = my code runs original code because level 2 don't have feature.
level 3 = pointer points correctly, no code writes 1, but feature address can still go to 1 for a very short amount of time (the needed to fail the mission).

strangely if i nop the code, works, ... but then other features will be disabled as well and i certainly don't want this to happen.

_________________
... Fresco
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 475

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

PostPosted: Wed Feb 22, 2012 5:13 am    Post subject: Reply with quote

This is quite game specific so you'll have to figure out yourself what is happening here.
Perhaps you could find out the address where the current level is stored and apply that info to your code?

_________________
Tools give you results. Knowledge gives you control.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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