Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <iostream>
- #include <tlhelp32.h>
- #define MAXWAIT 10000
- using namespace std;
- int main()
- {
- char exename[MAX_PATH];
- char dllname[MAX_PATH];
- cout << "Welcome to PhyX injector v1.0" << endl;
- Sleep(1000);
- cout << "Please enter dll name Example: c:\\PhyX.dll\n" << endl;
- cin >> dllname;
- cout << "Dll name is:" << dllname << endl;
- Sleep(1000);
- cout << " Please enter window name of the processor example:notepad " << endl;
- cin >> exename;
- cout << "Widnow name is" << exename << endl;
- Sleep(1000);
- BOOL bFound;
- PROCESSENTRY32 pe;
- HANDLE hSnap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
- pe.dwSize=sizeof(pe);
- bFound=Process32First(hSnap,&pe);
- do {
- if (strstr(pe.szExeFile,exename)) {
- insertDll(pe.th32ProcessID, dllname); // c:\\PhyX.dll
- cout << "Injection successful!" << endl;
- }else{ cout << "Injection failed!" << endl; }
- pe.dwSize=sizeof(pe);
- bFound=Process32Next(hSnap,&pe);
- } while(bFound);
- getchar();
- }
- bool insertDll(DWORD procID, char *dll)
- {
- //Find the address of the LoadLibrary api, luckily for us, it is loaded in the same address for every process
- HMODULE hLocKernel32 = GetModuleHandle("Kernel32");
- FARPROC hLocLoadLibrary = GetProcAddress(hLocKernel32, "LoadLibraryA");
- HANDLE hProc = OpenProcess(PROCESS_CREATE_THREAD|PROCESS_QUERY_INFORMATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_VM_OPERATION, FALSE, procID);
- printf("prochandle %d %d\n",hProc,procID);
- //Allocate memory to hold the path to the Dll File in the process's memory
- LPVOID hRemoteMem = VirtualAllocEx(hProc, NULL,strlen( dll)+1, MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE);
- printf("%x\n",hRemoteMem);
- //Write the path to the Dll File in the location just created
- WriteProcessMemory(hProc, hRemoteMem, dll, strlen(dll)+1,0);
- //Create a remote thread that starts begins at the LoadLibrary function and is passed are memory pointer
- HANDLE hRemoteThread = CreateRemoteThread(hProc, NULL, 0, (LPTHREAD_START_ROUTINE)hLocLoadLibrary, hRemoteMem, 0, NULL);
- //Release the handle to the other process
- CloseHandle(hProc);
- return 0;
- }
Add Comment
Please, Sign In to add comment