Hello,
I built a DLL injector that injects a dll into a process (obvious xD) but my problem is that when i inject my DLL the code in it doesnt run.
So after a lot of reserch i discovered that it would be necessary DllMain.
I'm tired of trying to use DllMain and it nevers works.
Could someone please paste a simple code of a DLL (like creating a blank file in C:\)
My DLL Injector code
Code:
#define PROCESS_NAME "explorer.exe"
#define DLL_NAME "inject.dll"
#define CREATE_THREAD_ACCESS (PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ)
unsigned long GetTargetProcessIdFromProcname(char *procName)
{
PROCESSENTRY32 pe;
HANDLE thSnapshot;
BOOL retval, ProcFound = 0;
thSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(thSnapshot == INVALID_HANDLE_VALUE)
{
puts("Erro");
return 0;
}
pe.dwSize = sizeof(PROCESSENTRY32);
retval = Process32First(thSnapshot, &pe);
while(retval)
{
if(strstr(pe.szExeFile, procName) )
{
ProcFound = 1;
break;
}
retval = Process32Next(thSnapshot,&pe);
pe.dwSize = sizeof(PROCESSENTRY32);
}
return pe.th32ProcessID;
}
main()
{
unsigned long id;
DWORD *pid;
HANDLE hd;
LPVOID gp,rs;
gp=(LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
id=GetTargetProcessIdFromProcname(PROCESS_NAME);
hd=OpenProcess(PROCESS_ALL_ACCESS, FALSE, id);
rs=(LPVOID)VirtualAllocEx(hd, NULL, strlen(DLL_NAME), MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
if(!WriteProcessMemory(hd, (LPVOID)rs, DLL_NAME, strlen(DLL_NAME), NULL))
{
puts("merda");
}
if(!CreateRemoteThread(hd, NULL, 0, (LPTHREAD_START_ROUTINE)gp, (LPVOID)rs, 0, NULL))
puts("merda2");
system("pause");
}
I need help, this is driving me cr4zy
PS: Using visual c++ 2010
EDIT: Sry placed topic on wrong section it's c++