OpenProcess() private method

private OpenProcess ( [ dwDesiredAccess, [ bInheritHandle, int dwProcessId ) : SafeProcessHandle
dwDesiredAccess [
bInheritHandle [
dwProcessId int
return SafeProcessHandle
Ejemplo n.º 1
0
        public void PrintDebugString(OUTPUT_DEBUG_STRING_INFO outputDbgStrInfo)
        {
            using (SafeProcessHandle hProcess = Process.OpenProcess(ProcessAccessFlags.VmRead, false, pid))
            {
                if (hProcess.IsInvalid)
                {
                    throw new ArgumentException(String.Format("Unable to open process {0}, error {x:8}", pid, Marshal.GetLastWin32Error()));
                }

                var dbgString = new byte[outputDbgStrInfo.nDebugStringLength];

                uint numberOfBytesRead;
                var  result = Process.ReadProcessMemory(hProcess, outputDbgStrInfo.lpDebugStringData, dbgString, outputDbgStrInfo.nDebugStringLength, out numberOfBytesRead);

                if (result)
                {
                    if (outputDbgStrInfo.fUnicode == 0)
                    {
                        Console.WriteLine("Debug String: {0}", Encoding.ASCII.GetString(dbgString));
                    }
                    else
                    {
                        Console.WriteLine("Debug String: {0}", Encoding.Unicode.GetString(dbgString));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public MiniDumper(string dumpFolder, int pid, string processName,
                          TextWriter logger, DumpType dumpType, bool writeAsync, string filter, int numberOfDumps)
        {
            this.dumpFolder  = dumpFolder;
            this.pid         = pid;
            this.processName = processName;
            this.logger      = logger;
            this.dumpType    = dumpType;
            this.writeAsync  = writeAsync;
            rgxFilter        = new Regex((filter ?? "*").Replace("*", ".*").Replace('?', '.'),
                                         RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase);
            hProcess = ProcessNativeMethod.OpenProcess(ProcessAccessFlags.QueryInformation | ProcessAccessFlags.VmRead, false, pid);
            if (hProcess.IsInvalid)
            {
                throw new ArgumentException(String.Format("Unable to open process {0}, error {1:x8}", pid, Marshal.GetLastWin32Error()));
            }

            this.numberOfDumps = numberOfDumps;
        }