Skip to content

Commit

Permalink
bypass improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
szaaamerik committed Jan 6, 2024
1 parent 6a98b31 commit f988eab
Showing 1 changed file with 19 additions and 59 deletions.
78 changes: 19 additions & 59 deletions Forza-Mods-AIO/Resources/Bypass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public abstract class Bypass
private static byte[]? _rtlUserThreadStartOrig;
private static byte[]? _ntCreateThreadExOrig;

private static readonly Detour Check1Detour = new(true), Check2Detour = new(true), Check3Detour = new(true), Check4Detour = new(true);

private static readonly Detour CheckDetour = new(true);
private static UIntPtr _memCopyAddress = UIntPtr.Zero;

public static bool DisableAntiCheat()
Expand All @@ -34,7 +33,7 @@ public static void EnableAntiCheat()
{
if (Mw.Gvp.Name.Contains('5'))
{
ClearDetours();
Destroy();
return;
}

Expand Down Expand Up @@ -73,87 +72,48 @@ private static bool PointChecksToCopy()
return true;
}

if (IsScanRunning || Mw.Gvp.Process?.MainModule == null)
if (IsScanRunning)
{
return false;
}

IsScanRunning = true;

const string sig = "40 8A ? E9 ? ? ? ? CC";
var checkAddr1 = Mw.M.ScanForSig(sig).FirstOrDefault();
var checkAddr = Mw.M.ScanForSig(sig).FirstOrDefault();

if (checkAddr1 < (UIntPtr)Mw.Gvp.Process.MainModule.BaseAddress)
if (checkAddr < (UIntPtr)Mw.Gvp.Process.MainModule!.BaseAddress)
{
return false;
}

checkAddr1 += Mw.Gvp.Plat == "MS" ? (UIntPtr)325 : 333;
var checkAddr2 = checkAddr1 + 40;
var checkAddr3 = checkAddr1 + 79;
var checkAddr4 = checkAddr1 + 119;

var baseAddress = Mw.Gvp.Process.MainModule!.BaseAddress;
var endAddress = baseAddress + Mw.Gvp.Process.MainModule.ModuleMemorySize;
checkAddr += Mw.Gvp.Plat == "MS" ? (UIntPtr)325 : 333;
var procHandle = Mw.Gvp.Process.Handle;
var memSize = (uint)Mw.Gvp.Process.MainModule.ModuleMemorySize;

while (_memCopyAddress == UIntPtr.Zero)
{
_memCopyAddress = VirtualAllocEx(procHandle, 0, memSize, MemCommit | MemReserve, Readwrite);
Task.Delay(5).Wait();
}

_memCopyAddress = VirtualAllocEx(procHandle, UIntPtr.Zero, memSize, MemCommit | MemReserve, ExecuteReadwrite);
WriteProcessMemory(procHandle, _memCopyAddress, Mw.M._memoryCache["default"], memSize, nint.Zero);
var addresses = GetBytes(baseAddress).Concat(GetBytes(endAddress)).Concat(GetBytes(_memCopyAddress)).ToArray();

const string check1Bytes = "53 48 8D 58 F0 48 3B 1D 2A 00 00 00 72 1D 48 3B 1D 29 00 00 00 77 14 48 2B 1D 18 00 00 00 48 03 1D 21 00 00 00 F3 0F 6F 03 EB 05 F3 0F 6F 40 F0 5B";
const string check2Bytes = "53 48 8D 18 48 3B 1D 2E 00 00 00 72 1D 48 3B 1D 2D 00 00 00 77 14 48 2B 1D 1C 00 00 00 48 03 1D 25 00 00 00 F3 0F 6F 03 EB 04 F3 0F 6F 00 5B F3 0F 6F 51 E8";
const string check3Bytes = "53 48 8D 58 10 48 3B 1D 2A 00 00 00 72 1D 48 3B 1D 29 00 00 00 77 14 48 2B 1D 18 00 00 00 48 03 1D 21 00 00 00 F3 0F 6F 03 EB 05 F3 0F 6F 40 10 5B";
const string check4Bytes = "53 48 8D 58 20 48 3B 1D 2A 00 00 00 72 1D 48 3B 1D 29 00 00 00 77 14 48 2B 1D 18 00 00 00 48 03 1D 21 00 00 00 F3 0F 6F 03 EB 05 F3 0F 6F 40 20 5B";

const string check1OriginalBytes = "F3 0F 6F 40 F0";
const string check2OriginalBytes = "F3 0F 6F 00 F3 0F 6F 51 E8";
const string check3OriginalBytes = "F3 0F 6F 40 10";
const string check4OriginalBytes = "F3 0F 6F 40 20";

if (!Check1Detour.Setup(checkAddr1, check1OriginalBytes, check1Bytes, 5, true))
{
ClearDetours();
return false;
}

if (!Check2Detour.Setup(checkAddr2, check2OriginalBytes, check2Bytes, 9, true))
{
ClearDetours();
return false;
}

if (!Check3Detour.Setup(checkAddr3, check3OriginalBytes, check3Bytes, 5, true))
{
ClearDetours();
return false;
}
const string checkBytes = "48 3B 05 23 00 00 00 72 17 48 3B 05 22 00 00 00 77 0E 48 2B 05 11 00 00 00 48 03 05 1A 00 00 00 F3 0F 6F 40 F0";
const string checkOriginalBytes = "F3 0F 6F 40 F0";

if (!Check4Detour.Setup(checkAddr4, check4OriginalBytes, check4Bytes, 5, true))
if (!CheckDetour.Setup(checkAddr, checkOriginalBytes, checkBytes, 5, true))
{
ClearDetours();
Destroy();
return false;
}

var list = new[] { Check1Detour,Check2Detour,Check3Detour,Check4Detour };
Parallel.ForEach(list, detour => detour.UpdateVariable(addresses));
var baseAddress = Mw.Gvp.Process.MainModule.BaseAddress;
var endAddress = baseAddress + Mw.Gvp.Process.MainModule.ModuleMemorySize;
var addresses = GetBytes(baseAddress).Concat(GetBytes(endAddress)).Concat(GetBytes(_memCopyAddress)).ToArray();
CheckDetour.UpdateVariable(addresses);
return Bypassed = true;
}

private static void ClearDetours()
private static void Destroy()
{
var list = new[] { Check1Detour,Check2Detour,Check3Detour,Check4Detour };
Parallel.ForEach(list, detour =>
{
detour.Destroy();
detour.Clear();
});

CheckDetour.Destroy();
CheckDetour.Clear();
const uint memRelease = 0x8000;
VirtualFreeEx(Mw.Gvp.Process.Handle, _memCopyAddress, 0, memRelease);
}
Expand Down

0 comments on commit f988eab

Please sign in to comment.