Example #1
0
        private bool HookProcess(ProcStatus procStatus)
        {
            if (procStatus.ProcessId == 0)
            {
                return(false);
            }

            Direct3DVersion direct3DVersion = Direct3DVersion.AutoDetect;
            CaptureConfig   cc = new CaptureConfig()
            {
                Direct3DVersion = direct3DVersion,
                ShowOverlay     = showFPSToolStripMenuItem.Checked
            };

            FileUnblocker.Unblock("EasyHook32Svc.exe");
            FileUnblocker.Unblock("EasyHook64Svc.exe");

            var captureInterface = new CaptureInterface();

            captureInterface.RemoteMessage += CaptureInterface_RemoteMessage;
            procStatus.CaptureProcess       = new CaptureProcess(procStatus.Process, cc, captureInterface);
            PrintStatus("* Hooked " + procStatus.Name);
            hookedProcesses.Add(procStatus.ProcessId, procStatus);
            AddExitHook(procStatus);
            return(true);
        }
 /// <summary>
 /// True if the returned version is D3D11.
 /// </summary>#
 public static bool IsD3D11(Direct3DVersion version)
 {
     return(version == Direct3DVersion.Direct3D11 || version == Direct3DVersion.Direct3D10_1 ||
            version == Direct3DVersion.Direct3D11_2 ||
            version == Direct3DVersion.Direct3D11_3 ||
            version == Direct3DVersion.Direct3D11_4);
 }
Example #3
0
        /// <summary>
        /// Instantiates the DirectX overlay, by first finding the applicable
        /// version of DirectX for the application and then finding the individual
        /// details. For more details, see <see cref="DX9Overlay"/>
        /// Note: This method is blocking and Reloaded mods are required to return in order
        /// to boot up the games, please do not assign this statically - instead assign it in a background thread!
        /// </summary>
        /// <param name="renderDelegate">
        ///     A delegate type to use for DirectX rendering. The delegate type should
        ///     contain an appropriate DirectX <see cref="Direct3D9Device_EndSceneDelegate"/>
        ///     object for drawing overlays.
        /// </param>
        /// <param name="resetDelegate">
        ///     A delegate or function of type of <see cref="Direct3D9Device_ResetDelegate"/> to call when D3D9 fires its Reset function,
        ///     called on resolution change or windowed/fullscreen change - we can reset some things as well.
        /// </param>
        /// <param name="hookDelay">
        ///     Specifies the amount of time to wait until the hook is instantiation begins.
        ///     Some games are known to crash if DirectX is hooked too early.
        /// </param>
        public static async Task <DX9Overlay> CreateDirectXOverlay(Direct3D9Device_EndSceneDelegate renderDelegate, Direct3D9Device_ResetDelegate resetDelegate, int hookDelay)
        {
            // Wait the hook delay.
            await Task.Delay(hookDelay);

            // Create a new self-object.
            DX9Overlay dx9Overlay = new DX9Overlay();

            // Wait for DirectX
            Direct3DVersion direct3DVersion = await DXHookCommon.DetermineDirectXVersion();

            // Return nothing if not D3D9
            if (direct3DVersion != Direct3DVersion.Direct3D9)
            {
                Bindings.PrintError(
                    "libReloaded Hooking: DirectX 9 module not found, the application is either not" +
                    "a DirectX 9 application or uses an unsupported version of DirectX.");

                return(null);
            }

            // Instantiate DX9 hook
            dx9Overlay.DirectX9Hook = new DX9Hook();

            // Obtain Virtual Function Table Entries
            VirtualFunctionTable.TableEntry endSceneTableEntry = dx9Overlay.DirectX9Hook.DirectXFunctions[(int)Direct3DDevice9.EndScene];
            VirtualFunctionTable.TableEntry resetTableEntry    = dx9Overlay.DirectX9Hook.DirectXFunctions[(int)Direct3DDevice9.Reset];

            // Hook relevant DirectX functions.
            dx9Overlay.EndSceneHook = new FunctionHook <Direct3D9Device_EndSceneDelegate>((long)endSceneTableEntry.FunctionPointer, renderDelegate);
            dx9Overlay.ResetHook    = new FunctionHook <Direct3D9Device_ResetDelegate>((long)resetTableEntry.FunctionPointer, resetDelegate);

            // Return our DX9Overlay
            return(dx9Overlay);
        }
        public static void Capture(IntPtr hwnd, Direct3DVersion direct3DVersion = Direct3DVersion.AUTO_DETECT)
        {
            NativeUtils.GetWindowThreadProcessId(hwnd, out var processID);
            var process = Process.GetProcessById(processID);

            var captureConfig = new CaptureConfig
            {
                Direct3DVersion       = direct3DVersion,
                ShowOverlay           = true,
                CaptureMouseEvents    = true,
                CaptureKeyboardEvents = true
            };

            var captureInterface = new CaptureInterface();

            captureInterface.RemoteMessage += e =>
            {
                Debug.WriteLine(e.Message);
            };

            captureInterface.Connected += () =>
            {
                captureInterface.DrawOverlayInGame(new Overlay
                {
                    Elements = new List <IOverlayElement>
                    {
                        new RectangleElement
                        {
                            Colour   = Color.FromArgb(Color.Gray.ToArgb() ^ (0x33 << 24)),
                            Location = new Point(0, 0),
                            Width    = -1,
                            Height   = -1
                        },
                        new RectangleMouseHookElement
                        {
                            Colour = Color.FromArgb(Color.Green.ToArgb() ^ (0x33 << 24)),
                            Width  = 0,
                            Height = 0
                        },
                        new FramesPerSecond(new Font("Arial", 16, FontStyle.Bold))
                        {
                            Location    = new Point(0, 0),
                            Color       = Color.Red,
                            AntiAliased = true,
                            Text        = "{0:N0} FPS"
                        }
                    },
                    Hidden = false
                });
            };

            var captureProcess = new CaptureProcess(process, captureConfig, captureInterface);

            while (!captureProcess.IsDisposed)
            {
                Thread.Sleep(500);
            }

            Debug.WriteLine("Disconnected from DirectX Hook");
        }
Example #5
0
        private void AttachProcess()
        {
            string exeName = "minitri";

            Process[] processes = Process.GetProcessesByName(exeName);
            foreach (Process process in processes)
            {
                if (process.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }

                // Skip if the process is already hooked (and we want to hook multiple applications)
                //if (HookManager.IsHooked(process.Id))
                //{
                //    continue;
                //}

                Direct3DVersion direct3DVersion = Direct3DVersion.AutoDetect;

                ConfigDll c = new ConfigDll()
                {
                    Direct3DVersion = direct3DVersion,
                    ShowOverlay     = true
                };

                var interfaceDll = new InterfaceDll();
                interfaceDll.RemoteMessage += InterfaceDll_RemoteMessage;

                _InjectProcess = new MainClass(process, c, interfaceDll);
                break;
            }
        }
 public ScreenshotInjection(
     RemoteHooking.IContext context,
     String channelName,
     Direct3DVersion version)
 {
     // Get reference to IPC to host application
     // Note: any methods called or events triggered against _interface will execute in the host process.
     _interface = RemoteHooking.IpcConnectClient<ScreenshotInterface.ScreenshotInterface>(channelName);
 }
 public ScreenshotInjection(
     RemoteHooking.IContext context,
     String channelName,
     Direct3DVersion version)
 {
     // Get reference to IPC to host application
     // Note: any methods called or events triggered against _interface will execute in the host process.
     _interface = RemoteHooking.IpcConnectClient <ScreenshotInterface.ScreenshotInterface>(channelName);
 }
Example #8
0
        public void AttachProcess()
        {
            Process[] processes = Process.GetProcessesByName("HuniePop 2 - Double Date");

            foreach (Process process in processes)
            {
                // Simply attach to the first one found.

                // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
                if (process.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }

                // Skip if the process is already hooked (and we want to hook multiple applications)
                if (HookManager.IsHooked(process.Id))
                {
                    continue;
                }

                Direct3DVersion direct3DVersion = Direct3DVersion.AutoDetect;

                CaptureConfig cc = new CaptureConfig()
                {
                    Direct3DVersion = direct3DVersion,
                    ShowOverlay     = true
                };

                processId = process.Id;
                _process  = process;

                var captureInterface = new CaptureInterface();
                captureInterface.RemoteMessage += new MessageReceivedEvent(CaptureInterface_RemoteMessage);
                _captureProcess = new CaptureProcess(process, cc, captureInterface);

                break;
            }
            Thread.Sleep(10);

            if (_captureProcess == null)
            {
                this.parent.launcHuniePop2Listener();
                hooked = false;
            }
            else
            {
                this.message.Foreground = new SolidColorBrush(Colors.DarkGreen);
                this.message.Text       = "Attached to game";
                hooked = true;
            }
        }
Example #9
0
        private void AttachProcess()
        {
            string exeName = "Bejeweled3";

            Process[] processes = Process.GetProcessesByName(exeName);
            foreach (Process process in processes)
            {
                // Simply attach to the first one found.

                // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
                if (process.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }

                // Skip if the process is already hooked (and we want to hook multiple applications)
                if (HookManager.IsHooked(process.Id))
                {
                    continue;
                }

                Direct3DVersion direct3DVersion = Direct3DVersion.AutoDetect;

                CaptureConfig cc = new CaptureConfig()
                {
                    Direct3DVersion = direct3DVersion,
                    ShowOverlay     = cbDrawOverlay.Checked
                };

                capturing.ProcessId = process.Id;
                capturing.Process   = process;

                var captureInterface = new CaptureInterface();
                captureInterface.RemoteMessage += new MessageReceivedEvent(CaptureInterface_RemoteMessage);
                capturing.CaptureProcess        = new CaptureProcess(process, cc, captureInterface);

                break;
            }
            Thread.Sleep(10);

            if (capturing.CaptureProcess == null)
            {
                MessageBox.Show("No executable found matching: '" + exeName + "'");
            }
            else
            {
                btnLoadTest.Enabled = true;
                btnCapture.Enabled  = true;
            }
        }
Example #10
0
        public void StartHook()
        {
            var exeName = "GTA5";

            Process[] processes = Process.GetProcessesByName(exeName);
            foreach (var process in processes)
            {
                if (process == null)
                {
                    continue;
                }
                if (HookManager.IsHooked(process.Id))
                {
                    continue;
                }

                Direct3DVersion direct3dVersion = Direct3DVersion.Direct3D11;

                /*
                 * switch (gameSettings.Graphics.DX_Version.Value)
                 * {
                 *  case 0:
                 *      direct3dVersion = Direct3DVersion.Direct3D10;
                 *      break;
                 *  case 1:
                 *      direct3dVersion = Direct3DVersion.Direct3D10_1;
                 *      break;
                 *  case 2:
                 *      direct3dVersion = Direct3DVersion.Direct3D11;
                 *      break;
                 * }*/

                CaptureConfig cc = new CaptureConfig()
                {
                    Direct3DVersion = direct3dVersion,
                    ShowOverlay     = true,
                };

                _gtaProcessId = process.Id;
                _gtaProcess   = process;

                var captureInterface = new CaptureInterface();
                _captureProcess = new CaptureProcess(process, cc, captureInterface);
                //Thread.Sleep(5000);
                //_captureProcess.CaptureInterface.DisplayInGameText("HELLO FROM PLAYMultiV!", TimeSpan.FromSeconds(60));
                //_captureProcess.CaptureInterface.up
            }
        }
Example #11
0
        /// <summary>
        /// Instantiates the DirectX overlay, by first finding the applicable
        /// version of DirectX for the application and then finding the individual
        /// details. For more details, see <see cref="DX11Overlay"/>
        ///
        /// Note: The delegates you will need to call the original function are members of this class, see <see cref="PresentHook"/> and <see cref="ResizeTargetHook"/>
        /// Note: This method is blocking and Reloaded mods are required to return in order
        /// to boot up the games, please do not assign this statically - instead assign it in a background thread!
        /// </summary>
        /// <param name="DXGIPresentDelegate">
        ///     A delegate type to use for DirectX rendering. The delegate type should
        ///     contain an appropriate DirectX <see cref="DXGISwapChain_PresentDelegate"/>
        ///     object for drawing overlays.
        /// </param>
        /// <param name="DXGIResizeTargetDelegate">
        ///     A delegate or function of type of <see cref="DXGISwapChain_ResizeTargetDelegate"/> to call when DXGI Buffer
        ///     commits a resolution change or windowed/fullscreen change.
        /// </param>
        /// <param name="hookDelay">
        ///     Specifies the amount of time to wait until the hook is instantiation begins.
        ///     Some games are known to crash if DirectX is hooked too early.
        /// </param>
        /// <remarks>The delegates you will need to call the original function are members of this class, see <see cref="PresentHook"/> and <see cref="ResizeTargetHook"/></remarks>
        public static async Task <DX11Overlay> CreateDirectXOverlay(DXGISwapChain_PresentDelegate DXGIPresentDelegate, DXGISwapChain_ResizeTargetDelegate DXGIResizeTargetDelegate, int hookDelay)
        {
            // Wait the hook delay.
            await Task.Delay(hookDelay);

            // Create a new self-object.
            DX11Overlay dx11Overlay = new DX11Overlay();

            // Wait for DirectX
            Direct3DVersion direct3DVersion = await DXHookCommon.GetDirectXVersion();

            // Return nothing if not D3D9
            if (direct3DVersion != Direct3DVersion.Direct3D11 && direct3DVersion != Direct3DVersion.Direct3D11_1 &&
                direct3DVersion != Direct3DVersion.Direct3D11_3 && direct3DVersion != Direct3DVersion.Direct3D11_4)
            {
                Bindings.PrintError(
                    "libReloaded Hooking: DirectX 11 module not found, the application is either not " +
                    "a DirectX 11 application or uses an unsupported version of DirectX.");

                return(null);
            }

            // Instantiate DX9 hook
            dx11Overlay.DirectX11Hook = new DX11Hook();;

            // Obtain Virtual Function Table Entries
            VirtualFunctionTable.TableEntry presentTableEntry = dx11Overlay.DirectX11Hook.DXGISwapChainFunctions[(int)IDXGISwapChain.Present];
            VirtualFunctionTable.TableEntry resizeTableEntry  = dx11Overlay.DirectX11Hook.DXGISwapChainFunctions[(int)IDXGISwapChain.ResizeTarget];

            // Hook relevant DirectX functions.
            if (IntPtr.Size == 4)
            {
                // X86
                dx11Overlay.PresentHook = FunctionHook <DXGISwapChain_PresentDelegate> .Create((long)presentTableEntry.FunctionPointer, DXGIPresentDelegate);

                dx11Overlay.ResizeTargetHook = FunctionHook <DXGISwapChain_ResizeTargetDelegate> .Create((long)resizeTableEntry.FunctionPointer, DXGIResizeTargetDelegate);
            }
            else if (IntPtr.Size == 8)
            {
                // X64
                dx11Overlay.PresentHook64 = X64FunctionHook <DXGISwapChain_PresentDelegate> .Create((long)presentTableEntry.FunctionPointer, DXGIPresentDelegate);

                dx11Overlay.ResizeTargetHook64 = X64FunctionHook <DXGISwapChain_ResizeTargetDelegate> .Create((long)resizeTableEntry.FunctionPointer, DXGIResizeTargetDelegate);
            }

            // Return our DX9Overlay
            return(dx11Overlay);
        }
Example #12
0
        private void AttachProcess()
        {
            string exeName = Path.GetFileNameWithoutExtension("Europa_Client.exe");

            Process[] processes = Process.GetProcessesByName(exeName);
            foreach (Process process in processes)
            {
                // Simply attach to the first one found.

                // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
                if (process.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }

                // Skip if the process is already hooked (and we want to hook multiple applications)
                if (HookManager.IsHooked(process.Id))
                {
                    continue;
                }

                Direct3DVersion direct3DVersion = Direct3DVersion.AutoDetect;

                CaptureConfig cc = new CaptureConfig()
                {
                    Direct3DVersion = direct3DVersion,
                    ShowOverlay     = true,
                    WallhackEnabled = checkBox1.Checked,
                    WeaponEnabled   = checkBox2.Checked
                };

                processId = process.Id;
                _process  = process;

                var captureInterface = new CaptureInterface();
                captureInterface.RemoteMessage += new MessageReceivedEvent(CaptureInterface_RemoteMessage);
                _captureProcess = new CaptureProcess(process, cc, captureInterface);

                break;
            }
            Thread.Sleep(10);

            if (_captureProcess == null)
            {
                MessageBox.Show("No executable found matching: '" + exeName + "'");
            }
        }
Example #13
0
        private void CreateCaptureProcess(Process process)
        {
            _process = process;

            Direct3DVersion direct3DVersion = Direct3DVersion.Direct3D10;

            if (rbDirect3D11.Checked)
            {
                direct3DVersion = Direct3DVersion.Direct3D11;
            }
            else if (rbDirect3D10_1.Checked)
            {
                direct3DVersion = Direct3DVersion.Direct3D10_1;
            }
            else if (rbDirect3D10.Checked)
            {
                direct3DVersion = Direct3DVersion.Direct3D10;
            }
            else if (rbDirect3D9.Checked)
            {
                direct3DVersion = Direct3DVersion.Direct3D9;
            }
            else if (rbAutodetect.Checked)
            {
                direct3DVersion = Direct3DVersion.AutoDetect;
            }

            var cc = new CaptureConfig
            {
                Direct3DVersion = direct3DVersion,
                ShowOverlay     = cbDrawOverlay.Checked,
                TestThisShit    = 300
            };

            var captureInterface = new CaptureInterface();

            if (frm2 != null)
            {
                frm2.Close();
                frm2.Dispose();
            }

            frm2 = new form2JT(captureInterface);

            captureInterface.RemoteMessage += CaptureInterface_RemoteMessage;
            _captureProcess = new CaptureProcess(process, cc, captureInterface);
        }
Example #14
0
        public void AttachProcess(string proc)
        {
            string exeName = Path.GetFileNameWithoutExtension(proc);

            Process[] processes = Process.GetProcessesByName(exeName);
            foreach (Process process in processes)
            {
                // Simply attach to the first one found.

                // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
                if (process.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }

                // Skip if the process is already hooked (and we want to hook multiple applications)
                if (HookManager.IsHooked(process.Id))
                {
                    continue;
                }

                Direct3DVersion direct3DVersion = Direct3DVersion.AutoDetect;
                

                CaptureConfig cc = new CaptureConfig()
                {
                    Direct3DVersion = direct3DVersion,
                    ShowOverlay = true
                };

                ProcessID = process.Id;
                Process = process;

                var captureInterface = new CaptureInterface();
                CaptureProcess = new CaptureProcess(process, cc, captureInterface);
                break;
            }
            Thread.Sleep(10);

            if (CaptureProcess == null)
            {
                MessageBox.Show("No executable found matching: '" + exeName + "'");
                Environment.Exit(0);
            }
        }
Example #15
0
        /// <summary>
        /// Creates a new ImGui hook.
        /// </summary>
        /// <param name="render">Renders your imgui UI</param>
        /// <param name="windowHandle">Handle to the window to render on. Pass IntPtr.Zero to select main window.</param>
        /// <param name="version">DirectX version to handle.</param>
        public static ImguiHook Create(Action render, IntPtr windowHandle, Direct3DVersion version)
        {
            var hook = new ImguiHook(render, windowHandle);

            if (Utility.IsD3D11(version))
            {
                hook.Implementation = new ImguiHookDX11(hook);
            }
            else if (Utility.IsD3D9(version))
            {
                hook.Implementation = new ImguiHookDX9(hook);
            }
            else
            {
                hook.Disable();
                throw new Exception("Unsupported or not found DirectX version.");
            }

            return(hook);
        }
Example #16
0
        private void AttachProcess(string proc)
        {
            string exeName = Path.GetFileNameWithoutExtension(proc);

            Process[] processes = Process.GetProcessesByName(exeName);
            foreach (Process process in processes)
            {
                if (process.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }

                if (HookManager.IsHooked(process.Id))
                {
                    continue;
                }

                Direct3DVersion direct3DVersion = Direct3DVersion.AutoDetect;

                CaptureConfig cc = new CaptureConfig()
                {
                    Direct3DVersion = direct3DVersion,
                    ShowOverlay     = true
                };

                processId = process.Id;
                _process  = process;

                var captureInterface = new CaptureInterface();
                //captureInterface.RemoteMessage += new MessageReceivedEvent(CaptureInterface_RemoteMessage); //DEBUG
                _captureProcess = new CaptureProcess(process, cc, captureInterface);

                break;
            }
            Thread.Sleep(10);

            if (_captureProcess == null)
            {
                MessageBox.Show("No executable found matching: '" + exeName + "'");
            }
        }
Example #17
0
        private bool InitialiseDirectXHook(CaptureConfig config)
        {
            Direct3DVersion version = config.Direct3DVersion;

            List <Direct3DVersion> loadedVersions = new List <Direct3DVersion>();

            bool isX64Process = EasyHook.RemoteHooking.IsX64Process(EasyHook.RemoteHooking.GetCurrentProcessId());

            _interface.Message(MessageType.Information, "Remote process is a {0}-bit process.", isX64Process ? "64" : "32");

            try
            {
                if (version == Direct3DVersion.AutoDetect)
                {
                    // Attempt to determine the correct version based on loaded module.
                    // In most cases this will work fine, however it is perfectly ok for an application to use a D3D10 device along with D3D11 devices
                    // so the version might matched might not be the one you want to use
                    IntPtr d3D9Loaded    = IntPtr.Zero;
                    IntPtr d3D10Loaded   = IntPtr.Zero;
                    IntPtr d3D10_1Loaded = IntPtr.Zero;
                    IntPtr d3D11Loaded   = IntPtr.Zero;
                    IntPtr d3D11_1Loaded = IntPtr.Zero;

                    int delayTime  = 100;
                    int retryCount = 0;
                    while (d3D9Loaded == IntPtr.Zero && d3D10Loaded == IntPtr.Zero && d3D10_1Loaded == IntPtr.Zero && d3D11Loaded == IntPtr.Zero && d3D11_1Loaded == IntPtr.Zero)
                    {
                        retryCount++;
                        d3D9Loaded    = NativeMethods.GetModuleHandle("d3d9.dll");
                        d3D10Loaded   = NativeMethods.GetModuleHandle("d3d10.dll");
                        d3D10_1Loaded = NativeMethods.GetModuleHandle("d3d10_1.dll");
                        d3D11Loaded   = NativeMethods.GetModuleHandle("d3d11.dll");
                        d3D11_1Loaded = NativeMethods.GetModuleHandle("d3d11_1.dll");
                        System.Threading.Thread.Sleep(delayTime);

                        if (retryCount * delayTime > 5000)
                        {
                            _interface.Message(MessageType.Error, "Unsupported Direct3D version, or Direct3D DLL not loaded within 5 seconds.");
                            return(false);
                        }
                    }

                    version = Direct3DVersion.Unknown;
                    if (d3D11_1Loaded != IntPtr.Zero)
                    {
                        _interface.Message(MessageType.Debug, "Autodetect found Direct3D 11.1");
                        version = Direct3DVersion.Direct3D11_1;
                        loadedVersions.Add(version);
                    }
                    if (d3D11Loaded != IntPtr.Zero)
                    {
                        _interface.Message(MessageType.Debug, "Autodetect found Direct3D 11");
                        version = Direct3DVersion.Direct3D11;
                        loadedVersions.Add(version);
                    }
                    if (d3D10_1Loaded != IntPtr.Zero)
                    {
                        _interface.Message(MessageType.Debug, "Autodetect found Direct3D 10.1");
                        version = Direct3DVersion.Direct3D10_1;
                        loadedVersions.Add(version);
                    }
                    if (d3D10Loaded != IntPtr.Zero)
                    {
                        _interface.Message(MessageType.Debug, "Autodetect found Direct3D 10");
                        version = Direct3DVersion.Direct3D10;
                        loadedVersions.Add(version);
                    }
                    if (d3D9Loaded != IntPtr.Zero)
                    {
                        _interface.Message(MessageType.Debug, "Autodetect found Direct3D 9");
                        version = Direct3DVersion.Direct3D9;
                        loadedVersions.Add(version);
                    }
                }

                foreach (var dxVersion in loadedVersions)
                {
                    version = dxVersion;
                    switch (version)
                    {
                    case Direct3DVersion.Direct3D9:
                        _directXHook = new DXHookD3D9(_interface);
                        break;

                    case Direct3DVersion.Direct3D10:
                        _directXHook = new DXHookD3D10(_interface);
                        break;

                    case Direct3DVersion.Direct3D10_1:
                        _directXHook = new DXHookD3D10_1(_interface);
                        break;

                    case Direct3DVersion.Direct3D11:
                        _directXHook = new DXHookD3D11(_interface);
                        break;

                    //case Direct3DVersion.Direct3D11_1:
                    //    _directXHook = new DXHookD3D11_1(_interface);
                    //    return;
                    default:
                        _interface.Message(MessageType.Error, "Unsupported Direct3D version: {0}", version);
                        return(false);
                    }

                    _directXHook.Config = config;
                    _directXHook.Hook();

                    _directXHooks.Add(_directXHook);
                }

                return(true);
            }
            catch (Exception e)
            {
                // Notify the host/server application about this error
                _interface.Message(MessageType.Error, "Error in InitialiseHook: {0}", e.ToString());
                return(false);
            }
        }
        /// <summary>
        /// Called by EasyHook to begin any hooking etc in the target process
        /// </summary>
        /// <param name="InContext"></param>
        /// <param name="channelName"></param>
        /// <param name="strVersion">Direct3DVersion passed as a string so that GAC registration is not required</param>
        /// <param name="showOverlay">Whether or not to show an overlay</param>
        public void Run(
            RemoteHooking.IContext InContext,
            String channelName,
            String strVersion,
            bool showOverlay)
        {
            Direct3DVersion version = (Direct3DVersion)Enum.Parse(typeof(Direct3DVersion), strVersion);

            // NOTE: We are now already running within the target process
            try
            {
                _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "DLL Injection succeeded");

                bool isX64Process = RemoteHooking.IsX64Process(RemoteHooking.GetCurrentProcessId());
                _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "64-bit Process: " + isX64Process.ToString());

                if (version == Direct3DVersion.AutoDetect)
                {
                    // Attempt to determine the correct version based on loaded module.
                    // In most cases this will work fine, however it is perfectly ok for an application to use a D3D10 device along with D3D11 devices
                    // so the version might matched might not be the one you want to use
                    IntPtr d3D9Loaded    = IntPtr.Zero;
                    IntPtr d3D10Loaded   = IntPtr.Zero;
                    IntPtr d3D10_1Loaded = IntPtr.Zero;
                    IntPtr d3D11Loaded   = IntPtr.Zero;
                    IntPtr d3D11_1Loaded = IntPtr.Zero;

                    int delayTime  = 100;
                    int retryCount = 0;
                    while (d3D9Loaded == IntPtr.Zero && d3D10Loaded == IntPtr.Zero && d3D10_1Loaded == IntPtr.Zero && d3D11Loaded == IntPtr.Zero && d3D11_1Loaded == IntPtr.Zero)
                    {
                        retryCount++;
                        d3D9Loaded    = GetModuleHandle("d3d9.dll");
                        d3D10Loaded   = GetModuleHandle("d3d10.dll");
                        d3D10_1Loaded = GetModuleHandle("d3d10_1.dll");
                        d3D11Loaded   = GetModuleHandle("d3d11.dll");
                        d3D11_1Loaded = GetModuleHandle("d3d11_1.dll");
                        Thread.Sleep(delayTime);

                        if (retryCount * delayTime > 5000)
                        {
                            _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "Unsupported Direct3DVersion, or Direct3D DLL not loaded within 5 seconds.");
                            return;
                        }
                    }

                    version = Direct3DVersion.Unknown;
                    if (d3D11_1Loaded != IntPtr.Zero)
                    {
                        _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "Autodetect found Direct3D 11.1");
                        version = Direct3DVersion.Direct3D11_1;
                    }
                    else if (d3D11Loaded != IntPtr.Zero)
                    {
                        _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "Autodetect found Direct3D 11");
                        version = Direct3DVersion.Direct3D11;
                    }
                    else if (d3D10_1Loaded != IntPtr.Zero)
                    {
                        _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "Autodetect found Direct3D 10.1");
                        version = Direct3DVersion.Direct3D10_1;
                    }
                    else if (d3D10Loaded != IntPtr.Zero)
                    {
                        _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "Autodetect found Direct3D 10");
                        version = Direct3DVersion.Direct3D10;
                    }
                    else if (d3D9Loaded != IntPtr.Zero)
                    {
                        _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "Autodetect found Direct3D 9");
                        version = Direct3DVersion.Direct3D9;
                    }
                }

                switch (version)
                {
                case Direct3DVersion.Direct3D9:
                    _directXHook = new DXHookD3D9(_interface);
                    break;

                case Direct3DVersion.Direct3D10:
                    _directXHook = new DXHookD3D10(_interface);
                    break;

                case Direct3DVersion.Direct3D10_1:
                    _directXHook = new DXHookD3D10_1(_interface);
                    break;

                case Direct3DVersion.Direct3D11:
                    _directXHook = new DXHookD3D11(_interface);
                    break;

                default:
                    _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "Unsupported Direct3DVersion");
                    break;
                }
                _directXHook.ShowOverlay = showOverlay;

                _directXHook.Hook();
            }
            catch (Exception e)
            {
                /*
                 *  We should notify our host process about this error...
                 */
                //_interface.ReportError(RemoteHooking.GetCurrentProcessId(), e);
                _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "Exception during device creation and hooking: \r\n" + e.Message);
                while (_interface.Ping(RemoteHooking.GetCurrentProcessId()))
                {
                    Thread.Sleep(100);
                }

                return;
            }

            // Wait for host process termination...
            try
            {
                // When not using GAC there can be issues with remoting assemblies resolving correctly
                // this is a workaround that ensures that the current assembly is correctly associated
                AppDomain currentDomain = AppDomain.CurrentDomain;
                currentDomain.AssemblyResolve += (sender, args) =>
                {
                    return(this.GetType().Assembly.FullName == args.Name ? this.GetType().Assembly : null);
                };

                while (_interface.Ping(RemoteHooking.GetCurrentProcessId()))
                {
                    Thread.Sleep(10);

                    ScreenshotRequest request = _interface.GetScreenshotRequest(RemoteHooking.GetCurrentProcessId());

                    if (request != null)
                    {
                        _directXHook.Request = request;
                    }
                }
            }
            catch
            {
                // .NET Remoting will raise an exception if host is unreachable
            }
            finally
            {
                try
                {
                    _directXHook.Cleanup();
                }
                catch
                {
                }
            }
        }
Example #19
0
        private void AttachProcessEx(int processID)
        {
            string exeName = Path.GetFileNameWithoutExtension(textBox1.Text);

            Process process = Process.GetProcessById(processID);

            if (process != null)
            {
                textBox1.Text = process.ProcessName;
            }
            do
            {
                // Simply attach to the first one found.

                // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
                if (process.MainWindowHandle == IntPtr.Zero)
                {
                    break;
                }

                // Skip if the process is already hooked (and we want to hook multiple applications)
                if (HookManager.IsHooked(process.Id))
                {
                    break;
                }

                Direct3DVersion direct3DVersion = Direct3DVersion.Direct3D10;

                if (rbDirect3D11.Checked)
                {
                    direct3DVersion = Direct3DVersion.Direct3D11;
                }
                else if (rbDirect3D10_1.Checked)
                {
                    direct3DVersion = Direct3DVersion.Direct3D10_1;
                }
                else if (rbDirect3D10.Checked)
                {
                    direct3DVersion = Direct3DVersion.Direct3D10;
                }
                else if (rbDirect3D9.Checked)
                {
                    direct3DVersion = Direct3DVersion.Direct3D9;
                }
                else if (rbAutodetect.Checked)
                {
                    direct3DVersion = Direct3DVersion.AutoDetect;
                }

                CaptureConfig cc = new CaptureConfig()
                {
                    Direct3DVersion = direct3DVersion,
                    ShowOverlay     = cbDrawOverlay.Checked
                };

                processId = process.Id;
                _process  = process;

                var captureInterface = new CaptureInterface();
                captureInterface.RemoteMessage += new MessageReceivedEvent(CaptureInterface_RemoteMessage);
                _captureProcess = new CaptureProcess(process, cc, captureInterface);

                break;
            } while (false);
            Thread.Sleep(10);

            if (_captureProcess == null)
            {
                MessageBox.Show("No executable found matching: '" + exeName + "'");
            }
            else
            {
                btnLoadTest.Enabled = true;
                btnCapture.Enabled  = true;
            }
        }
        /// <summary>
        /// Called by EasyHook to begin any hooking etc in the target process
        /// </summary>
        /// <param name="InContext"></param>
        /// <param name="InArg1"></param>
        public void Run(
            RemoteHooking.IContext InContext,
            String channelName,
            Direct3DVersion version,
            int VertexMode)
        {
            // NOTE: We are now already running within the target process
            try
            {
                _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "DLL Injection succeeded");

                bool isX64Process = RemoteHooking.IsX64Process(RemoteHooking.GetCurrentProcessId());
                _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "64-bit Process: " + isX64Process.ToString());

                switch (version)
                {
                case Direct3DVersion.Direct3D9:
                    _directXHook = new DXHookD3D9(_interface, VertexMode);
                    break;

                case Direct3DVersion.Direct3D10:
                    _directXHook = new DXHookD3D10(_interface);
                    break;

                //case Direct3DVersion.Direct3D10_1:
                //    _directXHook = new DXHookD3D10(_interface);
                //    break;
                case Direct3DVersion.Direct3D11:
                    _directXHook = new DXHookD3D11(_interface);
                    break;

                default:
                    _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "Unsupported Direct3DVersion");
                    break;
                }

                _directXHook.Hook();
            }
            catch (Exception e)
            {
                /*
                 *  We should notify our host process about this error...
                 */
                _interface.ReportError(RemoteHooking.GetCurrentProcessId(), e);

                return;
            }

            // Wait for host process termination...
            try
            {
                while (_interface.Ping(RemoteHooking.GetCurrentProcessId()))
                {
                    Thread.Sleep(10);

                    ScreenshotRequest request = _interface.GetScreenshotRequest(RemoteHooking.GetCurrentProcessId());

                    if (request != null)
                    {
                        _directXHook.Request = request;
                    }
                }
            }
            catch
            {
                // .NET Remoting will raise an exception if host is unreachable
            }
            finally
            {
                try
                {
                    _directXHook.Cleanup();
                }
                catch
                {
                }
            }
        }
Example #21
0
        /// <summary>
        /// Called by EasyHook to begin any hooking etc in the target process
        /// </summary>
        /// <param name="InContext"></param>
        /// <param name="InArg1"></param>
        public void Run(
            RemoteHooking.IContext InContext,
            String channelName,
            Direct3DVersion version,
            int VertexMode)
        {
            // NOTE: We are now already running within the target process
            try
            {
                _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "DLL Injection succeeded");

                bool isX64Process = RemoteHooking.IsX64Process(RemoteHooking.GetCurrentProcessId());
                _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "64-bit Process: " + isX64Process.ToString());

                switch (version)
                {
                    case Direct3DVersion.Direct3D9:
                        _directXHook = new DXHookD3D9(_interface, VertexMode);
                        break;
                    case Direct3DVersion.Direct3D10:
                        _directXHook = new DXHookD3D10(_interface);
                        break;
                    //case Direct3DVersion.Direct3D10_1:
                    //    _directXHook = new DXHookD3D10(_interface);
                    //    break;
                    case Direct3DVersion.Direct3D11:
                        _directXHook = new DXHookD3D11(_interface);
                        break;
                    default:
                        _interface.OnDebugMessage(RemoteHooking.GetCurrentProcessId(), "Unsupported Direct3DVersion");
                        break;

                }

                _directXHook.Hook();
            }
            catch (Exception e)
            {
                /*
                    We should notify our host process about this error...
                 */
                _interface.ReportError(RemoteHooking.GetCurrentProcessId(), e);

                return;
            }

            // Wait for host process termination...
            try
            {
                while (_interface.Ping(RemoteHooking.GetCurrentProcessId()))
                {
                    Thread.Sleep(10);

                    ScreenshotRequest request = _interface.GetScreenshotRequest(RemoteHooking.GetCurrentProcessId());

                    if (request != null)
                    {
                        _directXHook.Request = request;
                    }
                }
            }
            catch
            {
                // .NET Remoting will raise an exception if host is unreachable
            }
            finally
            {
                try
                {
                    _directXHook.Cleanup();
                }
                catch
                {
                }
            }
        }
Example #22
0
        private void AttachProcess()
        {
            string exeName = Path.GetFileNameWithoutExtension(textBox1.Text);

            Process[] processes = Process.GetProcessesByName(exeName);
            foreach (Process process in processes)
            {
                // Simply attach to the first one found.

                // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
                if (process.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }

                // Skip if the process is already hooked (and we want to hook multiple applications)
                if (HookManager.IsHooked(process.Id))
                {
                    continue;
                }

                Direct3DVersion direct3DVersion = Direct3DVersion.Direct3D9;

                if (rbDirect3D9.Checked)
                {
                    direct3DVersion = Direct3DVersion.Direct3D9;
                }

                CaptureConfig captureConfig = new CaptureConfig()
                {
                    Direct3DVersion = direct3DVersion,
                    CaptureWidth    = 720,
                    CaptureHeight   = 540
                };

                processId = process.Id;
                _process  = process;

                var captureInterface = new CaptureInterface();
                captureInterface.RemoteMessage += new MessageReceivedEvent(CaptureInterface_RemoteMessage);
                _captureProcess = new CaptureProcess(process, captureConfig, captureInterface);

                break;
            }
            Thread.Sleep(50);

            if (_captureProcess == null)
            {
                MessageBox.Show("No executable found matching: '" + exeName + "'");
            }
            else
            {
                IntPtr windowHandle = StreamingWindow.FindStreamingPanel(_captureProcess.Process);
                windowControl = new WindowControl(_captureProcess.Process.MainWindowHandle, windowHandle);

                Size size = windowControl.GetWindowSize();
                if (size.Width < (int)numUpDownWidth.Value || size.Height < (int)numUpDownHeight.Value)
                {
                    windowControl.ResizeWindow(new Size((int)numUpDownWidth.Value, (int)numUpDownHeight.Value), false);
                }
            }
        }
 /// <summary>
 /// True if the returned version is D3D11.
 /// </summary>#
 public static bool IsD3D9(Direct3DVersion version)
 {
     return(version == Direct3DVersion.Direct3D9);
 }
Example #24
0
        private void AttachProcess()
        {
            bool newInstanceFound = false;

            Direct3DVersion direct3DVersion = Direct3DVersion.Direct3D10;

            if (rbDirect3D11.Checked)
            {
                direct3DVersion = Direct3DVersion.Direct3D11;
            }
            else if (rbDirect3D10_1.Checked)
            {
                direct3DVersion = Direct3DVersion.Direct3D10_1;
            }
            else if (rbDirect3D10.Checked)
            {
                direct3DVersion = Direct3DVersion.Direct3D10;
            }
            else if (rbDirect3D9.Checked)
            {
                direct3DVersion = Direct3DVersion.Direct3D9;
            }
            else if (rbAutodetect.Checked)
            {
                direct3DVersion = Direct3DVersion.AutoDetect;
            }

            string exeName = Path.GetFileNameWithoutExtension(textBox1.Text);

            while (!newInstanceFound)
            {
                Process[] processes = Process.GetProcessesByName(exeName);
                foreach (Process process in processes)
                {
                    // Simply attach to the first one found.

                    // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
                    if (process.MainWindowHandle == IntPtr.Zero)
                    {
                        continue;
                    }

                    // Skip if the process is already hooked (and we want to hook multiple applications)
                    if (HookManager.IsHooked(process.Id))
                    {
                        continue;
                    }

                    // Keep track of hooked processes in case more than one needs to be hooked
                    HookManager.AddHookedProcess(process.Id);

                    processId = process.Id;
                    _process  = process;

                    // Inject DLL into target process
                    RemoteHooking.Inject(
                        process.Id,
                        InjectionOptions.Default,
                        typeof(ScreenshotInject.ScreenshotInjection).Assembly.Location, //"ScreenshotInject.dll", // 32-bit version (the same because AnyCPU) could use different assembly that links to 32-bit C++ helper dll
                        typeof(ScreenshotInject.ScreenshotInjection).Assembly.Location, //"ScreenshotInject.dll", // 64-bit version (the same because AnyCPU) could use different assembly that links to 64-bit C++ helper dll
                        // the optional parameter list...
                        ChannelName,                                                    // The name of the IPC channel for the injected assembly to connect to
                        direct3DVersion.ToString(),                                     // The direct3DVersion used in the target application
                        cbDrawOverlay.Checked
                        );

                    // Ensure the target process is in the foreground,
                    // this prevents an issue where the target app appears to be in
                    // the foreground but does not receive any user inputs.
                    // Note: the first Alt+Tab out of the target application after injection
                    //       may still be an issue - switching between windowed and
                    //       fullscreen fixes the issue however (see ScreenshotInjection.cs for another option)
                    BringProcessWindowToFront(process);

                    newInstanceFound = true;
                    break;
                }
                Thread.Sleep(10);
            }

            btnLoadTest.Enabled = true;
            btnCapture.Enabled  = true;
        }