-
-
Save egomeh/c632406d67e5bdf2906779d743ebbe9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include <iostream> | |
int main() | |
{ | |
STARTUPINFO startupInfo; | |
PROCESS_INFORMATION processInfo; | |
ZeroMemory(&startupInfo, sizeof(startupInfo)); | |
startupInfo.cb = sizeof(startupInfo); | |
ZeroMemory(&processInfo, sizeof(processInfo)); | |
CreateProcess(L"CrashingProgram.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &processInfo); | |
DebugActiveProcess(processInfo.dwProcessId); | |
while (true) | |
{ | |
DEBUG_EVENT debugEvent; | |
if (!WaitForDebugEvent(&debugEvent, 2'000)) | |
break; | |
const EXCEPTION_RECORD& exceptionRecord = debugEvent.u.Exception.ExceptionRecord; | |
const DWORD exceptionCode = exceptionRecord.ExceptionCode; | |
// We only care about access violation events | |
if (debugEvent.dwDebugEventCode == EXCEPTION_DEBUG_EVENT && exceptionCode == EXCEPTION_ACCESS_VIOLATION) | |
{ | |
DWORD64 address = debugEvent.u.Exception.ExceptionRecord.ExceptionInformation[1]; | |
std::cout << "Access violation at address: " << std::hex << address << std::endl; | |
return 0; | |
} | |
ContinueDebugEvent(debugEvent.dwProcessId, debugEvent.dwThreadId, DBG_CONTINUE); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment