diff --git a/Dalamud/Game/SigScanner.cs b/Dalamud/Game/SigScanner.cs index 86eba33ee..1d4fc7df8 100644 --- a/Dalamud/Game/SigScanner.cs +++ b/Dalamud/Game/SigScanner.cs @@ -7,7 +7,15 @@ using System.Runtime.InteropServices; using Serilog; namespace Dalamud.Game { + /// + /// A SigScanner facilitates searching for memory signatures in a given ProcessModule. + /// public sealed class SigScanner : IDisposable { + /// + /// Set up the SigScanner. + /// + /// The ProcessModule to be used for scanning + /// Whether or not to copy the module upon initialization for search operations to use, as to not get disturbed by possible hooks. public SigScanner(ProcessModule module, bool doCopy = false) { Module = module; Is32BitProcess = !Environment.Is64BitProcess; @@ -23,20 +31,50 @@ namespace Dalamud.Game { Log.Verbose("Module size: {Size}", TextSectionSize); } + /// + /// If the search on this module is performed on a copy. + /// public bool IsCopy { get; private set; } + /// + /// If the ProcessModule is 32-bit. + /// public bool Is32BitProcess { get; } + /// + /// The base address of the search area. When copied, this will be the address of the copy. + /// public IntPtr SearchBase => IsCopy ? this.moduleCopyPtr : Module.BaseAddress; + /// + /// The base address of the .text section search area. + /// public IntPtr TextSectionBase => new IntPtr(SearchBase.ToInt64() + TextSectionOffset); + /// + /// The offset of the .text section from the base of the module. + /// public long TextSectionOffset { get; private set; } + /// + /// The size of the text section. + /// public int TextSectionSize { get; private set; } + /// + /// The base address of the .data section search area. + /// public IntPtr DataSectionBase => new IntPtr(SearchBase.ToInt64() + DataSectionOffset); + /// + /// The offset of the .data section from the base of the module. + /// public long DataSectionOffset { get; private set; } + /// + /// The size of the .data section. + /// public int DataSectionSize { get; private set; } + /// + /// The ProcessModule on which the search is performed. + /// public ProcessModule Module { get; } private IntPtr TextSectionTop => TextSectionBase + TextSectionSize; @@ -98,10 +136,18 @@ namespace Dalamud.Game { Log.Verbose("copy OK!"); } + /// + /// Free the memory of the copied module search area on object disposal, if applicable. + /// public void Dispose() { Marshal.FreeHGlobal(this.moduleCopyPtr); } + /// + /// Scan for a byte signature in the .text section. + /// + /// The signature. + /// The real offset of the found signature. public IntPtr ScanText(string signature) { var mBase = IsCopy ? this.moduleCopyPtr : TextSectionBase; @@ -113,6 +159,11 @@ namespace Dalamud.Game { return scanRet; } + /// + /// Scan for a byte signature in the .data section. + /// + /// The signature. + /// The real offset of the found signature. public IntPtr ScanData(string signature) { var scanRet = Scan(DataSectionBase, DataSectionSize, signature); @@ -122,6 +173,11 @@ namespace Dalamud.Game { return scanRet; } + /// + /// Scan for a byte signature in the whole module search area. + /// + /// The signature. + /// The real offset of the found signature. public IntPtr ScanModule(string signature) { var scanRet = Scan(SearchBase, Module.ModuleMemorySize, signature);