Difference between revisions of "Lua:readString"

From Cheat Engine
Jump to navigation Jump to search
m
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
'''function''' readString(''Address'', ''Maxlength'', ''isWideString'')
+
[[Category:Lua]]
 +
'''function''' readString(''Address'', ''MaxLength'', [''WideChar'']) ''':''' String
  
Reads the bytes the given address and interprets them as a string
+
Reads a string from the specified address in the currently opened (target) process until a 0-terminator is encountered. 
 +
The maximum number of characters to read is limited by ''MaxLength'' to prevent freezing. 
 +
Set ''WideChar'' to true if the string is encoded using widechar (UTF-16/Unicode) formatting.
  
 
===Function Parameters===
 
===Function Parameters===
{|width="85%" cellpadding="10%" cellpadding="5%" cellspacing="0" border="0"
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 
!align="left"|Parameter
 
!align="left"|Parameter
 
!align="left"|Type
 
!align="left"|Type
Line 10: Line 13:
 
|-
 
|-
 
|Address
 
|Address
|[[CEAddressString]] or Integer
+
|Integer or [[CEAddressString]]
|The address to read
+
|The address in the target process to read from.
 
|-
 
|-
|Maxlength
+
|MaxLength
 
|Integer
 
|Integer
|The maximum number of characters to read. If the string does not have a 0-terminator this will be the length of the string returned
+
|The maximum number of characters to read (prevents infinite loops; use 6000 if you don't care).
 
|-
 
|-
|isWideString
+
|WideChar
|Boolean
+
|Boolean (optional)
|Determines if this string is read out as a widestring or a normal ascii string
+
|Set to true to read as a widechar (UTF-16/Unicode) string. Default is false (ASCII/ANSI).
 
|}
 
|}
  
== See also ==
+
===Returns===
* [[readBytes]]
+
String — The string read from the specified address.
* [[readInteger]]
+
 
* [[readFloat]]
+
===Examples===
* [[readDouble]]
+
<pre>
* [[Lua]]
+
-- Read an ASCII string from address 0x123456, up to 100 characters
 +
local str = readString(0x123456, 100)
 +
print("String:", str)
 +
 
 +
-- Read a widechar (Unicode) string from a CEAddressString
 +
local wstr = readString("game.exe+1234", 256, true)
 +
print("Wide string:", wstr)
 +
</pre>
 +
 
 +
{{LuaSeeAlso}}
 +
 
 +
=== Related Functions ===
 +
* [[ansiToUtf8]]
 +
* [[utf8ToAnsi]]
 +
* [[translate]]
 +
{{ReadWriteMemory}}

Latest revision as of 17:03, 11 July 2025

function readString(Address, MaxLength, [WideChar]) : String

Reads a string from the specified address in the currently opened (target) process until a 0-terminator is encountered. The maximum number of characters to read is limited by MaxLength to prevent freezing. Set WideChar to true if the string is encoded using widechar (UTF-16/Unicode) formatting.

Function Parameters[edit]

Parameter Type Description
Address Integer or CEAddressString The address in the target process to read from.
MaxLength Integer The maximum number of characters to read (prevents infinite loops; use 6000 if you don't care).
WideChar Boolean (optional) Set to true to read as a widechar (UTF-16/Unicode) string. Default is false (ASCII/ANSI).

Returns[edit]

String — The string read from the specified address.

Examples[edit]

-- Read an ASCII string from address 0x123456, up to 100 characters
local str = readString(0x123456, 100)
print("String:", str)

-- Read a widechar (Unicode) string from a CEAddressString
local wstr = readString("game.exe+1234", 256, true)
print("Wide string:", wstr)

See also[edit]

Related Functions[edit]