Is it normal for an injector to crash if no DLL exists yet?
I'm following Fleep Hacks' tutorials (I'm a noob in this field still, what can you expect
) and trying to write them in my own way somewhat. I'm wondering why the injector crashes during runtime... (I'm suspecting it's something to do with FARPROC loadLibraryAddr variable, but I'm not sure... I haven't actually created my DLL yet, but it still should be able to inject nothing into a process too, right?
) and trying to write them in my own way somewhat. I'm wondering why the injector crashes during runtime... (I'm suspecting it's something to do with FARPROC loadLibraryAddr variable, but I'm not sure... I haven't actually created my DLL yet, but it still should be able to inject nothing into a process too, right?Code:
#include <iostream>
#include <windows.h>
#include <TlHelp32.h>
char* procName = "ac_client.exe";
char* FileToInject = "ACDLL.dll";
bool injectDLL(DWORD procID){
HANDLE hProc;
LPVOID paramAddr;
HINSTANCE hDLL = LoadLibrary("KERNEL32");
FARPROC loadLibraryAddr = GetProcAddress(hDLL, "LoadLibraryA");
hProc = OpenProcess(PROCESS_ALL_ACCESS, false, procID);
char* dllPath = "C:\\Users\\Kalist\\Desktop\\";
strcat(dllPath, FileToInject);
paramAddr = VirtualAllocEx(hProc, 0, strlen(dllPath)+1, MEM_COMMIT, PAGE_READWRITE);
bool memoryWritten = WriteProcessMemory(hProc, paramAddr, dllPath, strlen(dllPath)+1, 0);
CreateRemoteThread(hProc, 0, 0, (LPTHREAD_START_ROUTINE)loadLibraryAddr, paramAddr, 0, 0);
CloseHandle(hProc);
return memoryWritten;
}
int main(){
DWORD procID = 0;
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(PROCESSENTRY32);
HANDLE hProcSnap;
while(!procID){
std::cout << "Searching for " << procName; Sleep(500); std::cout << "."; Sleep(500); std::cout << "."; Sleep(500); std::cout << "."; Sleep(500);
hProcSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, procID);
if(Process32First(hProcSnap, &pe32)){
do{
if(!strcmp(pe32.szExeFile, procName)){
procID = pe32.th32ProcessID;
break;
}
}while(Process32Next(hProcSnap, &pe32));
}
if(!procID){
system("CLS");
}
}
while(!injectDLL(procID)){
system("CLS");
std::cout << "Injecting"; Sleep(500); std::cout << "."; Sleep(500); std::cout << "."; Sleep(500); std::cout << "."; Sleep(500);
}
system("CLS");
std::cout << std::endl << "Injected successfully!";
}