Lua:registerAssembler

From Cheat Engine
Revision as of 20:33, 26 June 2026 by Leunsel (talk | contribs) (Initial page creation.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

<> Lua API Reference

function registerAssembler(callback) : void

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.

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)

Main Pages

Core Lua documentation entry points

Lua
Script Engine

Assembler and Disassembler Related Lua Functions

Auto assembler, disassembly helpers, instruction size lookup, and assembler callbacks