我试图将NtAllocateVirtualMemory用于项目,并且我确信其他人已经取得了成功,但这不会在VSC ++ 2010上编译,也不会编译。在两个编译器上都说
FARPROC:呼叫
的参数太多了有谁知道如何编译这段代码?谢谢你的时间。
FARPROC NtAllocateVirtualMemory;
NtAllocateVirtualMemory = GetProcAddress(GetModuleHandle("NTDLL.DLL"), "NtAllocateVirtualMemory");
printf( "NtAllocateVirtualMemory %08x\n", NtAllocateVirtualMemory);
ReturnCode = NtAllocateVirtualMemory(GetCurrentProcess(),
&BaseAddress,
0,
&RegionSize,
MEM_COMMIT | MEM_RESERVE,
PAGE_EXECUTE_READWRITE);
答案 0 :(得分:2)
您需要将GetProcAddress
的结果转换为正确类型的函数指针。在这种情况下:
typedef NTSTATUS WINAPI (*PNtAllocateVirtualMemory)(HANDLE ProcessHandle,
PVOID *BaseAddress,
ULONG_PTR ZeroBits,
PSIZE_T RegionSize,
ULONG AllocationType,
ULONG Protect);
FARPROC NAVM = GetProcAddress(...);
PNtAllocateVirtualMemory NtAllocateVirtualMemory = (PNtAllocateVirtualMemory)NAVM;
...
当然,简单地使用VirtualAlloc
会容易得多。
VirtualAlloc(&BaseAddress, RegionSize, MEM_COMMIT | MEM_RESERVE,
PAGE_EXECUTE_READWRITE);