/// <summary> /// Opens the main thread of the process already opened by this class object. /// </summary> /// <returns>Returns true on success, false on failure.</returns> public bool OpenThread() { if (m_bProcessOpen) { return(this.OpenThread(SThread.GetMainThreadId(m_ProcessId))); } return(false); }
/// <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); }