void *virtual_alloc_ex(HANDLE process_handle, void *addr, uintptr_t size, uint32_t allocation_type, uint32_t protection) { assert(pNtAllocateVirtualMemory != NULL, "pNtAllocateVirtualMemory is NULL!", NULL); SIZE_T real_size = size; if(NT_SUCCESS(pNtAllocateVirtualMemory(process_handle, &addr, 0, &real_size, allocation_type, protection)) != FALSE) { return addr; } return NULL; }
hook_data_t *alloc_hookdata_near(void *addr) { PVOID BaseAddress; int offset = -(1024 * 1024 * 1024); SIZE_T RegionSize = sizeof(hook_data_t); LONG status; do { if (offset < 0 && (ULONG_PTR)addr < (ULONG_PTR)-offset) offset = 0x10000; BaseAddress = (PCHAR)addr + offset; status = pNtAllocateVirtualMemory(GetCurrentProcess(), &BaseAddress, 0, &RegionSize, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); if (status >= 0) return (hook_data_t *)BaseAddress; offset += 0x10000; } while (status < 0 && offset <= (1024 * 1024 * 1024)); return NULL; }