Difference between revisions of "Lua:autoAssembleCheck"

From Cheat Engine
Jump to navigation Jump to search
(Related Functions)
m (Updated example.)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
[[Category:Assembler]]
+
{{CodeBox|'''function''' autoAssembleCheck(''text'', ''enable'', ''targetself'')}}
'''function''' autoAssembleCheck(''AutoAssemblerScript'', ''Enable'' OPTIONAL, ''TargetSelf'' OPTIONAL) ''':''' nil '''-''' boolean
 
  
Checks the script for syntax errors. Returns true on succes, false with an error message on failure.
+
Checks the given Auto Assembler script for syntax errors.
 
+
Returns '''true''' on success, or '''false''' with an error message on failure.
Tip: Use '[[ ]]' or '[==[ ]==]' quotes for multiline script.
 
  
 
=== Function Parameters ===
 
=== Function Parameters ===
 
+
{|width="85%" cellpadding="5%" cellspacing="0" border="0"
{|width="85%" cellpadding="10%" cellpadding="5%" cellspacing="0" border="0"
 
 
!align="left"|Parameter
 
!align="left"|Parameter
 
!align="left"|Type
 
!align="left"|Type
!style="width: 80%;background-color:white;" align="left"|Description
+
!align="left"|Description
 
|-
 
|-
|AutoAssemblerScript
+
| text
|string
+
| String
|The script to run with Cheat Engine's auto assembler.
+
| The Auto Assembler script to validate.
 
|-
 
|-
|Enable
+
| enable
|boolean
+
| Boolean
|If true the [Enable] section will be checked, else the [Disable] section is checked.
+
| If set, checks the [ENABLE] part of the script.
 
|-
 
|-
|TargetSelf
+
| targetself
|boolean
+
| Boolean
|If set it will check as if assembling into Cheat Engine itself.
+
| If true, checks the script as if assembling into Cheat Engine itself.
 
|}
 
|}
  
 +
=== Example ===
 +
<pre>
 +
local script = [[
 +
alloc(newmem,2048,"cheatengine-x86_64-SSE4-AVX2.exe"+3E18)
 +
label(returnhere)
 +
label(originalcode)
 +
label(exit)
  
== Examples ==
+
newmem: //this is allocated memory, you have read,write,execute access
 
+
//place your code here
 
 
  local checkOk, errMsg = autoAssembleCheck("{$lua}\n print('Checked Form Auto Assembler Script!')")
 
 
 
 
 
  local scriptStr = &#91;==&#91;
 
    alloc(memExample, 0x100)
 
    label(returnHere)
 
    &nbsp;
 
    memExample:
 
      mov eax,123
 
      jmp returnHere
 
    &nbsp;
 
    00400500:
 
      jmp memExample
 
      returnHere:
 
  &#93;==&#93;
 
  &nbsp;
 
  local checkOk, errMsg = autoAssembleCheck(scriptStr)
 
  if not checkOk then
 
    print('The auto assembler script failed.')
 
    print(errMsg)
 
  else
 
    print('The auto assembler script passed.')
 
  end
 
 
 
  
  local scriptStr = &#91;==&#91;
+
originalcode:
    [Enable]
+
lea rsp,[rsp+28]
    alloc(memExample, 0x100)
 
    label(returnHere)
 
    &nbsp;
 
    memExample:
 
      mov eax,123
 
      jmp returnHere
 
    &nbsp;
 
    00400500:
 
      jmp memExample
 
      returnHere:
 
    [Disable]
 
      dealloc(memExample)
 
  &#93;==&#93;
 
  &nbsp;
 
  local checkOk, errMsg = autoAssembleCheck(scriptStr, true)
 
  if not checkOk then
 
    print('The auto assembler script failed.')
 
    print(errMsg)
 
  else
 
    print('The auto assembler script passed.')
 
  end
 
  
 +
exit:
 +
jmp returnhere
  
  local scriptStr = &#91;==&#91;
+
"cheatengine-x86_64-SSE4-AVX2.exe"+3E18:
    [Enable]
+
jmp newmem
    alloc(memExample, 0x100)
+
returnhere:
    label(returnHere)
+
]]
    &nbsp;
 
    memExample:
 
      mov eax,123
 
      jmp returnHere
 
    &nbsp;
 
    00400500:
 
      jmp memExample
 
      returnHere:
 
    [Disable]
 
      dealloc(memExample)
 
  &#93;==&#93;
 
  &nbsp;
 
  local checkOk, errMsg = autoAssembleCheck(scriptStr, false, true)
 
  if not checkOk then
 
    print('The auto assembler script failed.')
 
    print(errMsg)
 
  else
 
    print('The auto assembler script passed.')
 
  end
 
  
 +
local ok, err = autoAssembleCheck(script, true, false)
 +
if ok then
 +
  print("Script is valid")
 +
else
 +
  print("Syntax error:", err)
 +
end
 +
</pre>
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}
  
=== Related Functions ===
+
{{Assembly}}
* [[Lua:autoAssemble|autoAssemble]]
 
* [[Lua:AOBScan|AOBScan]]
 
* [[Lua:disassemble|disassemble]]
 
* [[Lua:getInstructionSize|getInstructionSize]]
 
* [[Lua:getPreviousOpcode|getPreviousOpcode]]
 
* [[Lua:allocateSharedMemory|allocateSharedMemory]]
 
* [[Lua:mapMemory|mapMemory]]
 
* [[Lua:unmapMemory|unmapMemory]]
 
* [[Lua:readBytes|readBytes]]
 
* [[Lua:readPointer|readPointer]]
 
* [[Lua:writeBytes|writeBytes]]
 
* [[Lua:readBytesLocal|readBytesLocal]]
 
* [[Lua:readPointerLocal|readPointerLocal]]
 
* [[Lua:writeBytesLocal|writeBytesLocal]]
 
* [[Lua:wordToByteTable|wordToByteTable]]
 
* [[Lua:dwordToByteTable|dwordToByteTable]]
 
* [[Lua:qwordToByteTable|qwordToByteTable]]
 
* [[Lua:floatToByteTable|floatToByteTable]]
 
* [[Lua:doubleToByteTable|doubleToByteTable]]
 
* [[Lua:stringToByteTable|stringToByteTable]]
 
* [[Lua:wideStringToByteTable|wideStringToByteTable]]
 
* [[Lua:byteTableToWord|byteTableToWord]]
 
* [[Lua:byteTableToDword|byteTableToDword]]
 
* [[Lua:byteTableToQword|byteTableToQword]]
 
* [[Lua:byteTableToFloat|byteTableToFloat]]
 
* [[Lua:byteTableToDouble|byteTableToDouble]]
 
* [[Lua:byteTableToString|byteTableToString]]
 
* [[Lua:byteTableToWideString|byteTableToWideString]]
 

Latest revision as of 00:30, 5 December 2025

<> Function

function autoAssembleCheck(text, enable, targetself)

Checks the given Auto Assembler script for syntax errors. Returns true on success, or false with an error message on failure.

Function Parameters[edit]

Parameter Type Description
text String The Auto Assembler script to validate.
enable Boolean If set, checks the [ENABLE] part of the script.
targetself Boolean If true, checks the script as if assembling into Cheat Engine itself.

Example[edit]

local script = [[
alloc(newmem,2048,"cheatengine-x86_64-SSE4-AVX2.exe"+3E18)
label(returnhere)
label(originalcode)
label(exit)

newmem: //this is allocated memory, you have read,write,execute access
//place your code here

originalcode:
lea rsp,[rsp+28]

exit:
jmp returnhere

"cheatengine-x86_64-SSE4-AVX2.exe"+3E18:
jmp newmem
returnhere:
]]

local ok, err = autoAssembleCheck(script, true, false)
if ok then
  print("Script is valid")
else
  print("Syntax error:", err)
end

See also[edit]

Lua
Script Engine

Related Functions[edit]

autoAssemble
autoAssembleCheck
disassemble
splitDisassembledString
getInstructionSize
getPreviousOpcode
registerAssembler
unregisterAssembler