C++ CreateRemoteThread不能与DLL一起工作
我试图注入一个简单的dll,在目标进程中创建一个MessageBox。使用www中的喷油器工作时没有任何问题。但是,使用我自己的代码进行注入根本不起任何作用(我在notepad.exe上使用它) 我在VS2017中将dll和此代码编译为x64调试。Injector创建为Win32控制台项目 代码中的所有阶段都通过了。我得到了进程的句柄,线程句柄也是有效的。但是GetExitCode返回0,所以它总是失败,但我不知道为什么C++ CreateRemoteThread不能与DLL一起工作,c++,dll-injection,createremotethread,C++,Dll Injection,Createremotethread,我试图注入一个简单的dll,在目标进程中创建一个MessageBox。使用www中的喷油器工作时没有任何问题。但是,使用我自己的代码进行注入根本不起任何作用(我在notepad.exe上使用它) 我在VS2017中将dll和此代码编译为x64调试。Injector创建为Win32控制台项目 代码中的所有阶段都通过了。我得到了进程的句柄,线程句柄也是有效的。但是GetExitCode返回0,所以它总是失败,但我不知道为什么 HANDLE process = OpenProcess(PROC
HANDLE process = OpenProcess(PROCESS_ALL_ACCESS, false, pid);
if (process == NULL)
{
std::cout << "Error opening process." << std::endl;
return false;
}
const char * dllString = "C:\\test.dll";
// load memory for dll
int bytes = sizeof(dllString);
PVOID mem = VirtualAllocEx(process, NULL, sizeof(dllString) + 1, MEM_COMMIT, PAGE_READWRITE);
if (mem == NULL)
{
std::cout << "Unable to allocate mem." << std::endl;
CloseHandle(process);
return false;
}
// write dll path to that location
SIZE_T bytesWritten;
BOOL status = WriteProcessMemory(process, mem, dllString, sizeof(dllString) + 1, &bytesWritten);
if (!status)
{
std::cout << "Writing dll path failed." << std::endl;
VirtualFreeEx(process, mem, sizeof(dllString) + 1, MEM_RELEASE);
CloseHandle(process);
return false;
}
FARPROC loadLibrary = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
HANDLE thread = CreateRemoteThread(process, NULL, NULL, reinterpret_cast<LPTHREAD_START_ROUTINE>(loadLibrary), mem, NULL, NULL);
if (thread == INVALID_HANDLE_VALUE)
{
std::cout << "Unable to create thread in remote process. " << std::endl;
VirtualFreeEx(process, mem, sizeof(dllString) + 1, MEM_RELEASE);
CloseHandle(process);
}
WaitForSingleObject(thread, INFINITE);
DWORD exitCode = 0;
GetExitCodeThread(thread, &exitCode);
if (exitCode != 0)
std::cout << "DLL loaded successfully." << std::endl;
else
std::cout << "DLL loading failed." << std::endl;
CloseHandle(thread);
VirtualFreeEx(process, mem, sizeof(dllString) + 1, MEM_RELEASE);
CloseHandle(process);
return true;
HANDLE process=OpenProcess(process\u ALL\u ACCESS,false,pid);
if(进程==NULL)
{
std::cout刚刚自己解决了这个问题。实际上是一个noob问题。sizeof实际上是返回指针的大小,对于x64是64位,而不是我需要分配的内存的字符串长度。因此,将其更改为strlen后,它就起作用了