private XmlDocument Get_Xml_Data() { //Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "INFO: {0}:getXmlData", this.ToString())); if (this._xmlData == null) { string filename = AsmDudeToolsStatic.Get_Install_Path() + "Resources" + Path.DirectorySeparatorChar + "AsmDudeData.xml"; Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "INFO: AsmDudeTools:getXmlData: going to load file \"{0}\"", filename)); try { this._xmlData = new XmlDocument(); this._xmlData.Load(filename); } catch (FileNotFoundException) { AsmDudeToolsStatic.Output_ERROR("AsmTokenTagger: could not find file \"" + filename + "\"."); } catch (XmlException) { AsmDudeToolsStatic.Output_ERROR("AsmTokenTagger: xml error while reading file \"" + filename + "\"."); } catch (Exception e) { AsmDudeToolsStatic.Output_ERROR("AsmTokenTagger: error while reading file \"" + filename + "\"." + e); } } return(this._xmlData); }
private void Load_Icons() { Uri uri = null; string installPath = AsmDudeToolsStatic.Get_Install_Path(); try { uri = new Uri(installPath + "Resources/images/icon-R-blue.png"); this.icons_[AsmTokenType.Register] = AsmDudeToolsStatic.Bitmap_From_Uri(uri); } catch (FileNotFoundException) { //MessageBox.Show("ERROR: AsmCompletionSource: could not find file \"" + uri.AbsolutePath + "\"."); } try { uri = new Uri(installPath + "Resources/images/icon-M.png"); this.icons_[AsmTokenType.Mnemonic] = AsmDudeToolsStatic.Bitmap_From_Uri(uri); this.icons_[AsmTokenType.Jump] = this.icons_[AsmTokenType.Mnemonic]; } catch (FileNotFoundException) { //MessageBox.Show("ERROR: AsmCompletionSource: could not find file \"" + uri.AbsolutePath + "\"."); } try { uri = new Uri(installPath + "Resources/images/icon-question.png"); this.icons_[AsmTokenType.Misc] = AsmDudeToolsStatic.Bitmap_From_Uri(uri); this.icons_[AsmTokenType.Directive] = this.icons_[AsmTokenType.Misc]; } catch (FileNotFoundException) { //MessageBox.Show("ERROR: AsmCompletionSource: could not find file \"" + uri.AbsolutePath + "\"."); } try { uri = new Uri(installPath + "Resources/images/icon-L.png"); this.icons_[AsmTokenType.Label] = AsmDudeToolsStatic.Bitmap_From_Uri(uri); } catch (FileNotFoundException) { //MessageBox.Show("ERROR: AsmCompletionSource: could not find file \"" + uri.AbsolutePath + "\"."); } }
private XmlDocument Get_Xml_Data() { //Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "INFO: {0}:getXmlData", this.ToString())); if (this.xmlData_ == null) { string filename = AsmDudeToolsStatic.Get_Install_Path() + "Resources" + Path.DirectorySeparatorChar + "AsmDudeData.xml"; Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "INFO: AsmDudeTools:getXmlData: going to load file \"{0}\"", filename)); try { this.xmlData_ = new XmlDocument() { XmlResolver = null }; System.IO.StringReader sreader = new System.IO.StringReader(File.ReadAllText(filename)); using (XmlReader reader = XmlReader.Create(sreader, new XmlReaderSettings() { XmlResolver = null })) { this.xmlData_.Load(reader); } } catch (FileNotFoundException) { AsmDudeToolsStatic.Output_ERROR("AsmTokenTagger: could not find file \"" + filename + "\"."); } catch (XmlException) { AsmDudeToolsStatic.Output_ERROR("AsmTokenTagger: xml error while reading file \"" + filename + "\"."); } catch (Exception e) { AsmDudeToolsStatic.Output_ERROR("AsmTokenTagger: error while reading file \"" + filename + "\"." + e); } } return(this.xmlData_); }
/// <summary> /// Singleton pattern: use AsmDudeTools.Instance for the instance of this class /// </summary> private AsmDudeTools() { //AsmDudeToolsStatic.Output_INFO("AsmDudeTools constructor"); ThreadHelper.ThrowIfNotOnUIThread(); #region Initialize ErrorListProvider IServiceProvider serviceProvider = new ServiceProvider(Package.GetGlobalService(typeof(Microsoft.VisualStudio.OLE.Interop.IServiceProvider)) as Microsoft.VisualStudio.OLE.Interop.IServiceProvider); this._errorListProvider = new ErrorListProvider(serviceProvider) { ProviderName = "Asm Errors", ProviderGuid = new Guid(EnvDTE.Constants.vsViewKindCode), }; #endregion this._threadPool = new SmartThreadPool(); #region load Signature Store and Performance Store string path = AsmDudeToolsStatic.Get_Install_Path() + "Resources" + Path.DirectorySeparatorChar; { string filename_Regular = path + "signature-may2019.txt"; string filename_Hand = path + "signature-hand-1.txt"; this._mnemonicStore = new MnemonicStore(filename_Regular, filename_Hand); } { this._performanceStore = new PerformanceStore(path + "Performance" + Path.DirectorySeparatorChar); } #endregion this.Init_Data(); this._mnemonics_switched_on = new HashSet <Mnemonic>(); this.UpdateMnemonicSwitchedOn(); this._register_switched_on = new HashSet <Rn>(); this.UpdateRegisterSwitchedOn(); #region Experiments if (false) { string filename2 = AsmDudeToolsStatic.Get_Install_Path() + "Resources" + Path.DirectorySeparatorChar + "mnemonics-nasm.txt"; MnemonicStore store2 = new MnemonicStore(filename2, null); ISet <string> archs = new SortedSet <string>(); IDictionary <string, string> signaturesIntel = new Dictionary <string, string>(); IDictionary <string, string> signaturesNasm = new Dictionary <string, string>(); foreach (Mnemonic mnemonic in Enum.GetValues(typeof(Mnemonic))) { IEnumerable <AsmSignatureElement> intel = this._mnemonicStore.GetSignatures(mnemonic); IEnumerable <AsmSignatureElement> nasm = store2.GetSignatures(mnemonic); signaturesIntel.Clear(); signaturesNasm.Clear(); int intelCount = 0; foreach (AsmSignatureElement e in intel) { intelCount++; string instruction = e.Mnemonic.ToString() + " " + e.Operands_Str; if (signaturesIntel.ContainsKey(instruction)) { AsmDudeToolsStatic.Output_WARNING("Intel " + instruction + ": is already present with arch " + signaturesIntel[instruction] + "; new arch " + e.Arch_Str); } else { signaturesIntel.Add(instruction, e.Arch_Str); } } int nasmCount = 0; foreach (AsmSignatureElement e in nasm) { nasmCount++; string instruction = e.Mnemonic.ToString() + " " + e.Operands_Str; if (signaturesNasm.ContainsKey(instruction)) { // AsmDudeToolsStatic.Output_WARNING("Nasm " + instruction + ": is already present with arch " + signaturesNasm[instruction] + "; new arch " + e.archStr); } else { signaturesNasm.Add(instruction, e.Arch_Str); } } foreach (AsmSignatureElement e in intel) { string instruction = e.Mnemonic.ToString() + " " + e.Operands_Str; //AsmDudeToolsStatic.Output_INFO("Intel " + instruction + ": arch" + e.archStr); if ((e.Arch_Str == null) || (e.Arch_Str.Length == 0)) { if (signaturesNasm.ContainsKey(instruction)) { AsmDudeToolsStatic.Output_INFO("Intel " + instruction + " has no arch, but NASM has \"" + signaturesNasm[instruction] + "\"."); } else { if (signaturesNasm.Count == 1) { AsmDudeToolsStatic.Output_INFO("Intel " + instruction + " has no arch, but NASM has \"" + signaturesNasm.GetEnumerator().Current + "\"."); } else { AsmDudeToolsStatic.Output_INFO("Intel " + instruction + " has no arch:"); foreach (KeyValuePair <string, string> pair in signaturesNasm) { AsmDudeToolsStatic.Output_INFO("\tNASM has " + pair.Key + ": \"" + pair.Value + "\"."); } AsmDudeToolsStatic.Output_INFO(" ----"); } } } } if (false) { if (intelCount != nasmCount) { foreach (AsmSignatureElement e in intel) { AsmDudeToolsStatic.Output_INFO("INTEL " + mnemonic + ": " + e); } foreach (AsmSignatureElement e in nasm) { AsmDudeToolsStatic.Output_INFO("NASM " + mnemonic + ": " + e); } } } } foreach (string str in archs) { AsmDudeToolsStatic.Output_INFO("INTEL arch " + str); } } if (false) { foreach (Arch arch in Enum.GetValues(typeof(Arch))) { int counter = 0; ISet <Mnemonic> usedMnemonics = new HashSet <Mnemonic>(); foreach (Mnemonic mnemonic in Enum.GetValues(typeof(Mnemonic))) { if (this.Mnemonic_Store.GetArch(mnemonic).Contains(arch)) { //AsmDudeToolsStatic.Output_INFO("AsmDudeTools constructor: arch="+arch+"; mnemonic=" + mnemonic); counter++; usedMnemonics.Add(mnemonic); } } string str = string.Empty; foreach (Mnemonic mnemonic in usedMnemonics) { str += mnemonic.ToString() + ","; } AsmDudeToolsStatic.Output_INFO("AsmDudeTools constructor: Architecture Option " + arch + " enables mnemonics " + str); } } if (false) { foreach (Mnemonic mnemonic in Enum.GetValues(typeof(Mnemonic))) { string keyword = mnemonic.ToString().ToUpper(); if (this._description.ContainsKey(keyword)) { string description = this._description[keyword]; string reference = this.Get_Url(mnemonic); this.Mnemonic_Store.SetHtmlRef(mnemonic, reference); } } AsmDudeToolsStatic.Output_INFO(this.Mnemonic_Store.ToString()); } if (false) { ISet <string> archs = new HashSet <string>(); foreach (Mnemonic mnemonic in Enum.GetValues(typeof(Mnemonic))) { if (!this._mnemonicStore.HasElement(mnemonic)) { AsmDudeToolsStatic.Output_INFO("AsmDudeTools constructor: mnemonic " + mnemonic + " is not present"); } foreach (AsmSignatureElement e in this._mnemonicStore.GetSignatures(mnemonic)) { foreach (string s in e.Arch_Str.Split(',')) { archs.Add(s.Trim()); } } } foreach (string s in archs) { AsmDudeToolsStatic.Output_INFO(s + ","); } } #endregion }