mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-15 13:14:17 +01:00
Patch Process.Handle
This commit is contained in:
parent
d23b710edf
commit
d0c2c1bf9d
1 changed files with 34 additions and 0 deletions
|
|
@ -1,4 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
@ -19,6 +21,7 @@ using Dalamud.Interface.Internal;
|
||||||
using Dalamud.IoC.Internal;
|
using Dalamud.IoC.Internal;
|
||||||
using Dalamud.Plugin.Internal;
|
using Dalamud.Plugin.Internal;
|
||||||
using Dalamud.Plugin.Ipc.Internal;
|
using Dalamud.Plugin.Ipc.Internal;
|
||||||
|
using HarmonyLib;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using Serilog.Core;
|
using Serilog.Core;
|
||||||
|
|
||||||
|
|
@ -52,6 +55,8 @@ namespace Dalamud
|
||||||
/// <param name="configuration">The Dalamud configuration.</param>
|
/// <param name="configuration">The Dalamud configuration.</param>
|
||||||
public Dalamud(DalamudStartInfo info, LoggingLevelSwitch loggingLevelSwitch, ManualResetEvent finishSignal, DalamudConfiguration configuration)
|
public Dalamud(DalamudStartInfo info, LoggingLevelSwitch loggingLevelSwitch, ManualResetEvent finishSignal, DalamudConfiguration configuration)
|
||||||
{
|
{
|
||||||
|
this.ApplyProcessPatch();
|
||||||
|
|
||||||
Service<Dalamud>.Set(this);
|
Service<Dalamud>.Set(this);
|
||||||
Service<DalamudStartInfo>.Set(info);
|
Service<DalamudStartInfo>.Set(info);
|
||||||
Service<DalamudConfiguration>.Set(configuration);
|
Service<DalamudConfiguration>.Set(configuration);
|
||||||
|
|
@ -363,5 +368,34 @@ namespace Dalamud
|
||||||
var oldFilter = NativeFunctions.SetUnhandledExceptionFilter(releaseFilter);
|
var oldFilter = NativeFunctions.SetUnhandledExceptionFilter(releaseFilter);
|
||||||
Log.Debug("Reset ExceptionFilter, old: {0}", oldFilter);
|
Log.Debug("Reset ExceptionFilter, old: {0}", oldFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Patch method for the class Process.Handle. This patch facilitates fixing Reloaded so that it
|
||||||
|
/// uses pseudo-handles to access memory, to prevent permission errors.
|
||||||
|
/// It should never be called manually.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="__instance">The equivalent of `this`.</param>
|
||||||
|
/// <param name="__result">The result from the original method.</param>
|
||||||
|
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1313:Parameter names should begin with lower-case letter", Justification = "Enforced naming for special injected parameters")]
|
||||||
|
private static void ProcessHandlePatch(Process __instance, ref IntPtr __result)
|
||||||
|
{
|
||||||
|
if (__instance.Id == Environment.ProcessId)
|
||||||
|
{
|
||||||
|
__result = (IntPtr)0xFFFFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.Verbose($"Process.Handle // {__instance.ProcessName} // {__result:X}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyProcessPatch()
|
||||||
|
{
|
||||||
|
var harmony = new Harmony("goatcorp.dalamud");
|
||||||
|
|
||||||
|
var targetType = typeof(Process);
|
||||||
|
|
||||||
|
var handleTarget = AccessTools.PropertyGetter(targetType, nameof(Process.Handle));
|
||||||
|
var handlePatch = AccessTools.Method(typeof(Dalamud), nameof(Dalamud.ProcessHandlePatch));
|
||||||
|
harmony.Patch(handleTarget, postfix: new(handlePatch));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue