Difference between revisions of "Lua:readBytes"

From Cheat Engine
Jump to navigation Jump to search
(Created page with '= readBytes = '''function''' readBytes(''Address'', ''Bytecount'', ''ReturnAsTable'' ) Returns the bytes at the given address ===Function Parameters=== {|width="85%" cellpaddi…')
 
m
 
(27 intermediate revisions by 3 users not shown)
Line 1: Line 1:
= readBytes =
+
[[Category:Lua]]
 +
'''function''' readBytes(''Address'', ''ByteCount'', [''ReturnAsTable''])
  
'''function''' readBytes(''Address'', ''Bytecount'', ''ReturnAsTable'' )
+
Reads bytes from the specified address in the currently opened (target) process. 
 +
Returns the bytes as multiple return values or as a table if ''ReturnAsTable'' is true.
  
Returns the bytes at the given address
+
===Function Parameters===
  
===Function Parameters===
+
{|width="85%" cellpadding="10%" 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
Line 12: Line 13:
 
|-
 
|-
 
|Address
 
|Address
|String or Integer
+
|Integer or [[CEAddressString]]
|The address to read
+
|The address in the target process to read from.
 
|-
 
|-
|Bytecount
+
|ByteCount
 
|Integer
 
|Integer
|The number of bytes to read
+
|The number of bytes to read.
 
|-
 
|-
 
|ReturnAsTable
 
|ReturnAsTable
|Boolean
+
|Boolean (optional)
|Returns a table object instead of multiple return values
+
|If true, returns a table of bytes. If false or omitted, returns each byte as a separate return value.
 
|}
 
|}
 +
 +
===Examples===
 +
<pre>
 +
-- Read 4 bytes and get them as separate values
 +
local b1, b2, b3, b4 = readBytes(0x123456, 4)
 +
print(b1, b2, b3, b4)
 +
 +
-- Read 4 bytes and get them as a table
 +
local bytes = readBytes(0x123456, 4, true)
 +
for i, v in ipairs(bytes) do
 +
  print("Byte " .. i .. ": " .. v)
 +
end
 +
</pre>
 +
 +
{{LuaSeeAlso}}
 +
 +
=== Related Functions ===
 +
{{ReadWriteMemory}}

Latest revision as of 16:01, 11 July 2025

function readBytes(Address, ByteCount, [ReturnAsTable])

Reads bytes from the specified address in the currently opened (target) process. Returns the bytes as multiple return values or as a table if ReturnAsTable is true.

Function Parameters[edit]

Parameter Type Description
Address Integer or CEAddressString The address in the target process to read from.
ByteCount Integer The number of bytes to read.
ReturnAsTable Boolean (optional) If true, returns a table of bytes. If false or omitted, returns each byte as a separate return value.

Examples[edit]

-- Read 4 bytes and get them as separate values
local b1, b2, b3, b4 = readBytes(0x123456, 4)
print(b1, b2, b3, b4)

-- Read 4 bytes and get them as a table
local bytes = readBytes(0x123456, 4, true)
for i, v in ipairs(bytes) do
  print("Byte " .. i .. ": " .. v)
end

See also[edit]

Related Functions[edit]