Beispiel #1
0
        public bool OpenThread(int dwThreadId)
        {
            if (dwThreadId == 0)
            {
                return(false);
            }

            if (dwThreadId == m_ThreadId)
            {
                return(true);
            }

            if (m_bThreadOpen)
            {
                this.CloseThread();
            }

            m_bThreadOpen = (m_hThread = SThread.OpenThread(dwThreadId)) != IntPtr.Zero;

            if (m_bThreadOpen)
            {
                m_ThreadId = dwThreadId;
            }

            return(m_bThreadOpen);
        }
Beispiel #2
0
        /// <summary>
        /// Injects a dll into a process by hijacking the process' main thread and redirecting it to LoadLibrary.
        /// </summary>
        /// <param name="hProcess">Handle to the process into which dll will be injected.</param>
        /// <param name="dwProcessId">Id of the process into which dll will be injected.</param>
        /// <param name="szDllPath">Full path to the dll to be injected.</param>
        /// <returns>Returns the base address of the injected dll on success, zero on failure.</returns>
        public static uint InjectDllRedirectThread(IntPtr hProcess, int dwProcessId, string szDllPath)
        {
            IntPtr hThread;
            uint   dwBaseAddress;

            hThread = SThread.OpenThread(SThread.GetMainThreadId(dwProcessId));
            if (hThread == IntPtr.Zero)
            {
                return(RETURN_ERROR);
            }

            dwBaseAddress = InjectDllRedirectThread(hProcess, hThread, szDllPath);

            Imports.CloseHandle(hThread);

            return(dwBaseAddress);
        }