Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <Windows.h>
  3. #include <cstdio>
  4. #include <TlHelp32.h>
  5. #include <string>
  6. #include <cstdlib>
  7.  
  8.  
  9.  
  10. //USE FUCKING MULTIBYTE YOU STUPID TROGLODYTE FUCK!
  11. LPCTSTR wName = "Notepad";
  12. char MyTitle[10] = "WINDOW";
  13. char MyText[16] = "Found Window";
  14. char MyText2[15] = "Process Open";
  15. char MyTextFail[20] = "Did not find window";
  16. char process[27] = "notepad.exe";
  17. char sPID[3];
  18.  
  19. HANDLE wHandle = NULL;
  20. DWORD baseAddr = NULL;
  21.  
  22. int access = PROCESS_ALL_ACCESS;
  23.  
  24. DWORD PID;
  25.  
  26.  
  27.  
  28. DWORD AttachToProcess(char* ProcName) {
  29.     auto hPID = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
  30.     PROCESSENTRY32 ProcEntry;
  31.     ProcEntry.dwSize = sizeof(ProcEntry);
  32.  
  33.     do
  34.         if (!strcmp(ProcEntry.szExeFile, ProcName))
  35.         {
  36.             PID = ProcEntry.th32ProcessID;
  37.             wHandle = OpenProcess(access, 0, PID);
  38.             CloseHandle(hPID);
  39.  
  40.             return PID;
  41.         }while (Process32Next(hPID, &ProcEntry));
  42.  
  43.         return NULL;
  44.  
  45.  
  46. }
  47.  
  48. void FindModule(char* ModuleName) {
  49.     auto hModule = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, PID);
  50.     MODULEENTRY32 mEntry;
  51.     mEntry.dwSize = sizeof(mEntry);
  52.  
  53.     do
  54.         if (!strcmp(mEntry.szModule, ModuleName))
  55.         {
  56.             CloseHandle(hModule);
  57.  
  58.             baseAddr = reinterpret_cast<DWORD>(mEntry.modBaseAddr);
  59.             return;
  60.         }while (Module32Next(hModule, &mEntry));
  61. }
  62.  
  63.  
  64.  
  65.  
  66. void find_window()
  67. {
  68.  
  69.     __asm
  70.     {
  71.         mov         esi, esp
  72.         push        0
  73.         mov         eax, wName
  74.         push        eax
  75.         push        0
  76.         push        0
  77.         call        FindWindowExA
  78.         cmp         eax, 0
  79.         je         no_find
  80.  
  81.         ;process found
  82.         mov         esi, esp
  83.         push        20h
  84.         push        offset MyTitle
  85.         push        offset MyText
  86.         push        0
  87.         call        MessageBoxA
  88.         cmp         esi, esp
  89.        
  90.         mov         esi, esp
  91.         push        offset process
  92.         call        AttachToProcess
  93.         mov         esp, esi
  94.  
  95.         mov         esi, esp
  96.         push        PID
  97.         push        FALSE
  98.         push        access
  99.         call        OpenProcess
  100.         mov         esp,esi
  101.  
  102.         test        eax,0
  103.         jnz         end_here
  104.         push        20h
  105.         push        offset MyTitle
  106.         push        offset MyText2
  107.         push        0
  108.         call        MessageBoxA
  109.        
  110.         jmp         end_here
  111.  
  112.  
  113.  
  114.         no_find :
  115.         mov         esi, esp
  116.         push        20h
  117.         push        offset MyTitle
  118.         push        offset MyTextFail
  119.         push        0
  120.         call        MessageBoxA
  121.         cmp         esi, esp
  122.  
  123.         end_here:
  124.     }
  125.     return;
  126. }
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134. int main()
  135. {
  136.     find_window();
  137.     printf("PID: %d", PID);
  138.  
  139.     //FindModule(process);
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement