Esempio n. 1
0
        public RawInputHook(string path)
        {
            foreach (string file in Directory.GetFiles(path, "NativeHook_*.dll"))
            {
                if (!IsFileLocked(file))
                {
                    File.Delete(file);
                }
            }

            NativeHookPath = Path.Combine(path, "NativeHook.dll");

            if (File.Exists(NativeHookPath) && IsFileLocked(NativeHookPath))
            {
                while (File.Exists(NativeHookPath))
                {
                    NativeHookPath = Path.Combine(path, $"NativeHook_{Guid.NewGuid().ToString()}.dll");
                }
            }

            if (!File.Exists(NativeHookPath))
            {
                File.WriteAllBytes(NativeHookPath, GetBytes("NativeHook.dll"));
            }

            NativeHook = new UnmanagedLibrary(NativeHookPath);

            InstallHook   = NativeHook.GetUnmanagedFunction <InstallHook>("InstallHook");
            UninstallHook = NativeHook.GetUnmanagedFunction <UninstallHook>("UninstallHook");
        }
Esempio n. 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            IntPtr hMod = LoadLibrary(tbDllPath.Text);

            if (rbManualMap.Checked)
            {
                if (hMod != IntPtr.Zero)
                {
                    IntPtr InjectDllPtr = GetProcAddress(hMod, "InjectDll");
                    InjectDllFunc = (InjectDll)Marshal.GetDelegateForFunctionPointer(InjectDllPtr, typeof(InjectDll));
                }

                if (InjectDllFunc != null)
                {
                    foreach (Process proc in Process.GetProcessesByName(tbProcessName.Text))
                    {
                        Int32 rval = InjectDllFunc(this.Handle, tbDllPath.Text, proc.Id);
                        Log(string.Format("Injected {0} into process {1}.  rval = {2}\n", tbDllPath.Text, proc.Id, rval));
                    }
                    button2.Enabled = false;
                }
            }
            else if (rbWindowHook.Checked)
            {
                if (hMod != IntPtr.Zero)
                {
                    IntPtr InstallHookPtr = GetProcAddress(hMod, "InstallHook");
                    IntPtr ReleaseHookPtr = GetProcAddress(hMod, "ReleaseHook");

                    InstallHookFunc = (InstallHook)Marshal.GetDelegateForFunctionPointer(InstallHookPtr, typeof(InstallHook));
                    ReleaseHookFunc = (ReleaseHook)Marshal.GetDelegateForFunctionPointer(ReleaseHookPtr, typeof(ReleaseHook));
                }

                if (InstallHookFunc != null)
                {
                    InstallHookFunc(this.Handle, tbProcessName.Text);
                    button2.Enabled = false;
                    Log("Created global window hook.  Launch the target process now...\n");
                }
            }
        }
Esempio n. 3
0
        private void button2_Click(object sender, EventArgs e)
        {
            IntPtr hMod = LoadLibrary(tbDllPath.Text);
            if (rbManualMap.Checked)
            {
                if (hMod != IntPtr.Zero)
                {
                    IntPtr InjectDllPtr = GetProcAddress(hMod, "InjectDll");
                    InjectDllFunc = (InjectDll)Marshal.GetDelegateForFunctionPointer(InjectDllPtr, typeof(InjectDll));
                }

                if (InjectDllFunc != null)
                {
                    foreach( Process proc in Process.GetProcessesByName(tbProcessName.Text) )
                    {
                        Int32 rval = InjectDllFunc(this.Handle, tbDllPath.Text, proc.Id);
                        Log(string.Format("Injected {0} into process {1}.  rval = {2}\n", tbDllPath.Text, proc.Id, rval));
                    }
                    button2.Enabled = false;
                }
            }
            else if (rbWindowHook.Checked)
            {
                if (hMod != IntPtr.Zero)
                {
                    IntPtr InstallHookPtr = GetProcAddress(hMod, "InstallHook");
                    IntPtr ReleaseHookPtr = GetProcAddress(hMod, "ReleaseHook");

                    InstallHookFunc = (InstallHook)Marshal.GetDelegateForFunctionPointer(InstallHookPtr, typeof(InstallHook));
                    ReleaseHookFunc = (ReleaseHook)Marshal.GetDelegateForFunctionPointer(ReleaseHookPtr, typeof(ReleaseHook));
                }

                if (InstallHookFunc != null)
                {
                    InstallHookFunc(this.Handle, tbProcessName.Text);
                    button2.Enabled = false;
                    Log("Created global window hook.  Launch the target process now...\n");
                }
            }
        }