feat: add exception handler debug

This commit is contained in:
goat 2020-06-06 18:44:52 +02:00
parent 2d6de01c39
commit e2ac9ddd43
2 changed files with 45 additions and 2 deletions

View file

@ -5,6 +5,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -154,6 +155,10 @@ namespace Dalamud {
} }
public void Start() { public void Start() {
#if DEBUG
ReplaceExceptionHandler();
#endif
this.Framework.Enable(); this.Framework.Enable();
this.ClientState.Enable(); this.ClientState.Enable();
} }
@ -194,7 +199,7 @@ namespace Dalamud {
this.SigScanner.Dispose(); this.SigScanner.Dispose();
} }
#region Interface #region Interface
private bool isImguiDrawDemoWindow = false; private bool isImguiDrawDemoWindow = false;
@ -269,6 +274,9 @@ namespace Dalamud {
{ {
Process.GetCurrentProcess().Kill(); Process.GetCurrentProcess().Kill();
} }
if (ImGui.MenuItem("Cause AccessViolation")) {
var a = Marshal.ReadByte(IntPtr.Zero);
}
ImGui.Separator(); ImGui.Separator();
ImGui.MenuItem(this.assemblyVersion, false); ImGui.MenuItem(this.assemblyVersion, false);
ImGui.MenuItem(this.StartInfo.GameVersion, false); ImGui.MenuItem(this.StartInfo.GameVersion, false);
@ -276,6 +284,14 @@ namespace Dalamud {
ImGui.EndMenu(); ImGui.EndMenu();
} }
if (ImGui.BeginMenu("Game")) {
if (ImGui.MenuItem("Replace ExceptionHandler")) {
ReplaceExceptionHandler();
}
ImGui.EndMenu();
}
if (ImGui.BeginMenu("Plugins")) if (ImGui.BeginMenu("Plugins"))
{ {
if (ImGui.MenuItem("Open Plugin installer")) if (ImGui.MenuItem("Open Plugin installer"))
@ -396,7 +412,16 @@ namespace Dalamud {
} }
} }
#endregion private void ReplaceExceptionHandler() {
var semd = this.SigScanner.ScanText(
"40 55 53 56 48 8D AC 24 ?? ?? ?? ?? B8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 2B E0 48 8B 05 ?? ?? ?? ?? 48 33 C4 48 89 85 ?? ?? ?? ?? 48 83 3D ?? ?? ?? ?? ??");
Log.Debug($"SE debug filter at {semd.ToInt64():X}");
var oldFilter = NativeFunctions.SetUnhandledExceptionFilter(semd);
Log.Debug("Reset ExceptionFilter, old: {0}", oldFilter);
}
#endregion
private void SetupCommands() { private void SetupCommands() {
CommandManager.AddHandler("/xldclose", new CommandInfo(OnUnloadCommand) { CommandManager.AddHandler("/xldclose", new CommandInfo(OnUnloadCommand) {

View file

@ -56,6 +56,15 @@ namespace Dalamud
FLASHW_TIMERNOFG = 12 FLASHW_TIMERNOFG = 12
} }
[Flags]
public enum ErrorModes : uint
{
SYSTEM_DEFAULT = 0x0,
SEM_FAILCRITICALERRORS = 0x0001,
SEM_NOALIGNMENTFAULTEXCEPT = 0x0004,
SEM_NOGPFAULTERRORBOX = 0x0002,
SEM_NOOPENFILEERRORBOX = 0x8000
}
#endregion #endregion
@ -109,5 +118,14 @@ namespace Dalamud
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)] [DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)]
public static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)]string lpFileName); public static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)]string lpFileName);
[DllImport("kernel32.dll")]
public static extern IntPtr SetUnhandledExceptionFilter(IntPtr lpTopLevelExceptionFilter);
[DllImport("kernel32.dll")]
public static extern ErrorModes SetErrorMode(ErrorModes uMode);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool DebugActiveProcess(uint dwProcessId);
} }
} }