private static void AddMmcCommands(SpecialCommandConfigurationElementCollection cmdList) { Icon[] IconsList = IconHandler.IconsFromFile(Path.Combine(SystemRoot.FullName, "mmc.exe"), IconSize.Small); Random rnd = new Random(); foreach (FileInfo file in SystemRoot.GetFiles("*.msc")) { MMCFile fileMMC = new MMCFile(file); SpecialCommandConfigurationElement elm1 = new SpecialCommandConfigurationElement(file.Name); if (IconsList != null && IconsList.Length > 0) { if (fileMMC.SmallIcon != null) { elm1.Thumbnail = fileMMC.SmallIcon.ToBitmap().ImageToBase64(System.Drawing.Imaging.ImageFormat.Png); } else { elm1.Thumbnail = IconsList[rnd.Next(IconsList.Length - 1)].ToBitmap().ImageToBase64(System.Drawing.Imaging.ImageFormat.Png); } elm1.Name = fileMMC.Parsed ? fileMMC.Name : file.Name.Replace(file.Extension, ""); } elm1.Executable = @"%systemroot%\system32\" + file.Name; cmdList.Add(elm1); } }
private static void AddRegEditCommand(SpecialCommandConfigurationElementCollection cmdList) { string regEditFile = Path.Combine(SystemRoot.FullName, "regedt32.exe"); Icon[] regeditIcons = IconHandler.IconsFromFile(regEditFile, IconSize.Small); SpecialCommandConfigurationElement regEditElm = new SpecialCommandConfigurationElement("Registry Editor"); if (regeditIcons != null && regeditIcons.Length > 0) { regEditElm.Thumbnail = regeditIcons[0].ToBitmap().ImageToBase64(System.Drawing.Imaging.ImageFormat.Png); } regEditElm.Executable = regEditFile; cmdList.Add(regEditElm); }
private static void AddControlPanelApplets(SpecialCommandConfigurationElementCollection cmdList) { foreach (FileInfo file in SystemRoot.GetFiles("*.cpl")) { SpecialCommandConfigurationElement elm1 = new SpecialCommandConfigurationElement(file.Name); Icon[] fileIcons = IconHandler.IconsFromFile(file.FullName, IconSize.Small); if (fileIcons != null && fileIcons.Length > 0) { elm1.Thumbnail = fileIcons[0].ToBitmap().ImageToBase64(System.Drawing.Imaging.ImageFormat.Png); elm1.Name = file.Name; elm1.Executable = @"%systemroot%\system32\" + file.Name; cmdList.Add(elm1); } } }
private void Parse() { try { using (FileStream fs = new FileStream(this.mmcFileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite & FileShare.Delete)) { using (StreamReader stream = new StreamReader(fs)) { this.rawContents = stream.ReadToEnd(); } } if (this.rawContents != null && this.rawContents.Trim() != "" && this.rawContents.StartsWith("<?xml")) { XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml(this.rawContents); XmlNode node = xDoc.SelectSingleNode("/MMC_ConsoleFile/StringTables/StringTable/Strings"); foreach (XmlNode cNode in node.ChildNodes) { string name = cNode.InnerText; if (name != "Favorites" && name != "Console Root") { this.Name = name; this.Parsed = true; break; } } XmlNode visual = xDoc.SelectSingleNode("/MMC_ConsoleFile/VisualAttributes/Icon"); if (visual != null) { string iconFile = visual.Attributes["File"].Value; int index = Convert.ToInt32(visual.Attributes["Index"].Value); Icon[] icons = IconHandler.IconsFromFile(iconFile, IconSize.Small); if (icons != null && icons.Length > 0) { this.SmallIcon = icons.Length > index ? icons[index] : icons[0]; } } } } catch (Exception exc) { Log.Error("Error parsing MMC File", exc); } }
private void LoadIconsFromExe() { try { Icon[] IconsList = IconHandler.IconsFromFile(this.executableTextBox.Text, IconSize.Small); if (IconsList != null && IconsList.Length > 0) { this.iconPicturebox.Image = IconsList[0].ToBitmap(); this.IconImageList.Images.Clear(); this.toolStrip1.Items.Clear(); foreach (Icon TmpIcon in IconsList) { this.IconImageList.Images.Add(TmpIcon); this.toolStrip1.Items.Add(TmpIcon.ToBitmap()); } } } catch (Exception exc) { Log.Error("LoadIconsFromExe", exc); } }
private void Parse() { try { using (FileStream fs = new FileStream(this.mmcFileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite & FileShare.Delete)) { using (StreamReader stream = new StreamReader(fs)) { this.rawContents = stream.ReadToEnd(); } } if (this.rawContents != null && this.rawContents.Trim() != "" && this.rawContents.StartsWith("<?xml")) { XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml(this.rawContents); XmlNode node = xDoc.SelectSingleNode("/MMC_ConsoleFile/StringTables/StringTable/Strings"); foreach (XmlNode cNode in node.ChildNodes) { string name = cNode.InnerText; if (name != "Favorites" && name != "Console Root") { this.Name = name; this.Parsed = true; break; } } //System.Xml.XmlNode binarynode = xDoc.SelectSingleNode("/MMC_ConsoleFile/BinaryStorage"); //foreach (System.Xml.XmlNode child in binarynode.ChildNodes) //{ // string childname = child.Attributes["Name"].Value; // if (childname.ToLower().Contains("small")) // { // string image = child.InnerText; // byte[] buff = System.Convert.FromBase64String(child.InnerText.Trim()); // System.IO.MemoryStream stm = new System.IO.MemoryStream(buff); // if (stm.Position > 0 && stm.CanSeek) stm.Seek(0, System.IO.SeekOrigin.Begin); // System.IO.File.WriteAllBytes(@"C:\Users\Administrator\Desktop\foo.ico", buff); // System.Drawing.Icon ico = new System.Drawing.Icon(stm); // } //} XmlNode visual = xDoc.SelectSingleNode("/MMC_ConsoleFile/VisualAttributes/Icon"); if (visual != null) { string iconFile = visual.Attributes["File"].Value; int index = Convert.ToInt32(visual.Attributes["Index"].Value); Icon[] icons = IconHandler.IconsFromFile(iconFile, IconSize.Small); if (icons != null && icons.Length > 0) { this.SmallIcon = icons.Length > index ? icons[index] : icons[0]; } } } } catch (Exception exc) { Log.Error("Error parsing MMC File", exc); } }