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 66 67 68
|
#include <Windows.h>
#include <iostream>
using namespace std;
int main(){
DWORD_PTR address = 0x7FF607979711;
STARTUPINFO si = {0};
PROCESS_INFORMATION pi = {0};
si.cb = sizeof(si);
char filename[]= "Notepad.exe";
auto result = CreateProcess(filename, NULL, NULL, NULL, FALSE, DEBUG_PROCESS, NULL, NULL, &si, &pi);
DEBUG_EVENT debugEvent = { 0 };
bool continueDebugging = true;
CONTEXT ctx = {0};
ctx.ContextFlags = CONTEXT_DEBUG_REGISTERS | CONTEXT_INTEGER;
HWND hwnd = NULL;
DWORD processid;
HANDLE hThread = NULL;
hwnd = FindWindowA(NULL, "Notepad");
GetWindowThreadProcessId(hwnd, &processid);
hThread = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processid);
// hThread with enough permissions
SetThreadContext(hThread, &ctx);
while (true)
{
if (WaitForDebugEvent(&debugEvent, INFINITE) == 0)
if (debugEvent.dwDebugEventCode == EXCEPTION_DEBUG_EVENT &&
debugEvent.u.Exception.ExceptionRecord.ExceptionCode == EXCEPTION_SINGLE_STEP) // EXCEPTION_BREAKPOINT
{
CONTEXT newCtx = {0};
newCtx.ContextFlags = CONTEXT_ALL;
GetThreadContext(hThread, &newCtx);
if (debugEvent.u.Exception.ExceptionRecord.ExceptionAddress == (LPVOID)address)
{
newCtx.Dr0 = newCtx.Dr6 = newCtx.Dr7 = 0;
newCtx.EFlags |= (1 << 8);
std::cout << "No good." << std::endl;
}else{
newCtx.Dr0 = address;
newCtx.Dr7 = 0x7FF607979711;
newCtx.EFlags &= ~(1 << 8);
std::cout << "Good." << std::endl;
}
SetThreadContext(hThread, &newCtx);
}
ContinueDebugEvent(debugEvent.dwProcessId, debugEvent.dwThreadId, DBG_CONTINUE);
}
std::cout << "Ok" << std::endl;
std::string s;
std::getline(std::cin, s);
return 0;
} |
Partager