public ITagger <T> CreateTagger <T>(ITextBuffer buffer) where T : ITag { //AsmDudeToolsStatic.Output_INFO(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:CreateTagger", this.ToString())); ITagger <T> sc() { if (AsmDudeToolsStatic.Used_Assembler_Disassembly_Window.HasFlag(AssemblerEnum.AUTO_DETECT)) { int nLinesMax = 40; bool has_intel_syntax = AsmDudeToolsStatic.Guess_Intel_Syntax(buffer, nLinesMax); return((has_intel_syntax) ? new MasmDisassemblyTokenTagger(buffer) as ITagger <T> : new NasmAttDisassemblyTokenTagger(buffer) as ITagger <T>); } if (AsmDudeToolsStatic.Used_Assembler_Disassembly_Window.HasFlag(AssemblerEnum.NASM_ATT)) { return(new NasmAttDisassemblyTokenTagger(buffer) as ITagger <T>); } if (AsmDudeToolsStatic.Used_Assembler_Disassembly_Window.HasFlag(AssemblerEnum.MASM)) { return(new MasmDisassemblyTokenTagger(buffer) as ITagger <T>); } AsmDudeToolsStatic.Output_WARNING(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:CreateTagger: could not determine the used assembler", this.ToString())); return(new MasmDisassemblyTokenTagger(buffer) as ITagger <T>); } return(buffer.Properties.GetOrCreateSingletonProperty(sc)); }
/// <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 }
private void Init_Data() { this._type = new Dictionary <string, AsmTokenType>(); this._arch = new Dictionary <string, Arch>(); this._assembler = new Dictionary <string, AssemblerEnum>(); this._description = new Dictionary <string, string>(); // fill the dictionary with keywords XmlDocument xmlDoc = this.Get_Xml_Data(); foreach (XmlNode node in xmlDoc.SelectNodes("//misc")) { XmlAttribute nameAttribute = node.Attributes["name"]; if (nameAttribute == null) { AsmDudeToolsStatic.Output_WARNING("AsmDudeTools:Init_Data: found misc with no name"); } else { string name = nameAttribute.Value.ToUpper(); this._type[name] = AsmTokenType.Misc; this._arch[name] = this.Retrieve_Arch(node); this._description[name] = this.Retrieve_Description(node); } } foreach (XmlNode node in xmlDoc.SelectNodes("//directive")) { XmlAttribute nameAttribute = node.Attributes["name"]; if (nameAttribute == null) { AsmDudeToolsStatic.Output_WARNING("AsmDudeTools:Init_Data: found directive with no name"); } else { string name = nameAttribute.Value.ToUpper(); this._type[name] = AsmTokenType.Directive; this._arch[name] = this.Retrieve_Arch(node); this._assembler[name] = this.Retrieve_Assembler(node); this._description[name] = this.Retrieve_Description(node); } } foreach (XmlNode node in xmlDoc.SelectNodes("//register")) { XmlAttribute nameAttribute = node.Attributes["name"]; if (nameAttribute == null) { AsmDudeToolsStatic.Output_WARNING("AsmDudeTools:Init_Data: found register with no name"); } else { string name = nameAttribute.Value.ToUpper(); //this._type[name] = AsmTokenType.Register; this._arch[name] = this.Retrieve_Arch(node); this._description[name] = this.Retrieve_Description(node); } } foreach (XmlNode node in xmlDoc.SelectNodes("//userdefined1")) { XmlAttribute nameAttribute = node.Attributes["name"]; if (nameAttribute == null) { AsmDudeToolsStatic.Output_WARNING("AsmDudeTools:Init_Data: found userdefined1 with no name"); } else { string name = nameAttribute.Value.ToUpper(); this._type[name] = AsmTokenType.UserDefined1; this._description[name] = this.Retrieve_Description(node); } } foreach (XmlNode node in xmlDoc.SelectNodes("//userdefined2")) { XmlAttribute nameAttribute = node.Attributes["name"]; if (nameAttribute == null) { AsmDudeToolsStatic.Output_WARNING("AsmDudeTools:Init_Data: found userdefined2 with no name"); } else { string name = nameAttribute.Value.ToUpper(); this._type[name] = AsmTokenType.UserDefined2; this._description[name] = this.Retrieve_Description(node); } } foreach (XmlNode node in xmlDoc.SelectNodes("//userdefined3")) { XmlAttribute nameAttribute = node.Attributes["name"]; if (nameAttribute == null) { AsmDudeToolsStatic.Output_WARNING("AsmDudeTools:Init_Data: found userdefined3 with no name"); } else { string name = nameAttribute.Value.ToUpper(); this._type[name] = AsmTokenType.UserDefined3; this._description[name] = this.Retrieve_Description(node); } } }