'To access and allocate Virtual Memory
I am required to talk directly with the OS asking it to allocate pages in your Python process virtual memory.
How do i access the virtual memory with the address of 0xB621740000 and reserve the memory?
Do i use VirtualAlloc? before this, do i have to OpenProcess?
Below is my code:
PVOID = LPVOID
SIZE_T = ctypes.c_size_t
PAGE_SIZE = 4 * 1024
kernel32 = ctypes.WinDLL('Kernel32', use_last_error=True)
address_str = input('Please enter an address where pages should be allocated: ')
address = int(address_str, 0)
handle = OpenProcess(PROCESS_VM_READ, True, 15460)
VirtualAlloc(address, PAGE_SIZE, MEM_RESERVE, PAGE_READWRITE)
Solution 1:[1]
have you heard of the win32api library? It should be possible to do it using that library which would be an easier alternative to using ctypes. You can use VirtualAllocEx in said library to solve this issue. Since you are trying to do it in I assume the same python process that is running the code, you do not need OpenProcess, instead win32proces.GetCurrentProcess() should suffice.
win32process.VirtualAllocEx(win32process.GetCurrentProcess(), address, PAGE_SIZE, win32con.MEM_RESERVE, win32con.PAGE_READWRITE)
Would allocate permissions to read and write in the allocated memory spaces of size PAGE_SIZE.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | seameetsocean |
