Difference between revisions of "Lua:AOBScan"
Mr millchick (talk | contribs) m (fixed formatting, restored accidentally deleted references) |
m (Syntax Highlighting.) |
||
| (One intermediate revision by the same user 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}} | ||
| − | + | 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=== | |
| − | + | ====String Pattern Form==== | |
| − | + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | === Function Parameters === | ||
| − | |||
| − | ==== | ||
| − | |||
| − | {|width="85%" cellpadding="10 | ||
!align="left"|Parameter | !align="left"|Parameter | ||
!align="left"|Type | !align="left"|Type | ||
| − | !style="width: 80%;" align="left"|Description | + | !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. |
|} | |} | ||
| − | ==== | + | ====Byte Parameter Form==== |
| − | + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | |
| − | {|width="85%" cellpadding="10 | ||
!align="left"|Parameter | !align="left"|Parameter | ||
!align="left"|Type | !align="left"|Type | ||
| − | !style="width: 80%;" align="left"|Description | + | !style="width: 80%;background-color:white;" align="left"|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=== | ||
| + | StringList — A StringList containing all matching addresses as strings. | ||
| − | + | The returned list must be destroyed manually when it is no longer needed. | |
| − | The | + | ===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. | ||
| + | |} | ||
| − | === Alignment | + | ===Alignment Types=== |
| + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | ||
| + | !align="left"|Value | ||
| + | !align="left"|Name | ||
| + | !style="width: 80%;background-color:white;" align="left"|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=== | |
| + | 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 | ||
| + | |- | ||
| + | |0 | ||
| + | |Not used. | ||
| + | |- | ||
| + | |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") | |
| − | |||
| − | |||
| − | |||
| − | + | if results ~= nil then | |
| − | + | print("Results found: " .. tostring(results.Count)) | |
| − | |||
| − | |||
| − | |||
| − | + | for i = 0, results.Count - 1 do | |
| − | + | print(results[i]) | |
| − | + | end | |
| − | |||
| − | |||
| − | + | results.destroy() | |
| − | + | end | |
| − | + | </syntaxhighlight> | |
| − | |||
| − | |||
| − | + | <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}} | ||
| − | + | {{Scanning}} | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
=== Readonly Classes === | === Readonly Classes === | ||
* [[Lua:Class:Stringlist|StringList]] - String list object documentation | * [[Lua:Class:Stringlist|StringList]] - String list object documentation | ||
Latest revision as of 16:23, 25 June 2026
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.
Contents
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.
Related Pages
Readonly Classes[edit]
- StringList - String list object documentation