1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include <iostream>
#include <windows.h>
#include <tlhelp32.h>
//#include <stdio.h>
using namespace std;
void enableDebugPrivileges(void) {
HANDLE hcurrent=GetCurrentProcess();
HANDLE hToken;
BOOL bret=OpenProcessToken(hcurrent,40,&hToken);
LUID luid;
bret=LookupPrivilegeValue(NULL,"SeDebugPrivilege",&luid);
TOKEN_PRIVILEGES NewState,PreviousState;
DWORD ReturnLength;
NewState.PrivilegeCount =1;
NewState.Privileges[0].Luid =luid;
NewState.Privileges[0].Attributes=2;
AdjustTokenPrivileges(hToken,FALSE,&NewState,28,&PreviousState,&ReturnLength);
}
int main()
{
enableDebugPrivileges();
DWORD oldProtection = 0;
HANDLE snapshot = CreateToolhelp32Snapshot ( TH32CS_SNAPPROCESS, NULL );
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
if(!Process32First(snapshot, &entry))
{
cout << endl << "Error in P32F\n";
}
while ( Process32Next ( snapshot, &entry ) == TRUE )
{
if ( stricmp ( entry.szExeFile, "cf.exe" ) == 0 )
{
HANDLE hProcess = OpenProcess ( PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, FALSE, entry.th32ProcessID );
DWORD baseAddress = 0x001AF45C;
DWORD address = 0;
ReadProcessMemory ( hProcess, (LPVOID)baseAddress, &address, sizeof(address), NULL );
cout << "Error code: " << GetLastError() << endl;
DWORD off1 = address + 0x98;
ReadProcessMemory ( hProcess, (LPVOID)off1, &address, sizeof(address), NULL);
cout << "Error code: " << GetLastError() << endl;
cout << hProcess;
VirtualProtectEx ( hProcess, (LPVOID)address, sizeof(address), PAGE_READWRITE, &oldProtection );
BYTE amount = 123;
WriteProcessMemory ( hProcess, (LPVOID)address, &amount, sizeof(amount), NULL );
VirtualProtectEx ( hProcess, (LPVOID)address, sizeof(address), oldProtection, NULL );
}
}
cin.get();
return 0;
}
|