Protection - Rob--/memoryjs GitHub Wiki
Details
This library exposes VirtualProtectEx
allowing you to change the protection of a region of memory.
Refer to MSDN's VirtualProtectEx documentation for more information.
Protection Type
When calling setProtection
you are required to pass a protection type which is a number, or a constant from within the library.
Protection Type | Value | Constant |
---|---|---|
PAGE_NOACCESS | 0x01 | memoryjs.PAGE_NOACCESS |
PAGE_READONLY | 0x02 | memoryjs.PAGE_READONLY |
PAGE_READWRITE | 0x04 | memoryjs.PAGE_READWRITE |
PAGE_WRITECOPY | 0x08 | memoryjs.PAGE_WRITECOPY |
PAGE_EXECUTE | 0x10 | memoryjs.PAGE_EXECUTE |
PAGE_EXECUTE_READ | 0x20 | memoryjs.PAGE_EXECUTE_READ |
PAGE_EXECUTE_READWRITE | 0x40 | memoryjs.PAGE_EXECUTE_READWRITE |
PAGE_EXECUTE_WRITECOPY | 0x80 | memoryjs.PAGE_EXECUTE_WRITECOPY |
PAGE_GUARD | 0x100 | memoryjs.PAGE_GUARD |
PAGE_NOCACHE | 0x200 | memoryjs.PAGE_NOCACHE |
PAGE_WRITECOMBINE | 0x400 | memoryjs.PAGE_WRITECOMBINE |
PAGE_ENCLAVE_UNVALIDATED | 0x20000000 | memoryjs.PAGE_ENCLAVE_UNVALIDATED |
PAGE_TARGETS_INVALID | 0x40000000 | memoryjs.PAGE_TARGETS_INVALID |
PAGE_TARGETS_NO_UPDATE | 0x40000000 | memoryjs.PAGE_TARGETS_NO_UPDATE |
PAGE_ENCLAVE_THREAD_CONTROL | 0x80000000 | memoryjs.PAGE_ENCLAVE_THREAD_CONTROL |
Refer to MSDN's Memory Protection Constants page for more information.
Functions
setProtection(handle, address, size, protection[, callback])
- handle - the handle of the process, retrieved from calling
openProcess
- address - address of the region in memory whose access protection attributes are to be changed
- size - size of the memory region to change in bytes
- protection - the type of protection to be set, has to be one of the constants referenced above
- callback - has two parameters:
- error - error message (if one occurred)
- oldProtection - the previous access protection of the memory region
returns (if no callback provided): the previous access protection of the memory region
Changes the protection of a specified memory region.
// synchronously
const oldProtection = memoryjs.setProtection(handle, address, size, protection);
// asynchronously
memoryjs.setProtection(handle, address, size, protection, (error, oldProtection) => {
});