Difference between revisions of "Lua:AOBScan"

From Cheat Engine
Jump to navigation Jump to search
m
m (Syntax Highlighting.)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
−
'''function''' AOBScan('''''...''''')
+
{{CodeBox|'''function''' AOBScan(''aobstring'', ''protectionflags'', ''alignmenttype'', ''alignmentparam'') ''':''' StringList}}
 +
{{CodeBox|'''function''' AOBScan(''byte1'', ''byte2'', ''...'') ''':''' StringList}}
  
−
'''function''' AOBScan(''AOBString'', ''ProtectionFlags'' OPTIONAL, ''AlignmentType'' OPTIONAL, ''AlignmentParam'' HALFOPTIONAL)
+
Scans the currently opened process for an array of bytes and returns a StringList containing all matching addresses.
  
−
Scans the currently opened process and returns a [[Lua:Class:Stringlist|StringList]] object containing all the results.
+
The returned StringList must be destroyed when it is no longer needed.
−
Don't forget to free this list when done.
 
−
Byte value of higher than 255 or anything not an integer will be seen as a wildcard.
 
  
 +
===Function Parameters===
 +
====String Pattern Form====
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Parameter
 +
!align="left"|Type
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|aobstring
 +
|String
 +
|The array-of-bytes pattern to scan for. Wildcards can be used in the pattern.
 +
|-
 +
|protectionflags
 +
|String (optional)
 +
|A string that controls which memory regions are scanned based on executable, writable, and copy-on-write protection flags.
 +
|-
 +
|alignmenttype
 +
|Integer (optional)
 +
|Controls the address alignment check.
 +
|-
 +
|alignmentparam
 +
|String
 +
|The alignment parameter. Required when the selected alignment type needs a value.
 +
|}
  
−
=== Function Parameters ===
+
====Byte Parameter Form====
−
 
+
{|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
 
!style="width: 80%;background-color:white;" align="left"|Description
 
!style="width: 80%;background-color:white;" align="left"|Description
 
|-
 
|-
−
|...
+
|byte1, byte2, ...
−
|'''...'''
+
|Integer
−
|Bytes to scan for seperated as arguments
+
|The byte values to scan for. Values higher than 255 or values that are not integers are treated as wildcards.
 +
|}
 +
 
 +
===Returns===
 +
StringList — A StringList containing all matching addresses as strings.
 +
 
 +
The returned list must be destroyed manually when it is no longer needed.
 +
 
 +
===Protection Flags===
 +
The protectionflags parameter is a string made from memory protection flags.
 +
 
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Flag
 +
!align="left"|Meaning
 +
|-
 +
|X
 +
|Executable memory.
 +
|-
 +
|W
 +
|Writable memory.
 +
|-
 +
|C
 +
|Copy-on-write memory.
 +
|}
 +
 
 +
Each flag can be prefixed with one of the following operators:
 +
 
 +
{|cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Operator
 +
!align="left"|Meaning
 +
|-
 +
|'''+'''
 +
|The flag must be set.
 +
|-
 +
|'''-'''
 +
|The flag must not be set.
 +
|-
 +
|'''*'''
 +
|The flag does not matter.
 
|}
 
|}
  
 +
===Protection Flag Examples===
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Protection Flags
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|'''+W-C'''
 +
|Scans writable memory, excludes copy-on-write memory, and does not care about the executable flag.
 +
|-
 +
|'''+X-C-W'''
 +
|Scans read-only executable memory.
 +
|-
 +
|'''+W'''
 +
|Scans writable memory and does not care about copy-on-write or executable memory.
 +
|-
 +
|
 +
|Scans everything. This is the same as *X*C*W.
 +
|}
  
−
{|width="85%" cellpadding="10%" cellpadding="5%" cellspacing="0" border="0"
+
===Alignment Types===
−
!align="left"|Parameter
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
−
!align="left"|Type
+
!align="left"|Value
 +
!align="left"|Name
 
!style="width: 80%;background-color:white;" align="left"|Description
 
!style="width: 80%;background-color:white;" align="left"|Description
 
|-
 
|-
−
|AOBString
+
|0
−
|string
+
|No alignment check
−
|A string of bytes, as hex, to scan for
+
|No alignment restriction is applied.
 
|-
 
|-
−
|ProtectionFlags
+
|1
−
|string
+
|Divisible alignment
−
|A string of flags used to set protection type of memory to be scanned
+
|The address must be divisible by alignmentparam.
 
|-
 
|-
−
|AlignmentType
+
|2
−
|integer
+
|Last digits alignment
−
|Used with 'AlignmentParam' to set scan alignment
+
|The address must end with the digits specified by alignmentparam.
 +
|}
 +
 
 +
===Alignment Parameter===
 +
The alignmentparam parameter is a string.
 +
 
 +
Its meaning depends on alignmenttype:
 +
 
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Alignment Type
 +
!style="width: 80%;background-color:white;" align="left"|alignmentparam Meaning
 
|-
 
|-
−
|AlignmentParam
+
|0
−
|string
+
|Not used.
−
|A string which either holds the value the addresses must be dividable by or what the last digits of the address must be
+
|-
 +
|1
 +
|The value the address must be divisible by.
 +
|-
 +
|2
 +
|The last digits the address must end with.
 
|}
 
|}
  
 +
===Wildcard Behavior===
 +
In the byte parameter form, every value higher than 255 or every value that is not an integer is treated as a wildcard.
 +
 +
In the string pattern form, use the normal array-of-bytes wildcard syntax inside the pattern string.
 +
 +
===Examples===
 +
<syntaxhighlight lang="lua" line>
 +
local results = AOBScan("48 8B ?? ?? ?? 89")
  
−
* '''''protectionflags''''' is a string:
+
if results ~= nil then
−
** Add a + to indicate that flag MUST be set and a - to indicate that that flag MUST NOT be set. (* sets it to don't care)
+
   print("Results found: " .. tostring(results.Count))
−
** X = Executable
 
−
** W = Writable memory
 
−
** C = Copy On Write.
 
−
Examples:
 
−
  +W-C = Writable memory exluding copy on write and doesn't care about the Executable flag
 
−
  +X-C-W = Find readonly executable memory
 
−
  +W = Finds all writable memory and don't care about copy on write or execute
 
−
   "" = Find everything (is the same as "*X*C*W" )
 
  
 +
  for i = 0, results.Count - 1 do
 +
    print(results[i])
 +
  end
  
−
* '''''alignmenttype''''' is an integer:
+
  results.destroy()
−
** 0 = No alignment check
+
end
−
** 1 = Address must be dividable by alignmentparam
+
</syntaxhighlight>
−
** 2 = Address must end with alignmentparam
 
  
 +
<syntaxhighlight lang="lua" line>
 +
local results = AOBScan("48 8B ?? ?? ?? 89", "+X-C-W")
 +
 +
if results ~= nil then
 +
  print("Executable read-only results: " .. tostring(results.Count))
 +
  results.destroy()
 +
end
 +
</pre>
 +
 +
<syntaxhighlight lang="lua" line>
 +
local results = AOBScan("48 8B ?? ?? ?? 89", "+W-C", 1, "4")
 +
 +
if results ~= nil then
 +
  print("Writable aligned results: " .. tostring(results.Count))
 +
  results.destroy()
 +
end
 +
</syntaxhighlight>
 +
 +
<syntaxhighlight lang="lua" line>
 +
local results = AOBScan(0x48, 0x8B, 999, 0x89)
 +
 +
if results ~= nil then
 +
  print("Results found: " .. tostring(results.Count))
 +
  results.destroy()
 +
end
 +
</syntaxhighlight>
 +
 +
===Notes===
 +
* AOBScan scans the currently opened process.
 +
* The returned StringList must be destroyed when it is no longer needed.
 +
* The string pattern form is usually easier to read and maintain.
 +
* The byte parameter form treats values higher than 255 or non-integer values as wildcards.
 +
* An empty protectionflags string scans all memory regions.
 +
* Use protection flags and alignment when you want to reduce false positives or improve scan performance.
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}
  
−
=== Related Functions ===
+
{{Scanning}}
−
* [[Lua:autoAssemble|autoAssemble]]
+
 
−
* [[Lua:disassemble|disassemble]]
+
=== Readonly Classes ===
−
* [[Lua:getInstructionSize|getInstructionSize]]
+
* [[Lua:Class:Stringlist|StringList]] - String list object documentation
−
* [[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 16:23, 25 June 2026

<> Lua API Reference

function AOBScan(aobstring, protectionflags, alignmenttype, alignmentparam) : StringList

<> Lua API Reference

function AOBScan(byte1, byte2, ...) : StringList

Scans the currently opened process for an array of bytes and returns a StringList containing all matching addresses.

The returned StringList must be destroyed when it is no longer needed.

Function Parameters[edit]

String Pattern Form[edit]

Parameter Type Description
aobstring String The array-of-bytes pattern to scan for. Wildcards can be used in the pattern.
protectionflags String (optional) A string that controls which memory regions are scanned based on executable, writable, and copy-on-write protection flags.
alignmenttype Integer (optional) Controls the address alignment check.
alignmentparam String The alignment parameter. Required when the selected alignment type needs a value.

Byte Parameter Form[edit]

Parameter Type Description
byte1, byte2, ... Integer The byte values to scan for. Values higher than 255 or values that are not integers are treated as wildcards.

Returns[edit]

StringList — A StringList containing all matching addresses as strings.

The returned list must be destroyed manually when it is no longer needed.

Protection Flags[edit]

The protectionflags parameter is a string made from memory protection flags.

Flag Meaning
X Executable memory.
W Writable memory.
C Copy-on-write memory.

Each flag can be prefixed with one of the following operators:

Operator Meaning
+ The flag must be set.
- The flag must not be set.
* The flag does not matter.

Protection Flag Examples[edit]

Protection Flags Description
+W-C Scans writable memory, excludes copy-on-write memory, and does not care about the executable flag.
+X-C-W Scans read-only executable memory.
+W Scans writable memory and does not care about copy-on-write or executable memory.
Scans everything. This is the same as *X*C*W.

Alignment Types[edit]

Value Name Description
0 No alignment check No alignment restriction is applied.
1 Divisible alignment The address must be divisible by alignmentparam.
2 Last digits alignment The address must end with the digits specified by alignmentparam.

Alignment Parameter[edit]

The alignmentparam parameter is a string.

Its meaning depends on alignmenttype:

Alignment Type alignmentparam Meaning
0 Not used.
1 The value the address must be divisible by.
2 The last digits the address must end with.

Wildcard Behavior[edit]

In the byte parameter form, every value higher than 255 or every value that is not an integer is treated as a wildcard.

In the string pattern form, use the normal array-of-bytes wildcard syntax inside the pattern string.

Examples[edit]

 1 local results = AOBScan("48 8B ?? ?? ?? 89")
 2 
 3 if results ~= nil then
 4   print("Results found: " .. tostring(results.Count))
 5 
 6   for i = 0, results.Count - 1 do
 7     print(results[i])
 8   end
 9 
10   results.destroy()
11 end
 1 local results = AOBScan("48 8B ?? ?? ?? 89", "+X-C-W")
 2 
 3 if results ~= nil then
 4   print("Executable read-only results: " .. tostring(results.Count))
 5   results.destroy()
 6 end
 7 </pre>
 8 
 9 <syntaxhighlight lang="lua" line>
10 local results = AOBScan("48 8B ?? ?? ?? 89", "+W-C", 1, "4")
11 
12 if results ~= nil then
13   print("Writable aligned results: " .. tostring(results.Count))
14   results.destroy()
15 end
1 local results = AOBScan(0x48, 0x8B, 999, 0x89)
2 
3 if results ~= nil then
4   print("Results found: " .. tostring(results.Count))
5   results.destroy()
6 end

Notes[edit]

  • AOBScan scans the currently opened process.
  • The returned StringList must be destroyed when it is no longer needed.
  • The string pattern form is usually easier to read and maintain.
  • The byte parameter form treats values higher than 255 or non-integer values as wildcards.
  • An empty protectionflags string scans all memory regions.
  • Use protection flags and alignment when you want to reduce false positives or improve scan performance.

Main Pages

Core Lua documentation entry points

◆ Lua
◆ Script Engine

Related Pages

Readonly Classes[edit]