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.
/// </summary>
/// <param name="module">The ProcessModule to be used for scanning</param>
/// <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>
/// <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>
public SigScanner(ProcessModule module, bool doCopy = false) {
Module = module;
Is32BitProcess = !Environment.Is64BitProcess;
@ -46,7 +43,7 @@ namespace Dalamud.Game {
/// <summary>
/// The base address of the search area. When copied, this will be the address of the copy.
/// </summary>
public IntPtr SearchBase => IsCopy ? _moduleCopyPtr : Module.BaseAddress;
public IntPtr SearchBase => IsCopy ? this.moduleCopyPtr : Module.BaseAddress;
/// <summary>
/// The base address of the .text section search area.
@ -126,15 +123,15 @@ 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!");
}
@ -142,7 +139,7 @@ namespace Dalamud.Game {
/// Free the memory of the copied module search area on object disposal, if applicable.
/// </summary>
public void Dispose() {
Marshal.FreeHGlobal(_moduleCopyPtr);
Marshal.FreeHGlobal(this.moduleCopyPtr);
}
public IntPtr ResolveRelativeAddress(IntPtr nextInstAddr, int relOffset) {
@ -156,10 +153,10 @@ namespace Dalamud.Game {
/// <param name="signature">The signature.</param>
/// <returns>The real offset of the found signature.</returns>
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 {
}
/// <summary>
/// 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.
/// </summary>
/// <param name="sigLocation">The address the CALL sig resolved to.</param>
/// <returns>The real offset of the signature.</returns>
@ -206,7 +202,7 @@ namespace Dalamud.Game {
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;
}
@ -218,7 +214,7 @@ namespace Dalamud.Game {
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;
}