Beispiel #1
0
        public bool IsWow64Process(SafeProcessHandle process)
        {
            IntPtr handle = process == null?GetCurrentProcess() : process.DangerousGetHandle();

            if (IO.Windows.FileSystemWin.StaticIsOSVersionGreaterOrEqual(IO.Windows.FileSystemWin.MinWindowsVersionThatSupportsWow64Processes))
            {
                return(ExternIsWow64Process(handle, out bool result) && result);
            }

            return(false);
        }
Beispiel #2
0
 private static extern CreateDetouredProcessStatus ExternCreateDetouredProcess(
     [MarshalAs(UnmanagedType.LPWStr)] string lpcwCommandLine,
     int dwCreationFlags,
     IntPtr lpEnvironment,
     [MarshalAs(UnmanagedType.LPWStr)] string lpcwWorkingDirectory,
     SafeHandle hStdInput,
     SafeHandle hStdOutput,
     SafeHandle hStdError,
     SafeHandle hJob,
     IntPtr injector,
     bool addProcessToSilo,
     out SafeProcessHandle phProcess,
     out SafeThreadHandle phThread,
     out int pdwProcessId);
Beispiel #3
0
        /// <inheritdoc />
        public CreateDetouredProcessStatus CreateDetouredProcess(
            string lpcwCommandLine,
            int dwCreationFlags,
            IntPtr lpEnvironment,
            string lpcwWorkingDirectory,
            SafeHandle hStdInput,
            SafeHandle hStdOutput,
            SafeHandle hStdError,
            SafeHandle hJob,
            IProcessInjector injector,
            bool addProcessToSilo,
            out SafeProcessHandle phProcess,
            out SafeThreadHandle phThread,
            out int pdwProcessId,
            out int errorCode)
        {
            Assert64Process();

            var status = ExternCreateDetouredProcess(
                lpcwCommandLine,
                dwCreationFlags,
                lpEnvironment,
                lpcwWorkingDirectory,
                hStdInput,
                hStdOutput,
                hStdError,
                hJob,
                injector == null ? IntPtr.Zero : injector.Injector(),
                addProcessToSilo,
                out phProcess,
                out phThread,
                out pdwProcessId);

            errorCode = status == CreateDetouredProcessStatus.Succeeded ? 0 : Marshal.GetLastWin32Error();

            // TODO: Enforce this postcondition.
            // Contract.Assume(status == CreateDetouredProcessStatus.Succeeded || errorCode != 0, "Expected a valid error code on failure.");
            return(status);
        }
Beispiel #4
0
 /// <inheritdoc />
 public bool GetExitCodeProcess(SafeProcessHandle hProcess, out int exitCode)
 => ExternGetExitCodeProcess(hProcess, out exitCode);
Beispiel #5
0
 /// <inheritdoc />
 public bool TerminateProcess(SafeProcessHandle hProcess, int exitCode)
 => ExternTerminateProcess(hProcess, exitCode);
Beispiel #6
0
 private static extern uint ExternGetModuleFileNameEx(
     SafeProcessHandle hProcess,
     IntPtr hModule,
     [Out] StringBuilder lpBaseName,
     uint nSize);
Beispiel #7
0
 private static extern bool ExternIsProcessInJob(SafeProcessHandle hProcess, IntPtr hJob, [MarshalAs(UnmanagedType.Bool)] out bool result);
Beispiel #8
0
 private static extern bool ExternGetExitCodeProcess(SafeProcessHandle processHandle, out int exitCode);
Beispiel #9
0
 private static extern bool ExternTerminateProcess(SafeProcessHandle hProcess, int exitCode);
Beispiel #10
0
 /// <inheritdoc />
 public uint GetModuleFileNameEx(SafeProcessHandle hProcess, IntPtr hModule, StringBuilder lpBaseName, uint nSize)
 => ExternGetModuleFileNameEx(hProcess, hModule, lpBaseName, nSize);
Beispiel #11
0
 /// <inheritdoc />
 public bool IsProcessInJob(SafeProcessHandle hProcess, IntPtr hJob, out bool result)
 => ExternIsProcessInJob(hProcess, hJob, out result);