Lua:registerAssembler
Jump to navigation
Jump to search
Registers a callback function that is called when Cheat Engine's single-line assembler is invoked to convert an instruction into a list of bytes.
The callback can return a byte table to provide the assembled instruction bytes. Return nil to let another registered assembler callback, or the original x86 assembler, handle the instruction.
Contents
- 1 Function Parameters
- 2 Returns
- 3 Callback Parameters
- 4 Callback Return Value
- 5 Byte Table Format
- 6 Examples
- 6.1 Register an assembler callback that lets CE handle everything
- 6.2 Assemble a custom single-byte instruction
- 6.3 Assemble a custom two-byte NOP
- 6.4 Normalize the instruction text before comparing
- 6.5 Use the address parameter
- 6.6 Support a small custom instruction alias
- 6.7 Use with auto assembler
- 6.8 Log unhandled instructions
Function Parameters[edit]
| Parameter | Type | Description |
|---|---|---|
| callback | Function | The assembler callback to register. It receives the target address and instruction text. |
Returns[edit]
This function does not return a value.
Callback Parameters[edit]
| Parameter | Type | Description |
|---|---|---|
| address | Integer | The address where the instruction is being assembled. |
| instruction | String | The single-line assembler instruction text. |
Callback Return Value[edit]
| Return Type | Description |
|---|---|
| Table | Return a byte table containing the exact bytes to emit for the instruction. |
| nil | Return nil to let another assembler callback or the original x86 assembler handle the instruction. |
Byte Table Format[edit]
The returned byte table should contain integer byte values.
1 return {0x90}
This example returns a single NOP byte.
Examples[edit]
Register an assembler callback that lets CE handle everything[edit]
1 registerAssembler(function(address, instruction)
2 return nil
3 end)
Assemble a custom single-byte instruction[edit]
1 registerAssembler(function(address, instruction)
2 if instruction == "customnop" then
3 return {0x90}
4 end
5
6 return nil
7 end)
Assemble a custom two-byte NOP[edit]
1 registerAssembler(function(address, instruction)
2 if instruction == "customnop2" then
3 return {0x66, 0x90}
4 end
5
6 return nil
7 end)
Normalize the instruction text before comparing[edit]
1 registerAssembler(function(address, instruction)
2 local text = instruction:lower()
3 text = text:gsub("^%s+", "")
4 text = text:gsub("%s+$", "")
5
6 if text == "customnop" then
7 return {0x90}
8 end
9
10 return nil
11 end)
Use the address parameter[edit]
1 registerAssembler(function(address, instruction)
2 local text = instruction:lower()
3
4 if text == "addresslowbyte" then
5 local lowByte = address & 0xff
6 return {lowByte}
7 end
8
9 return nil
10 end)
Support a small custom instruction alias[edit]
1 registerAssembler(function(address, instruction)
2 local text = instruction:lower():gsub("^%s+", ""):gsub("%s+$", "")
3
4 if text == "ret0" then
5 -- xor eax,eax
6 -- ret
7 return {0x31, 0xC0, 0xC3}
8 end
9
10 return nil
11 end)
Use with auto assembler[edit]
1 registerAssembler(function(address, instruction)
2 if instruction:lower() == "customnop" then
3 return {0x90}
4 end
5
6 return nil
7 end)
8
9 autoAssemble([[
10 customnop
11 ]])
Log unhandled instructions[edit]
1 registerAssembler(function(address, instruction)
2 print(string.format("Assembling at %X: %s", address, instruction))
3
4 return nil
5 end)