Auto Assembler:TRY EXCEPT

From Cheat Engine
Revision as of 21:35, 17 November 2018 by Csimbi (talk | contribs)
Jump to navigation Jump to search

CE 6.8 added {$try}/{$except} to auto assembler scripts.

Essentially, any code included in the {$try}/{$except} block will jump to the {$EXCEPT} part when any kind of exception happens within the block.

This means, you will want to put the code likely to result in an error between {$try} and {$except}.

Next, at the end of {$try} you will want to force a jump to a location indicating success; if you do not, then the code after {$except} will be executed.

Also note that the exception may break from any line in the {$try}/{$except} block, so make sure that your exception code can handle unexpected register values.

How does it work? It works by assembling an exception handler in the game and then register it using addvectoredexception handler. Then, it adds a list of eip/rip ranges and where to jump to on exception. So, when an exception happens it checks if it's in the list, and if so, change eip/rip to the exception address.


In this example, if any error occurs - for example, ecx is zero or ecx+10 is unreadable -, eax will be set to zero:

{$try}

mov eax,[ecx+10]

jmp short @f

{$except}

xor eax,eax

@@:

Benefits:

- There should be hardly any performance hit as long as no exception happens.