Exemplo n.º 1
0
        /// <summary>
        /// Add (and overwrite) return true if an existing signature element is overwritten;
        /// </summary>
        /// <param name="asmSignatureElement"></param>
        private bool Add(AsmSignatureElement asmSignatureElement)
        {
            Mnemonic mnemonic = asmSignatureElement.mnemonic;
            bool     result   = false;

            if (this.data_.TryGetValue(mnemonic, out IList <AsmSignatureElement> signatureElementList))
            {
                if (signatureElementList.Contains(asmSignatureElement))
                {
                    signatureElementList.Remove(asmSignatureElement);
                    result = true;
                }
                signatureElementList.Add(asmSignatureElement);
            }
            else
            {
                this.data_.Add(mnemonic, new List <AsmSignatureElement> {
                    asmSignatureElement
                });
            }
            return(result);
        }
Exemplo n.º 2
0
        private void LoadHandcraftedData(string filename)
        {
            //AsmDudeToolsStatic.Output_INFO("MnemonicStore:load_data_intel: filename=" + filename);
            try
            {
                StreamReader file = new StreamReader(filename);
                string       line;
                while ((line = file.ReadLine()) != null)
                {
                    if ((line.Length > 0) && (!line.StartsWith(";", StringComparison.Ordinal)))
                    {
                        string[] columns = line.Split('\t');
                        if (columns.Length == 4)
                        { // general description
                            #region
                            Mnemonic mnemonic = AsmSourceTools.ParseMnemonic(columns[1], false);
                            if (mnemonic == Mnemonic.NONE)
                            {
                                AsmDudeToolsStatic.Output_WARNING("MnemonicStore:loadHandcraftedData: unknown mnemonic in line" + line);
                            }
                            else
                            {
                                if (this.description_.ContainsKey(mnemonic))
                                {
                                    this.description_.Remove(mnemonic);
                                }
                                this.description_.Add(mnemonic, columns[2]);

                                if (this.htmlRef_.ContainsKey(mnemonic))
                                {
                                    this.htmlRef_.Remove(mnemonic);
                                }
                                this.htmlRef_.Add(mnemonic, columns[3]);
                            }
                            #endregion
                        }
                        else if ((columns.Length == 5) || (columns.Length == 6))
                        { // signature description, ignore an old sixth column
                            #region
                            Mnemonic mnemonic = AsmSourceTools.ParseMnemonic(columns[0], false);
                            if (mnemonic == Mnemonic.NONE)
                            {
                                AsmDudeToolsStatic.Output_WARNING("MnemonicStore:loadHandcraftedData: unknown mnemonic in line" + line);
                            }
                            else
                            {
                                AsmSignatureElement se = new AsmSignatureElement(mnemonic, columns[1], columns[2], columns[3], columns[4]);
                                this.Add(se);
                            }
                            #endregion
                        }
                        else
                        {
                            AsmDudeToolsStatic.Output_WARNING("MnemonicStore:loadHandcraftedData: s.Length=" + columns.Length + "; funky line" + line);
                        }
                    }
                }
                file.Close();

                #region Fill Arch
                foreach (KeyValuePair <Mnemonic, IList <AsmSignatureElement> > pair in this.data_)
                {
                    ISet <Arch> archs = new HashSet <Arch>();
                    foreach (AsmSignatureElement signatureElement in pair.Value)
                    {
                        foreach (Arch arch in signatureElement.Arch)
                        {
                            archs.Add(arch);
                        }
                    }
                    IList <Arch> list = new List <Arch>();
                    foreach (Arch a in archs)
                    {
                        list.Add(a);
                    }
                    this.arch_[pair.Key] = list;
                }
                #endregion
            }
            catch (FileNotFoundException)
            {
                AsmDudeToolsStatic.Output_ERROR("MnemonicStore:LoadHandcraftedData: could not find file \"" + filename + "\".");
            }
            catch (Exception e)
            {
                AsmDudeToolsStatic.Output_ERROR("MnemonicStore:LoadHandcraftedData: error while reading file \"" + filename + "\"." + e);
            }
        }
Exemplo n.º 3
0
        private void LoadRegularData(string filename)
        {
            //AsmDudeToolsStatic.Output_INFO("MnemonicStore:loadRegularData: filename=" + filename);
            try
            {
                StreamReader file = new StreamReader(filename);
                string       line;
                while ((line = file.ReadLine()) != null)
                {
                    if ((line.Length > 0) && (!line.StartsWith(";", StringComparison.Ordinal)))
                    {
                        string[] columns = line.Split('\t');
                        if (columns.Length == 4)
                        { // general description
                            #region
                            Mnemonic mnemonic = AsmSourceTools.ParseMnemonic(columns[1], false);
                            if (mnemonic == Mnemonic.NONE)
                            {
                                // ignore the unknown mnemonic
                                //AsmDudeToolsStatic.Output_WARNING("MnemonicStore:loadRegularData: unknown mnemonic in line: " + line);
                            }
                            else
                            {
                                if (!this.description_.ContainsKey(mnemonic))
                                {
                                    this.description_.Add(mnemonic, columns[2]);
                                }
                                else
                                {
                                    // this happens when the mnemonic is defined in multiple files, using the data from the first file
                                    //AsmDudeToolsStatic.Output_WARNING("MnemonicStore:loadRegularData: mnemonic " + mnemonic + " already has a description");
                                }
                                if (!this.htmlRef_.ContainsKey(mnemonic))
                                {
                                    this.htmlRef_.Add(mnemonic, columns[3]);
                                }
                                else
                                {
                                    // this happens when the mnemonic is defined in multiple files, using the data from the first file
                                    //AsmDudeToolsStatic.Output_WARNING("MnemonicStore:loadRegularData: mnemonic " + mnemonic + " already has a html ref");
                                }
                            }
                            #endregion
                        }
                        else if ((columns.Length == 5) || (columns.Length == 6))
                        { // signature description, ignore an old sixth column
                            #region
                            Mnemonic mnemonic = AsmSourceTools.ParseMnemonic(columns[0], false);
                            if (mnemonic == Mnemonic.NONE)
                            {
                                AsmDudeToolsStatic.Output_WARNING("MnemonicStore:loadRegularData: unknown mnemonic in line: " + line);
                            }
                            else
                            {
                                AsmSignatureElement se = new AsmSignatureElement(mnemonic, columns[1], columns[2], columns[3], columns[4]);
                                if (this.Add(se))
                                {
                                    AsmDudeToolsStatic.Output_WARNING("MnemonicStore:loadRegularData: signature already exists" + se.ToString());
                                }
                            }
                            #endregion
                        }
                        else
                        {
                            AsmDudeToolsStatic.Output_WARNING("MnemonicStore:loadRegularData: s.Length=" + columns.Length + "; funky line" + line);
                        }
                    }
                }
                file.Close();

                #region Fill Arch
                foreach (KeyValuePair <Mnemonic, IList <AsmSignatureElement> > pair in this.data_)
                {
                    ISet <Arch> archs = new HashSet <Arch>();
                    foreach (AsmSignatureElement signatureElement in pair.Value)
                    {
                        foreach (Arch arch in signatureElement.Arch)
                        {
                            if (arch == Arch.ARCH_NONE)
                            {
                                AsmDudeToolsStatic.Output_WARNING("MnemonicStore:loadRegularData: found ARCH NONE.");
                            }
                            else
                            {
                                archs.Add(arch);
                            }
                        }
                    }
                    IList <Arch> list = new List <Arch>();
                    foreach (Arch a in archs)
                    {
                        list.Add(a);
                    }
                    this.arch_[pair.Key] = list;
                }
                #endregion
            }
            catch (FileNotFoundException)
            {
                AsmDudeToolsStatic.Output_ERROR("MnemonicStore:loadRegularData: could not find file \"" + filename + "\".");
            }
            catch (Exception e)
            {
                AsmDudeToolsStatic.Output_ERROR("MnemonicStore:loadRegularData: error while reading file \"" + filename + "\"." + e);
            }
        }
Exemplo n.º 4
0
        private void loadHandcraftedData(string filename)
        {
            //AsmDudeToolsStatic.Output("INFO: MnemonicStore:load_data_intel: filename=" + filename);
            try {
                System.IO.StreamReader file = new System.IO.StreamReader(filename);
                string line;
                while ((line = file.ReadLine()) != null)
                {
                    if ((line.Length > 0) && (!line.StartsWith(";")))
                    {
                        string[] columns = line.Split('\t');
                        if (columns.Length == 4)   // general description
                        {
                            #region
                            Mnemonic mnemonic = AsmSourceTools.parseMnemonic(columns[1]);
                            if (mnemonic == Mnemonic.UNKNOWN)
                            {
                                AsmDudeToolsStatic.Output("WARNING: MnemonicStore:loadHandcraftedData: unknown mnemonic in line" + line);
                            }
                            else
                            {
                                if (this._description.ContainsKey(mnemonic))
                                {
                                    this._description.Remove(mnemonic);
                                }
                                this._description.Add(mnemonic, columns[2]);

                                if (this._htmlRef.ContainsKey(mnemonic))
                                {
                                    this._htmlRef.Remove(mnemonic);
                                }
                                this._htmlRef.Add(mnemonic, columns[3]);
                            }
                            #endregion
                        }
                        else if ((columns.Length == 5) || (columns.Length == 6))     // signature description, ignore an old sixth column
                        {
                            #region
                            Mnemonic mnemonic = AsmSourceTools.parseMnemonic(columns[0]);
                            if (mnemonic == Mnemonic.UNKNOWN)
                            {
                                AsmDudeToolsStatic.Output("WARNING: MnemonicStore:loadHandcraftedData: unknown mnemonic in line" + line);
                            }
                            else
                            {
                                AsmSignatureElement se = new AsmSignatureElement(mnemonic, columns[1], columns[2], columns[3], columns[4]);
                                this.add(se);
                            }
                            #endregion
                        }
                        else
                        {
                            AsmDudeToolsStatic.Output("WARNING: MnemonicStore:loadHandcraftedData: s.Length=" + columns.Length + "; funky line" + line);
                        }
                    }
                }
                file.Close();

                #region Fill Arch
                foreach (KeyValuePair <Mnemonic, IList <AsmSignatureElement> > pair in this._data)
                {
                    ISet <Arch> archs = new HashSet <Arch>();
                    foreach (AsmSignatureElement signatureElement in pair.Value)
                    {
                        foreach (Arch arch in signatureElement.arch)
                        {
                            archs.Add(arch);
                        }
                    }
                    IList <Arch> list = new List <Arch>();
                    foreach (Arch a in archs)
                    {
                        list.Add(a);
                    }
                    this._arch[pair.Key] = list;
                }
                #endregion
            } catch (FileNotFoundException) {
                MessageBox.Show("ERROR: AsmTokenTagger: could not find file \"" + filename + "\".");
            } catch (Exception e) {
                MessageBox.Show("ERROR: AsmTokenTagger: error while reading file \"" + filename + "\"." + e);
            }
        }