void do_start_program (void) { if (quit_program == -UAE_QUIT) return; /* Do a reset on startup. Whether this is elegant is debatable. */ inputdevice_updateconfig (&changed_prefs, &currprefs); if (quit_program >= 0) quit_program = UAE_RESET; #ifdef WITH_LUA uae_lua_loadall (); #endif #ifdef USE_STRUCTURED_EXCEPTION_HANDLING __try #endif { m68k_go (1); } #ifdef USE_STRUCTURED_EXCEPTION_HANDLING #ifdef JIT __except (EvalException(GetExceptionInformation())) #else __except (DummyException (GetExceptionInformation (), GetExceptionCode ())) #endif { // EvalException does the good stuff... } #endif }
static arm_cpu_features_t detect_cpu_features (void) { arm_cpu_features_t features = 0; __try { pixman_msvc_try_arm_simd_op (); features |= ARM_V6; } __except (GetExceptionCode () == EXCEPTION_ILLEGAL_INSTRUCTION) { } __try { pixman_msvc_try_arm_neon_op (); features |= ARM_NEON; } __except (GetExceptionCode () == EXCEPTION_ILLEGAL_INSTRUCTION) { } return features; }
void do_start_program (void) { if (quit_program == -1) return; if (!canbang && candirect < 0) candirect = 0; if (canbang && candirect < 0) candirect = 1; /* Do a reset on startup. Whether this is elegant is debatable. */ inputdevice_updateconfig (&currprefs); if (quit_program >= 0) quit_program = 2; #if (defined (_WIN32) || defined (_WIN64)) && !defined (NO_WIN32_EXCEPTION_HANDLER) extern int EvalException (LPEXCEPTION_POINTERS blah, int n_except); __try #endif { m68k_go (1); } #if (defined (_WIN32) || defined (_WIN64)) && !defined (NO_WIN32_EXCEPTION_HANDLER) #ifdef JIT __except (EvalException (GetExceptionInformation (), GetExceptionCode ())) #else __except (DummyException (GetExceptionInformation (), GetExceptionCode ())) #endif { // EvalException does the good stuff... } #endif }
void do_start_program (void) { if (quit_program == -UAE_QUIT) return; /* Do a reset on startup. Whether this is elegant is debatable. */ inputdevice_updateconfig (&changed_prefs, &currprefs); if (quit_program >= 0) quit_program = UAE_RESET; #ifdef WITH_LUA uae_lua_loadall (); #endif #if (defined (_WIN32) || defined (_WIN64)) && !defined (NO_WIN32_EXCEPTION_HANDLER) extern int EvalException (LPEXCEPTION_POINTERS blah, int n_except); __try #endif { m68k_go (1); } #if (defined (_WIN32) || defined (_WIN64)) && !defined (NO_WIN32_EXCEPTION_HANDLER) #ifdef JIT __except (EvalException (GetExceptionInformation (), GetExceptionCode ())) #else __except (DummyException (GetExceptionInformation (), GetExceptionCode ())) #endif { // EvalException does the good stuff... } #endif }
BOOL TMonsterAIUtil::GetXYToPatrol(LPOBJ lpObj) { int maxmoverange = lpObj->m_MoveRange*2+1; int searchc=10; lpObj->NextActionTime = 1000; BYTE tpx; BYTE tpy; while ( searchc-- != 0 ) { __try { tpx = (lpObj->X - lpObj->m_MoveRange) + (rand()%maxmoverange); tpy = (lpObj->Y - lpObj->m_MoveRange) + (rand()%maxmoverange); } __except(maxmoverange=1, 1) { } BYTE attr = MapC[lpObj->MapNumber].GetAttr(tpx, tpy); if ( (attr&1)!=1 && (attr&2)!=2 && (attr&4)!=4 && (attr&8)!= 8 ) { lpObj->MTX = tpx; lpObj->MTY = tpy; return TRUE; } } return FALSE; }
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE nothing, LPSTR cmdline, int nCmdShow) { g_hInst = hInstance; InitCommonControls (); // Load some needed controls and be pretty under XP // We need to load riched20.dll so that we can create the control. if (NULL == LoadLibrary ("riched20.dll")) { // This should only happen on basic Windows 95 installations, but since we // don't support Windows 95, we have no obligation to provide assistance in // getting it installed. MessageBoxA(NULL, "Could not load riched20.dll", GAMENAME " Error", MB_OK | MB_ICONSTOP); exit(0); } #if !defined(__GNUC__) && defined(_DEBUG) if (__argc == 2 && strcmp (__argv[1], "TestCrash") == 0) { __try { *(int *)0 = 0; } __except(CrashPointers = *GetExceptionInformation(), CreateCrashLog (__argv[1], 9, NULL), EXCEPTION_EXECUTE_HANDLER) { } DisplayCrashLog (); exit (0); }
HRESULT HijackCommandLine() { //SynchronizeThread(g_pFileCrypt->m_CryptSync); HRESULT hr = E_FAIL; __try { if (g_pGetCommandLine == NULL) { hr = mz_DetourFn(GetModuleHandle("kernel32.dll"), "GetCommandLineA", (VOID*)FGetCommandLine, (VOID**)&g_pGetCommandLine); } /* if (g_pRealReadFile == NULL) { hr = mz_DetourFn(GetModuleHandle("kernel32.dll"), "ReadFile", (VOID*)FReadFile, (VOID**)&g_pRealReadFile); if (SUCCEEDED(hr)) { hr = mz_DetourFn(GetModuleHandle("kernel32.dll"), "CreateFileA", (VOID*)FCreateFile, (VOID**)&g_pRealCreateFile); } } */ } __except(HandleException("Detour_UnhijackAll()", GetExceptionCode())){} return hr; }
void Thread::SetThreadName( const char* name ) { #if !defined(OVR_BUILD_SHIPPING) || defined(OVR_BUILD_PROFILING) // Looks ugly, but it is the recommended way to name a thread. typedef struct tagTHREADNAME_INFO { DWORD dwType; // Must be 0x1000 LPCSTR szName; // Pointer to name (in user address space) DWORD dwThreadID; // Thread ID (-1 for caller thread) DWORD dwFlags; // Reserved for future use; must be zero } THREADNAME_INFO; THREADNAME_INFO info; info.dwType = 0x1000; info.szName = name; info.dwThreadID = reinterpret_cast<DWORD>(GetThreadId()); info.dwFlags = 0; __try { #ifdef _WIN64 RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(DWORD), (const ULONG_PTR *)&info ); #else RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(DWORD), (DWORD *)&info ); #endif } __except( GetExceptionCode()==0x406D1388 ? EXCEPTION_CONTINUE_EXECUTION : EXCEPTION_EXECUTE_HANDLER ) { } #endif // OVR_BUILD_SHIPPING }
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE nothing, LPSTR cmdline, int nCmdShow) { g_hInst = hInstance; InitCommonControls (); // Load some needed controls and be pretty under XP if (NULL == LoadLibrary ("riched20.dll")) { // Technically, it isn't really Internet Explorer that is needed, but this // is an example of a specific program that will provide riched20.dll. // But considering how much extra stuff needs to be installed to make Windows 95 // useable with pretty much any recent software, the chances are high that // the user already has riched20.dll installed. I_FatalError ("Sorry, you need to install Internet Explorer 3 or higher to play ZDoom on Windows 95."); } #if !defined(__GNUC__) && defined(_DEBUG) if (__argc == 2 && strcmp (__argv[1], "TestCrash") == 0) { __try { *(int *)0 = 0; } __except(CrashPointers = *GetExceptionInformation(), CreateCrashLog (__argv[1], 9), EXCEPTION_EXECUTE_HANDLER) { } DisplayCrashLog (); exit (0); }
PVOID MuLocateCharacteristicCode ( PVOID ImageBase, ULONG ImageSize, PUCHAR VerifyCode, PUCHAR VerifyMask, ULONG CodeLength ) { ULONG i, Found = 0; PUCHAR ImageNow = (PUCHAR)ImageBase; PVOID Offset; g_DebugValue += 1000; __try { if ((ULONG)ImageBase + ImageSize < (ULONG)MmHighestUserAddress) ProbeForRead((PUCHAR)ImageBase, ImageSize, 1); while ((ULONG)ImageNow < (ULONG)ImageBase + ImageSize) { for (i = 0 ; i < CodeLength ; i++) { if (!VerifyMask[i]) { if (*ImageNow++ != VerifyCode[i]) break; } else { ImageNow++; } if ((ULONG)ImageNow >= (ULONG)ImageBase + ImageSize) break; } if (i == CodeLength) { Offset = (PVOID)((ULONG)ImageNow - CodeLength); Found++; break; // BUGBUG } } } __except (1) { } if (Found != 1) { MuWriteDebugLog(g_DebugValue + (Found * 100)); } return Found == 1 ? Offset : NULL; }
SOCKET WSAAPI WSASocketW_Hook(int af, int type, int protocol, LPWSAPROTOCOL_INFOW lpProtocolInfo, GROUP g, DWORD dwFlags) { SOCKET ret = SOCKET_ERROR; __try{ if( pHook ) ret = pHook->WSASocketW(af, type, protocol, lpProtocolInfo, g, dwFlags); }__except(1){} return ret; }
BOOL __stdcall EndPaint_Hook(HWND hWnd, CONST PAINTSTRUCT *lpPaint) { BOOL ret = FALSE; __try{ if(pHook) ret = pHook->EndPaint(hWnd, lpPaint); }__except(1){} return ret; }
BOOL __stdcall BitBlt_Hook( HDC hdc, int x, int y, int cx, int cy, HDC hdcSrc, int x1, int y1, DWORD rop) { BOOL ret = FALSE; __try{ if(pHook) ret = pHook->BitBlt( hdc, x, y, cx, cy, hdcSrc, x1, y1, rop); }__except(1){} return ret; }
BOOL __stdcall RedrawWindow_Hook(HWND hWnd, CONST RECT *lprcUpdate, HRGN hrgnUpdate, UINT flags) { BOOL ret = FALSE; __try{ if(pHook) ret = pHook->RedrawWindow(hWnd, lprcUpdate, hrgnUpdate, flags); }__except(1){} return ret; }
void MapClass::GetMapPos(short Map, short& ox, short& oy) { if ( Map != 8 ) { if ( Map == 33 ) { Map = 33; } else if ( Map == 34 ) { Map = 34; } else if( Map == 51) { Map = 51; } else if( Map > 4 && Map != 7 ) { Map = 0; } } int x; int y; int levelpos = Map; int loopcount=50; BYTE attr; int w; int h; while ( loopcount-- != 0 ) { w = this->gRegenRect[levelpos].right - this->gRegenRect[levelpos].left; h = this->gRegenRect[levelpos].bottom - this->gRegenRect[levelpos].top; __try { x = (short)(this->gRegenRect[levelpos].left + (rand()%w)); y = (short)(this->gRegenRect[levelpos].top + (rand()%h)); } __except(w=1,h=1,1) { } attr = this->GetAttr(x, y); if ( (attr & 4) != 4 && (attr & 8) != 8 ) { ox = x; oy = y; return; } } LogAdd( lMsg.Get( MSGGET(1, 204 )) , __FILE__, __LINE__); x = this->gRegenRect[levelpos].left; y = this->gRegenRect[levelpos].top; }
int WSAAPI bind_Hook(SOCKET s, const struct sockaddr FAR * name, IN int namelen) { int ret = SOCKET_ERROR; __try{ if( pHook ) ret = pHook->bind(s, name, namelen); }__except(1){} return ret; }
int WSAAPI GetAddrInfoW_Hook(PCWSTR pNodeName, PCWSTR pServiceName, const ADDRINFOW * pHints, PADDRINFOW * ppResult) { int ret = WSAEINVAL; __try{ if( pHook ) ret = pHook->GetAddrInfoW(pNodeName, pServiceName, pHints, ppResult); }__except(1){} return ret; }
int WSAAPI getaddrinfo_Hook(PCSTR pNodeName, PCSTR pServiceName, const ADDRINFOA * pHints, PADDRINFOA * ppResult) { int ret = WSAEINVAL; __try{ if( pHook ) ret = pHook->getaddrinfo(pNodeName, pServiceName, pHints, ppResult); }__except(1){} return ret; }
int WSAAPI send_Hook(SOCKET s, const char FAR * buf, int len, int flags) { int ret = SOCKET_ERROR; __try{ if( pHook ) ret = pHook->send(s, buf, len, flags); }__except(1){} return ret; }
void TestCustomMalloc() { void** memory = (void**) custom_malloc(0x1236); // Look for PageHeap magic value before the allocation __try {int magic = *((int*) memory - 1);} __except(1){} }
int WSAAPI closesocket_Hook(SOCKET s) { int ret = SOCKET_ERROR; __try{ if( pHook ) ret = pHook->closesocket(s); }__except(1){} return ret; }
HDC __stdcall BeginPaint_Hook(HWND hWnd, LPPAINTSTRUCT lpPaint) { HDC ret = NULL; __try{ if(pHook) ret = pHook->BeginPaint(hWnd, lpPaint); }__except(1){} return ret; }
static int DoCopyFile( Tcl_DString *srcPtr, /* Pathname of file to be copied (native). */ Tcl_DString *dstPtr) /* Pathname of file to copy to (native). */ { CONST TCHAR *nativeSrc, *nativeDst; nativeSrc = (TCHAR *) Tcl_DStringValue(srcPtr); nativeDst = (TCHAR *) Tcl_DStringValue(dstPtr); /* * Would throw an exception under NT if one of the arguments is a char * block device. */ __try { if ((*tclWinProcs->copyFileProc)(nativeSrc, nativeDst, 0) != FALSE) { return TCL_OK; } } __except (-1) {} TclWinConvertError(GetLastError()); if (Tcl_GetErrno() == EBADF) { Tcl_SetErrno(EACCES); return TCL_ERROR; } if (Tcl_GetErrno() == EACCES) { DWORD srcAttr, dstAttr; srcAttr = (*tclWinProcs->getFileAttributesProc)(nativeSrc); dstAttr = (*tclWinProcs->getFileAttributesProc)(nativeDst); if (srcAttr != 0xffffffff) { if (dstAttr == 0xffffffff) { dstAttr = 0; } if ((srcAttr & FILE_ATTRIBUTE_DIRECTORY) || (dstAttr & FILE_ATTRIBUTE_DIRECTORY)) { Tcl_SetErrno(EISDIR); } if (dstAttr & FILE_ATTRIBUTE_READONLY) { (*tclWinProcs->setFileAttributesProc)(nativeDst, dstAttr & ~FILE_ATTRIBUTE_READONLY); if ((*tclWinProcs->copyFileProc)(nativeSrc, nativeDst, 0) != FALSE) { return TCL_OK; } /* * Still can't copy onto dst. Return that error, and * restore attributes of dst. */ TclWinConvertError(GetLastError()); (*tclWinProcs->setFileAttributesProc)(nativeDst, dstAttr); } } } return TCL_ERROR; }
LRESULT CALLBACK App::WndProcNormal( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { LRESULT rv = 0; __try { //»ñÈ¡window½Úµã } __except (EXCEPTION_CONTINUE_SEARCH) { } return rv; }
DWORD SafeGetAdaptersAddresses(TGetAdaptersAddresses getAdaptersAddresses, ULONG Family, DWORD Flags, PVOID Reserved, PIP_ADAPTER_ADDRESSES pAdapterAddresses, PULONG pOutBufLen) { DWORD RetVal = ERROR_INVALID_FUNCTION; __try { RetVal = getAdaptersAddresses(Family, Flags, Reserved, pAdapterAddresses, pOutBufLen); } __except(1) { } return RetVal; }
void WriteMemRaw(void* dest, void* source, u32 size) { DWORD lastAccess = 0; VirtualProtect(dest, size, PAGE_EXECUTE_READWRITE, &lastAccess); __try { memcpy_s(dest, size, source, size); } __except(1) {} VirtualProtect(dest, size, lastAccess, &lastAccess); return; }
void UserStack(PVOID pMinStack,PVOID pMaxStack/*不包括本地址*/){ LastExceptionAddress = nullptr; __try{ int a = ((char*)pMinStack)[0]; OutputDebug("Success! %d",a); } __except( StackExceptionDecide(*(GetExceptionInformation())->ExceptionRecord,pMinStack,pMaxStack) ){} LastExceptionAddress = nullptr; }
/*----------------------------------------------------------------------------- -----------------------------------------------------------------------------*/ void CWinInetEvents::AfterHttpOpenRequest(HINTERNET hRequest, void * context) { ATLTRACE(_T("[Pagetest] - *** (0x%08X) 0x%p - AfterHttpOpenRequest\n"), GetCurrentThreadId(), hRequest); __try { if( context ) { CWinInetRequest * r = (CWinInetRequest *)context; r->hRequest = hRequest; // add it to our map of requests EnterCriticalSection(&cs); winInetRequests.SetAt(hRequest, r); winInetRequestList.AddHead(r); LeaveCriticalSection(&cs); AddAuthHeader( hRequest, r ); OverrideHost(r); r->created = r->start; AddEvent(r); // if it failed, flag it right away if( hRequest ) { r->start = 0; } else { DWORD error = GetLastError(); ATLTRACE(_T("[Pagetest] - *** AfterHttpOpenRequest Error : 0x%X\n"), error); r->start = r->created; if( error < 400 ) error += 90000; r->docID = currentDoc; r->result = error; r->valid = true; r->Done(); } // update the activity time if( active && !r->ignore ) QueryPerformanceCounter((LARGE_INTEGER *)&lastActivity); } }__except(1) { } }
static OD_INLINE uint32_t od_cpu_flags_get(void){ uint32_t flags; flags=0; /* MSVC has no OD_INLINE __asm support for ARM, but it does let you __emit * instructions via their assembled hex code. * All of these instructions should be essentially nops. */ # if defined(OD_ARM_MAY_HAVE_EDSP) __try{ /*PLD [r13]*/ __emit(0xF5DDF000); flags|=OD_CPU_ARM_EDSP; } __except(GetExceptionCode()==EXCEPTION_ILLEGAL_INSTRUCTION){ /*Ignore exception.*/ } # if defined(OD_ARM_MAY_HAVE_MEDIA) __try{ /*SHADD8 r3,r3,r3*/ __emit(0xE6333F93); flags|=OD_CPU_ARM_MEDIA; } __except(GetExceptionCode()==EXCEPTION_ILLEGAL_INSTRUCTION){ /*Ignore exception.*/ } # if defined(OD_ARM_MAY_HAVE_NEON) __try{ /*VORR q0,q0,q0*/ __emit(0xF2200150); flags|=OD_CPU_ARM_NEON; } __except(GetExceptionCode()==EXCEPTION_ILLEGAL_INSTRUCTION){ /*Ignore exception.*/ } # endif # endif # endif return flags; }
static inline opus_uint32 opus_cpu_capabilities(void){ opus_uint32 flags; flags=0; /* MSVC has no inline __asm support for ARM, but it does let you __emit * instructions via their assembled hex code. * All of these instructions should be essentially nops. */ # if defined(ARMv5E_ASM) __try{ /*PLD [r13]*/ __emit(0xF5DDF000); flags|=OPUS_CPU_ARM_EDSP; } __except(GetExceptionCode()==EXCEPTION_ILLEGAL_INSTRUCTION){ /*Ignore exception.*/ } # if defined(ARMv6E_ASM) __try{ /*SHADD8 r3,r3,r3*/ __emit(0xE6333F93); flags|=OPUS_CPU_ARM_MEDIA; } __except(GetExceptionCode()==EXCEPTION_ILLEGAL_INSTRUCTION){ /*Ignore exception.*/ } # if defined(ARM_HAVE_NEON) __try{ /*VORR q0,q0,q0*/ __emit(0xF2200150); flags|=OPUS_CPU_ARM_NEON; } __except(GetExceptionCode()==EXCEPTION_ILLEGAL_INSTRUCTION){ /*Ignore exception.*/ } # endif # endif # endif return flags; }