Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <cstdio>
- #include <TlHelp32.h>
- #include <string>
- #include <cstdlib>
- //USE FUCKING MULTIBYTE YOU STUPID TROGLODYTE FUCK!
- LPCTSTR wName = "Notepad";
- char MyTitle[10] = "WINDOW";
- char MyText[16] = "Found Window";
- char MyText2[15] = "Process Open";
- char MyTextFail[20] = "Did not find window";
- char process[27] = "notepad.exe";
- char sPID[3];
- HANDLE wHandle = NULL;
- DWORD baseAddr = NULL;
- int access = PROCESS_ALL_ACCESS;
- DWORD PID;
- DWORD AttachToProcess(char* ProcName) {
- auto hPID = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
- PROCESSENTRY32 ProcEntry;
- ProcEntry.dwSize = sizeof(ProcEntry);
- do
- if (!strcmp(ProcEntry.szExeFile, ProcName))
- {
- PID = ProcEntry.th32ProcessID;
- wHandle = OpenProcess(access, 0, PID);
- CloseHandle(hPID);
- return PID;
- }while (Process32Next(hPID, &ProcEntry));
- return NULL;
- }
- void FindModule(char* ModuleName) {
- auto hModule = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, PID);
- MODULEENTRY32 mEntry;
- mEntry.dwSize = sizeof(mEntry);
- do
- if (!strcmp(mEntry.szModule, ModuleName))
- {
- CloseHandle(hModule);
- baseAddr = reinterpret_cast<DWORD>(mEntry.modBaseAddr);
- return;
- }while (Module32Next(hModule, &mEntry));
- }
- void find_window()
- {
- __asm
- {
- mov esi, esp
- push 0
- mov eax, wName
- push eax
- push 0
- push 0
- call FindWindowExA
- cmp eax, 0
- je no_find
- ;process found
- mov esi, esp
- push 20h
- push offset MyTitle
- push offset MyText
- push 0
- call MessageBoxA
- cmp esi, esp
- mov esi, esp
- push offset process
- call AttachToProcess
- mov esp, esi
- mov esi, esp
- push PID
- push FALSE
- push access
- call OpenProcess
- mov esp,esi
- test eax,0
- jnz end_here
- push 20h
- push offset MyTitle
- push offset MyText2
- push 0
- call MessageBoxA
- jmp end_here
- no_find :
- mov esi, esp
- push 20h
- push offset MyTitle
- push offset MyTextFail
- push 0
- call MessageBoxA
- cmp esi, esp
- end_here:
- }
- return;
- }
- int main()
- {
- find_window();
- printf("PID: %d", PID);
- //FindModule(process);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement