Advertisement
cgrunwald

Untitled

Oct 21st, 2010
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. #undef UNICODE
  2. #include <vector>
  3. #include <string>
  4. #include <windows.h>
  5. #include <Tlhelp32.h>
  6. #include <iostream>
  7. #include <conio.h>
  8. using std::vector;
  9. using std::string;
  10.  
  11. int main(void)
  12. {
  13.     vector<string>processNames;
  14.     PROCESSENTRY32 pe32;
  15.     pe32.dwSize = sizeof(PROCESSENTRY32);
  16.     HANDLE hTool32 = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
  17.     BOOL bProcess = Process32First(hTool32, &pe32);
  18.     bool blTest = false;
  19.     if(bProcess == TRUE)
  20.     {
  21.         while((Process32Next(hTool32, &pe32)) == TRUE) {
  22.             if(strcmp(pe32.szExeFile,"tb.exe") == 0) {
  23.                 char* DirPath = new char[MAX_PATH];
  24.                 char* FullPath = new char[MAX_PATH];
  25.                 GetCurrentDirectory(MAX_PATH, DirPath);
  26.                 sprintf_s(FullPath, MAX_PATH, "%s\\TBHookDll.dll", DirPath);
  27.                 HANDLE hProcess = OpenProcess(PROCESS_CREATE_THREAD    | PROCESS_VM_OPERATION    |
  28.                     PROCESS_VM_WRITE, FALSE, pe32.th32ProcessID);
  29.                 LPVOID LoadLibraryAddr = (LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"),
  30.                     "LoadLibraryA");
  31.                 LPVOID LLParam = (LPVOID)VirtualAllocEx(hProcess, NULL, strlen(FullPath),
  32.                     MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
  33.                 WriteProcessMemory(hProcess, LLParam, FullPath, strlen(FullPath), NULL);
  34.                 CreateRemoteThread(hProcess, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibraryAddr,
  35.                     LLParam, NULL, NULL);
  36.                 CloseHandle(hProcess);
  37.                 delete [] DirPath;
  38.                 delete [] FullPath;
  39.                 blTest = true;
  40.             }
  41.        
  42.         }
  43.     }
  44.     CloseHandle(hTool32);
  45.     if(!blTest) {
  46.         std::cout << "Did not detect tb.exe running on your computer.\nPress the enter key to close this dialog.";
  47.     } else {
  48.         std::cout << "Found tb.exe. Hooking..\nPress the enter key to close this window. (This will not affect the hook.)\n";
  49.     }
  50.     std::cin.ignore(0,'\n');
  51.     _getch();
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement