<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.cheatengine.org/index.php?action=history&amp;feed=atom&amp;title=Lua%3AregisterAssembler</id>
	<title>Lua:registerAssembler - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.cheatengine.org/index.php?action=history&amp;feed=atom&amp;title=Lua%3AregisterAssembler"/>
	<link rel="alternate" type="text/html" href="https://wiki.cheatengine.org/index.php?title=Lua:registerAssembler&amp;action=history"/>
	<updated>2026-07-27T05:57:50Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.32.0</generator>
	<entry>
		<id>https://wiki.cheatengine.org/index.php?title=Lua:registerAssembler&amp;diff=8378&amp;oldid=prev</id>
		<title>Leunsel: Initial page creation.</title>
		<link rel="alternate" type="text/html" href="https://wiki.cheatengine.org/index.php?title=Lua:registerAssembler&amp;diff=8378&amp;oldid=prev"/>
		<updated>2026-06-26T20:33:09Z</updated>

		<summary type="html">&lt;p&gt;Initial page creation.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:Lua]]&lt;br /&gt;
{{CodeBox|'''function''' registerAssembler(''callback'') ''':''' void}}&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===Function Parameters===&lt;br /&gt;
{|width=&amp;quot;85%&amp;quot; cellpadding=&amp;quot;10%&amp;quot; cellspacing=&amp;quot;0&amp;quot; border=&amp;quot;0&amp;quot;&lt;br /&gt;
!align=&amp;quot;left&amp;quot;|Parameter&lt;br /&gt;
!align=&amp;quot;left&amp;quot;|Type&lt;br /&gt;
!style=&amp;quot;width: 80%;background-color:white;&amp;quot; align=&amp;quot;left&amp;quot;|Description&lt;br /&gt;
|-&lt;br /&gt;
|callback&lt;br /&gt;
|Function&lt;br /&gt;
|The assembler callback to register. It receives the target address and instruction text.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
This function does not return a value.&lt;br /&gt;
&lt;br /&gt;
===Callback Parameters===&lt;br /&gt;
{|width=&amp;quot;85%&amp;quot; cellpadding=&amp;quot;10%&amp;quot; cellspacing=&amp;quot;0&amp;quot; border=&amp;quot;0&amp;quot;&lt;br /&gt;
!align=&amp;quot;left&amp;quot;|Parameter&lt;br /&gt;
!align=&amp;quot;left&amp;quot;|Type&lt;br /&gt;
!style=&amp;quot;width: 80%;background-color:white;&amp;quot; align=&amp;quot;left&amp;quot;|Description&lt;br /&gt;
|-&lt;br /&gt;
|address&lt;br /&gt;
|Integer&lt;br /&gt;
|The address where the instruction is being assembled.&lt;br /&gt;
|-&lt;br /&gt;
|instruction&lt;br /&gt;
|String&lt;br /&gt;
|The single-line assembler instruction text.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Callback Return Value===&lt;br /&gt;
{|width=&amp;quot;85%&amp;quot; cellpadding=&amp;quot;10%&amp;quot; cellspacing=&amp;quot;0&amp;quot; border=&amp;quot;0&amp;quot;&lt;br /&gt;
!align=&amp;quot;left&amp;quot;|Return Type&lt;br /&gt;
!style=&amp;quot;width: 80%;background-color:white;&amp;quot; align=&amp;quot;left&amp;quot;|Description&lt;br /&gt;
|-&lt;br /&gt;
|Table&lt;br /&gt;
|Return a byte table containing the exact bytes to emit for the instruction.&lt;br /&gt;
|-&lt;br /&gt;
|nil&lt;br /&gt;
|Return nil to let another assembler callback or the original x86 assembler handle the instruction.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Byte Table Format===&lt;br /&gt;
The returned byte table should contain integer byte values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
return {0x90}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example returns a single NOP byte.&lt;br /&gt;
&lt;br /&gt;
===Examples===&lt;br /&gt;
&lt;br /&gt;
====Register an assembler callback that lets CE handle everything====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
registerAssembler(function(address, instruction)&lt;br /&gt;
  return nil&lt;br /&gt;
end)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Assemble a custom single-byte instruction====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
registerAssembler(function(address, instruction)&lt;br /&gt;
  if instruction == &amp;quot;customnop&amp;quot; then&lt;br /&gt;
    return {0x90}&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  return nil&lt;br /&gt;
end)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Assemble a custom two-byte NOP====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
registerAssembler(function(address, instruction)&lt;br /&gt;
  if instruction == &amp;quot;customnop2&amp;quot; then&lt;br /&gt;
    return {0x66, 0x90}&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  return nil&lt;br /&gt;
end)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Normalize the instruction text before comparing====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
registerAssembler(function(address, instruction)&lt;br /&gt;
  local text = instruction:lower()&lt;br /&gt;
  text = text:gsub(&amp;quot;^%s+&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
  text = text:gsub(&amp;quot;%s+$&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  if text == &amp;quot;customnop&amp;quot; then&lt;br /&gt;
    return {0x90}&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  return nil&lt;br /&gt;
end)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use the address parameter====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
registerAssembler(function(address, instruction)&lt;br /&gt;
  local text = instruction:lower()&lt;br /&gt;
&lt;br /&gt;
  if text == &amp;quot;addresslowbyte&amp;quot; then&lt;br /&gt;
    local lowByte = address &amp;amp; 0xff&lt;br /&gt;
    return {lowByte}&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  return nil&lt;br /&gt;
end)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Support a small custom instruction alias====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
registerAssembler(function(address, instruction)&lt;br /&gt;
  local text = instruction:lower():gsub(&amp;quot;^%s+&amp;quot;, &amp;quot;&amp;quot;):gsub(&amp;quot;%s+$&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  if text == &amp;quot;ret0&amp;quot; then&lt;br /&gt;
    -- xor eax,eax&lt;br /&gt;
    -- ret&lt;br /&gt;
    return {0x31, 0xC0, 0xC3}&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  return nil&lt;br /&gt;
end)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Use with auto assembler====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
registerAssembler(function(address, instruction)&lt;br /&gt;
  if instruction:lower() == &amp;quot;customnop&amp;quot; then&lt;br /&gt;
    return {0x90}&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  return nil&lt;br /&gt;
end)&lt;br /&gt;
&lt;br /&gt;
autoAssemble([[&lt;br /&gt;
customnop&lt;br /&gt;
]])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Log unhandled instructions====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot; line highlight=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
registerAssembler(function(address, instruction)&lt;br /&gt;
  print(string.format(&amp;quot;Assembling at %X: %s&amp;quot;, address, instruction))&lt;br /&gt;
&lt;br /&gt;
  return nil&lt;br /&gt;
end)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{LuaSeeAlso}}&lt;br /&gt;
&lt;br /&gt;
{{Assembly}}&lt;/div&gt;</summary>
		<author><name>Leunsel</name></author>
		
	</entry>
</feed>