/// <summary> /// Writes the native crash log for specified context. It does not actually treat this as a crash, it just writes out to file as if this was a crash. /// Warning: plugins may still treat this as a crash and modify registers or perform functions that would happen on crash! /// </summary> /// <param name="cpu">The cpu context.</param> /// <param name="nativeThreadId">The native thread identifier. Set int.MinValue for current thread.</param> /// <param name="filePath">The file path to write to (including file name). If file exists it will append.</param> /// <exception cref="System.ArgumentNullException">cpu</exception> public static bool WriteNativeCrashLog(CPURegisters cpu, int nativeThreadId, string filePath) { if (cpu == null) { throw new ArgumentNullException("cpu"); } if (string.IsNullOrEmpty(filePath)) { throw new ArgumentOutOfRangeException("filePath"); } if (nativeThreadId == int.MinValue) { nativeThreadId = Memory.GetCurrentNativeThreadId(); } int handled = 0; try { var cl = new NativeCrashLog(cpu); handled = cl.Write(true, filePath, true); } catch (Exception ex2) { Main.Log.Append(ex2); } return(handled > 0); }
/// <summary> /// Unhandled exception filter. /// </summary> /// <param name="cpu">The cpu context.</param> /// <returns></returns> internal static bool UnhandledExceptionFilter(CPURegisters cpu) { int handled = 0; string logmsg = "Unhandled native exception occurred at " + cpu.IP.ToHexString() + CrashLog.GetAddressInModule(cpu.IP, System.Diagnostics.Process.GetCurrentProcess().Modules, " ") + " on thread " + Memory.GetCurrentNativeThreadId() + "!"; try { var cl = new NativeCrashLog(cpu); handled = cl.Write(true); if (cl.Skipped) { logmsg = null; } } catch (Exception ex2) { Main.Log.Append(ex2); } if (logmsg != null) { Log.AppendLine(logmsg); } return(handled > 0); }