Esempio n. 1
0
        private void PopulateProcessList()
        {
            //grab the list of processes
            Process[]       proc_list    = Process.GetProcesses();
            List <CProcess> Raw_procList = new List <CProcess>(proc_list.Length); //can only be as much as the proclist and less

            //grab their icons
            for (int p = 0; p < proc_list.Length; p++)
            {
                Process proc = proc_list[p];
                try
                {
                    String filePID   = String.Format("{0}-{1}", Utilities.ToHexPID(proc.Id), proc.ProcessName);
                    String filePath  = proc.Modules[0].FileName;
                    Icon   proc_icon = IconTools.GetIconForFile(filePath, ShellIconSize.LargeIcon);
                    if (proc_icon == null)
                    {
                        throw new Exception("unable to get icon for proc");
                    }
                    Raw_procList.Add(new CProcess(proc, proc_icon));
                }
                catch
                {
                    //Console.WriteLine("Populate Process List Exception: " + ex.Message + "=>" + proc.ProcessName);
                }
            }

            //sort by PID
            List <CProcess> Sorted_procList = Raw_procList.OrderBy(o => o.iProcess.Id).ToList();

            //finally populate the list
            for (int i = 0; i < Sorted_procList.Count; i++)
            {
                CProcess current = Sorted_procList[i];

                //Format a nice name to display
                String ProcName = String.Format("{0}-{1}", Utilities.ToHexPID(current.iProcess.Id), current.iProcess.ProcessName);

                //add the icon to our imagelist
                iconList.Images.Add(current.IconAsBitmap);

                ListViewItem list_item = new ListViewItem(ProcName, iconList.Images.Count - 1); //(ICON) Name
                ListViewItem.ListViewSubItem sub_item_Path = new ListViewItem.ListViewSubItem(list_item, current.iProcess.Modules[0].FileName);

                list_item.SubItems.Add(sub_item_Path); //add subItem
                list_item.Tag = current;               //add our proc as a Tag

                procListView.Items.Add(list_item);     //add to list
            }

            //select the first item
            if (procListView.Items.Count > 0)
            {
                procListView.Items[0].Selected = true;
                procListView.Select();
            }
        }
Esempio n. 2
0
        public string GetIconForProcess(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return("null");
            }
            var icon = IconTools.GetIconForFile(path, ShellIconSize.LargeIcon);

            if (icon == null)
            {
                return("null");
            }
            var ms = new MemoryStream();

            icon.ToBitmap().Save(ms, ImageFormat.Png);
            var byteImage = ms.ToArray();
            var sigBase64 = Convert.ToBase64String(byteImage); //Get Base64

            return(sigBase64);
        }
        public void SetItems(ProcessModuleCollection processModules)
        {
            if (this.Created == false)
            {
                return;
            }

            List <ListViewItem>  list = new List <ListViewItem>();
            List <ProcessModule> processModuleList = processModules.Cast <ProcessModule>().ToList();

            processModuleList.Sort(delegate(ProcessModule a, ProcessModule b)
            {
                return(a.BaseAddress.ToInt64().CompareTo(b.BaseAddress.ToInt64()));
            });

            try
            {
                foreach (ProcessModule processModule in processModuleList)
                {
                    ListViewItem item = new ListViewItem();
                    item.Text = processModule.ModuleName;

                    string startAddress      = String.Format("0x{0}", processModule.BaseAddress.ToString("X16"));
                    string endAddress        = String.Format("0x{0}", (processModule.BaseAddress.ToInt64() + processModule.ModuleMemorySize).ToString("X16"));
                    string entryPointAddress = String.Format("0x{0}", processModule.EntryPointAddress.ToString("X16"));

                    item.SubItems.Add(startAddress);
                    item.SubItems.Add(endAddress);
                    item.SubItems.Add(entryPointAddress);
                    item.SubItems.Add(processModule.FileVersionInfo.ProductVersion);
                    item.SubItems.Add(processModule.FileVersionInfo.FileVersion);
                    item.SubItems.Add(processModule.FileVersionInfo.FileDescription);
                    item.SubItems.Add(processModule.FileVersionInfo.FileName);

                    try
                    {
                        string fileName  = processModule.FileVersionInfo.FileName;
                        string extension = Path.GetExtension(fileName).ToLower();
                        item.ImageKey = extension;

                        if (SmallImageList.Images.ContainsKey(extension) == false)
                        {
                            Icon icon = IconTools.GetIconForFile(fileName, ShellIconSize.SmallIcon);
                            if (icon != null)
                            {
                                SmallImageList.Images.Add(icon);
                                SmallImageList.Images.SetKeyName(SmallImageList.Images.Count - 1, extension);
                            }
                        }
                    }
                    catch
                    {
                    }
                    item.Tag = processModule;

                    list.Add(item);
                }
            }
            catch
            {
            }

            BeginUpdate();
            Items.Clear();
            Items.AddRange(list.ToArray());
            AutoResizeColumns();
            EndUpdate();
        }