Advertisement
Guest User

Untitled

a guest
Jan 12th, 2012
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.88 KB | None | 0 0
  1. #include <tchar.h>
  2. #include <windows.h>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. bool EnableDebugPrivilege(bool Enable);
  8.  
  9. int _tmain(int argc, TCHAR* argv[])
  10. {
  11. DWORD processID;
  12. DWORD address = 0x01002394;
  13. int value=0;
  14.  
  15. EnableDebugPrivilege(true);
  16.  
  17. HWND gameHwnd = FindWindowA( NULL, "Сапер" );
  18. cout << "Handle " << gameHwnd << endl;
  19. GetWindowThreadProcessId( gameHwnd, &processID );
  20. cout << "processID " << processID << endl;
  21. HANDLE gameProcess;
  22. gameProcess = OpenProcess(PROCESS_ALL_ACCESS, false, processID);
  23.  
  24. if(!gameProcess)
  25.     cout << "Error " << GetLastError() << endl;
  26. else
  27. {
  28.     ReadProcessMemory(gameProcess, (void*)address, &value, 1, NULL);
  29.     cout << "Value " << value << endl;
  30. }
  31.  
  32. cin.get();
  33. return 0;
  34. }
  35.  
  36. bool EnableDebugPrivilege( bool Enable )
  37. {
  38.     bool Success = false;
  39.  
  40.     HANDLE hToken = NULL;
  41.  
  42.     DWORD ec = 0;
  43.  
  44.     do
  45.     {
  46.         // Open the process' token
  47.  
  48.         if( !OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken ) )
  49.         {
  50.             ec = GetLastError();
  51.             _ASSERTE( !_T("OpenProcessToken() failed.") );
  52.             break;
  53.         }
  54.  
  55.  
  56.         // Lookup the privilege value
  57.  
  58.         TOKEN_PRIVILEGES tp;
  59.  
  60.         tp.PrivilegeCount = 1;
  61.  
  62.         if( !LookupPrivilegeValue( NULL, SE_DEBUG_NAME, &tp.Privileges[0].Luid ) )
  63.         {
  64.             ec = GetLastError();
  65.             _ASSERTE( !_T("LookupPrivilegeValue() failed.") );
  66.             break;
  67.         }
  68.  
  69.  
  70.         // Enable/disable the privilege
  71.  
  72.         tp.Privileges[0].Attributes = Enable ? SE_PRIVILEGE_ENABLED : 0;
  73.  
  74.         if( !AdjustTokenPrivileges( hToken, FALSE, &tp, sizeof(tp), NULL, NULL ) )
  75.         {
  76.             ec = GetLastError();
  77.             _ASSERTE( !_T("AdjustPrivilegeValue() failed.") );
  78.             break;
  79.         }
  80.  
  81.  
  82.         // Success
  83.  
  84.         Success = true;
  85.  
  86.     }
  87.     while( 0 );
  88.  
  89.  
  90.     // Cleanup
  91.  
  92.     if( hToken != NULL )
  93.     {
  94.         if( !CloseHandle( hToken ) )
  95.         {
  96.             ec = GetLastError();
  97.             _ASSERTE( !_T("CloseHandle() failed.") );
  98.         }
  99.     }
  100.  
  101.  
  102.     // Complete
  103.  
  104.     return Success;
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement