Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <tchar.h>
- #include <windows.h>
- #include <iostream>
- using namespace std;
- bool EnableDebugPrivilege(bool Enable);
- int _tmain(int argc, TCHAR* argv[])
- {
- DWORD processID;
- DWORD address = 0x01002394;
- int value=0;
- EnableDebugPrivilege(true);
- HWND gameHwnd = FindWindowA( NULL, "Сапер" );
- cout << "Handle " << gameHwnd << endl;
- GetWindowThreadProcessId( gameHwnd, &processID );
- cout << "processID " << processID << endl;
- HANDLE gameProcess;
- gameProcess = OpenProcess(PROCESS_ALL_ACCESS, false, processID);
- if(!gameProcess)
- cout << "Error " << GetLastError() << endl;
- else
- {
- ReadProcessMemory(gameProcess, (void*)address, &value, 1, NULL);
- cout << "Value " << value << endl;
- }
- cin.get();
- return 0;
- }
- bool EnableDebugPrivilege( bool Enable )
- {
- bool Success = false;
- HANDLE hToken = NULL;
- DWORD ec = 0;
- do
- {
- // Open the process' token
- if( !OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken ) )
- {
- ec = GetLastError();
- _ASSERTE( !_T("OpenProcessToken() failed.") );
- break;
- }
- // Lookup the privilege value
- TOKEN_PRIVILEGES tp;
- tp.PrivilegeCount = 1;
- if( !LookupPrivilegeValue( NULL, SE_DEBUG_NAME, &tp.Privileges[0].Luid ) )
- {
- ec = GetLastError();
- _ASSERTE( !_T("LookupPrivilegeValue() failed.") );
- break;
- }
- // Enable/disable the privilege
- tp.Privileges[0].Attributes = Enable ? SE_PRIVILEGE_ENABLED : 0;
- if( !AdjustTokenPrivileges( hToken, FALSE, &tp, sizeof(tp), NULL, NULL ) )
- {
- ec = GetLastError();
- _ASSERTE( !_T("AdjustPrivilegeValue() failed.") );
- break;
- }
- // Success
- Success = true;
- }
- while( 0 );
- // Cleanup
- if( hToken != NULL )
- {
- if( !CloseHandle( hToken ) )
- {
- ec = GetLastError();
- _ASSERTE( !_T("CloseHandle() failed.") );
- }
- }
- // Complete
- return Success;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement