Difference between revisions of "Lua:allocateMemory"
Jump to navigation
Jump to search
(Created page with "Category:Lua '''function''' allocateMemory(''size'', ''BaseAddress'' '''''OPTIONAL''''', ''Protection'' '''''OPTIONAL''''') Allocates a specified size of memory into the...") |
m (Syntax Highlighting.) |
||
| (3 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
[[Category:Lua]] | [[Category:Lua]] | ||
| − | '''function''' allocateMemory(''size'', ''BaseAddress | + | {{CodeBox|'''function''' allocateMemory(''size'', ''BaseAddress'', ''Protection'') ''':''' integer}} |
| − | Allocates | + | Allocates memory in the target process. |
| + | The optional ''BaseAddress'' parameter can be used to specify a preferred base address for the allocation. The optional ''Protection'' parameter can be used to specify the memory protection for the allocated region. | ||
===Function Parameters=== | ===Function Parameters=== | ||
| − | {|width="85%" cellpadding="10 | + | {|width="85%" cellpadding="10%" 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 | ||
|- | |- | ||
| − | | | + | |size |
|Integer | |Integer | ||
| − | |The | + | |The number of bytes to allocate in the target process. |
|- | |- | ||
| − | | | + | |BaseAddress |
| − | |Integer | + | |Integer or [[CEAddressString]] (optional) |
| − | |The address | + | |The preferred base address for the allocation. |
|- | |- | ||
|Protection | |Protection | ||
| − | | | + | |Integer or String (optional) |
| − | | | + | |The memory protection to use for the allocated region. |
|} | |} | ||
| + | |||
| + | ===Returns=== | ||
| + | integer — The address of the allocated memory block. | ||
| + | |||
| + | ===Examples=== | ||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local address = allocateMemory(1024) | ||
| + | |||
| + | print("Allocated memory at: " .. string.format("%X", address)) | ||
| + | |||
| + | deAlloc(address) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | <syntaxhighlight lang="lua" line> | ||
| + | local baseAddress = getAddress("game.exe") | ||
| + | local address = allocateMemory(2048, baseAddress) | ||
| + | |||
| + | print("Allocated memory at: " .. string.format("%X", address)) | ||
| + | |||
| + | deAlloc(address) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | {{LuaSeeAlso}} | ||
| + | |||
| + | {{Memory}} | ||
Latest revision as of 16:31, 25 June 2026
Allocates memory in the target process.
The optional BaseAddress parameter can be used to specify a preferred base address for the allocation. The optional Protection parameter can be used to specify the memory protection for the allocated region.
Function Parameters[edit]
| Parameter | Type | Description |
|---|---|---|
| size | Integer | The number of bytes to allocate in the target process. |
| BaseAddress | Integer or CEAddressString (optional) | The preferred base address for the allocation. |
| Protection | Integer or String (optional) | The memory protection to use for the allocated region. |
Returns[edit]
integer — The address of the allocated memory block.
Examples[edit]
1 local address = allocateMemory(1024)
2
3 print("Allocated memory at: " .. string.format("%X", address))
4
5 deAlloc(address)
1 local baseAddress = getAddress("game.exe")
2 local address = allocateMemory(2048, baseAddress)
3
4 print("Allocated memory at: " .. string.format("%X", address))
5
6 deAlloc(address)