Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <intrin.h>
- #include <iostream>
- int main(int argc, const char *argv[])
- {
- std::cout << "Starting..." << std::endl;
- if(FALSE == IsDebuggerPresent())
- {
- PROCESS_INFORMATION pi;
- STARTUPINFOA si;
- std::cout << "Ill debug! :)" << std::endl;
- memset(&si, 0, sizeof(si));
- si.cb = sizeof(si);
- if(FALSE == CreateProcessA(argv[0], NULL, NULL, NULL, FALSE, DEBUG_PROCESS | CREATE_SUSPENDED, NULL, NULL, &si, &pi))
- {
- std::cout << "Failed to create process" << std::endl;
- return 0;
- }
- std::cout << "Process started!" << std::endl;
- ResumeThread(pi.hThread);
- for(;;)
- {
- DEBUG_EVENT dbg;
- if(FALSE == WaitForDebugEvent(&dbg, INFINITE))
- {
- std::cout << "GG" << std::endl;
- return 0;
- }
- if(EXCEPTION_DEBUG_EVENT == dbg.dwDebugEventCode)
- {
- const EXCEPTION_RECORD &e = dbg.u.Exception.ExceptionRecord;
- std::cout << "Exception code: " << std::hex << e.ExceptionCode << " @ 0x" << e.ExceptionAddress << std::endl;
- }
- ContinueDebugEvent(dbg.dwProcessId, dbg.dwThreadId, DBG_EXCEPTION_NOT_HANDLED);
- }
- }
- else
- {
- __try
- {
- //
- // Raise int3, this simulates the behaviour of a VEH debugger
- //
- std::cout << "Rasing #bp" << std::endl;
- __debugbreak();
- }
- __except(EXCEPTION_EXECUTE_HANDLER)
- {
- __try
- {
- //
- // Raise trap fault, also to simuate a VEH debugger
- //
- std::cout << "Raising #tf" << std::endl;
- __writeeflags(__readeflags() | 0x100);
- }
- __except(EXCEPTION_EXECUTE_HANDLER)
- {
- std::cout << "All is good" << std::endl;
- ExitThread(0);
- }
- }
- }
- std::cout << "The world is broken" << std::endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment