// Patch to retrieve accurate speed values public void GamePatch() { int callCodePtr = MemoryHelper.Allocate(0, 100); List <byte> callCode = new List <byte>(); // backup registers callCode.Add(0x50); // push eax callCode.Add(0x51); // push ecx callCode.Add(0x52); // push edx // call the managed function callCode.Add(0x53); // push ebx callCode.Add(0x57); // push edi callCode.Add(0xE8); // call ... callCode.AddRange(BitConverter.GetBytes(calculateSpeedPtr - (callCodePtr + callCode.Count + 4))); // ... CalculateSpeed // restore registers callCode.Add(0x5a); // pop edx callCode.Add(0x59); // pop ecx callCode.Add(0x58); // pop eax // run original code and return callCode.AddRange(new byte[] { 0x0F, 0x28, 0x87, 0x20, 0x01, 0x00, 0x00 }); // movaps xmm0, [edi + 120] callCode.Add(0xC3); // ret MemoryHelper.Write(callCodePtr, callCode.ToArray()); List <byte> jumpCode = new List <byte>(); jumpCode.Add(0xE8); // call ... jumpCode.AddRange(BitConverter.GetBytes(callCodePtr - 0x4308A2 - 5)); // ... callCodePtr jumpCode.Add(0x90); // nop jumpCode.Add(0x90); // nop MemoryHelper.Write(0x4308A2, jumpCode.ToArray()); }
internal MemoryAllocation(IProcess process, int size, uint protection, bool mustBeDisposed = true) : base(process, MemoryHelper.Allocate(process.SafeHandle, size, protection)) { Size = size; MusBeDisposed = mustBeDisposed; IsDisposed = false; }
/// <summary> /// Initializes a new instance of the <see cref="AllocatedMemory" /> class. /// </summary> /// <param name="processPlus">The reference of the <see cref="IProcess" /> object.</param> /// <param name="name"></param> /// <param name="size">The size of the allocated memory.</param> /// <param name="protection">The protection of the allocated memory.</param> /// <param name="mustBeDisposed">The allocated memory will be released when the finalizer collects the object.</param> public AllocatedMemory(IProcess processPlus, string name, int size, MemoryProtectionFlags protection = MemoryProtectionFlags.ExecuteReadWrite, bool mustBeDisposed = true) : base(processPlus, MemoryHelper.Allocate(processPlus.Handle, size, protection)) { // Set local vars Identifier = name; MustBeDisposed = mustBeDisposed; IsDisposed = false; Size = size; }