A different way to get handles

Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Üye
Katılım
19 Mar 2020
Mesajlar
10
Tepki puanı
9
Ödüller
3
Yaş
27
6 HİZMET YILI
Typically in external hacks, I see people using tlhelp32 functions that are difficult for beginners to understand. I just wanted to share the way I do it using psapi functions. The functions I use are well documented on MSDN.

Code:

  1. #include <Windows.h>
  2. #include <psapi.h>
  3. #include <tchar.h>
  4. HANDLE getProcessHandleFromHWND(HWND hWindow)
  5. {
  6. HANDLE hThread = OpenThread(THREAD_QUERY_LIMITED_INFORMATION, false, GetWindowThreadProcessId(hWindow, NULL));
  7. if (hThread)
  8. {
  9. HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, GetProcessIdOfThread(hThread));
  10. CloseHandle(hThread);
  11. return hProcess;
  12. }
  13. else
  14. {
  15. return NULL;
  16. }
  17. }
  18. HMODULE getModuleHandle(HANDLE hProcess, LPCTSTR lpModuleName)
  19. {
  20. HMODULE hMods[1024];
  21. DWORD cbNeeded;
  22. if (EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded))
  23. {
  24. for (int i = 0; i < (cbNeeded / sizeof(HMODULE)); i++)
  25. {
  26. TCHAR szModName[MAX_PATH];
  27. if (GetModuleBaseName(hProcess, hMods, szModName, sizeof(szModName) / sizeof(TCHAR)) && !_tcscmp(szModName, lpModuleName))
    [*] {
    [*] return hMods;
    [*] }
    [*] }
    [*] }
    [*]
    [*] return NULL;
    [*]}
 
STILL FINDING MY LOVE
Seçkin Üye
Katılım
9 Mar 2020
Mesajlar
484
Çözümler
5
Tepki puanı
57
Ödüller
2
Yaş
23
6 HİZMET YILI
nice but too difficult
 
Üye
Katılım
22 Mar 2019
Mesajlar
16
Tepki puanı
0
Ödüller
3
Yaş
28
7 HİZMET YILI
I preffer TLHelp32 because it's more known and used in projects but this is a nice option to know.
 
Üye
Katılım
1 Şub 2021
Mesajlar
13
Tepki puanı
0
Yaş
28
5 HİZMET YILI
Where exactly can I view the MSDN document where is it?
 
a simple Russian man who helps people
Uzman Üye
Katılım
16 Ağu 2020
Mesajlar
195
Çözümler
2
Tepki puanı
8
Ödüller
5
Yaş
26
5 HİZMET YILI
Good knowledge thank you
 
Moderatörün son düzenlenenleri:
Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Üst