private void InitializeAntiCheatHook() { byte[] bytes = HookPtr.GetReturnToPtr(); MemoryModule module = TargetFuncPtr.GetMyModule(); if (module == null) { throw new NullReferenceException("Cannot find a module which belongs to the specified pointer."); } MemoryAddress codeCave = module.FindCodeCaveInModule((uint)bytes.Length); CodeCavePatch = new MemoryPatch(codeCave, bytes); byte[] retToCodeCave = CodeCavePatch.PatchAddress.GetReturnToPtr(); HookPatch = new MemoryPatch(TargetFuncPtr, retToCodeCave); }
public SafeFunction() { Delegate @delegate = ToCallDelegate(); MemoryAddress originalFuncPtr = @delegate.ToFunctionPtr(); MemoryModule module = originalFuncPtr.GetMyModule(); List <byte> bytes = new List <byte>(); bytes.AddRange(originalFuncPtr.GetReturnToPtr()); IMemoryAddress codeCave = module.FindCodeCaveInModule((uint)bytes.Count); codeCave.Write(bytes.ToArray()); Type typeOfDelegate = @delegate.GetType(); SafeFunctionDelegate = Marshal.GetDelegateForFunctionPointer(codeCave.Address, typeOfDelegate); }