From 1d9d3833486161d9f4a438669a8107a5096f7234 Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 6 Sep 2021 22:08:59 -0400 Subject: [PATCH] revert only the required length of bytes --- Dalamud/Hooking/Internal/HookManager.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Dalamud/Hooking/Internal/HookManager.cs b/Dalamud/Hooking/Internal/HookManager.cs index e955b43a1..483a0e4af 100644 --- a/Dalamud/Hooking/Internal/HookManager.cs +++ b/Dalamud/Hooking/Internal/HookManager.cs @@ -169,15 +169,14 @@ namespace Dalamud.Hooking.Internal break; } + var snippet = originalBytes[0..i]; + if (i > 0) { - Log.Verbose($"Reverting hook at 0x{address.ToInt64():X}"); - fixed (byte* original = originalBytes) - { - MemoryHelper.ChangePermission(address, i, MemoryProtection.ExecuteReadWrite, out var oldPermissions); - MemoryHelper.WriteRaw(address, originalBytes); - MemoryHelper.ChangePermission(address, i, oldPermissions); - } + Log.Verbose($"Reverting hook at 0x{address.ToInt64():X} ({snippet.Length} bytes)"); + MemoryHelper.ChangePermission(address, i, MemoryProtection.ExecuteReadWrite, out var oldPermissions); + MemoryHelper.WriteRaw(address, snippet); + MemoryHelper.ChangePermission(address, i, oldPermissions); } } }