Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////////////////////////////////////
- //
- // Hooking DLL loader\injector GUI by Mikhail Remizov aka keng
- // 2012-2013
- //
- ///////////////////////////////////////////////////////////////////////////////
- #include <d3d9.h>
- #include <tlhelp32.h>
- #include "resource.h"
- #pragma comment(lib, "d3d9.lib")
- ///////////////////////////////////////////////////////////////////////////////
- unsigned long GetTargetThreadIDFromProcName(const char *);
- int Inject(const unsigned long, const char *);
- ///////////////////////////////////////////////////////////////////////////////
- int __stdcall WinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int nCmdShow)
- {
- HRSRC hRes = FindResource(0, MAKEINTRESOURCE(IDR_DLL2), "DLL");
- if (hRes == NULL)
- {
- Beep(500, 1000);
- }
- HGLOBAL hMem = LoadResource(0, hRes);
- void* pMem = LockResource(hMem);
- DWORD size = SizeofResource(0, hRes);
- WNDCLASSEX wc;
- HWND hWnd;
- MSG msg;
- unsigned long pID;
- pID = GetTargetThreadIDFromProcName("csgo.exe");
- if (pID == 0)
- {
- MessageBox(0, "CS:GO not found. Please start ur game.",
- "Start", MB_OK);
- return 0;
- }
- else
- {
- char buf[MAX_PATH] = { 0 };
- Beep(1000, 100);
- GetFullPathName("ezhook.dll", MAX_PATH, buf, 0);
- Inject(pID, buf);
- return 0;
- }
- return msg.wParam;
- }
- ///////////////////////////////////////////////////////////////////////////////
- char* Customstrstr(const char *in, const char *str)
- {
- char c;
- size_t len;
- c = *str++;
- if (!c)
- return (char *)in;
- len = strlen(str);
- do {
- char sc;
- do {
- sc = *in++;
- if (!sc)
- return (char *)0;
- } while (sc != c);
- } while (strncmp(in, str, len) != 0);
- return (char *)(in - 1);
- }
- ///////////////////////////////////////////////////////////////////////////////
- //
- // Game process ID searching function
- //
- unsigned long GetTargetThreadIDFromProcName(const char *procName)
- {
- PROCESSENTRY32 pe; // process snapshot
- int retval;
- // getting the whole system processes snapshot
- HANDLE thSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- pe.dwSize = sizeof(PROCESSENTRY32);
- retval = Process32First(thSnapShot, &pe); // get the 1-st process
- while (retval) { // while there are any processes left
- // if process name == our needed name, then return the pid and quit
- if (Customstrstr(pe.szExeFile, procName))
- return pe.th32ProcessID;
- // if not - get the next process
- retval = Process32Next(thSnapShot, &pe);
- }
- return 0; //if nothing was found - return 0 and quit
- }
- ///////////////////////////////////////////////////////////////////////////////
- int Inject(const unsigned long pID, const char* dllName)
- {
- HANDLE pHandle;
- unsigned long loadLibAddr;
- LPVOID rString;
- //HANDLE hThread;
- if (!pID)
- return 1;
- pHandle = OpenProcess(PROCESS_ALL_ACCESS, 0, pID);
- // get the LoadLibraryA() address from kernel32.dll
- loadLibAddr =
- (unsigned long)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
- rString = (LPVOID)VirtualAllocEx(pHandle, 0, strlen(dllName),
- MEM_RESERVE | MEM_COMMIT,
- PAGE_READWRITE);
- WriteProcessMemory(pHandle, (LPVOID)rString, dllName, strlen(dllName), 0);
- CreateRemoteThread(pHandle, 0, 0,
- (LPTHREAD_START_ROUTINE)loadLibAddr,
- (LPVOID)rString, 0, 0);
- CloseHandle(pHandle); // close the opened handle
- return 0; // everything is done, so quit
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement