当前位置: 首页>>代码示例>>C#>>正文


C# ProcessHandle.Dispose方法代码示例

本文整理汇总了C#中ProcessHandle.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ProcessHandle.Dispose方法的具体用法?C# ProcessHandle.Dispose怎么用?C# ProcessHandle.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProcessHandle的用法示例。


在下文中一共展示了ProcessHandle.Dispose方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Search


//.........这里部分代码省略.........
                    if (info.Protect == MemoryProtection.AccessDenied)
                        return true;
                    if (info.State != MemoryState.Commit)
                        return true;

                    if ((!opt_priv) && (info.Type == MemoryType.Private))
                        return true;

                    if ((!opt_img) && (info.Type == MemoryType.Image))
                        return true;

                    if ((!opt_map) && (info.Type == MemoryType.Mapped))
                        return true;

                    byte[] data = new byte[info.RegionSize.ToInt32()];
                    int bytesRead = 0;

                    CallSearchProgressChanged(
                        String.Format("Searching 0x{0} ({1} found)...", info.BaseAddress.ToString("x"), count));

                    try
                    {
                        bytesRead = phandle.ReadMemory(info.BaseAddress, data, data.Length);

                        if (bytesRead == 0)
                            return true;
                    }
                    catch
                    {
                        return true;
                    }

                    StringBuilder curstr = new StringBuilder();
                    bool isUnicode = false;
                    byte byte2 = 0;
                    byte byte1 = 0;

                    for (int i = 0; i < bytesRead; i++)
                    {
                        bool isChar = IsChar(data[i]);

                        if (unicode && isChar && isUnicode && byte1 != 0)
                        {
                            isUnicode = false;

                            if (curstr.Length > 0)
                                curstr.Remove(curstr.Length - 1, 1);

                            curstr.Append((char)data[i]);
                        }
                        else if (isChar)
                        {
                            curstr.Append((char)data[i]);
                        }
                        else if (unicode && data[i] == 0 && IsChar(byte1) && !IsChar(byte2))
                        {

                            isUnicode = true;
                        }
                        else if (unicode &&
                            data[i] == 0 && IsChar(byte1) && IsChar(byte2) && curstr.Length < minsize)
                        {

                            isUnicode = true;
                            curstr = new StringBuilder();
                            curstr.Append((char)byte1);
                        }
                        else
                        {
                            if (curstr.Length >= minsize)
                            {
                                int length = curstr.Length;

                                if (isUnicode)
                                    length *= 2;

                                Results.Add(new string[] { Utils.FormatAddress(info.BaseAddress),
                                    String.Format("0x{0:x}", i - length), length.ToString(),
                                    curstr.ToString() });

                                count++;
                            }

                            isUnicode = false;
                            curstr = new StringBuilder();
                        }

                        byte2 = byte1;
                        byte1 = data[i];
                    }

                    data = null;

                    return true;
                });

            phandle.Dispose();

            CallSearchFinished();
        }
开发者ID:RoDaniel,项目名称:featurehouse,代码行数:101,代码来源:StringSearcher.cs

示例2: GetCsrProcesses

        private List<ProcessHandle> GetCsrProcesses()
        {
            List<ProcessHandle> csrProcesses = new List<ProcessHandle>();

            try
            {
                foreach (var process in Windows.GetProcesses())
                {
                    if (process.Key <= 4)
                        continue;

                    try
                    {
                        var phandle = new ProcessHandle(process.Key,
                            Program.MinProcessQueryRights | ProcessAccess.DupHandle
                            );

                        if (phandle.GetKnownProcessType() == KnownProcess.WindowsSubsystem)
                            csrProcesses.Add(phandle);
                        else
                            phandle.Dispose();
                    }
                    catch
                    { }
                }
            }
            catch (Exception ex)
            {
                PhUtils.ShowException("Unable to get the list of CSR processes", ex);
                return new List<ProcessHandle>();
            }

            return csrProcesses;
        }
开发者ID:andyvand,项目名称:ProcessHacker,代码行数:34,代码来源:HiddenProcessesWindow.cs

示例3: Search

        public override void Search()
        {
            Results.Clear();

            ProcessHandle phandle;
            int count = 0;

            bool opt_priv = (bool)Params["private"];
            bool opt_img = (bool)Params["image"];
            bool opt_map = (bool)Params["mapped"];

            string structName = (string)Params["struct"];
            int align = (int)BaseConverter.ToNumberParse((string)Params["struct_align"]);

            if (!Program.Structs.ContainsKey(structName))
            {
                CallSearchError("Struct '" + structName + "' is not defined.");
                return;
            }

            StructDef structDef = Program.Structs[structName];
            string structLen = structDef.Size.ToString();

            structDef.IOProvider = new ProcessMemoryIO(PID);

            try
            {
                phandle = new ProcessHandle(PID, ProcessHacker.Native.Security.ProcessAccess.QueryInformation);
            }
            catch
            {
                CallSearchError("Could not open process: " + Win32.GetLastErrorMessage());
                return;
            }

            phandle.EnumMemory((info) =>
                {

                    if (info.Protect == MemoryProtection.AccessDenied)
                        return true;
                    if (info.State != MemoryState.Commit)
                        return true;

                    if ((!opt_priv) && (info.Type == MemoryType.Private))
                        return true;

                    if ((!opt_img) && (info.Type == MemoryType.Image))
                        return true;

                    if ((!opt_map) && (info.Type == MemoryType.Mapped))
                        return true;

                    CallSearchProgressChanged(
                        String.Format("Searching 0x{0} ({1} found)...", info.BaseAddress.ToString("x"), count));

                    for (int i = 0; i < info.RegionSize.ToInt32(); i += align)
                    {
                        try
                        {
                            structDef.Offset = info.BaseAddress.Increment(i);
                            structDef.Read();

                            Results.Add(new string[] { Utils.FormatAddress(info.BaseAddress),
                                String.Format("0x{0:x}", i), structLen, "" });
                            count++;
                        }
                        catch
                        { }
                    }

                    return true;
                });

            phandle.Dispose();

            CallSearchFinished();
        }
开发者ID:RoDaniel,项目名称:featurehouse,代码行数:77,代码来源:StructSearcher.cs

示例4: Search


//.........这里部分代码省略.........
            byte[] text = (byte[])Params["text"];
            ProcessHandle phandle;
            int count = 0;

            bool opt_priv = (bool)Params["private"];
            bool opt_img = (bool)Params["image"];
            bool opt_map = (bool)Params["mapped"];

            bool nooverlap = (bool)Params["nooverlap"];

            if (text.Length == 0)
            {
                CallSearchFinished();
                return;
            }

            try
            {
                phandle = new ProcessHandle(PID,
                    ProcessAccess.QueryInformation |
                    Program.MinProcessReadMemoryRights);
            }
            catch
            {
                CallSearchError("Could not open process: " + Win32.GetLastErrorMessage());
                return;
            }

            phandle.EnumMemory((info) =>
                {

                    if (info.Protect == MemoryProtection.AccessDenied)
                        return true;
                    if (info.State != MemoryState.Commit)
                        return true;

                    if ((!opt_priv) && (info.Type == MemoryType.Private))
                        return true;

                    if ((!opt_img) && (info.Type == MemoryType.Image))
                        return true;

                    if ((!opt_map) && (info.Type == MemoryType.Mapped))
                        return true;

                    byte[] data = new byte[info.RegionSize.ToInt32()];
                    int bytesRead = 0;

                    CallSearchProgressChanged(
                        String.Format("Searching 0x{0} ({1} found)...", info.BaseAddress.ToString("x"), count));

                    try
                    {
                        bytesRead = phandle.ReadMemory(info.BaseAddress, data, data.Length);

                        if (bytesRead == 0)
                            return true;
                    }
                    catch
                    {
                        return true;
                    }

                    for (int i = 0; i < bytesRead; i++)
                    {
                        bool good = true;

                        for (int j = 0; j < text.Length; j++)
                        {
                            if (i + j > bytesRead - 1)
                                continue;

                            if (data[i + j] != text[j])
                            {
                                good = false;
                                break;
                            }
                        }

                        if (good)
                        {
                            Results.Add(new string[] { Utils.FormatAddress(info.BaseAddress),
                                String.Format("0x{0:x}", i), text.Length.ToString(), "" });

                            count++;

                            if (nooverlap)
                                i += text.Length - 1;
                        }
                    }

                    data = null;

                    return true;
                });

            phandle.Dispose();

            CallSearchFinished();
        }
开发者ID:RoDaniel,项目名称:featurehouse,代码行数:101,代码来源:LiteralSearcher.cs

示例5: Search


//.........这里部分代码省略.........

            bool opt_priv = (bool)Params["private"];
            bool opt_img = (bool)Params["image"];
            bool opt_map = (bool)Params["mapped"];

            if (regex.Length == 0)
            {
                CallSearchFinished();
                return;
            }

            try
            {
                if ((bool)Params["ignorecase"])
                    options |= RegexOptions.IgnoreCase;

                rx = new Regex(regex, options);
            }
            catch (Exception ex)
            {
                CallSearchError("Could not initialize regex: " + ex.Message);
                return;
            }

            try
            {
                phandle = new ProcessHandle(PID,
                    ProcessAccess.QueryInformation |
                    Program.MinProcessReadMemoryRights);
            }
            catch
            {
                CallSearchError("Could not open process: " + Win32.GetLastErrorMessage());
                return;
            }

            phandle.EnumMemory((info) =>
                {
                    // skip unreadable areas
                    if (info.Protect == MemoryProtection.AccessDenied)
                        return true;
                    if (info.State != MemoryState.Commit)
                        return true;

                    if ((!opt_priv) && (info.Type == MemoryType.Private))
                        return true;

                    if ((!opt_img) && (info.Type == MemoryType.Image))
                        return true;

                    if ((!opt_map) && (info.Type == MemoryType.Mapped))
                        return true;

                    byte[] data = new byte[info.RegionSize.ToInt32()];
                    int bytesRead = 0;

                    CallSearchProgressChanged(
                        String.Format("Searching 0x{0} ({1} found)...", info.BaseAddress.ToString("x"), count));

                    try
                    {
                        bytesRead = phandle.ReadMemory(info.BaseAddress, data, data.Length);

                        if (bytesRead == 0)
                            return true;
                    }
                    catch
                    {
                        return true;
                    }

                    StringBuilder sdata = new StringBuilder();
                    string sdata2 = "";

                    for (int i = 0; i < data.Length; i++)
                        sdata.Append((char)data[i]);

                    sdata2 = sdata.ToString();
                    sdata = null;

                    MatchCollection mc = rx.Matches(sdata2);

                    foreach (Match m in mc)
                    {
                        Results.Add(new string[] { Utils.FormatAddress(info.BaseAddress),
                                String.Format("0x{0:x}", m.Index), m.Length.ToString(),
                                Utils.MakePrintable(m.Value) });

                        count++;
                    }

                    data = null;

                    return true;
                });

            phandle.Dispose();

            CallSearchFinished();
        }
开发者ID:andyvand,项目名称:ProcessHacker,代码行数:101,代码来源:RegexSearcher.cs

示例6: GetCsrProcesses

        private ProcessHandle[] GetCsrProcesses()
        {
            List<ProcessHandle> csrProcesses = new List<ProcessHandle>();

            try
            {
                foreach (KeyValuePair<int, SystemProcess> process in Windows.GetProcesses())
                {
                    if (process.Key <= 4)
                        continue;

                    try
                    {
                        ProcessHandle phandle = new ProcessHandle(process.Key,
                            Program.MinProcessQueryRights | ProcessAccess.DupHandle
                            );

                        if (phandle.KnownProcessType == KnownProcess.WindowsSubsystem)
                            csrProcesses.Add(phandle);
                        else
                            phandle.Dispose();
                    }
                    catch
                    { }
                }
            }
            catch (Exception ex)
            {
                PhUtils.ShowException("Unable to get the list of CSR processes", ex);
            }

            return csrProcesses.ToArray();
        }
开发者ID:john-peterson,项目名称:processhacker,代码行数:33,代码来源:HiddenProcessesWindow.cs


注:本文中的ProcessHandle.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。