如何将 DLL 加载到用户定义的内存地址中,或者是否可以在使用loadlibrary()
函数加载 DLL 后更改 DLL 地址。
我尝试使用VirtualAllocEx()
分配内存地址并将DLL加载到远程进程。DLL 正在加载到远程进程中,但地址不同。
//virtually allocating the memory address
DWORD *arg = (PDWORD)VirtualAllocEx(process, /*(LPVOID)0x81200000*/0, strlen(buffer), MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
if(arg == NULL) {
return 1;
}
//Write the argument to LoadLibraryA to the process's newly allocated memory region.
int n = WriteProcessMemory(process, arg, buffer, strlen(buffer), NULL);
if(n == 0) {
return 1;
}
//Inject our DLL into the process's address space.
HANDLE threadID = CreateRemoteThread(process, NULL, 0, (LPTHREAD_START_ROUTINE)address, arg, NULL, NULL);
我也尝试过使用rebaseimage()
函数,但加载 DLL 后内存地址发生了变化。
//rebaseimage function to change the base address of the DLL
ret = ReBaseImage("WinMemoryDLL.dll","",TRUE,TRUE,FALSE,0,&OldImage,&OldImageBase,&NewImageSize,&NewImageBase,0);
hinstLib = LoadLibrary(TEXT("WinMemoryDLL.dll"));