mirror of
https://github.com/mirror/processhacker
synced 2026-06-08 16:03:24 +00:00
b02427417c
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@5614 21ef857c-d57f-4fe0-8362-d861dc6d29cd
84 lines
2.5 KiB
C#
84 lines
2.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Forms;
|
|
using ProcessHacker.Common;
|
|
using ProcessHacker.Common.Ui;
|
|
using ProcessHacker.Native;
|
|
using ProcessHacker.Native.Objects;
|
|
using ProcessHacker.Native.Security;
|
|
using ProcessHacker.UI;
|
|
|
|
namespace ProcessHacker
|
|
{
|
|
public partial class HandleStatisticsWindow : Form
|
|
{
|
|
private int _pid;
|
|
|
|
public HandleStatisticsWindow(int pid)
|
|
{
|
|
InitializeComponent();
|
|
this.AddEscapeToClose();
|
|
this.SetTopMost();
|
|
|
|
_pid = pid;
|
|
|
|
listTypes.SetDoubleBuffered(true);
|
|
listTypes.SetTheme("explorer");
|
|
listTypes.AddShortcuts();
|
|
listTypes.ContextMenu = listTypes.GetCopyMenu();
|
|
listTypes.ListViewItemSorter = new SortedListViewComparer(listTypes);
|
|
|
|
var typeStats = new Dictionary<string, int>();
|
|
|
|
using (var phandle = new ProcessHandle(pid, ProcessAccess.DupHandle))
|
|
{
|
|
var handles = Windows.GetHandles();
|
|
|
|
foreach (var handle in handles)
|
|
{
|
|
if (pid != -1 && handle.ProcessId != pid)
|
|
continue;
|
|
|
|
ObjectInformation info;
|
|
|
|
try
|
|
{
|
|
if (pid != -1)
|
|
{
|
|
info = handle.GetHandleInfo(phandle, false);
|
|
}
|
|
else
|
|
{
|
|
info = handle.GetHandleInfo(false);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logging.Log(ex);
|
|
info = new ObjectInformation() { TypeName = "(unknown)" };
|
|
}
|
|
|
|
if (typeStats.ContainsKey(info.TypeName))
|
|
typeStats[info.TypeName]++;
|
|
else
|
|
typeStats.Add(info.TypeName, 1);
|
|
}
|
|
}
|
|
|
|
foreach (var pair in typeStats)
|
|
{
|
|
listTypes.Items.Add(new ListViewItem(new string[]
|
|
{
|
|
pair.Key,
|
|
pair.Value.ToString("N0")
|
|
}));
|
|
}
|
|
}
|
|
|
|
private void buttonClose_Click(object sender, System.EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
}
|
|
}
|