def _crashHandler(exceptionInfo): threadId = ctypes.windll.kernel32.GetCurrentThreadId() # An exception might have been set for this thread. # Clear it so that it doesn't get raised in this function. ctypes.pythonapi.PyThreadState_SetAsyncExc(threadId, None) # Write a minidump. dumpPath = os.path.abspath(os.path.join(globalVars.appArgs.logFileName, "..", "nvda_crash.dmp")) try: with file(dumpPath, "w") as mdf: mdExc = MINIDUMP_EXCEPTION_INFORMATION(ThreadId=threadId, ExceptionPointers=exceptionInfo, ClientPointers=False) if not ctypes.windll.DbgHelp.MiniDumpWriteDump( ctypes.windll.kernel32.GetCurrentProcess(), os.getpid(), msvcrt.get_osfhandle(mdf.fileno()), 0, # MiniDumpNormal ctypes.byref(mdExc), None, None ): raise ctypes.WinError() except: log.critical("NVDA crashed! Error writing minidump", exc_info=True) else: log.critical("NVDA crashed! Minidump written to %s" % dumpPath) log.info("Restarting due to crash") core.restart() return 1 # EXCEPTION_EXECUTE_HANDLER
def _crashHandler(exceptionInfo): threadId = ctypes.windll.kernel32.GetCurrentThreadId() # An exception might have been set for this thread. # Clear it so that it doesn't get raised in this function. ctypes.pythonapi.PyThreadState_SetAsyncExc(threadId, None) # Write a minidump. dumpPath = os.path.abspath(os.path.join(globalVars.appArgs.logFileName, "..", "nvda_crash.dmp")) try: with file(dumpPath, "w") as mdf: mdExc = MINIDUMP_EXCEPTION_INFORMATION(ThreadId=threadId, ExceptionPointers=exceptionInfo, ClientPointers=False) if not ctypes.windll.DbgHelp.MiniDumpWriteDump( ctypes.windll.kernel32.GetCurrentProcess(), os.getpid(), msvcrt.get_osfhandle(mdf.fileno()), 0, # MiniDumpNormal ctypes.byref(mdExc), None, None ): raise ctypes.WinError() except: log.critical("NVDA crashed! Error writing minidump", exc_info=True) else: log.critical("NVDA crashed! Minidump written to %s" % dumpPath) # Log Python stacks for every thread. for logThread, logFrame in sys._current_frames().iteritems(): log.info("Python stack for thread %d" % logThread, stack_info=traceback.extract_stack(logFrame)) log.info("Restarting due to crash") core.restart() return 1 # EXCEPTION_EXECUTE_HANDLER
def initialize(): global _remoteLib, _remoteLoader64, localLib, winEventHookID,generateBeep,VBuf_getTextInRange localLib=cdll.LoadLibrary('lib/nvdaHelperLocal.dll') for name,func in [ ("nvdaController_speakText",nvdaController_speakText), ("nvdaController_cancelSpeech",nvdaController_cancelSpeech), ("nvdaController_brailleMessage",nvdaController_brailleMessage), ("nvdaControllerInternal_inputLangChangeNotify",nvdaControllerInternal_inputLangChangeNotify), ("nvdaControllerInternal_displayModelTextChangeNotify",nvdaControllerInternal_displayModelTextChangeNotify), ("nvdaControllerInternal_logMessage",nvdaControllerInternal_logMessage), ]: try: _setDllFuncPointer(localLib,"_%s"%name,func) except AttributeError: log.error("nvdaHelperLocal function pointer for %s could not be found, possibly old nvdaHelperLocal dll"%name) localLib.startServer() generateBeep=localLib.generateBeep generateBeep.argtypes=[c_char_p,c_float,c_uint,c_ubyte,c_ubyte] generateBeep.restype=c_uint # Handle VBuf_getTextInRange's BSTR out parameter so that the BSTR will be freed automatically. VBuf_getTextInRange = CFUNCTYPE(c_int, c_int, c_int, c_int, POINTER(BSTR), c_int)( ("VBuf_getTextInRange", localLib), ((1,), (1,), (1,), (2,), (1,))) #Load nvdaHelperRemote.dll but with an altered search path so it can pick up other dlls in lib h=windll.kernel32.LoadLibraryExW(os.path.abspath(ur"lib\nvdaHelperRemote.dll"),0,0x8) if not h: log.critical("Error loading nvdaHelperRemote.dll: %s" % WinError()) return _remoteLib=CDLL("nvdaHelperRemote",handle=h) if _remoteLib.injection_initialize(globalVars.appArgs.secure) == 0: raise RuntimeError("Error initializing NVDAHelperRemote") if os.environ.get('PROCESSOR_ARCHITEW6432')=='AMD64': _remoteLoader64=RemoteLoader64() winEventHookID=winUser.setWinEventHook(EVENT_TYPEDCHARACTER,EVENT_TYPEDCHARACTER,0,winEventCallback,0,0,0)
def initialize(): global _remoteLib, _remoteLoader64, localLib, generateBeep, VBuf_getTextInRange, lastLanguageID, lastLayoutString hkl=c_ulong(windll.User32.GetKeyboardLayout(0)).value lastLanguageID=winUser.LOWORD(hkl) KL_NAMELENGTH=9 buf=create_unicode_buffer(KL_NAMELENGTH) res=windll.User32.GetKeyboardLayoutNameW(buf) if res: lastLayoutString=buf.value localLib=cdll.LoadLibrary(os.path.join(versionedLibPath,'nvdaHelperLocal.dll')) for name,func in [ ("nvdaController_speakText",nvdaController_speakText), ("nvdaController_cancelSpeech",nvdaController_cancelSpeech), ("nvdaController_brailleMessage",nvdaController_brailleMessage), ("nvdaControllerInternal_requestRegistration",nvdaControllerInternal_requestRegistration), ("nvdaControllerInternal_inputLangChangeNotify",nvdaControllerInternal_inputLangChangeNotify), ("nvdaControllerInternal_typedCharacterNotify",nvdaControllerInternal_typedCharacterNotify), ("nvdaControllerInternal_displayModelTextChangeNotify",nvdaControllerInternal_displayModelTextChangeNotify), ("nvdaControllerInternal_logMessage",nvdaControllerInternal_logMessage), ("nvdaControllerInternal_inputCompositionUpdate",nvdaControllerInternal_inputCompositionUpdate), ("nvdaControllerInternal_inputCandidateListUpdate",nvdaControllerInternal_inputCandidateListUpdate), ("nvdaControllerInternal_IMEOpenStatusUpdate",nvdaControllerInternal_IMEOpenStatusUpdate), ("nvdaControllerInternal_inputConversionModeUpdate",nvdaControllerInternal_inputConversionModeUpdate), ("nvdaControllerInternal_vbufChangeNotify",nvdaControllerInternal_vbufChangeNotify), ("nvdaControllerInternal_installAddonPackageFromPath",nvdaControllerInternal_installAddonPackageFromPath), ("nvdaControllerInternal_drawFocusRectNotify",nvdaControllerInternal_drawFocusRectNotify), ]: try: _setDllFuncPointer(localLib,"_%s"%name,func) except AttributeError as e: log.error("nvdaHelperLocal function pointer for %s could not be found, possibly old nvdaHelperLocal dll"%name,exc_info=True) raise e localLib.nvdaHelperLocal_initialize() generateBeep=localLib.generateBeep generateBeep.argtypes=[c_char_p,c_float,c_int,c_int,c_int] generateBeep.restype=c_int # The rest of this function (to do with injection) only applies if NVDA is not running as a Windows store application # Handle VBuf_getTextInRange's BSTR out parameter so that the BSTR will be freed automatically. VBuf_getTextInRange = CFUNCTYPE(c_int, c_int, c_int, c_int, POINTER(BSTR), c_int)( ("VBuf_getTextInRange", localLib), ((1,), (1,), (1,), (2,), (1,))) if config.isAppX: log.info("Remote injection disabled due to running as a Windows Store Application") return #Load nvdaHelperRemote.dll but with an altered search path so it can pick up other dlls in lib h=windll.kernel32.LoadLibraryExW(os.path.abspath(os.path.join(versionedLibPath,u"nvdaHelperRemote.dll")),0,0x8) if not h: log.critical("Error loading nvdaHelperRemote.dll: %s" % WinError()) return _remoteLib=CDLL("nvdaHelperRemote",handle=h) if _remoteLib.injection_initialize(globalVars.appArgs.secure) == 0: raise RuntimeError("Error initializing NVDAHelperRemote") if not _remoteLib.installIA2Support(): log.error("Error installing IA2 support") #Manually start the in-process manager thread for this NVDA main thread now, as a slow system can cause this action to confuse WX _remoteLib.initInprocManagerThreadIfNeeded() if os.environ.get('PROCESSOR_ARCHITEW6432')=='AMD64': _remoteLoader64=RemoteLoader64()
def initialize(): global _remoteLib, _remoteLoader64, localLib, generateBeep, VBuf_getTextInRange, lastLanguageID, lastLayoutString hkl=c_ulong(windll.User32.GetKeyboardLayout(0)).value lastLanguageID=winUser.LOWORD(hkl) KL_NAMELENGTH=9 buf=create_unicode_buffer(KL_NAMELENGTH) res=windll.User32.GetKeyboardLayoutNameW(buf) if res: lastLayoutString=buf.value localLib=cdll.LoadLibrary(os.path.join(versionedLibPath,'nvdaHelperLocal.dll')) for name,func in [ ("nvdaController_speakText",nvdaController_speakText), ("nvdaController_cancelSpeech",nvdaController_cancelSpeech), ("nvdaController_brailleMessage",nvdaController_brailleMessage), ("nvdaControllerInternal_requestRegistration",nvdaControllerInternal_requestRegistration), ("nvdaControllerInternal_inputLangChangeNotify",nvdaControllerInternal_inputLangChangeNotify), ("nvdaControllerInternal_typedCharacterNotify",nvdaControllerInternal_typedCharacterNotify), ("nvdaControllerInternal_displayModelTextChangeNotify",nvdaControllerInternal_displayModelTextChangeNotify), ("nvdaControllerInternal_logMessage",nvdaControllerInternal_logMessage), ("nvdaControllerInternal_inputCompositionUpdate",nvdaControllerInternal_inputCompositionUpdate), ("nvdaControllerInternal_inputCandidateListUpdate",nvdaControllerInternal_inputCandidateListUpdate), ("nvdaControllerInternal_IMEOpenStatusUpdate",nvdaControllerInternal_IMEOpenStatusUpdate), ("nvdaControllerInternal_inputConversionModeUpdate",nvdaControllerInternal_inputConversionModeUpdate), ("nvdaControllerInternal_vbufChangeNotify",nvdaControllerInternal_vbufChangeNotify), ("nvdaControllerInternal_installAddonPackageFromPath",nvdaControllerInternal_installAddonPackageFromPath), ("nvdaControllerInternal_drawFocusRectNotify",nvdaControllerInternal_drawFocusRectNotify), ]: try: _setDllFuncPointer(localLib,"_%s"%name,func) except AttributeError as e: log.error("nvdaHelperLocal function pointer for %s could not be found, possibly old nvdaHelperLocal dll"%name,exc_info=True) raise e localLib.nvdaHelperLocal_initialize() generateBeep=localLib.generateBeep generateBeep.argtypes=[c_char_p,c_float,c_int,c_int,c_int] generateBeep.restype=c_int # The rest of this function (to do with injection) only applies if NVDA is not running as a Windows store application # Handle VBuf_getTextInRange's BSTR out parameter so that the BSTR will be freed automatically. VBuf_getTextInRange = CFUNCTYPE(c_int, c_int, c_int, c_int, POINTER(BSTR), c_int)( ("VBuf_getTextInRange", localLib), ((1,), (1,), (1,), (2,), (1,))) if config.isAppX: log.info("Remote injection disabled due to running as a Windows Store Application") return #Load nvdaHelperRemote.dll but with an altered search path so it can pick up other dlls in lib h=windll.kernel32.LoadLibraryExW(os.path.abspath(os.path.join(versionedLibPath,u"nvdaHelperRemote.dll")),0,0x8) if not h: log.critical("Error loading nvdaHelperRemote.dll: %s" % WinError()) return _remoteLib=CDLL("nvdaHelperRemote",handle=h) if _remoteLib.injection_initialize(globalVars.appArgs.secure) == 0: raise RuntimeError("Error initializing NVDAHelperRemote") if not _remoteLib.installIA2Support(): log.error("Error installing IA2 support") #Manually start the in-process manager thread for this NVDA main thread now, as a slow system can cause this action to confuse WX _remoteLib.initInprocManagerThreadIfNeeded() if os.environ.get('PROCESSOR_ARCHITEW6432') in ('AMD64', 'ARM64'): _remoteLoader64=RemoteLoader64()
def initialize(): global _remoteLib, _remoteLoader64, localLib, generateBeep,VBuf_getTextInRange localLib=cdll.LoadLibrary('lib/nvdaHelperLocal.dll') for name,func in [ ("nvdaController_speakText",nvdaController_speakText), ("nvdaController_cancelSpeech",nvdaController_cancelSpeech), ("nvdaController_brailleMessage",nvdaController_brailleMessage), ("nvdaControllerInternal_requestRegistration",nvdaControllerInternal_requestRegistration), ("nvdaControllerInternal_inputLangChangeNotify",nvdaControllerInternal_inputLangChangeNotify), ("nvdaControllerInternal_typedCharacterNotify",nvdaControllerInternal_typedCharacterNotify), ("nvdaControllerInternal_displayModelTextChangeNotify",nvdaControllerInternal_displayModelTextChangeNotify), ("nvdaControllerInternal_logMessage",nvdaControllerInternal_logMessage), ("nvdaControllerInternal_inputCompositionUpdate",nvdaControllerInternal_inputCompositionUpdate), ("nvdaControllerInternal_inputCandidateListUpdate",nvdaControllerInternal_inputCandidateListUpdate), ("nvdaControllerInternal_IMEOpenStatusUpdate",nvdaControllerInternal_IMEOpenStatusUpdate), ("nvdaControllerInternal_inputConversionModeUpdate",nvdaControllerInternal_inputConversionModeUpdate), ("nvdaControllerInternal_vbufChangeNotify",nvdaControllerInternal_vbufChangeNotify), ("nvdaControllerInternal_installAddonPackageFromPath",nvdaControllerInternal_installAddonPackageFromPath), ("nvdaControllerInternal_drawFocusRectNotify",nvdaControllerInternal_drawFocusRectNotify), ]: try: _setDllFuncPointer(localLib,"_%s"%name,func) except AttributeError as e: log.error("nvdaHelperLocal function pointer for %s could not be found, possibly old nvdaHelperLocal dll"%name,exc_info=True) raise e localLib.nvdaHelperLocal_initialize() generateBeep=localLib.generateBeep generateBeep.argtypes=[c_char_p,c_float,c_int,c_int,c_int] generateBeep.restype=c_int # Handle VBuf_getTextInRange's BSTR out parameter so that the BSTR will be freed automatically. VBuf_getTextInRange = CFUNCTYPE(c_int, c_int, c_int, c_int, POINTER(BSTR), c_int)( ("VBuf_getTextInRange", localLib), ((1,), (1,), (1,), (2,), (1,))) #Load nvdaHelperRemote.dll but with an altered search path so it can pick up other dlls in lib h=windll.kernel32.LoadLibraryExW(os.path.abspath(ur"lib\nvdaHelperRemote.dll"),0,0x8) if not h: log.critical("Error loading nvdaHelperRemote.dll: %s" % WinError()) return _remoteLib=CDLL("nvdaHelperRemote",handle=h) if _remoteLib.injection_initialize(globalVars.appArgs.secure) == 0: raise RuntimeError("Error initializing NVDAHelperRemote") if not _remoteLib.installIA2Support(): log.error("Error installing IA2 support") #Manually start the in-process manager thread for this NVDA main thread now, as a slow system can cause this action to confuse WX _remoteLib.initInprocManagerThreadIfNeeded() if os.environ.get('PROCESSOR_ARCHITEW6432')=='AMD64': _remoteLoader64=RemoteLoader64()
def _crashHandler(exceptionInfo): threadId = ctypes.windll.kernel32.GetCurrentThreadId() # An exception might have been set for this thread. # Clear it so that it doesn't get raised in this function. ctypes.pythonapi.PyThreadState_SetAsyncExc(threadId, None) # Write a minidump. dumpPath = os.path.join(globalVars.appArgs.logFileName, "..", "nvda_crash.dmp") try: # Though we aren't using pythonic functions to write to the dump file, # open it in binary mode as opening it in text mode (the default) doesn't make sense. with open(dumpPath, "wb") as mdf: mdExc = MINIDUMP_EXCEPTION_INFORMATION( ThreadId=threadId, ExceptionPointers=exceptionInfo, ClientPointers=False) if not ctypes.windll.DbgHelp.MiniDumpWriteDump( ctypes.windll.kernel32.GetCurrentProcess(), os.getpid(), msvcrt.get_osfhandle(mdf.fileno()), 0, # MiniDumpNormal ctypes.byref(mdExc), None, None): raise ctypes.WinError() except: log.critical("NVDA crashed! Error writing minidump", exc_info=True) else: log.critical("NVDA crashed! Minidump written to %s" % dumpPath) # Log Python stacks for every thread. stacks = getFormattedStacksForAllThreads() log.info(f"Listing stacks for Python threads:\n{stacks}") log.info("Restarting due to crash") # if NVDA has crashed we cannot rely on the queue handler to start the new NVDA instance core.restartUnsafely() return 1 # EXCEPTION_EXECUTE_HANDLER