Difference between revisions of "Cheat Engine:Auto Assembler"

From Cheat Engine
Jump to navigation Jump to search
(General Information)
(General Information)
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{cleanup}}
+
[[Category:Assembler]]
=== Writing a Script ===
+
== Writing a Script ==
 
You need to have the Memory Viewer window open and go to "Tools->Auto Assemble" or hit CTRL+A to open the Auto assemble window.  When you click "Execute" the code is '''not''' actually executed, but ''assembled'' into machine code.  The code is actually executed when you overwrite existing game code and the game executes it in the normal course of playing or when you call CREATETHREAD.
 
You need to have the Memory Viewer window open and go to "Tools->Auto Assemble" or hit CTRL+A to open the Auto assemble window.  When you click "Execute" the code is '''not''' actually executed, but ''assembled'' into machine code.  The code is actually executed when you overwrite existing game code and the game executes it in the normal course of playing or when you call CREATETHREAD.
  
Line 7: Line 7:
 
[[Auto Assembler Example 1|Simple Example]] - Example showing ALLOC, LABEL, REGISTERSYMBOL and CREATETHREAD.
 
[[Auto Assembler Example 1|Simple Example]] - Example showing ALLOC, LABEL, REGISTERSYMBOL and CREATETHREAD.
  
=== Assigning a Script to a CheatTable ===
+
 
 +
== Assigning a Script to a CheatTable ==
 
Scripts assigned to cheat tables usually have two sections, "[ENABLE]" and "[DISABLE]".  Code before "[ENABLE]" will be '''''assembled''''' every time the script is enabled OR disabled.  The code in the "[ENABLE]" section will be '''''assembled''''' (not executed) when the entry is checked and the code in the "[DISABLE]" section will be '''''assembled''''' when the entry is unchecked.
 
Scripts assigned to cheat tables usually have two sections, "[ENABLE]" and "[DISABLE]".  Code before "[ENABLE]" will be '''''assembled''''' every time the script is enabled OR disabled.  The code in the "[ENABLE]" section will be '''''assembled''''' (not executed) when the entry is checked and the code in the "[DISABLE]" section will be '''''assembled''''' when the entry is unchecked.
  
 
You will generally alloc memory in [ENABLE] and overwrite existing instructions inside the process you have opened to jump to your code where you can modify values  and jump back.  You will then dealloc the memory and put the original instructions back when disabling.
 
You will generally alloc memory in [ENABLE] and overwrite existing instructions inside the process you have opened to jump to your code where you can modify values  and jump back.  You will then dealloc the memory and put the original instructions back when disabling.
  
To assign it to your cheat table, click on "File->Assign to current cheat table" and close the window because to edit the table script you have to double-click on the "<script>" value in your table.
+
To assign it to your cheat table, click on "File->Assign to current cheat table" and close the window because to edit the table script you have to double-click on the "&lt;script&gt;" value in your table.
  
 
[[Auto Assembler Example 2|Serious Sam 3 BFE Example]] - Example showing ENABLE and DISABLE
 
[[Auto Assembler Example 2|Serious Sam 3 BFE Example]] - Example showing ENABLE and DISABLE
  
=== Injecting a DLL ===
+
 
 +
== Injecting a DLL ==
 
loadlibrary(name) can be used to load a dll and register it's symbols for
 
loadlibrary(name) can be used to load a dll and register it's symbols for
 
use by your assembly code.  Note that you should not put quotes around the DLL name.  Here's an examle:
 
use by your assembly code.  Note that you should not put quotes around the DLL name.  Here's an examle:
Line 22: Line 24:
 
[[Auto Assembler Example 3|LoadLibrary Example]]
 
[[Auto Assembler Example 3|LoadLibrary Example]]
  
=== General Information ===
+
 
 +
== General Information ==
 
Auto assemble allows you to write assembler code at different locations using a script. It can be found in the memory view part of cheat engine under extra.
 
Auto assemble allows you to write assembler code at different locations using a script. It can be found in the memory view part of cheat engine under extra.
  
Line 32: Line 35:
 
|-
 
|-
 
| [[Auto Assembler:aobScanModule|AOBSCANMODULE]](name, moduleName, xx xx xx xx xx) || Scans the memory of a specific module for the given array of byte and sets the result to the symbol names "name"
 
| [[Auto Assembler:aobScanModule|AOBSCANMODULE]](name, moduleName, xx xx xx xx xx) || Scans the memory of a specific module for the given array of byte and sets the result to the symbol names "name"
 +
|-
 +
| [[Auto Assembler:aobScanREGION|AOBSCANREGION]](name, Sadd$, Fadd$, xx xx xx)  || Will scan the specific range from start address to finish addressfor the given AOB and labels it with the given name
 
|-
 
|-
 
| [[Auto Assembler:alloc|ALLOC]](allocName, sizeInBytes, Optional: AllocateNearThisAddress) || Allocates a certain amount of memory and defines the specified name in the script. If AllocateNearThisAddress is specified CE will try to allocate the memory near that address. This is useful for 64-bit targets where the jump distance could be bigger than 2GB otherwise
 
| [[Auto Assembler:alloc|ALLOC]](allocName, sizeInBytes, Optional: AllocateNearThisAddress) || Allocates a certain amount of memory and defines the specified name in the script. If AllocateNearThisAddress is specified CE will try to allocate the memory near that address. This is useful for 64-bit targets where the jump distance could be bigger than 2GB otherwise
Line 61: Line 66:
  
 
=== {$lua} ===
 
=== {$lua} ===
Auto assembler scripts support section written in Lua.You can start such a section using the {$lua} keyword, and end it with {$asm}.
+
Auto assembler scripts support section written in Lua.You can start such a section using the [[Auto Assembler:LUA ASM|{$lua}]] keyword, and end it with [[Auto Assembler:LUA ASM|{$asm}]].
  
 
The return value of such a function (if it returns a value at all) will be interpreted as normal auto assembler commands.
 
The return value of such a function (if it returns a value at all) will be interpreted as normal auto assembler commands.
Line 72: Line 77:
 
Of course, if your script is meant to generate code, do make it return code so that it passes the initial syntax check. (e.g label definitions etc...)
 
Of course, if your script is meant to generate code, do make it return code so that it passes the initial syntax check. (e.g label definitions etc...)
  
 +
== Examples ==
  
== Basic Example ==
+
=== Basic Example ===
 
<pre>
 
<pre>
 
00451029:
 
00451029:
Line 88: Line 94:
 
</pre>
 
</pre>
  
== Example using LABEL ==
+
 
 +
=== Example using LABEL ===
 
<pre>
 
<pre>
 
label(mylabel)
 
label(mylabel)
Line 106: Line 113:
 
</pre>
 
</pre>
  
== Example using ALLOC ==
+
 
 +
=== Example using ALLOC ===
 
<pre>
 
<pre>
 
alloc(memloc1,4)
 
alloc(memloc1,4)
Line 123: Line 131:
 
</pre>
 
</pre>
  
== Example using ALLOC and LABEL ==
+
 
 +
=== Example using ALLOC and LABEL ===
 
<pre>
 
<pre>
 
alloc(alloc1,4)
 
alloc(alloc1,4)
Line 142: Line 151:
 
</pre>
 
</pre>
  
== Example using FULLACCESS ==
+
 
 +
=== Example using FULLACCESS ===
 
<pre>
 
<pre>
 
FULLACCESS(00400800,4) //00400800 is usually read only non executable data, this makes it writeable and executable
 
FULLACCESS(00400800,4) //00400800 is usually read only non executable data, this makes it writeable and executable
Line 158: Line 168:
 
</pre>
 
</pre>
  
== Example using DEFINE ==
+
 
 +
=== Example using DEFINE ===
 
<pre>
 
<pre>
 
DEFINE(clear_eax,xor eax,eax)
 
DEFINE(clear_eax,xor eax,eax)
Line 165: Line 176:
 
</pre>
 
</pre>
  
== Example using READMEM ==
+
 
 +
=== Example using READMEM ===
 
<pre>
 
<pre>
 
alloc(x,16)
 
alloc(x,16)
Line 178: Line 190:
 
readmem(00410000,16) //place the contents of address 00410000 at the address of X
 
readmem(00410000,16) //place the contents of address 00410000 at the address of X
 
</pre>
 
</pre>
 +
 +
 +
== See also ==
 +
* [[Assembler]]
 +
* [[Tutorials]]

Revision as of 18:46, 5 May 2017

Writing a Script

You need to have the Memory Viewer window open and go to "Tools->Auto Assemble" or hit CTRL+A to open the Auto assemble window. When you click "Execute" the code is not actually executed, but assembled into machine code. The code is actually executed when you overwrite existing game code and the game executes it in the normal course of playing or when you call CREATETHREAD.

Writing an address or label followed by a colon will do one of two opposite things. If the label is known, i.e. it is an address or if there is a defined symbol or memory has been allocated with that name, the assembler will move to that address for assembling the following code. If the label is unknown, it must have been passed to LABEL(name) (or you will get an error) and the value of that label will be set to the current position where code is set to be assembled.

Simple Example - Example showing ALLOC, LABEL, REGISTERSYMBOL and CREATETHREAD.


Assigning a Script to a CheatTable

Scripts assigned to cheat tables usually have two sections, "[ENABLE]" and "[DISABLE]". Code before "[ENABLE]" will be assembled every time the script is enabled OR disabled. The code in the "[ENABLE]" section will be assembled (not executed) when the entry is checked and the code in the "[DISABLE]" section will be assembled when the entry is unchecked.

You will generally alloc memory in [ENABLE] and overwrite existing instructions inside the process you have opened to jump to your code where you can modify values and jump back. You will then dealloc the memory and put the original instructions back when disabling.

To assign it to your cheat table, click on "File->Assign to current cheat table" and close the window because to edit the table script you have to double-click on the "<script>" value in your table.

Serious Sam 3 BFE Example - Example showing ENABLE and DISABLE


Injecting a DLL

loadlibrary(name) can be used to load a dll and register it's symbols for use by your assembly code. Note that you should not put quotes around the DLL name. Here's an examle:

LoadLibrary Example


General Information

Auto assemble allows you to write assembler code at different locations using a script. It can be found in the memory view part of cheat engine under extra.

{$lua}

Auto assembler scripts support section written in Lua.You can start such a section using the {$lua} keyword, and end it with {$asm}.

The return value of such a function (if it returns a value at all) will be interpreted as normal auto assembler commands.

When syntax checking, the lua sections get executed. To make sure your lua script behaves properly in those situations, check the "syntaxcheck" boolean. If it's true, then do not make permanent changes. e.g:

if syntaxcheck then return end

Of course, if your script is meant to generate code, do make it return code so that it passes the initial syntax check. (e.g label definitions etc...)

Examples

Basic Example

00451029:
jmp 00410000
nop
nop
nop

00410000:
mov [00580120],esi
mov [esi+80],ebx
xor eax,eax
jmp 00451031


Example using LABEL

label(mylabel)

00451029:
jmp 00410000
nop
nop
nop
mylabel:

00410000:
mov [00580120],esi
mov [esi+80],ebx
xor eax,eax
jmp mylabel


Example using ALLOC

alloc(memloc1,4)

00451029:
jmp 00410000
nop
nop
nop

00410000:
mov [alloc1],esi
mov [esi+80],ebx
xor eax,eax
jmp 00451031


Example using ALLOC and LABEL

alloc(alloc1,4)
label(mylabel)

00451029:
jmp 00410000
nop
nop
nop
mylabel:

00410000:
mov [alloc1],esi
mov [esi+80],ebx
xor eax,eax
jmp mylabel


Example using FULLACCESS

FULLACCESS(00400800,4) //00400800 is usually read only non executable data, this makes it writeable and executable
00451029:
jmp 00410000
nop
nop
nop

00410000:
mov [00400800],esi
mov [esi+80],ebx
xor eax,eax
jmp 00451031


Example using DEFINE

DEFINE(clear_eax,xor eax,eax)
00400500:
clear_eax


Example using READMEM

alloc(x,16)
alloc(script,2048)

script:
mov eax,[x]
mov edx,[x+c]
ret

x:
readmem(00410000,16) //place the contents of address 00410000 at the address of X


See also