Exemplo n.º 1
0
        bool LoadManagedDll(string targetExecutable, string dllPath, string className, string method, string argument)
        {
            try
            {
                Win32.STARTUPINFO startup_info = new Win32.STARTUPINFO();
                Win32.PROCESS_INFORMATION proc_info;

                if (!Win32.CreateProcess
                  (
                        targetExecutable,
                        string.Empty,
                        IntPtr.Zero,
                        IntPtr.Zero,
                        false,
                        Win32.CreationFlags.CREATE_SUSPENDED,
                        IntPtr.Zero,
                        Path.GetDirectoryName(targetExecutable),
                        ref startup_info,
                        out proc_info
                  ))
                    return false;

                if (!InjectManagedDll(Process.GetProcessById(proc_info.dwProcessId), dllPath, className, method, argument))
                    return false;

                Win32.ResumeThread(proc_info.hThread);

                return true;
            }
            catch
            {
                return false;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Opens a new process and loads the dll to it.
        /// </summary>
        /// <param name="targetExecutable">The executable to open.</param>
        /// <param name="dllPath">The Dll to inject.</param>
        bool LoadDll(string targetExecutable, string dllPath, bool native = true)
        {
            try
            {
                Win32.STARTUPINFO startup_info = new Win32.STARTUPINFO();
                Win32.PROCESS_INFORMATION proc_info;

                //create suspended process!
                if (!Win32.CreateProcess
                    (
                        targetExecutable,
                        string.Empty,
                        IntPtr.Zero,
                        IntPtr.Zero,
                        false,
                        Win32.CreationFlags.CREATE_SUSPENDED,
                        IntPtr.Zero,
                        Path.GetDirectoryName(targetExecutable),
                        ref startup_info,
                        out proc_info
                    ))
                    return false;

                //inject dll
                if (!InjectDll(Process.GetProcessById(proc_info.dwProcessId), dllPath))
                    return false;

                //resume suspended process-thread
                Win32.ResumeThread(proc_info.hThread);

                return true;
            }
            catch { return false; }
        }