예제 #1
0
        /// <summary>
        /// Initialize hooks for our file I/O functions.
        /// </summary>
        /// <param name="context"></param>
        public void Run(IContext context)
        {
            _readFileHook  = HookFactory.CreateHook <ReadFileDelegate>(LocalHook.GetProcAddress(Interop.Libraries.Kernel32, "ReadFile"), Detour_ReadFile, this);
            _writeFileHook = HookFactory.CreateHook <WriteFileDelegate>(LocalHook.GetProcAddress(Interop.Libraries.Kernel32, "WriteFile"), Detour_WriteFile, this);

            DisplayFileAccess().GetAwaiter().GetResult();
        }
예제 #2
0
        public void ShouldEnableHookWithProperty()
        {
            using (var hook = HookFactory.CreateHook <GetVersionDelegate>(
                       LocalHook.GetProcAddress("kernel32.dll", "GetVersion"),
                       GetVersionDetour, this))
            {
                // Enable the hook for all threads
                hook.Enabled = true;
                Assert.Equal <uint>(0, GetVersion());
                Assert.Equal <uint>(0, hook.Target());

                // Disable the hook for all threads
                hook.Enabled = false;
                Assert.NotEqual <uint>(0, GetVersion());
                Assert.NotEqual <uint>(0, hook.Target());
                Assert.NotEqual <uint>(0, hook.Original());

                // Enable the hook for the current thread
                hook.ThreadACL.SetInclusiveACL(new int[1]);
                Assert.Equal <uint>(0, GetVersion());
                Assert.Equal <uint>(0, hook.Target());
                Assert.NotEqual <uint>(0, hook.Original());

                // Disable the hook for the current thread
                hook.ThreadACL.SetExclusiveACL(new int[1]);
                Assert.NotEqual <uint>(0, GetVersion());
                Assert.NotEqual <uint>(0, hook.Target());
            }
        }
예제 #3
0
        public void DetourApiAndInternalFunctionUsingInterfaceBypassAddress()
        {
            using (var hookInternal = HookFactory.CreateHook <InternalFindAtom>(
                       LocalHook.GetProcAddress("kernel32.dll", "InternalFindAtom"),
                       InternalFindAtom_Hook,
                       this))
            {
                hookInternal.ThreadACL.SetInclusiveACL(new int[] { 0 });

                InternalFindAtomFunction = hookInternal.Original;

                _internalFindAtomCalled = false;

                string atomName = "TestLocalAtomName";
                ushort atomId   = AddAtomW(atomName);

                ushort foundAtomId = FindAtomW(atomName);

                Assert.NotEqual(0, atomId);
                Assert.True(_internalFindAtomCalled);
                Assert.Equal(atomId, foundAtomId);

                Assert.Equal <ushort>(0, DeleteAtom(atomId));
            }
        }
예제 #4
0
        public override unsafe void CreateHooks()
        {
            _d3DDeviceFunctions = new List <IntPtr>();

            using (var direct3D = new SharpDX.Direct3D9.Direct3D())
            {
                using (var device = new Device(direct3D, 0, DeviceType.NullReference, IntPtr.Zero,
                                               CreateFlags.HardwareVertexProcessing,
                                               new PresentParameters {
                    BackBufferWidth = 1, BackBufferHeight = 1, DeviceWindowHandle = IntPtr.Zero
                }))
                {
                    _d3DDeviceFunctions.AddRange(ReadVTableAddresses(device.NativePointer, D3DDevice9FunctionCount));
                }
            }

            // Create the hooks for our target Direct3D Device functions.
            _d3DEndSceneHook = HookFactory.CreateHook <IDirect3DDevice9_EndSceneDelegate>(
                _d3DDeviceFunctions[(int)FunctionOrdinals.EndScene],
                Detour_EndScene,
                this);

            _d3DPresentHook = HookFactory.CreateHook <IDirect3DDevice9_PresentDelegate>(
                _d3DDeviceFunctions[(int)FunctionOrdinals.Present],
                Detour_Present,
                this);

            _d3DResetHook = HookFactory.CreateHook <IDirect3DDevice9_ResetDelegate>(
                _d3DDeviceFunctions[(int)FunctionOrdinals.Reset],
                Detour_Reset,
                this);

            // Add the Frames Per Second overlay.
            Overlays = new List <IOverlay>
            {
                new Direct3D.Core.Drawing.Overlay
                {
                    Elements =
                    {
                        new FramesPerSecondOverlay(new System.Drawing.Font("Arial",  16, FontStyle.Bold))
                        {
                            Location    = new System.Drawing.Point(25,              25),
                            Color       = Color.Red,
                            AntiAliased = true,
                            Text        = "{0:N0} FPS"
                        }
                    },
                    Hidden = false
                }
            };

            // Enable the hooks for all threads except the current thread.
            _d3DEndSceneHook.ThreadACL.SetExclusiveACL(new int[1]);
            _d3DPresentHook.ThreadACL.SetExclusiveACL(new int[1]);
            _d3DResetHook.ThreadACL.SetExclusiveACL(new int[1]);
        }
예제 #5
0
        public override void CreateHooks()
        {
            var renderForm = new SharpDX.Windows.RenderForm();

            Device.CreateWithSwapChain(
                DriverType.Hardware,
                DeviceCreationFlags.BgraSupport,
                CreateSwapChainDescription(renderForm.Handle),
                out _device,
                out _swapChain);

            if (_swapChain != null)
            {
                _d3DDeviceFunctions.AddRange(ReadVTableAddresses(_swapChain.NativePointer, DXGI_SWAPCHAIN_METHOD_COUNT));
            }

            _d3DPresentHook = HookFactory.CreateHook <DXGISwapChain_PresentDelegate>(
                _d3DDeviceFunctions[(int)FunctionOrdinals.Present],
                Detour_Present,
                this);

            Overlays = new List <IOverlay>
            {
                // Add the Frames Per Second overlay
                new Direct3D.Core.Drawing.Overlay
                {
                    Elements =
                    {
                        new FramesPerSecondOverlay(new Font("Arial",  16, FontStyle.Bold))
                        {
                            Location    = new Point(25,              25),
                            Color       = Color.Red,
                            AntiAliased = true,
                            Text        = "{0:N0} FPS"
                        }
                    },
                    Hidden = false
                }
            };

            _d3DPresentHook.Enabled = true;
        }
예제 #6
0
        /// <summary>
        /// First method called during plugin load.
        /// Can be used to create hooks and initialize
        /// variables.
        /// </summary>
        /// <param name="context">Contains any standard information required for each plugin.</param>
        public unsafe void Run(IContext context)
        {
            // Create network function hooks
            _wsaRecvHook  = HookFactory.CreateHook <WSARecvDelegate>(LocalHook.GetProcAddress(Interop.Libraries.Ws2_32, "WSARecv"), Detour_WSARecv, this);
            _wsaSendHook  = HookFactory.CreateHook <WSASendDelegate>(LocalHook.GetProcAddress(Interop.Libraries.Ws2_32, "WSASend"), Detour_WsaSend, this);
            _recvHook     = HookFactory.CreateHook <RecvDelegate>(LocalHook.GetProcAddress(Interop.Libraries.Ws2_32, "recv"), Detour_recv, this);
            _sendHook     = HookFactory.CreateHook <SendDelegaqte>(LocalHook.GetProcAddress(Interop.Libraries.Ws2_32, "send"), Detour_send, this);
            _recvfromHook = HookFactory.CreateHook <RecvfromDelegate>(LocalHook.GetProcAddress(Interop.Libraries.Ws2_32, "recvfrom"), Detour_recvfrom, this);
            _sendtoHook   = HookFactory.CreateHook <SendtoDelegate>(LocalHook.GetProcAddress(Interop.Libraries.Ws2_32, "sendto"), Detour_sendto, this);

            // Enable hooks for all threads
            _wsaSendHook.Enabled  = true;
            _wsaRecvHook.Enabled  = true;
            _recvHook.Enabled     = true;
            _sendHook.Enabled     = true;
            _recvfromHook.Enabled = true;
            _sendtoHook.Enabled   = true;

            ProcessPackets().GetAwaiter().GetResult();
        }