Home > Software engineering >  Novice, write DLL path name failed
Novice, write DLL path name failed

Time:09-16

Will help you a great god, why write failed, compile there is no problem, but to run will be prompted to write failure path name


 
# include "PCH. H"
#include
#include
# define GameClassName ZElementClient "Window", "
//# define dllFullpath "F: \ \ c + + Pritice \ \ GGG \ \ MFC_DLL \ \ Debug \ \ MFC_DLL DLL"
# define dllName "MFC_DLL. DLL
"Void InjectDll (HWND Gameh, const char * DllNameFullPath)
{

DWORD pid=0;
HANDLE hProcess=NULL;
LPDWORD AddressDW=NULL;
DWORD byWriteSize=NULL;
HANDLE threadHandle=NULL;
//get the game window handle
If (Gameh!=0)
{
//based on the game window handle to obtain process PID
GetWindowThreadProcessId (Gameh, & amp; Pid);
If (pid!=0)
{
//pid gain through process handle
HProcess=OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid);
If (hProcess!=NULL)
{
//a piece of memory space in the game process distribution
AddressDW=(LPDWORD) VirtualAllocEx (hProcess, NULL, 256, MEM_COMMIT, PAGE_READONLY);
If (AddressDW!=NULL)
{
//write DLL full path name
WriteProcessMemory (hProcess, AddressDW DllNameFullPath, strlen (DllNameFullPath) + 1, & amp; ByWriteSize);
If (byWriteSize & gt;=strlen (DllNameFullPath))
{
ThreadHandle=CreateRemoteThread (hProcess, NULL, NULL, LPTHREAD_START_ROUTINE LoadLibraryA, AddressDW, NULL, NULL);
The WaitForSingleObject (threadHandle, 0 XFFFFFFF);
The CloseHandle (threadHandle);
VirtualFreeEx (hProcess, AddressDW, 256, MEM_DECOMMIT);
The CloseHandle (hProcess);
}
The else
{
Printf (" write DLL path name failure \ n ");
}
}
}
}

}
}





Int main ()
{
Char DirName [256]="";//store directory name
Char dllNamePath [256]="";//used to store the DLL full path name
//injected DLL code
HWND Gameh=FindWindow (GameClassName, NULL);

Printf (" injection test \ r \ n ");
GetCurrentDirectoryA (sizeof (DirName), DirName);
Strcpy_s (dllNamePath DirName);
Strcat_s (dllNamePath, \ \ "");
Strcat_s (dllNamePath dllName);//append DLL name
Printf (" % s \ r \ n ", dllNamePath);
InjectDll (Gameh dllNamePath);//DLL injection into the game window


return 0;
}


CodePudding user response:

Check the WriteProcessMemory functions return values, if it fails, GetLastError () how much is the value?

CodePudding user response:

AddressDW=(LPDWORD) VirtualAllocEx (hProcess, NULL, 256, MEM_COMMIT, PAGE_READONLY ).
PAGE_READONLY you wrote in to my ass, with PAGE_READWRITE

CodePudding user response:

Well,,, good, go home later to try, thank you for your bosses