Update SigScanner.cs

revert style changes
This commit is contained in:
pohky 2021-01-14 00:07:08 +01:00
parent 4482f305b0
commit 8fd683c2b4

View file

@ -15,10 +15,7 @@ namespace Dalamud.Game {
/// Set up the SigScanner. /// Set up the SigScanner.
/// </summary> /// </summary>
/// <param name="module">The ProcessModule to be used for scanning</param> /// <param name="module">The ProcessModule to be used for scanning</param>
/// <param name="doCopy"> /// <param name="doCopy">Whether or not to copy the module upon initialization for search operations to use, as to not get disturbed by possible hooks.</param>
/// Whether or not to copy the module upon initialization for search operations to use, as to not get
/// disturbed by possible hooks.
/// </param>
public SigScanner(ProcessModule module, bool doCopy = false) { public SigScanner(ProcessModule module, bool doCopy = false) {
Module = module; Module = module;
Is32BitProcess = !Environment.Is64BitProcess; Is32BitProcess = !Environment.Is64BitProcess;
@ -46,7 +43,7 @@ namespace Dalamud.Game {
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
public IntPtr SearchBase => IsCopy ? _moduleCopyPtr : Module.BaseAddress; public IntPtr SearchBase => IsCopy ? this.moduleCopyPtr : Module.BaseAddress;
/// <summary> /// <summary>
/// The base address of the .text section search area. /// The base address of the .text section search area.
@ -126,15 +123,15 @@ namespace Dalamud.Game {
} }
} }
private IntPtr _moduleCopyPtr; private IntPtr moduleCopyPtr;
private long _moduleCopyOffset; private long moduleCopyOffset;
private unsafe void SetupCopiedSegments() { private unsafe void SetupCopiedSegments() {
Log.Verbose("module copy START"); Log.Verbose("module copy START");
// .text // .text
_moduleCopyPtr = Marshal.AllocHGlobal(Module.ModuleMemorySize); this.moduleCopyPtr = Marshal.AllocHGlobal(Module.ModuleMemorySize);
Buffer.MemoryCopy(Module.BaseAddress.ToPointer(), _moduleCopyPtr.ToPointer(), Module.ModuleMemorySize, Module.ModuleMemorySize); Buffer.MemoryCopy(Module.BaseAddress.ToPointer(), this.moduleCopyPtr.ToPointer(), Module.ModuleMemorySize, Module.ModuleMemorySize);
_moduleCopyOffset = _moduleCopyPtr.ToInt64() - Module.BaseAddress.ToInt64(); this.moduleCopyOffset = this.moduleCopyPtr.ToInt64() - Module.BaseAddress.ToInt64();
Log.Verbose("copy OK!"); Log.Verbose("copy OK!");
} }
@ -142,7 +139,7 @@ namespace Dalamud.Game {
/// 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.
/// </summary> /// </summary>
public void Dispose() { public void Dispose() {
Marshal.FreeHGlobal(_moduleCopyPtr); Marshal.FreeHGlobal(this.moduleCopyPtr);
} }
public IntPtr ResolveRelativeAddress(IntPtr nextInstAddr, int relOffset) { public IntPtr ResolveRelativeAddress(IntPtr nextInstAddr, int relOffset) {
@ -156,10 +153,10 @@ namespace Dalamud.Game {
/// <param name="signature">The signature.</param> /// <param name="signature">The signature.</param>
/// <returns>The real offset of the found signature.</returns> /// <returns>The real offset of the found signature.</returns>
public IntPtr ScanText(string signature) { public IntPtr ScanText(string signature) {
var mBase = IsCopy ? _moduleCopyPtr : TextSectionBase; var mBase = IsCopy ? this.moduleCopyPtr : TextSectionBase;
var scanRet = Scan(mBase, TextSectionSize, signature); var scanRet = Scan(mBase, TextSectionSize, signature);
if (IsCopy) if (IsCopy)
scanRet = new IntPtr(scanRet.ToInt64() - _moduleCopyOffset); scanRet = new IntPtr(scanRet.ToInt64() - this.moduleCopyOffset);
var insnByte = Marshal.ReadByte(scanRet); var insnByte = Marshal.ReadByte(scanRet);
if (insnByte == 0xE8 || insnByte == 0xE9) if (insnByte == 0xE8 || insnByte == 0xE9)
return ReadCallSig(scanRet); return ReadCallSig(scanRet);
@ -167,8 +164,7 @@ namespace Dalamud.Game {
} }
/// <summary> /// <summary>
/// Helper for ScanText to get the correct address for /// Helper for ScanText to get the correct address for IDA sigs that mark the first CALL location.
/// IDA sigs that mark the first CALL location.
/// </summary> /// </summary>
/// <param name="sigLocation">The address the CALL sig resolved to.</param> /// <param name="sigLocation">The address the CALL sig resolved to.</param>
/// <returns>The real offset of the signature.</returns> /// <returns>The real offset of the signature.</returns>
@ -206,7 +202,7 @@ namespace Dalamud.Game {
public IntPtr ScanData(string signature) { public IntPtr ScanData(string signature) {
var scanRet = Scan(DataSectionBase, DataSectionSize, signature); var scanRet = Scan(DataSectionBase, DataSectionSize, signature);
if (IsCopy) if (IsCopy)
scanRet = new IntPtr(scanRet.ToInt64() - _moduleCopyOffset); scanRet = new IntPtr(scanRet.ToInt64() - this.moduleCopyOffset);
return scanRet; return scanRet;
} }
@ -218,7 +214,7 @@ namespace Dalamud.Game {
public IntPtr ScanModule(string signature) { public IntPtr ScanModule(string signature) {
var scanRet = Scan(SearchBase, Module.ModuleMemorySize, signature); var scanRet = Scan(SearchBase, Module.ModuleMemorySize, signature);
if (IsCopy) if (IsCopy)
scanRet = new IntPtr(scanRet.ToInt64() - _moduleCopyOffset); scanRet = new IntPtr(scanRet.ToInt64() - this.moduleCopyOffset);
return scanRet; return scanRet;
} }