From 8fd683c2b44358842d201a1a262dfb53620c1e6b Mon Sep 17 00:00:00 2001 From: pohky Date: Thu, 14 Jan 2021 00:07:08 +0100 Subject: [PATCH] Update SigScanner.cs revert style changes --- Dalamud/Game/SigScanner.cs | 68 ++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/Dalamud/Game/SigScanner.cs b/Dalamud/Game/SigScanner.cs index a12b1bef8..e2261391f 100644 --- a/Dalamud/Game/SigScanner.cs +++ b/Dalamud/Game/SigScanner.cs @@ -8,17 +8,14 @@ using Serilog; namespace Dalamud.Game { /// - /// A SigScanner facilitates searching for memory signatures in a given ProcessModule. + /// A SigScanner facilitates searching for memory signatures in a given ProcessModule. /// public sealed class SigScanner : IDisposable { /// - /// Set up the SigScanner. + /// 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. - /// + /// 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; @@ -34,52 +31,52 @@ namespace Dalamud.Game { } /// - /// If the search on this module is performed on a copy. + /// If the search on this module is performed on a copy. /// public bool IsCopy { get; } /// - /// If the ProcessModule is 32-bit. + /// 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. + /// The base address of the search area. When copied, this will be the address of the copy. /// - public IntPtr SearchBase => IsCopy ? _moduleCopyPtr : Module.BaseAddress; + public IntPtr SearchBase => IsCopy ? this.moduleCopyPtr : Module.BaseAddress; /// - /// The base address of the .text section search area. + /// 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. + /// The offset of the .text section from the base of the module. /// public long TextSectionOffset { get; private set; } /// - /// The size of the text section. + /// The size of the text section. /// public int TextSectionSize { get; private set; } /// - /// The base address of the .data section search area. + /// 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. + /// The offset of the .data section from the base of the module. /// public long DataSectionOffset { get; private set; } /// - /// The size of the .data section. + /// The size of the .data section. /// public int DataSectionSize { get; private set; } /// - /// The ProcessModule on which the search is performed. + /// The ProcessModule on which the search is performed. /// public ProcessModule Module { get; } @@ -126,23 +123,23 @@ namespace Dalamud.Game { } } - private IntPtr _moduleCopyPtr; - private long _moduleCopyOffset; + private IntPtr moduleCopyPtr; + private long moduleCopyOffset; private unsafe void SetupCopiedSegments() { Log.Verbose("module copy START"); // .text - _moduleCopyPtr = Marshal.AllocHGlobal(Module.ModuleMemorySize); - Buffer.MemoryCopy(Module.BaseAddress.ToPointer(), _moduleCopyPtr.ToPointer(), Module.ModuleMemorySize, Module.ModuleMemorySize); - _moduleCopyOffset = _moduleCopyPtr.ToInt64() - Module.BaseAddress.ToInt64(); + this.moduleCopyPtr = Marshal.AllocHGlobal(Module.ModuleMemorySize); + Buffer.MemoryCopy(Module.BaseAddress.ToPointer(), this.moduleCopyPtr.ToPointer(), Module.ModuleMemorySize, Module.ModuleMemorySize); + this.moduleCopyOffset = this.moduleCopyPtr.ToInt64() - Module.BaseAddress.ToInt64(); Log.Verbose("copy OK!"); } /// - /// Free the memory of the copied module search area on object disposal, if applicable. + /// Free the memory of the copied module search area on object disposal, if applicable. /// public void Dispose() { - Marshal.FreeHGlobal(_moduleCopyPtr); + Marshal.FreeHGlobal(this.moduleCopyPtr); } public IntPtr ResolveRelativeAddress(IntPtr nextInstAddr, int relOffset) { @@ -151,15 +148,15 @@ namespace Dalamud.Game { } /// - /// Scan for a byte signature in the .text section. + /// 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 ? _moduleCopyPtr : TextSectionBase; + var mBase = IsCopy ? this.moduleCopyPtr : TextSectionBase; var scanRet = Scan(mBase, TextSectionSize, signature); if (IsCopy) - scanRet = new IntPtr(scanRet.ToInt64() - _moduleCopyOffset); + scanRet = new IntPtr(scanRet.ToInt64() - this.moduleCopyOffset); var insnByte = Marshal.ReadByte(scanRet); if (insnByte == 0xE8 || insnByte == 0xE9) return ReadCallSig(scanRet); @@ -167,8 +164,7 @@ namespace Dalamud.Game { } /// - /// Helper for ScanText to get the correct address for - /// IDA sigs that mark the first CALL location. + /// Helper for ScanText to get the correct address for IDA sigs that mark the first CALL location. /// /// The address the CALL sig resolved to. /// The real offset of the signature. @@ -178,9 +174,9 @@ namespace Dalamud.Game { } /// - /// Scan for a .data address using a .text function. - /// This is intended to be used with IDA sigs. - /// Place your cursor on the line calling a static address, and create and IDA sig. + /// Scan for a .data address using a .text function. + /// This is intended to be used with IDA sigs. + /// Place your cursor on the line calling a static address, and create and IDA sig. /// /// The signature of the function using the data. /// The offset from function start of the instruction using the data. @@ -199,26 +195,26 @@ namespace Dalamud.Game { } /// - /// Scan for a byte signature in the .data section. + /// 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); if (IsCopy) - scanRet = new IntPtr(scanRet.ToInt64() - _moduleCopyOffset); + scanRet = new IntPtr(scanRet.ToInt64() - this.moduleCopyOffset); return scanRet; } /// - /// Scan for a byte signature in the whole module search area. + /// 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); if (IsCopy) - scanRet = new IntPtr(scanRet.ToInt64() - _moduleCopyOffset); + scanRet = new IntPtr(scanRet.ToInt64() - this.moduleCopyOffset); return scanRet; }