From dfb4573c86a087e3c8e0998bd95c2d50cc4b48e8 Mon Sep 17 00:00:00 2001 From: Fabian Date: Tue, 4 Jul 2023 22:24:46 +0200 Subject: [PATCH] Also disable remapping when anti crash is disabled. --- src/IO/WinMemory.cs | 61 ++++++++++++++++++++++++++++----------------- src/Launcher.cs | 2 +- 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/IO/WinMemory.cs b/src/IO/WinMemory.cs index 3fa4474..c5ecaf7 100644 --- a/src/IO/WinMemory.cs +++ b/src/IO/WinMemory.cs @@ -232,28 +232,7 @@ class WinMemory if (result == NtStatus.Success) { // Apply our patches. - foreach (var p in patchList) - { - var address = p.Value.Address; - - if (address == 0) - continue; - - var patch = p.Value.Data; - - // We are in a different section here. - if (address > Data.Length) - { - if (address < BaseAddress) - address += BaseAddress; - - Write(address, patch, MemProtection.ReadWrite); - continue; - } - - for (var i = 0; i < patch.Length; i++) - Data[address + i] = patch[i]; - } + ApplyPatches(true); nint viewBase2 = 0; @@ -298,8 +277,44 @@ class WinMemory return false; } - public bool RemapAndPatch() + void ApplyPatches(bool remap) { + foreach (var p in patchList) + { + var address = p.Value.Address; + + if (address == 0) + continue; + + var patch = p.Value.Data; + + // We are in a different section here. + if (address > Data.Length) + { + if (address < BaseAddress) + address += BaseAddress; + + Write(address, patch, MemProtection.ReadWrite); + + continue; + } + + if (remap) + { + for (var i = 0; i < patch.Length; i++) + Data[address + i] = patch[i]; + } + } + } + + public bool RemapAndPatch(bool remap) + { + if (!remap) + { + ApplyPatches(remap); + return true; + } + if (VirtualQueryEx(ProcessHandle, BaseAddress, out MemoryBasicInformation mbi, MemoryBasicInformation.Size) != 0) return RemapAndPatch(mbi.BaseAddress, (int)mbi.RegionSize); diff --git a/src/Launcher.cs b/src/Launcher.cs index f4a0709..830e7c2 100644 --- a/src/Launcher.cs +++ b/src/Launcher.cs @@ -270,7 +270,7 @@ static class Launcher NativeWindows.NtResumeProcess(processInfo.ProcessHandle); - if (memory.RemapAndPatch()) + if (memory.RemapAndPatch(antiCrash)) { Console.WriteLine("Done :) ");