I'm trying to make a DLL injector but there are parameter errors in the functions.
I've tried changing the variable to char*, I've confirmed that the process ID is correct, I can't compile it in x64 or x86 because I'm using code blocks but the program I'm trying it on was created with code blocks, the DLL works with other injectors, I've confirmed that the dll path is correct.
void EchoLastError()
{
std::string ToExecute;
std::stringstream Command;
Command << "echo " << GetLastError();
ToExecute = Command.str();
system(ToExecute.c_str());
Command.str(std::string());
}
BOOL CreateRemoteThreadInject(DWORD IDofproc, const char * dll)
{
HANDLE Process;
LPVOID Memory, LoadLibrary;
if (!IDofproc)
{
return false;
}
Process = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION, FALSE, IDofproc);
EchoLastError();
system("pause");
LoadLibrary = (LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
Memory = (LPVOID)VirtualAllocEx(Process, NULL, strlen(dll) + 1, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
WriteProcessMemory(Process, (LPVOID)Memory, dll, strlen(dll) + 1, NULL);
CreateRemoteThread(Process, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibrary, (LPVOID)Memory, NULL, NULL);
EchoLastError();
CloseHandle(Process);
VirtualFreeEx(Process, (LPVOID)Memory, 0, MEM_RELEASE);
EchoLastError();
MessageBox(NULL, "Injected", "", MB_OK);
return true;
}
//other
bool Injectstuff(DWORD processId, char* dllpath)
{
std::stringstream kds;
kds << "echo Process ID: " << processId;
std::string dl = kds.str();
system(dl.c_str());
EchoLastError();
HANDLE hTargetProcess = OpenProcess(PROCESS_ALL_ACCESS, false, processId);
EchoLastError();
system("pause");
if (hTargetProcess)
{
LPVOID LoadLibAddress = (LPVOID)GetProcAddress(GetModuleHandleA("kernel32.dll"), "LoadLibraryA");
EchoLastError();
system("pause");
LPVOID LoadPath = VirtualAllocEx(hTargetProcess, 0, strlen(dllpath), MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
EchoLastError();
system("pause");
HANDLE RemoteThread = CreateRemoteThread(hTargetProcess, 0, 0, (LPTHREAD_START_ROUTINE)LoadLibAddress, LoadPath, 0, 0);
EchoLastError();
system("pause");
WaitForSingleObject(RemoteThread, INFINITE);
EchoLastError();
system("pause");
VirtualFreeEx(hTargetProcess, LoadPath, strlen(dllpath), MEM_RELEASE);
EchoLastError();
system("pause");
CloseHandle(RemoteThread);
CloseHandle(hTargetProcess);
return true;
}
return false;
}
The first function prints 87 on VirtualFreeEx, the second prints 6 on VirtualFreeEx. How do I fix these? I'm using GNU GCC compiler.