From 83d32fe02c113a2a5573c1fbe41801e5d12dcb40 Mon Sep 17 00:00:00 2001 From: Nukoooo <89713806+Nukoooo@users.noreply.github.com> Date: Tue, 5 Aug 2025 06:55:34 +0800 Subject: [PATCH] Read .text section bytes from file instead of process memory (#2251) * Read .text section bytes from file instead of memory * format * fix oversight * only read bytes from file once --- Dalamud/Game/SigScanner.cs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Dalamud/Game/SigScanner.cs b/Dalamud/Game/SigScanner.cs index 5aaf17f12..77d312aec 100644 --- a/Dalamud/Game/SigScanner.cs +++ b/Dalamud/Game/SigScanner.cs @@ -7,7 +7,6 @@ using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; - using Iced.Intel; using Newtonsoft.Json; using Serilog; @@ -21,6 +20,8 @@ namespace Dalamud.Game; /// public class SigScanner : IDisposable, ISigScanner { + private static byte[]? fileBytes; + private readonly FileInfo? cacheFile; private nint moduleCopyPtr; @@ -51,12 +52,16 @@ public class SigScanner : IDisposable, ISigScanner this.Is32BitProcess = !Environment.Is64BitProcess; this.IsCopy = doCopy; + if (this.IsCopy) + { + this.SetupCopiedSegments(); + + fileBytes ??= File.ReadAllBytes(module.FileName); + } + // Limit the search space to .text section. this.SetupSearchSpace(module); - if (this.IsCopy) - this.SetupCopiedSegments(); - Log.Verbose($"Module base: 0x{this.TextSectionBase.ToInt64():X}"); Log.Verbose($"Module size: 0x{this.TextSectionSize:X}"); @@ -494,6 +499,18 @@ public class SigScanner : IDisposable, ISigScanner case 0x747865742E: // .text this.TextSectionOffset = Marshal.ReadInt32(sectionCursor, 12); this.TextSectionSize = Marshal.ReadInt32(sectionCursor, 8); + + if (this.IsCopy) + { + var pointerToRawData = Marshal.ReadInt32(sectionCursor, 20); + + Marshal.Copy( + fileBytes.AsSpan(pointerToRawData, this.TextSectionSize).ToArray(), + 0, + this.moduleCopyPtr + (nint)this.TextSectionOffset, + this.TextSectionSize); + } + break; case 0x617461642E: // .data this.DataSectionOffset = Marshal.ReadInt32(sectionCursor, 12);