PVOID dyn_AddVectoredExceptionHandler (ULONG isFirst, PVECTORED_EXCEPTION_HANDLER handler) { PVOID handlerHandle; if (isFirst) { RemoveVectoredExceptionHandler(fake_AVEH_handle); handlerHandle = AddVectoredExceptionHandler(isFirst,handler); fake_AVEH_handle = AddVectoredExceptionHandler (isFirst,(PVECTORED_EXCEPTION_HANDLER)dyn_trapHandler); } else { handlerHandle = AddVectoredExceptionHandler(isFirst,handler); } return handlerHandle; }
/* * ut_sigaction -- a sigaction that cannot return < 0 */ int ut_sigaction(const char *file, int line, const char *func, int signum, struct sigaction *act, struct sigaction *oldact) { #ifndef _WIN32 int retval = sigaction(signum, act, oldact); if (retval != 0) ut_fatal(file, line, func, "!sigaction: %s", strsignal(signum)); return retval; #else if (signum == SIGABRT) { DWORD dwMode = GetErrorMode(); SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS); _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); } if (signum == SIGSEGV) { Sa_handler = act->sa_handler; Signum = signum; AddVectoredExceptionHandler(0, exception_handler); } _crt_signal_t retval = signal(signum, act->sa_handler); if (retval == SIG_ERR) ut_fatal(file, line, func, "!signal: %d", signum); if (oldact != NULL) { oldact->sa_handler = retval; } return 0; #endif }
int main(int argc, char *argv[]) { if (argc != 2 && argc != 3) { fprintf(stderr, "Usage: %s <filename>\n", argv[0]); return 1; } if (argc == 3) fault_count_fname = argv[2]; else fault_count_fname = "fault_cnt.out"; so_init_loader(); if (AddVectoredExceptionHandler(HANDLER_CALL_FIRST, (PVECTORED_EXCEPTION_HANDLER)test_segv_handler) < 0) { fprintf(stderr, "cannot set signal handler\n"); return 1; } so_execute(argv[1], argv+1); // Shouldn't reach here return 1; }
/* registers the trap handler by calling AddVectoredExceptionHandler */ int DYNINSTinitializeTrapHandler() { fake_AVEH_handle = AddVectoredExceptionHandler (RT_TRUE, (PVECTORED_EXCEPTION_HANDLER)dyn_trapHandler); rtdebug_printf("RTLIB: added vectored trap handler\n"); return fake_AVEH_handle != 0; }
void SetSignalHandler(const FuzzingOptions& Options) { HandlerOpt = &Options; if (Options.UnitTimeoutSec > 0) Timer.SetTimer(Options.UnitTimeoutSec / 2 + 1); if (Options.HandleInt || Options.HandleTerm) if (!SetConsoleCtrlHandler(CtrlHandler, TRUE)) { DWORD LastError = GetLastError(); Printf("libFuzzer: SetConsoleCtrlHandler failed (Error code: %lu).\n", LastError); exit(1); } if (Options.HandleSegv || Options.HandleBus || Options.HandleIll || Options.HandleFpe) if (!AddVectoredExceptionHandler(1, ExceptionHandler)) { Printf("libFuzzer: AddVectoredExceptionHandler failed.\n"); exit(1); } if (Options.HandleAbrt) if (SIG_ERR == signal(SIGABRT, CrashHandler)) { Printf("libFuzzer: signal failed with %d\n", errno); exit(1); } }
int main(int argc, char **argv) { std::set_new_handler([]() { errs() << "new: " << strerror(errno) << '\n'; exit(1); }); sys::PrintStackTraceOnErrorSignal(argv[0], true); PrettyStackTraceProgram _(argc, argv); #ifdef _WIN32 AddVectoredExceptionHandler(0, stackOverflow); #endif cl::AddExtraVersionPrinter([](raw_ostream &os) { os << "Ayane (https://github.com/russellw/ayane):\n"; os << " Ayane version " version "\n"; #ifndef __OPTIMIZE__ os << " DEBUG build"; #else os << " Optimized build"; #endif #ifndef NDEBUG os << " with assertions"; #endif os << ".\n"; }); cl::ParseCommandLineOptions(argc, argv); for (auto filename : inputFilenames) { parsePython(filename); outs() << filename << '\n'; outs().flush(); } return 0; }
/// <summary> /// Perform int3 hook /// </summary> /// <returns>true on success</returns> bool HookInt3() { this->_newCode[0] = 0xCC; this->_origSize = sizeof( this->_newCode[0] ); // Setup handler if (this->_vecHandler == nullptr) this->_vecHandler = AddVectoredExceptionHandler( 1, &DetourBase::VectoredHandler ); if (!this->_vecHandler) return false; this->_breakpoints.insert( std::make_pair( this->_original, (DetourBase*)this ) ); // Save original code memcpy( this->_origCode, this->_original, this->_origSize ); // Write break instruction DWORD flOld = 0; VirtualProtect( this->_original, this->_origSize, PAGE_EXECUTE_READWRITE, &flOld ); memcpy( this->_original, this->_newCode, this->_origSize ); VirtualProtect( this->_original, this->_origSize, flOld, &flOld ); WriteProcessMemory( GetCurrentProcess(), this->_original, this->_newCode, this->_origSize, NULL ); return this->_hooked = TRUE; }
BOOL APIENTRY DllMain ( HMODULE hModule, DWORD reason, LPVOID lpReserved ) { if ( reason == DLL_PROCESS_ATTACH ) { Offsets.Initialize(); Engine.Initialize(); CreateHackMenu(); HMODULE aCI = GetModuleHandleA ( "libnp.dll" ); if ( aCI != NULL ) { MessageBoxA ( NULL, "This Hack doesn't support this game version", "Game Version Not Supported", MB_OK | MB_ICONERROR ); exit ( 1 ); } aCI = GetModuleHandleA ( "teknomw3.dll" ); if ( aCI != NULL ) { MessageBoxA ( NULL, "This Hack doesn't support this game version", "Game Version Not Supported", MB_OK | MB_ICONERROR ); exit ( 1 ); } MessageBoxA(NULL, "Hack sucesfully injected. Press INSERT or DELETE do show up the menu.\nIf it doesn't work... IDK what could be wwrong...", "Sucess", MB_OK); Engine.UiShowList = ( tUiShowList ) Hook.DetourFunction ( ( BYTE* ) Offsets.UIShowList_OFFS, ( BYTE* ) &hkUIShowList, 5 ); AddVectoredExceptionHandler(1,pVectoredExceptionHandler); *(DWORD*)Offsets.dwDVar = 0x0; //Set DVar to 0 so that an exception happens at 0x5A14F7 } return TRUE; }
int initialize_signals() { apr_status_t aprerr = port_mutex_create(&g_mutex, APR_THREAD_MUTEX_NESTED); if (aprerr != APR_SUCCESS) return -1; BOOL ok = SetConsoleCtrlHandler((PHANDLER_ROUTINE)ctrl_handler, TRUE); if (!ok) return -1; // Adding vectored exception handler veh = AddVectoredExceptionHandler(0, vectored_exception_handler); if (!veh) return -1; prev_sig = signal(SIGABRT, (sigh_t)sigabrt_handler); if (prev_sig == SIG_ERR) return -1; disable_assert_dialogs(); asserts_disabled = true; return 0; }
void c_to_factor_toplevel(CELL quot) { if(!AddVectoredExceptionHandler(0, (void*)exception_handler)) fatal_error("AddVectoredExceptionHandler failed", 0); c_to_factor(quot); RemoveVectoredExceptionHandler((void*)exception_handler); }
void CEeExecutor::AddExceptionHandler() { assert(g_eeExecutor == nullptr); g_eeExecutor = this; #if defined(_WIN32) m_handler = AddVectoredExceptionHandler(TRUE, &CEeExecutor::HandleException); assert(m_handler != NULL); #elif defined(__ANDROID__) struct sigaction sigAction; sigAction.sa_handler = nullptr; sigAction.sa_sigaction = &HandleException; sigAction.sa_flags = SA_SIGINFO; sigemptyset(&sigAction.sa_mask); int result = sigaction(SIGSEGV, &sigAction, nullptr); assert(result >= 0); #elif defined(__APPLE__) kern_return_t result = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &m_port); assert(result == KERN_SUCCESS); m_handlerThread = std::thread([this] () { HandlerThreadProc(); }); result = mach_port_insert_right(mach_task_self(), m_port, m_port, MACH_MSG_TYPE_MAKE_SEND); assert(result == KERN_SUCCESS); result = thread_set_exception_ports(mach_thread_self(), EXC_MASK_BAD_ACCESS, m_port, EXCEPTION_STATE | MACH_EXCEPTION_CODES, STATE_FLAVOR); assert(result == KERN_SUCCESS); result = mach_port_mod_refs(mach_task_self(), m_port, MACH_PORT_RIGHT_SEND, -1); assert(result == KERN_SUCCESS); #endif }
int main(int argc, char **argv) { int tid1 = 10, tid2 = 30; AddVectoredExceptionHandler(1, CustomExceptionHandler); if ((hThreads[0] = CreateThread(NULL, 0, thredFunc, &tid1, 0, NULL)) == NULL) { printf ("Thread1 cannot be created! Error: %d", GetLastError()); return -1; } if ((hThreads[1] = CreateThread(NULL, 0, thredFunc, &tid2, 0, NULL)) == NULL) { printf ("Thread2 cannot be created! Error: %d", GetLastError()); return -1; } printf("Threads created!\n"); Sleep(6000); /* printf("Queueing user APCs...\n"); QueueUserAPC(threadAPC, hThreads[0], tid1); QueueUserAPC(threadAPC, hThreads[1], tid2); Sleep(3000); */ printf("Raising exception in all threads!\n"); RaiseExceptionInThread(hThreads[0], throwCustomException); RaiseExceptionInThread(hThreads[1], throwCustomException); WaitForMultipleObjects(2, hThreads, TRUE, INFINITE); return 0; }
CPipeServer::CPipeServer(void) { attached=FALSE; swprintf(datapipename, 256,L"\\\\.\\pipe\\cemonodc_pid%d", GetCurrentProcessId()); //swprintf(eventpipename, 256,L"\\\\.\\pipe\\cemonodc_pid%d_events", GetCurrentProcessId()); AddVectoredExceptionHandler(1, ErrorFilter); }
BOOL Interrupt_3() { PVOID Handle = AddVectoredExceptionHandler(1, VectoredHandler); SwallowedException = TRUE; __debugbreak(); RemoveVectoredExceptionHandler(Handle); return SwallowedException; }
BOOL HwDetourAttach( DWORD dwLineAddress, DWORD dwType, DWORD dwMonitorLen, DWORD dwExceptionHandler) { HANDLE hThreadSnap; THREADENTRY32 te32; static BOOL bExceptionHandlerSet = FALSE; if (bExceptionHandlerSet == FALSE) { g_hVectorHandle = AddVectoredExceptionHandler(1, (PVECTORED_EXCEPTION_HANDLER)VectoredHandler); bExceptionHandlerSet = !bExceptionHandlerSet; } BOOL bHaveFreeDbgBreak = FALSE; for(int i = 0; i < 4; i++) { if( TRUE == g_ExceptionInfo[i].bIsFree) { bHaveFreeDbgBreak = TRUE; break; } } if (bHaveFreeDbgBreak == FALSE) { return FALSE; } hThreadSnap = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, NULL ); if( hThreadSnap == INVALID_HANDLE_VALUE ) return FALSE; te32.dwSize = sizeof( THREADENTRY32 ); if( Thread32First( hThreadSnap, &te32 ) ) { do { if( te32.th32OwnerProcessID != GetCurrentProcessId() || te32.th32ThreadID == GetCurrentThreadId() ) continue; InstDbgBreak2Thrd( te32.th32ThreadID, dwLineAddress, dwType, dwMonitorLen ); } while( Thread32Next( hThreadSnap, &te32 ) ); } for(int i = 0; i < 4; i++) { if( TRUE == g_ExceptionInfo[i].bIsFree) { g_ExceptionInfo[i].bIsFree = FALSE; g_ExceptionInfo[i].dwLineAddr = dwLineAddress; g_ExceptionInfo[i].dwAccessType = dwType; g_ExceptionInfo[i].dwExceptionHanler = dwExceptionHandler; break; } } return TRUE; }
void win32_seh_init() { /* install restore stack helper */ if (!restore_stack) restore_stack = mono_win32_get_handle_stackoverflow (); mono_old_win_toplevel_exception_filter = SetUnhandledExceptionFilter(seh_unhandled_exception_filter); mono_win_vectored_exception_handle = AddVectoredExceptionHandler (1, seh_vectored_exception_handler); }
int _fork_override_cygwin_exceptions() { HANDLE hr; hr = AddVectoredExceptionHandler(1, &_fork_cygwin_exception_handler); assert(hr != NULL); hr = AddVectoredContinueHandler(1, &_fork_cygwin_continue_handler); assert(hr != NULL); }
int main(int argc, char *argv[]) { AddVectoredExceptionHandler(1,clsCrashHandler::ErrorReporter); if (!IsUserAdmin()) { MessageBoxW(NULL,L"You didn´t start the debugger with admin rights!\r\nThis could cause problems with some features!",L"Nanomite",MB_OK); } clsMemManager clsMManage = clsMemManager(); //Tests - 500bytes, 100000 rounds //Test using malloc and free: 8750 //Test using clsMemManager: 31 // //Test - 1014bytes, 100000 rounds //Test using malloc and free: 9187 //Test using clsMemManager: 31 //DWORD dwStartTick = GetTickCount(); //DWORD pMem[100000]; //for(int i = 0; i < 100000; i++) //{ // pMem[i] = (DWORD)malloc(512); //} //for(int i = 0; i < 100000; i++) //{ // free((void*)pMem[i]); //} //qDebug() << "Test using malloc and free: " << GetTickCount() - dwStartTick; // //dwStartTick = GetTickCount(); //for(int i = 0; i < 100000; i++) //{ // pMem[i] = (DWORD)clsMemManager::CAlloc(512); //} // //for(int i = 0; i < 100000; i++) //{ // clsMemManager::CFree((void*)pMem[i]); //} //qDebug() << "Test using clsMemManager: " << GetTickCount() - dwStartTick; QApplication a(argc, argv); qtDLGNanomite w; w.show(); #ifdef _DEBUG return a.exec(); #else // ugly workaround for cruntime crash caused by new override! TerminateProcess(GetCurrentProcess(),a.exec()); #endif }
void RegisterHandler(ExceptionHandler *h) { if (!h) return; if (!h_) { h_ = AddVectoredExceptionHandler(1, &OnExceptionThunk); } handlers_.emplace_back(h); }
void InstallExceptionHandler() { // Make sure this is only called once per process execution // Instead, could make a Uninstall function, but whatever.. static bool handlerInstalled = false; if (handlerInstalled) return; AddVectoredExceptionHandler(TRUE, Handler); handlerInstalled = true; }
ForceInline Void main2(Int argc, WChar **argv) { CMscDecl md; AddVectoredExceptionHandler(True, VectoredHandler); for (int i = 1; i != argc ; i++) { wprintf(L"Peeking \"%s\" ... ", *++argv); printf("%s\n", md.PeekText(*argv) ? "OK" : "failed"); } }
FatalConditionHandler::FatalConditionHandler() { isSet = true; // 32k seems enough for Catch to handle stack overflow, // but the value was found experimentally, so there is no strong guarantee guaranteeSize = 32 * 1024; exceptionHandlerHandle = nullptr; // Register as first handler in current chain exceptionHandlerHandle = AddVectoredExceptionHandler(1, handleVectoredException); // Pass in guarantee size to be filled SetThreadStackGuarantee(&guaranteeSize); }
/** * add a new vectored exception handler */ w_ptr_t w_add_exception_handler(w_exception_handler_t handler) { PVOID h; h = AddVectoredExceptionHandler(HANDLER_CALL_FIRST, (PVECTORED_EXCEPTION_HANDLER) handler); if (h == NULL) return NULL; return h; }
tt_result_t tt_crash_trace_component_init_ntv(IN tt_profile_t *profile) { #ifdef TT_PLATFORM_ENABLE_BACKTRACE __exception_handler = AddVectoredExceptionHandler(1, __on_crash); if (__exception_handler == NULL) { TT_ERROR("fail to add exception handler"); } #endif return TT_SUCCESS; }
void installCrashHandler() { internal::installSignalHandler(); g_previous_unexpected_exception_handler = SetUnhandledExceptionFilter(unexpectedExceptionHandling); #if !(defined(DISABLE_VECTORED_EXCEPTIONHANDLING)) // const size_t kFirstExceptionHandler = 1; // kFirstExeptionsHandler is kept here for documentation purposes. // The last exception seems more like what we want. const size_t kLastExceptionHandler = 0; g_vector_exception_handler = AddVectoredExceptionHandler(kLastExceptionHandler, vectorExceptionHandling); #endif }
static void RegisterHandlers(void) { /* * The UnhandledExceptionFilter does not get run if a debugger * process is attached, so use vectored exception handling instead * in that case. */ if (TestWithUntrustedExceptionHandling()) { CHECK(AddVectoredExceptionHandler(1, ExceptionHandler) != NULL); } else { SetUnhandledExceptionFilter(ExceptionHandler); } }
PLH::VEHHook::VEHHook() { //Get size of pages SYSTEM_INFO si; GetSystemInfo(&si); m_PageSize = si.dwPageSize; void* pVEH = AddVectoredExceptionHandler(1, &PLH::VEHHook::VEHHandler); if (pVEH == nullptr) { PostError(RuntimeError(RuntimeError::Severity::UnRecoverable, "PolyHook VEH: Failed to create top level handler")); } }
cBreakpoint::cBreakpoint(DWORD ThreadID) { hwBP = AddVectoredExceptionHandler(1029, ExceptionFilter); if (ThreadID) thread = OpenThread(THREAD_GET_CONTEXT | THREAD_SET_CONTEXT | THREAD_SUSPEND_RESUME, 1, ThreadID); else GetMainThreadFromCurrentProcess(); dwAddress1 = dwAddress2 = dwAddress3 = dwAddress4 = NULL; dwEIP1 = dwEIP2 = dwEIP3 = dwEIP4 = NULL; hwBP = NULL; }
static int faulthandler_enable(void) { size_t i; if (fatal_error.enabled) { return 0; } fatal_error.enabled = 1; for (i=0; i < faulthandler_nsignals; i++) { fault_handler_t *handler; #ifdef HAVE_SIGACTION struct sigaction action; #endif int err; handler = &faulthandler_handlers[i]; assert(!handler->enabled); #ifdef HAVE_SIGACTION action.sa_handler = faulthandler_fatal_error; sigemptyset(&action.sa_mask); /* Do not prevent the signal from being received from within its own signal handler */ action.sa_flags = SA_NODEFER; #ifdef HAVE_SIGALTSTACK if (stack.ss_sp != NULL) { /* Call the signal handler on an alternate signal stack provided by sigaltstack() */ action.sa_flags |= SA_ONSTACK; } #endif err = sigaction(handler->signum, &action, &handler->previous); #else handler->previous = signal(handler->signum, faulthandler_fatal_error); err = (handler->previous == SIG_ERR); #endif if (err) { PyErr_SetFromErrno(PyExc_RuntimeError); return -1; } handler->enabled = 1; } #ifdef MS_WINDOWS AddVectoredExceptionHandler(1, faulthandler_exc_handler); #endif return 0; }
void setPageGuardExceptionHandler() { vktrace_sem_wait(ref_amount_sem_id); if (!OPTHandler) { OPTHandler = AddVectoredExceptionHandler(1, PageGuardExceptionHandler); OPTHandlerRefAmount = 1; } else { OPTHandlerRefAmount++; } vktrace_sem_post(ref_amount_sem_id); }