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


C# ProcessHandle.GetMappedFileName方法代码示例

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


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

示例1: DoFilter

        private void DoFilter(string strFilter)
        {
            string lowerFilter = strFilter.ToLower();

            // Stop if cancel
            if (!CancelRequested)
            {
                var handles = Windows.GetHandles();
                Dictionary<int, ProcessHandle> processHandles = new Dictionary<int, ProcessHandle>();

                // Find handles
                for (int i = 0; i < handles.Length; i++)
                {
                    // Check for cancellation here too,
                    // otherwise the user might have to wait for much time                    
                    if (CancelRequested) return;

                    if (i % 20 == 0)
                        OnMatchProgress(i, handles.Length);

                    var handle = handles[i];

                    CompareHandleBestNameWithFilterString(processHandles, handle, lowerFilter);
                    // test Exception 
                    //if (i > 2000) throw new Exception("test");
                }

                foreach (ProcessHandle phandle in processHandles.Values)
                    phandle.Dispose();

                // Find DLLs and mapped files
                var processes = Windows.GetProcesses();

                foreach (var process in processes)
                {
                    try
                    {
                        using (var phandle = new ProcessHandle(process.Key,
                            Program.MinProcessQueryRights | Program.MinProcessReadMemoryRights))
                        {
                            phandle.EnumModules((module) =>
                            {
                                if (module.FileName.ToLower().Contains(lowerFilter))
                                    this.CallDllMatchListView(process.Key, module);
                                return true;
                            });
                        }

                        using (var phandle = new ProcessHandle(process.Key,
                            ProcessAccess.QueryInformation | Program.MinProcessReadMemoryRights))
                        {
                            phandle.EnumMemory((region) =>
                            {
                                if (region.Type != MemoryType.Mapped)
                                    return true;

                                string name = phandle.GetMappedFileName(region.BaseAddress);

                                if (name != null && name.ToLower().Contains(lowerFilter))
                                    this.CallMappedFileMatchListView(process.Key, region.BaseAddress, name);

                                return true;
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.Log(ex);
                    }
                }

                OnMatchListView(null);
            }
        }
开发者ID:andyvand,项目名称:ProcessHacker,代码行数:74,代码来源:HandleFilter.cs

示例2: DoFilter

        private void DoFilter()
        {
            // Stop if cancel
            if (!CancelRequested)
            {
                var handles = Windows.GetHandles();
                Dictionary<int, ProcessHandle> processHandles = new Dictionary<int, ProcessHandle>();

                // Find handles
                for (int i = 0; i < handles.Length; i++)
                {
                    // Check for cancellation here too,
                    // otherwise the user might have to wait for much time                    
                    if (CancelRequested) return;

                    if (i % 20 == 0)
                        OnMatchProgress(i, handles.Length);

                    var handle = handles[i];

                    CompareHandleBestNameWithFilter(processHandles, handle);
                    // test Exception 
                    //if (i > 2000) throw new Exception("test");
                }

                foreach (ProcessHandle phandle in processHandles.Values)
                    phandle.Dispose();

                // Find DLLs and mapped files
                Dictionary<int, SystemProcess> processes = Windows.GetProcesses();

                foreach (KeyValuePair<int, SystemProcess> process in processes)
                {
                    try
                    {
                        // Modules
                        using (ProcessHandle phandle = new ProcessHandle(process.Key, Program.MinProcessQueryRights | Program.MinProcessReadMemoryRights))
                        {
                            phandle.EnumModules(module =>
                            {
                                if (module.FileName.Contains(strFilterLower, StringComparison.OrdinalIgnoreCase))
                                    this.CallDllMatchListView(process.Key, module);
                                return true;
                            });
                        }

                        // Memory
                        using (ProcessHandle phandle = new ProcessHandle(process.Key, ProcessAccess.QueryInformation | Program.MinProcessReadMemoryRights))
                        {
                            phandle.EnumMemory(region =>
                            {
                                if (region.Type != MemoryType.Mapped)
                                    return true;

                                string name = phandle.GetMappedFileName(region.BaseAddress);

                                if (!string.IsNullOrEmpty(name) && name.Contains(strFilterLower, StringComparison.OrdinalIgnoreCase))
                                    this.CallMappedFileMatchListView(process.Key, region.BaseAddress, name);

                                return true;
                            });
                        }

                        // WOW64 Modules
                        if (OSVersion.Architecture == OSArch.Amd64)
                        {
                            using (DebugBuffer buffer = new DebugBuffer())
                            {
                                buffer.Query(
                                    process.Key,
                                    RtlQueryProcessDebugFlags.Modules32 |
                                    RtlQueryProcessDebugFlags.NonInvasive
                                    );

                                buffer.EnumModules(module =>
                                {
                                    if (module.FileName.Contains(strFilterLower, StringComparison.OrdinalIgnoreCase))
                                        this.CallDllMatchListView(process.Key, module);
                                    return true;
                                });
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.Log(ex);
                    }
                }

                OnMatchListView(null);
            }
        }
开发者ID:john-peterson,项目名称:processhacker,代码行数:92,代码来源:HandleFilter.cs


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