Difference between revisions of "Lua:splitDisassembledString"

From Cheat Engine
Jump to navigation Jump to search
m
m (Added CodeBox Template.)
 
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' splitDisassembledString(''DisassembledString'') ''':''' (string, string, string, string '''-''' nil)
+
{{CodeBox|'''function''' splitDisassembledString(''disassembledString'') ''':''' String, String, String, String}}
  
Slipts a disassembler string, returning 4 strings. The address, bytes, opcode and extra field.
+
Splits a disassembled instruction string (typically returned from <code>disassemble</code>) into '''four separate strings''':
To be used with return from [[disassemble]].
+
the address, opcode, bytes, and extra field (comment).
  
=== 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
 
!style="width: 80%;background-color:white;" align="left"|Description
 
|-
 
|-
|DisassembledString
+
|disassembledString
|string
+
|String
|The disassembled string to split
+
|The disassembled instruction string to parse.
 
|}
 
|}
  
 
+
===Example===
== Examples ==
+
<pre>
  local addr = getAddress('00123ABC')
+
local disStr = disassemble(0x00403E0B)
  local disassStr = disassemble(addr)
+
local address, opcode, bytes, extra = splitDisassembledString(disStr)
  local extraField, opcode, bytes, address = splitDisassembledString(disassStr)
+
print(address) -- e.g., "[cheatengine-x86_64-SSE4-AVX2.exe+7BF0A0]"
  local addr_2 = addr + getInstructionSize(addr)
+
print(opcode)   -- e.g., "lea rcx,[00BBF010]"
  local disassStr_2 = disassemble(addr)
+
print(bytes)    -- e.g., "48 8D 0D FEB17B00"
  local extraField_2, opcode_2, bytes_2, address_2 = splitDisassembledString(disassStr)
+
print(extra)    -- e.g., "00403E0B"
 
+
</pre>
 
 
Code:
 
  local addr = getAddress('Tutorial-x86_64.exe+164A7')
 
  local disassStr = disassemble(addr)
 
  local extraField, opcode, bytes, address = splitDisassembledString(disassStr)
 
  for i = 1, 10 do
 
    local a = getNameFromAddress(address) or address
 
    local b = bytes .. string.rep(' ', 20 - #bytes)
 
    local o = opcode .. string.rep(' ', 30 - #opcode)
 
    print(string.format('%s:  %s  -  %s    %s', a, b, o, extraField))
 
    addr = addr + getInstructionSize(addr)
 
    disassStr = disassemble(addr)
 
    extraField, opcode, bytes, address = splitDisassembledString(disassStr)
 
  end
 
Output:
 
  Tutorial-x86_64.exe+164A7:  48 63 40 3C          -  movsxd  rax,dword ptr [rax+3C]   
 
  Tutorial-x86_64.exe+164AB:  48 8D 04 03          - lea rax,[rbx+rax]                 
 
  Tutorial-x86_64.exe+164AF:  48 8B 40 60          -  mov rax,[rax+60]                  
 
   Tutorial-x86_64.exe+164B3:  90                    -  nop                               
 
  Tutorial-x86_64.exe+164B4:  48 8D 64 24 20        -  lea rsp,[rsp+20]                  
 
  Tutorial-x86_64.exe+164B9:  5B                    -  pop rbx                           
 
  Tutorial-x86_64.exe+164BA:  C3                    -  ret                               
 
  Tutorial-x86_64.exe+164BB:  00 00                -  add [rax],al                     
 
  Tutorial-x86_64.exe+164BD:  00 00                -  add [rax],al                     
 
  Tutorial-x86_64.exe+164BF:  00 53 48              -  add [rbx+48],dl 
 
 
 
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}
  
 
{{Assembly}}
 
{{Assembly}}

Latest revision as of 00:27, 5 December 2025

<> Function

function splitDisassembledString(disassembledString) : String, String, String, String

Splits a disassembled instruction string (typically returned from disassemble) into four separate strings: the address, opcode, bytes, and extra field (comment).

Function Parameters[edit]

Parameter Type Description
disassembledString String The disassembled instruction string to parse.

Example[edit]

local disStr = disassemble(0x00403E0B)
local address, opcode, bytes, extra = splitDisassembledString(disStr)
print(address)  -- e.g., "[cheatengine-x86_64-SSE4-AVX2.exe+7BF0A0]"
print(opcode)   -- e.g., "lea rcx,[00BBF010]"
print(bytes)    -- e.g., "48 8D 0D FEB17B00"
print(extra)    -- e.g., "00403E0B"

See also[edit]

Lua
Script Engine

Related Functions[edit]

autoAssemble
autoAssembleCheck
disassemble
splitDisassembledString
getInstructionSize
getPreviousOpcode
registerAssembler
unregisterAssembler