环境win7 x64,总是分配失败,求原因
代码如下
typedef NTSTATUS(WINAPI *ptrNtAllocateVirtualMemory)(
HANDLE ProcessHandle,
PVOID *BaseAddress,
ULONG ZeroBits,
PULONG AllocationSize,
ULONG AllocationType,
ULONG Protect
);
int main()
{
// Resolve NtAllocateVirtualMemory
ptrNtAllocateVirtualMemory NtAllocateVirtualMemory = (ptrNtAllocateVirtualMemory)GetProcAddress(GetModuleHandle("ntdll.dll"), "NtAllocateVirtualMemory");
if (NtAllocateVirtualMemory == NULL)
{
printf("[-] Failed to export NtAllocateVirtualMemory.");
exit(-1);
}
printf("[+] Found address of NtAllocateVirtualMemory: 0x%p\n", NtAllocateVirtualMemory);
// Allocate the NULL page
LPVOID baseAddress = (LPVOID)0x1;
ULONG allocSize = 0x1000;
char* uBuffer = (char*)NtAllocateVirtualMemory(
GetCurrentProcess(),
&baseAddress, // Putting a small non-zero value gets rounded down to page granularity, pointing to the NULL page
0,
&allocSize,
MEM_COMMIT | MEM_RESERVE,
PAGE_EXECUTE_READWRITE);
DWORD dummy;
if (!VirtualProtect(0x0, 0x1000, PAGE_EXECUTE_READWRITE, &dummy))
{
printf("[-] Failed to allocate the NULL page.\n");
exit(-1);
}
*(INT_PTR*)(uBuffer + 8) = 0x12345678;
//printf("[+] Successfully allocated the NULL page.\n");
}
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课
最后于 2018-4-20 10:12
被小旭msx编辑
,原因: