Merge pull request #1653 from KazWolfe/crash-menu

feat: Add "deref nullptr in hook" crash item
This commit is contained in:
goat 2024-02-15 02:18:54 +01:00 committed by GitHub
commit 63f32322f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -12,6 +12,7 @@ using Dalamud.Game.ClientState.Conditions;
using Dalamud.Game.ClientState.Keys; using Dalamud.Game.ClientState.Keys;
using Dalamud.Game.Gui; using Dalamud.Game.Gui;
using Dalamud.Game.Internal; using Dalamud.Game.Internal;
using Dalamud.Hooking;
using Dalamud.Interface.Animation.EasingFunctions; using Dalamud.Interface.Animation.EasingFunctions;
using Dalamud.Interface.Colors; using Dalamud.Interface.Colors;
using Dalamud.Interface.Internal.ManagedAsserts; using Dalamud.Interface.Internal.ManagedAsserts;
@ -89,7 +90,7 @@ internal class DalamudInterface : IDisposable, IServiceType
private bool isImPlotDrawDemoWindow = false; private bool isImPlotDrawDemoWindow = false;
private bool isImGuiTestWindowsInMonospace = false; private bool isImGuiTestWindowsInMonospace = false;
private bool isImGuiDrawMetricsWindow = false; private bool isImGuiDrawMetricsWindow = false;
[ServiceManager.ServiceConstructor] [ServiceManager.ServiceConstructor]
private DalamudInterface( private DalamudInterface(
Dalamud dalamud, Dalamud dalamud,
@ -188,7 +189,9 @@ internal class DalamudInterface : IDisposable, IServiceType
this.creditsDarkeningAnimation.Point1 = Vector2.Zero; this.creditsDarkeningAnimation.Point1 = Vector2.Zero;
this.creditsDarkeningAnimation.Point2 = new Vector2(CreditsDarkeningMaxAlpha); this.creditsDarkeningAnimation.Point2 = new Vector2(CreditsDarkeningMaxAlpha);
} }
private delegate nint CrashDebugDelegate(nint self);
/// <summary> /// <summary>
/// Gets the number of frames since Dalamud has loaded. /// Gets the number of frames since Dalamud has loaded.
/// </summary> /// </summary>
@ -744,28 +747,48 @@ internal class DalamudInterface : IDisposable, IServiceType
} }
ImGui.Separator(); ImGui.Separator();
if (ImGui.MenuItem("Access Violation")) if (ImGui.BeginMenu("Crash game"))
{ {
Marshal.ReadByte(IntPtr.Zero); if (ImGui.MenuItem("Access Violation"))
}
if (ImGui.MenuItem("Crash game (nullptr)"))
{
unsafe
{ {
var framework = Framework.Instance(); Marshal.ReadByte(IntPtr.Zero);
framework->UIModule = (UIModule*)0; }
}
} if (ImGui.MenuItem("Set UiModule to NULL"))
if (ImGui.MenuItem("Crash game (non-nullptr)"))
{
unsafe
{ {
var framework = Framework.Instance(); unsafe
framework->UIModule = (UIModule*)0x12345678; {
var framework = Framework.Instance();
framework->UIModule = (UIModule*)0;
}
} }
if (ImGui.MenuItem("Set UiModule to invalid ptr"))
{
unsafe
{
var framework = Framework.Instance();
framework->UIModule = (UIModule*)0x12345678;
}
}
if (ImGui.MenuItem("Deref nullptr in Hook"))
{
unsafe
{
var hook = Hook<CrashDebugDelegate>.FromAddress(
(nint)UIModule.StaticVTable.GetUIInputData,
self =>
{
_ = *(byte*)0;
return (nint)UIModule.Instance()->GetUIInputData();
});
hook.Enable();
}
}
ImGui.EndMenu();
} }
if (ImGui.MenuItem("Report crashes at shutdown", null, this.configuration.ReportShutdownCrashes)) if (ImGui.MenuItem("Report crashes at shutdown", null, this.configuration.ReportShutdownCrashes))