示例#1
0
        public override Hashtable Parse(string appName, string file, Hashtable elementTranslator)
        {
            Hashtable    outTable = new Hashtable();
            StreamReader ios      = new StreamReader(file);
            string       curLine  = ios.ReadLine();

            while (curLine != null)
            {
                // each line is just a simple registry line with no strings or substitution
                string regKey = INFSection.GetRegKey(curLine, "");
                string regVal = INFSection.GetRegValue(curLine);
                ManifestParser.addEntry(regKey, regVal, appName);
                curLine = ios.ReadLine();
            }
            return(outTable);
        }
示例#2
0
        protected string parseRegistry(string fullpath, string val, string file)
        {
            // just add this Registry entry to the Hashtable
            ManifestParser.addEntry(fullpath, val, file);

            // split off the first two elements from the path
            string[] components   = fullpath.Split(new char[] { '\\' }, 10);
            string   rootname     = components[0];
            string   toplevelname = components[1];

            if (rootname.Equals("HKCR"))
            {
                if (toplevelname.Equals("CLSID") ||
                    toplevelname.Equals("Interface"))
                {
                    return("Code NonLinked");
                }
            }
            else if (rootname.Equals("HKCU"))
            {
                if (toplevelname.Equals("Printers"))
                {
                    return("Code NonLinked");
                }
            }
            else if (rootname.Equals("HKLM"))
            {
                if (toplevelname.Equals("HARDWARE"))
                {
                    return("Hardware");
                }
                else if (toplevelname.Equals("SYSTEM"))
                {
                    return("Data Config Settings Permanent");
                }
            }
            return("Data Config Settings");
        }
示例#3
0
        public override string Classify(string appName, string file, XmlTextReader xmld, Hashtable wxElementTranslator)
        {
            string tagname = xmld.Name;

            if (tagname.Equals("file"))
            {
                string filename = xmld.GetAttribute("name");
                if (filename == null)
                {
                    // for those in Microsoft who don't seem to know that XML is case-sensitive
                    filename = xmld.GetAttribute("Name");
                    if (filename == null)
                    {
                        filename = xmld.GetAttribute("sourceName");
                    }
                }


                if (filename != null)
                {
                    // now register the fact that we provide this file
                    string dpath = xmld.GetAttribute("destinationPath");
                    if (dpath != null)
                    {
                        if (dpath.IndexOf("$(runtime.windows)") >= 0)
                        {
                            dpath = dpath.Replace("$(runtime.windows)", "\\windows");
                        }
                        else if (dpath.IndexOf("$(runtime.drivers)") >= 0)
                        {
                            dpath = dpath.Replace("$(runtime.drivers)", "\\windows\\system32\\drivers");
                        }
                        else if (dpath.IndexOf("$(runtime.system32)") >= 0)
                        {
                            dpath = dpath.Replace("$(runtime.system32)", "\\windows\\system32");
                        }

                        // make sure that it has no trailing \ and that it starts with a \
                        dpath = dpath.TrimEnd(new char[] { '\\' });
                        dpath = dpath.TrimStart(new char[] { '\\' });
                        dpath = '\\' + dpath;
                    }
                    ManifestParser.addProvidesFile(dpath == null ? "" : dpath, filename, appName);

                    if (dpath != null && !dpath.Equals("\\"))
                    {
                        string[] pathElts = dpath.Split(new char[] { '\\' }, 50);
                        string   curPath  = "";
                        for (int i = 0; i < pathElts.Length; i++)
                        {
                            if (pathElts[i].Equals(""))
                            {
                                continue;
                            }
                            string fullPath = curPath;
                            if (i != 0)
                            {
                                fullPath += "\\";
                            }
                            fullPath += pathElts[i];

                            if (parentDirectoriesAlreadySeen.ContainsKey(fullPath))
                            {
                                curPath = fullPath;
                                continue;
                            }
                            ManifestParser.addProvidesFile(curPath, pathElts[i], appName);
                            curPath = fullPath;
                            parentDirectoriesAlreadySeen[fullPath] = 1;
                        }
                    }

                    // and parse it to see if it's an interesting file
                    string[] components = filename.Split(new char[] { '.' }, 10);
                    string   suffix     = components[components.Length - 1];

                    if (isImageSuffix(suffix))
                    {
                        return("Data File Display UI");
                    }
                    else if (isFontSuffix(suffix))
                    {
                        return("Data File Display Fonts");
                    }
                    else
                    {
                        return("Data File");
                    }
                }
                return("");
            }
            else if (tagname.Equals("fileDependency"))
            {
                // then register this file dependency
                string filename = xmld.GetAttribute("name");
                if (filename != null)
                {
                    // now register the fact that we require this file
                    string dpath = xmld.GetAttribute("destinationPath");
                    if (dpath != null)
                    {
                        if (dpath.Equals("$(runtime.windows)"))
                        {
                            dpath = "\\windows\\system32";
                        }
                        // make sure that it has no trailing \ and that it starts with a \
                        dpath = dpath.TrimEnd(new char[] { '\\' });
                        dpath = dpath.TrimStart(new char[] { '\\' });
                        dpath = '\\' + dpath;
                    }
                    ManifestParser.addRequiresFile(dpath == null ? "" : dpath, filename, appName);
                    return((string)wxElementTranslator[tagname]);
                }
                return("");
            }
            else if (tagname.Equals("IPermission"))
            {
                // ADD: parse the permissions into types
                return("Access Authentication");
            }
            else if (tagname.Equals("registryKey"))
            {
                // capture this as the current key
                curRegKey = xmld.GetAttribute("keyName");
                return((string)wxElementTranslator[tagname]);
            }
            else if (tagname.Equals("registryValue"))
            {
                string tempname = xmld.GetAttribute("name");
                string tempval  = xmld.GetAttribute("value");
                return(this.parseRegistry(curRegKey + "\\" + tempname, tempval, appName));
            }
            else
            {
                // for now, just look up this element in our translator
                // (this may end up returning null)
                return((string)wxElementTranslator[tagname]);
            }
        }
示例#4
0
        public override Hashtable Parse(string appName, string file, Hashtable elementTranslator)
        {
            Hashtable    outTable = new Hashtable();
            StreamReader ios      = new StreamReader(file);

            #region Parse INF File
            ArrayList         sections       = new ArrayList();
            INFSection        curSection     = null;
            INFVersionSection versionSection = null;
            INFStringSection  strSection     = null;
            string            curLine        = ios.ReadLine();
            while (curLine != null)
            {
                // get rid of the whitespace on both sides
                curLine = curLine.Trim();

                if (curLine.Equals(""))
                {
                    curLine = ios.ReadLine();
                    continue;
                }
                // we don't like lines that start with control characters
                if (curLine[0] < 32)
                {
                    curLine = ios.ReadLine();
                    continue;
                }

                if (curLine.StartsWith("#pragma"))
                {
                    // I can't believe this is in an INF file!
                    curLine = ios.ReadLine();
                    continue;
                }

                if (curLine.StartsWith("----"))
                {
                    curLine = ios.ReadLine();
                    continue;
                }

                //Console.WriteLine(curLine);
                if (INFSection.IsComment(curLine))
                {
                    //Console.WriteLine("***Ignoring comment");
                    curLine = ios.ReadLine();
                    continue;
                }
                if (INFSection.IsSection(curLine))
                {
                    //Console.WriteLine("***Found Section");
                    if (curSection != null)
                    {
                        sections.Add(curSection);
                    }
                    if (INFSection.IsStringSection(curLine))
                    {
                        //Console.WriteLine("***It's a Strings section");

                        curSection = new INFStringSection(curLine);
                        strSection = (INFStringSection)curSection;
                    }
                    else
                    {
                        if (INFSection.IsVersionSection(curLine))
                        {
                            //Console.WriteLine("***It's a version section");

                            curSection     = new INFVersionSection(curLine);
                            versionSection = (INFVersionSection)curSection;
                        }
                        else
                        {
                            curSection = new INFSection(curLine);
                        }
                    }
                }
                else
                {
                    // I can only assume that the real INF parser just ignores
                    // everything that's not in a section, given what I've seen
                    // at the top of INF files so far
                    if (curSection != null)
                    {
                        //Console.WriteLine("***Adding Line to Section "  + curSection.Name);

                        curSection.AddLine(curLine);
                    }
                }
                curLine = ios.ReadLine();
            }
            if (curSection != null)
            {
                sections.Add(curSection);
            }
            #endregion

            #region Replace Strings
            //Debug.Assert(versionSection != null);
            // make sure we have a string table somewhere
            if (strSection != null)
            {
                // now grab the INFStringSection and pass it to each INFSection
                // so they can update their strings to be correct
                for (int i = 0; i < sections.Count; i++)
                {
                    ((INFSection)sections[i]).UpdateStrings(strSection);
                }
            }
            #endregion

            #region Record Registry Changes

            // now that we've replaced the strings, we can safely
            // discover all the Registry section lines
            for (int i = 0; i < sections.Count; i++)
            {
                ((INFSection)sections[i]).DiscoverRegistryLines();
            }

            // walk the sections again and accumulate all the AddReg and DelReg sections
            Hashtable addRegSections = new Hashtable();
            Hashtable delRegSections = new Hashtable();
            for (int i = 0; i < sections.Count; i++)
            {
                ((INFSection)sections[i]).GetAddRegSections(addRegSections);
                ((INFSection)sections[i]).GetDelRegSections(delRegSections);
            }

            for (int i = 0; i < sections.Count; i++)
            {
                string secName = ((INFSection)sections[i]).Name;
                if (addRegSections.ContainsKey(secName) ||
                    delRegSections.ContainsKey(secName))
                {
                    // now walk its lines and enter the registry values
                    ArrayList lines = ((INFSection)sections[i]).Lines;
                    for (int j = 0; j < lines.Count; j++)
                    {
                        string line = (string)lines[j];
                        if (line.Equals(""))
                        {
                            continue;
                        }
                        string versionGUID = null;
                        if (versionSection != null)
                        {
                            versionGUID = versionSection.Guid;
                        }
                        string regKey = INFSection.GetRegKey(line, versionGUID);
                        if (regKey != null)
                        {
                            //Console.WriteLine("Got RegKey " + regKey);
                            string regValue = INFSection.GetRegValue(line);
                            // remove all but the innermost double-quote strings from this value
                            int removeCount = 0;
                            for (int k = 0; k < regValue.Length; k++)
                            {
                                if (regValue[k] == '"')
                                {
                                    removeCount++;
                                }
                            }
                            if (removeCount > 0)
                            {
                                regValue = regValue.TrimStart(new char[] { '"' });
                                regValue = regValue.TrimEnd(new char[] { '"' });
                                regValue = "\"" + regValue + "\"";
                            }

                            //Console.WriteLine("Got RegValue " + regValue);

                            ManifestParser.addEntry(regKey, regValue, appName);
                        }
                    }
                }
            }


            #endregion

            return(outTable);
        }