Пример #1
0
        public static AssemblyInfo FromXml(Project project, XElement reader, Variables vars)
        {
            AssemblyInfo info = new AssemblyInfo(project);

            // pull out the file attribute, but don't process anything empty
            string val = Helper.GetAttribute(reader, "file", vars);

            if (val.Length > 0)
            {
                info.LoadAssembly(val);
            }
            else
            {
                throw new InvalidOperationException("Need valid file attribute.");
            }

            string isExcluded = Helper.GetAttribute(reader, "Exclude", vars);

            if ((isExcluded.Length > 0) && (isExcluded.ToLowerInvariant() == "true"))
            {
                info.Exclude = true;
            }

            if (!reader.IsEmpty)
            {
                FromXmlReadNode(reader, project, vars, info);
            }

            return(info);
        }
Пример #2
0
        internal static void ReadIncludeTag(XmlReader parentReader, Project project,
                                            Action <XmlReader, Project> readAction)
        {
            if (parentReader == null)
            {
                throw new ArgumentNullException("parentReader");
            }

            if (readAction == null)
            {
                throw new ArgumentNullException("readAction");
            }

            string path =
                Environment.ExpandEnvironmentVariables(project.vars.Replace(Helper.GetAttribute(parentReader, "path")));
            XmlReaderSettings includeReaderSettings = Obfuscator.GetReaderSettings();

            using (XmlReader includeReader = XmlReader.Create(File.OpenRead(path), includeReaderSettings))
            {
                // Start reading
                includeReader.Read();

                // Skip declaration, if present
                if (includeReader.NodeType == XmlNodeType.XmlDeclaration)
                {
                    includeReader.Read();
                }

                Debug.Assert(includeReader.NodeType == XmlNodeType.Element && includeReader.Name == "Include");

                readAction(includeReader, project);
            }
        }
Пример #3
0
        private static void FromXmlReadNode(XmlReader reader, Project project)
        {
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                    case "Var":
                    {
                        string name = Helper.GetAttribute(reader, "name");
                        if (name.Length > 0)
                        {
                            string value = Helper.GetAttribute(reader, "value");
                            if (value.Length > 0)
                            {
                                project.vars.Add(name, value);
                            }
                            else
                            {
                                project.vars.Remove(name);
                            }
                        }
                        break;
                    }

                    case "Module":
                        AssemblyInfo info = AssemblyInfo.FromXml(project, reader, project.vars);
                        if (info.Exclude)
                        {
                            project.copyAssemblyList.Add(info);
                            break;
                        }
                        Console.WriteLine("Processing assembly: " + info.Definition.Name.FullName);
                        project.assemblyList.Add(info);
                        project.assemblyMap[info.Name] = info;
                        break;

                    case "AssemblySearchPath":
                    {
                        string path =
                            Environment.ExpandEnvironmentVariables(
                                project.vars.Replace(Helper.GetAttribute(reader, "path")));
                        project.assemblySearchPaths.Add(path);
                        break;
                    }

                    case "Include":
                    {
                        ReadIncludeTag(reader, project, FromXmlReadNode);
                        break;
                    }
                    }
                }
            }
        }
Пример #4
0
        private static void FromXmlReadNode(XElement reader, Project project)
        {
            var settings = reader.Elements("Var");

            foreach (var setting in settings)
            {
                var name = setting.Attribute("name")?.Value;
                if (!string.IsNullOrEmpty(name))
                {
                    var value = setting.Attribute("value")?.Value;
                    if (!string.IsNullOrEmpty(value))
                    {
                        project.vars.Add(name, value);
                    }
                    else
                    {
                        project.vars.Remove(name);
                    }
                }
            }

            var includes = reader.Elements("Include");

            foreach (var include in includes)
            {
                ReadIncludeTag(include, project, FromXmlReadNode);
            }

            var searchPaths = reader.Elements("AssemblySearchPath");

            foreach (var searchPath in searchPaths)
            {
                string path =
                    Environment.ExpandEnvironmentVariables(Helper.GetAttribute(searchPath, "path", project.vars));
                project.assemblySearchPaths.Add(path);
            }

            var modules = reader.Elements("Module");

            foreach (var module in modules)
            {
                AssemblyInfo info = AssemblyInfo.FromXml(project, module, project.vars);
                if (info.Exclude)
                {
                    project.CopyAssemblyList.Add(info);
                    break;
                }

                Console.WriteLine("=> Processing assembly: " + info.Definition.Name.FullName);
                project.assemblyList.Add(info);
                project.assemblyMap[info.Name] = info;
            }
        }
Пример #5
0
        public static Project FromXml(XmlReader reader, string projectFileDirectory)
        {
            Project project = new Project();

            project.vars.Add(SPECIALVAR_PROJECTFILEDIRECTORY, string.IsNullOrEmpty(projectFileDirectory) ? "." : projectFileDirectory);

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                    case "Var":
                    {
                        string name = Helper.GetAttribute(reader, "name");
                        if (name.Length > 0)
                        {
                            string value = Helper.GetAttribute(reader, "value");
                            if (value.Length > 0)
                            {
                                project.vars.Add(name, value);
                            }
                            else
                            {
                                project.vars.Remove(name);
                            }
                        }
                        break;
                    }

                    case "Module":
                        AssemblyInfo info = AssemblyInfo.FromXml(project, reader, project.vars);
                        if (info.Exclude)
                        {
                            project.copyAssemblyList.Add(info);
                            break;
                        }
                        Console.WriteLine("Processing assembly: " + info.Definition.Name.FullName);
                        project.assemblyList.Add(info);
                        project.assemblyMap [info.Name] = info;
                        break;

                    case "AssemblySearchPath":
                        string path = Environment.ExpandEnvironmentVariables(project.vars.Replace(Helper.GetAttribute(reader, "path")));
                        project.assemblySearchPaths.Add(path);
                        break;
                    }
                }
            }

            return(project);
        }
Пример #6
0
        public static Project FromXml(XmlReader reader)
        {
            Project project = new Project( );

            while (reader.Read( ))
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                    case "Var":
                    {
                        string name = Helper.GetAttribute(reader, "name");
                        if (name.Length > 0)
                        {
                            string value = Helper.GetAttribute(reader, "value");
                            if (value.Length > 0)
                            {
                                project.vars.Add(name, value);
                            }
                            else
                            {
                                project.vars.Remove(name);
                            }
                        }
                        break;
                    }

                    case "Module":
                        AssemblyInfo info = AssemblyInfo.FromXml(project, reader, project.vars);
                        if (info.Exclude)
                        {
                            project.copyAssemblyList.Add(info);
                            break;
                        }
                        Console.WriteLine("Processing assembly: " + info.Definition.Name.FullName);
                        project.assemblyList.Add(info);
                        project.assemblyMap[info.Name] = info;
                        break;
                    }
                }
            }

            return(project);
        }
Пример #7
0
        public static Project FromXml(XmlReader reader, string projectFileDirectory)
        {
            Project project = new Project();

            project.vars.Add(SPECIALVAR_PROJECTFILEDIRECTORY, string.IsNullOrEmpty(projectFileDirectory) ? "." : projectFileDirectory);

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                    case "Var":
                    {
                        string name = Helper.GetAttribute(reader, "name");
                        if (name.Length > 0)
                        {
                            string value = Helper.GetAttribute(reader, "value");
                            if (value.Length > 0)
                            {
                                project.vars.Add(name, value);
                            }
                            else
                            {
                                project.vars.Remove(name);
                            }
                        }
                        break;
                    }

                    case "Module":
                        AssemblyInfo info = AssemblyInfo.FromXml(project, reader, project.vars);
                        project.assemblyList.Add(info);
                        project.assemblyMap[info.Name] = info;
                        break;
                    }
                }
            }

            return(project);
        }
Пример #8
0
        internal static void ReadIncludeTag(XElement parentReader, Project project,
                                            Action <XElement, Project> readAction)
        {
            if (parentReader == null)
            {
                throw new ArgumentNullException("parentReader");
            }

            if (readAction == null)
            {
                throw new ArgumentNullException("readAction");
            }

            string path =
                Environment.ExpandEnvironmentVariables(Helper.GetAttribute(parentReader, "path", project.vars));
            var includeReader = XDocument.Load(path);

            if (includeReader.Root.Name == "Include")
            {
                readAction(includeReader.Root, project);
            }
        }
Пример #9
0
        public static AssemblyInfo FromXml(Project project, XmlReader reader, Variables vars)
        {
            Debug.Assert(reader.NodeType == XmlNodeType.Element && reader.Name == "Module");

            AssemblyInfo info = new AssemblyInfo(project);

            // pull out the file attribute, but don't process anything empty
            string val = Helper.GetAttribute(reader, "file", vars);

            if (val.Length > 0)
            {
                info.LoadAssembly(val);

                if (AssemblyIsSigned(info.Definition) && project.Settings.KeyFile == null)
                {
                    throw new ObfuscarException("Obfuscating a signed assembly would result in an invalid assembly:  " +
                                                info.Name + "; use the KeyFile property to set a key to use");
                }
            }
            else
            {
                throw new InvalidOperationException("Need valid file attribute.");
            }

            string isExcluded = Helper.GetAttribute(reader, "Exclude", vars);

            if ((isExcluded.Length > 0) && (isExcluded.ToLowerInvariant() == "true"))
            {
                info.Exclude = true;
            }

            if (!reader.IsEmptyElement)
            {
                FromXmlReadNode(reader, project, vars, info);
            }

            return(info);
        }
Пример #10
0
        private static void FromXmlReadNode(XElement element, Project project, Variables vars, AssemblyInfo info)
        {
            foreach (var reader in element.Elements())
            {
                string name = Helper.GetAttribute(reader, "name", vars);

                string rxStr = Helper.GetAttribute(reader, "rx");
                Regex  rx    = null;
                if (!string.IsNullOrEmpty(rxStr))
                {
                    rx = new Regex(rxStr);
                }

                string isStaticStr = Helper.GetAttribute(reader, "static", vars);
                bool?  isStatic    = null;
                if (!string.IsNullOrEmpty(isStaticStr))
                {
                    isStatic = Convert.ToBoolean(isStaticStr);
                }

                string isSerializableStr = Helper.GetAttribute(reader, "serializable", vars);
                bool?  isSerializable    = null;
                if (!string.IsNullOrEmpty(isSerializableStr))
                {
                    isSerializable = Convert.ToBoolean(isSerializableStr);
                }

                string attrib     = Helper.GetAttribute(reader, "attrib", vars);
                string inherits   = Helper.GetAttribute(reader, "typeinherits", vars);
                string type       = Helper.GetAttribute(reader, "type", vars);
                string typeattrib = Helper.GetAttribute(reader, "typeattrib", vars);

                string val;
                switch (reader.Name.LocalName)
                {
                case "Include":
                {
                    Project.ReadIncludeTag(reader, project,
                                           (includeReader, proj) => FromXmlReadNode(includeReader, proj, vars, info));
                    break;
                }

                case "SkipNamespace":
                    if (rx != null)
                    {
                        info.skipNamespaces.Add(new NamespaceTester(rx));
                    }
                    else
                    {
                        info.skipNamespaces.Add(new NamespaceTester(name));
                    }
                    break;

                case "ForceNamespace":
                    if (rx != null)
                    {
                        info.forceNamespaces.Add(new NamespaceTester(rx));
                    }
                    else
                    {
                        info.forceNamespaces.Add(new NamespaceTester(name));
                    }
                    break;

                case "SkipType":
                    TypeAffectFlags skipFlags = TypeAffectFlags.SkipNone;

                    val = Helper.GetAttribute(reader, "skipMethods", vars);
                    if (val.Length > 0 && Convert.ToBoolean(val))
                    {
                        skipFlags |= TypeAffectFlags.AffectMethod;
                    }

                    val = Helper.GetAttribute(reader, "skipStringHiding", vars);
                    if (val.Length > 0 && Convert.ToBoolean(val))
                    {
                        skipFlags |= TypeAffectFlags.AffectString;
                    }

                    val = Helper.GetAttribute(reader, "skipFields", vars);
                    if (val.Length > 0 && Convert.ToBoolean(val))
                    {
                        skipFlags |= TypeAffectFlags.AffectField;
                    }

                    val = Helper.GetAttribute(reader, "skipProperties", vars);
                    if (val.Length > 0 && Convert.ToBoolean(val))
                    {
                        skipFlags |= TypeAffectFlags.AffectProperty;
                    }

                    val = Helper.GetAttribute(reader, "skipEvents", vars);
                    if (val.Length > 0 && Convert.ToBoolean(val))
                    {
                        skipFlags |= TypeAffectFlags.AffectEvent;
                    }

                    if (rx != null)
                    {
                        info.skipTypes.Add(new TypeTester(rx, skipFlags, attrib, inherits, isStatic,
                                                          isSerializable));
                    }
                    else
                    {
                        info.skipTypes.Add(new TypeTester(name, skipFlags, attrib, inherits, isStatic,
                                                          isSerializable));
                    }
                    break;

                case "ForceType":
                    TypeAffectFlags forceFlags = TypeAffectFlags.SkipNone;

                    val = Helper.GetAttribute(reader, "forceMethods", vars);
                    if (val.Length > 0 && Convert.ToBoolean(val))
                    {
                        forceFlags |= TypeAffectFlags.AffectMethod;
                    }

                    val = Helper.GetAttribute(reader, "forceStringHiding", vars);
                    if (val.Length > 0 && Convert.ToBoolean(val))
                    {
                        forceFlags |= TypeAffectFlags.AffectString;
                    }

                    val = Helper.GetAttribute(reader, "forceFields", vars);
                    if (val.Length > 0 && Convert.ToBoolean(val))
                    {
                        forceFlags |= TypeAffectFlags.AffectField;
                    }

                    val = Helper.GetAttribute(reader, "forceProperties", vars);
                    if (val.Length > 0 && Convert.ToBoolean(val))
                    {
                        forceFlags |= TypeAffectFlags.AffectProperty;
                    }

                    val = Helper.GetAttribute(reader, "forceEvents", vars);
                    if (val.Length > 0 && Convert.ToBoolean(val))
                    {
                        forceFlags |= TypeAffectFlags.AffectEvent;
                    }

                    if (rx != null)
                    {
                        info.forceTypes.Add(new TypeTester(rx, forceFlags, attrib, inherits, isStatic,
                                                           isSerializable));
                    }
                    else
                    {
                        info.forceTypes.Add(new TypeTester(name, forceFlags, attrib, inherits, isStatic,
                                                           isSerializable));
                    }
                    break;

                case "SkipMethod":
                    if (rx != null)
                    {
                        info.skipMethods.Add(new MethodTester(rx, type, attrib, typeattrib, inherits,
                                                              isStatic));
                    }
                    else
                    {
                        info.skipMethods.Add(new MethodTester(name, type, attrib, typeattrib, inherits,
                                                              isStatic));
                    }
                    break;

                case "ForceMethod":
                    if (rx != null)
                    {
                        info.forceMethods.Add(
                            new MethodTester(rx, type, attrib, typeattrib, inherits, isStatic));
                    }
                    else
                    {
                        info.forceMethods.Add(new MethodTester(name, type, attrib, typeattrib, inherits,
                                                               isStatic));
                    }
                    break;

                case "SkipStringHiding":
                    if (rx != null)
                    {
                        info.skipStringHiding.Add(new MethodTester(rx, type, attrib, typeattrib));
                    }
                    else
                    {
                        info.skipStringHiding.Add(new MethodTester(name, type, attrib, typeattrib));
                    }
                    break;

                case "ForceStringHiding":
                    if (rx != null)
                    {
                        info.forceStringHiding.Add(new MethodTester(rx, type, attrib, typeattrib));
                    }
                    else
                    {
                        info.forceStringHiding.Add(new MethodTester(name, type, attrib, typeattrib));
                    }
                    break;

                case "SkipField":
                    string decorator = Helper.GetAttribute(reader, "decorator", vars);

                    if (rx != null)
                    {
                        info.skipFields.Add(new FieldTester(rx, type, attrib, typeattrib, inherits, decorator,
                                                            isStatic, isSerializable));
                    }
                    else
                    {
                        info.skipFields.Add(new FieldTester(name, type, attrib, typeattrib, inherits, decorator,
                                                            isStatic, isSerializable));
                    }
                    break;

                case "ForceField":
                    string decorator1 = Helper.GetAttribute(reader, "decorator", vars);

                    if (rx != null)
                    {
                        info.forceFields.Add(new FieldTester(rx, type, attrib, typeattrib, inherits, decorator1,
                                                             isStatic, isSerializable));
                    }
                    else
                    {
                        info.forceFields.Add(new FieldTester(name, type, attrib, typeattrib, inherits,
                                                             decorator1, isStatic, isSerializable));
                    }
                    break;

                case "SkipProperty":
                    if (rx != null)
                    {
                        info.skipProperties.Add(new PropertyTester(rx, type, attrib, typeattrib));
                    }
                    else
                    {
                        info.skipProperties.Add(new PropertyTester(name, type, attrib, typeattrib));
                    }
                    break;

                case "ForceProperty":
                    if (rx != null)
                    {
                        info.forceProperties.Add(new PropertyTester(rx, type, attrib, typeattrib));
                    }
                    else
                    {
                        info.forceProperties.Add(new PropertyTester(name, type, attrib, typeattrib));
                    }
                    break;

                case "SkipEvent":
                    if (rx != null)
                    {
                        info.skipEvents.Add(new EventTester(rx, type, attrib, typeattrib));
                    }
                    else
                    {
                        info.skipEvents.Add(new EventTester(name, type, attrib, typeattrib));
                    }
                    break;

                case "ForceEvent":
                    if (rx != null)
                    {
                        info.forceEvents.Add(new EventTester(rx, type, attrib, typeattrib));
                    }
                    else
                    {
                        info.forceEvents.Add(new EventTester(name, type, attrib, typeattrib));
                    }
                    break;

                case "SkipEnums":
                    var skipEnumsValue = Helper.GetAttribute(reader, "value");
                    info.skipEnums = skipEnumsValue.Length > 0 && Convert.ToBoolean(skipEnumsValue);
                    break;
                }
            }
        }
Пример #11
0
        public static AssemblyInfo FromXml(Project project, XmlReader reader, Variables vars)
        {
            Debug.Assert(reader.NodeType == XmlNodeType.Element && reader.Name == "Module");

            AssemblyInfo info = new AssemblyInfo(project);

            // pull out the file attribute, but don't process anything empty
            string val = Helper.GetAttribute(reader, "file", vars);

            if (val.Length > 0)
            {
                info.LoadAssembly(val);

                if (AssemblyIsSigned(info.Definition) && project.Settings.KeyFile == null)
                {
                    throw new ObfuscarException("Obfuscating a signed assembly would result in an invalid assembly:  " + info.Name + "; use the KeyFile property to set a key to use");
                }
            }
            else
            {
                throw new InvalidOperationException("Need valid file attribute.");
            }

            string isExcluded = Helper.GetAttribute(reader, "Exclude", vars);

            if ((isExcluded.Length > 0) && (isExcluded.ToLowerInvariant() == "true"))
            {
                info.Exclude = true;
            }

            if (!reader.IsEmptyElement)
            {
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        string name = Helper.GetAttribute(reader, "name", vars);

                        string rxStr = Helper.GetAttribute(reader, "rx");
                        Regex  rx    = null;
                        if (!string.IsNullOrEmpty(rxStr))
                        {
                            rx = new Regex(rxStr);
                        }

                        string isStaticStr = Helper.GetAttribute(reader, "static", vars);
                        bool?  isStatic    = null;
                        if (!string.IsNullOrEmpty(isStaticStr))
                        {
                            isStatic = XmlConvert.ToBoolean(isStaticStr);
                        }

                        string isSerializableStr = Helper.GetAttribute(reader, "serializable", vars);
                        bool?  isSerializable    = null;
                        if (!string.IsNullOrEmpty(isSerializableStr))
                        {
                            isSerializable = XmlConvert.ToBoolean(isSerializableStr);
                        }

                        string attrib     = Helper.GetAttribute(reader, "attrib", vars);
                        string inherits   = Helper.GetAttribute(reader, "typeinherits", vars);
                        string type       = Helper.GetAttribute(reader, "type", vars);
                        string typeattrib = Helper.GetAttribute(reader, "typeattrib", vars);

                        switch (reader.Name)
                        {
                        case "SkipNamespace":
                            if (rx != null)
                            {
                                info.skipNamespaces.Add(new NamespaceTester(rx));
                            }
                            else
                            {
                                info.skipNamespaces.Add(new NamespaceTester(name));
                            }
                            break;

                        case "ForceNamespace":
                            if (rx != null)
                            {
                                info.forceNamespaces.Add(new NamespaceTester(rx));
                            }
                            else
                            {
                                info.forceNamespaces.Add(new NamespaceTester(name));
                            }
                            break;

                        case "SkipType":
                            TypeAffectFlags skipFlags = TypeAffectFlags.SkipNone;

                            val = Helper.GetAttribute(reader, "skipMethods", vars);
                            if (val.Length > 0 && XmlConvert.ToBoolean(val))
                            {
                                skipFlags |= TypeAffectFlags.AffectMethod;
                            }

                            val = Helper.GetAttribute(reader, "skipStringHiding", vars);
                            if (val.Length > 0 && XmlConvert.ToBoolean(val))
                            {
                                skipFlags |= TypeAffectFlags.SkipStringHiding;
                            }

                            val = Helper.GetAttribute(reader, "skipFields", vars);
                            if (val.Length > 0 && XmlConvert.ToBoolean(val))
                            {
                                skipFlags |= TypeAffectFlags.AffectField;
                            }

                            val = Helper.GetAttribute(reader, "skipProperties", vars);
                            if (val.Length > 0 && XmlConvert.ToBoolean(val))
                            {
                                skipFlags |= TypeAffectFlags.AffectProperty;
                            }

                            val = Helper.GetAttribute(reader, "skipEvents", vars);
                            if (val.Length > 0 && XmlConvert.ToBoolean(val))
                            {
                                skipFlags |= TypeAffectFlags.AffectEvent;
                            }

                            if (rx != null)
                            {
                                info.skipTypes.Add(new TypeTester(rx, skipFlags, attrib, inherits, isStatic, isSerializable));
                            }
                            else
                            {
                                info.skipTypes.Add(new TypeTester(name, skipFlags, attrib, inherits, isStatic, isSerializable));
                            }
                            break;

                        case "ForceType":
                            TypeAffectFlags forceFlags = TypeAffectFlags.SkipNone;

                            val = Helper.GetAttribute(reader, "forceMethods", vars);
                            if (val.Length > 0 && XmlConvert.ToBoolean(val))
                            {
                                forceFlags |= TypeAffectFlags.AffectMethod;
                            }

                            val = Helper.GetAttribute(reader, "forceFields", vars);
                            if (val.Length > 0 && XmlConvert.ToBoolean(val))
                            {
                                forceFlags |= TypeAffectFlags.AffectField;
                            }

                            val = Helper.GetAttribute(reader, "forceProperties", vars);
                            if (val.Length > 0 && XmlConvert.ToBoolean(val))
                            {
                                forceFlags |= TypeAffectFlags.AffectProperty;
                            }

                            val = Helper.GetAttribute(reader, "forceEvents", vars);
                            if (val.Length > 0 && XmlConvert.ToBoolean(val))
                            {
                                forceFlags |= TypeAffectFlags.AffectEvent;
                            }

                            if (rx != null)
                            {
                                info.forceTypes.Add(new TypeTester(rx, forceFlags, attrib, inherits, isStatic, isSerializable));
                            }
                            else
                            {
                                info.forceTypes.Add(new TypeTester(name, forceFlags, attrib, inherits, isStatic, isSerializable));
                            }
                            break;

                        case "SkipMethod":
                            if (rx != null)
                            {
                                info.skipMethods.Add(new MethodTester(rx, type, attrib, typeattrib, inherits, isStatic));
                            }
                            else
                            {
                                info.skipMethods.Add(new MethodTester(name, type, attrib, typeattrib, inherits, isStatic));
                            }
                            break;

                        case "ForceMethod":
                            if (rx != null)
                            {
                                info.forceMethods.Add(new MethodTester(rx, type, attrib, typeattrib, inherits, isStatic));
                            }
                            else
                            {
                                info.forceMethods.Add(new MethodTester(name, type, attrib, typeattrib, inherits, isStatic));
                            }
                            break;

                        case "SkipStringHiding":
                            if (rx != null)
                            {
                                info.skipStringHiding.Add(new MethodTester(rx, type, attrib, typeattrib));
                            }
                            else
                            {
                                info.skipStringHiding.Add(new MethodTester(name, type, attrib, typeattrib));
                            }
                            break;

                        case "SkipField":
                            string decorator = Helper.GetAttribute(reader, "decorator", vars);

                            if (rx != null)
                            {
                                info.skipFields.Add(new FieldTester(rx, type, attrib, typeattrib, inherits, decorator, isStatic, isSerializable));
                            }
                            else
                            {
                                info.skipFields.Add(new FieldTester(name, type, attrib, typeattrib, inherits, decorator, isStatic, isSerializable));
                            }
                            break;

                        case "ForceField":
                            string decorator1 = Helper.GetAttribute(reader, "decorator", vars);

                            if (rx != null)
                            {
                                info.forceFields.Add(new FieldTester(rx, type, attrib, typeattrib, inherits, decorator1, isStatic, isSerializable));
                            }
                            else
                            {
                                info.forceFields.Add(new FieldTester(name, type, attrib, typeattrib, inherits, decorator1, isStatic, isSerializable));
                            }
                            break;

                        case "SkipProperty":
                            if (rx != null)
                            {
                                info.skipProperties.Add(new PropertyTester(rx, type, attrib, typeattrib));
                            }
                            else
                            {
                                info.skipProperties.Add(new PropertyTester(name, type, attrib, typeattrib));
                            }
                            break;

                        case "ForceProperty":
                            if (rx != null)
                            {
                                info.forceProperties.Add(new PropertyTester(rx, type, attrib, typeattrib));
                            }
                            else
                            {
                                info.forceProperties.Add(new PropertyTester(name, type, attrib, typeattrib));
                            }
                            break;

                        case "SkipEvent":
                            if (rx != null)
                            {
                                info.skipEvents.Add(new EventTester(rx, type, attrib, typeattrib));
                            }
                            else
                            {
                                info.skipEvents.Add(new EventTester(name, type, attrib, typeattrib));
                            }
                            break;

                        case "ForceEvent":
                            if (rx != null)
                            {
                                info.forceEvents.Add(new EventTester(rx, type, attrib, typeattrib));
                            }
                            else
                            {
                                info.forceEvents.Add(new EventTester(name, type, attrib, typeattrib));
                            }
                            break;
                        }
                    }
                    else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "Module")
                    {
                        // hit end of module element...stop reading
                        break;
                    }
                }
            }

            return(info);
        }
Пример #12
0
        internal static AssemblyInfo FromXml(Project project, XmlReader reader, Variables vars)
        {
            Debug.Assert(reader.NodeType == XmlNodeType.Element && reader.Name == "Module");

            AssemblyInfo info = new AssemblyInfo(project);

            // pull out the file attribute, but don't process anything empty
            string val = Helper.GetAttribute(reader, "file", vars);

            if (val.Length > 0)
            {
                info.LoadAssembly(val);

                if (AssemblyIsSigned(info.Definition) && project.KeyValue == null)
                {
                    throw new ApplicationException("Obfuscating a signed assembly would result in an invalid assembly:  " + info.Name + "; use the KeyValue property to set a key to use");
                }
            }
            else
            {
                throw new InvalidOperationException("Need valid file attribute.");
            }

            string isExcluded = Helper.GetAttribute(reader, "Exclude", vars);

            if ((isExcluded.Length > 0) && (isExcluded.ToLowerInvariant() == "true"))
            {
                info.Exclude = true;
            }

            if (!reader.IsEmptyElement)
            {
                while (reader.Read( ))
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        switch (reader.Name)
                        {
                        case "SkipNamespace":
                        {
                            val = Helper.GetAttribute(reader, "name", vars);
                            if (val.Length > 0)
                            {
                                info.skipNamespaces.Add(new NamespaceTester(val));
                            }
                        }
                        break;

                        case "SkipType":
                        {
                            val = Helper.GetAttribute(reader, "name", vars);
                            if (val.Length > 0)
                            {
                                string typeName = val;

                                TypeSkipFlags skipFlags = TypeSkipFlags.SkipNone;

                                val = Helper.GetAttribute(reader, "skipMethods", vars);
                                if (val.Length > 0 && XmlConvert.ToBoolean(val))
                                {
                                    skipFlags |= TypeSkipFlags.SkipMethod;
                                }

                                val = Helper.GetAttribute(reader, "skipStringHiding", vars);
                                if (val.Length > 0 && XmlConvert.ToBoolean(val))
                                {
                                    skipFlags |= TypeSkipFlags.SkipStringHiding;
                                }

                                val = Helper.GetAttribute(reader, "skipFields", vars);
                                if (val.Length > 0 && XmlConvert.ToBoolean(val))
                                {
                                    skipFlags |= TypeSkipFlags.SkipField;
                                }

                                val = Helper.GetAttribute(reader, "skipProperties", vars);
                                if (val.Length > 0 && XmlConvert.ToBoolean(val))
                                {
                                    skipFlags |= TypeSkipFlags.SkipProperty;
                                }

                                val = Helper.GetAttribute(reader, "skipEvents", vars);
                                if (val.Length > 0 && XmlConvert.ToBoolean(val))
                                {
                                    skipFlags |= TypeSkipFlags.SkipEvent;
                                }

                                info.skipTypes.Add(new TypeTester(typeName, skipFlags));
                            }
                        }
                        break;

                        case "SkipMethod":
                        {
                            val = Helper.GetAttribute(reader, "name", vars);
                            string type   = Helper.GetAttribute(reader, "type", vars);
                            string attrib = Helper.GetAttribute(reader, "attrib", vars);

                            if (val.Length > 0)
                            {
                                info.skipMethods.Add(new MethodTester(val, type, attrib));
                            }
                            else
                            {
                                val = Helper.GetAttribute(reader, "rx");
                                if (val.Length > 0)
                                {
                                    info.skipMethods.Add(new MethodTester(new Regex(val), type, attrib));
                                }
                            }
                        }
                        break;

                        case "SkipStringHiding":
                        {
                            val = Helper.GetAttribute(reader, "name", vars);
                            string type   = Helper.GetAttribute(reader, "type", vars);
                            string attrib = Helper.GetAttribute(reader, "attrib", vars);

                            if (val.Length > 0)
                            {
                                info.skipStringHiding.Add(new MethodTester(val, type, attrib));
                            }
                            else
                            {
                                val = Helper.GetAttribute(reader, "rx");
                                if (val.Length > 0)
                                {
                                    info.skipStringHiding.Add(new MethodTester(new Regex(val), type, attrib));
                                }
                            }
                        }
                        break;

                        case "SkipField":
                        {
                            val = Helper.GetAttribute(reader, "name", vars);
                            string type   = Helper.GetAttribute(reader, "type", vars);
                            string attrib = Helper.GetAttribute(reader, "attrib", vars);

                            if (val.Length > 0)
                            {
                                info.skipFields.Add(new FieldTester(val, type, attrib));
                            }
                            else
                            {
                                val = Helper.GetAttribute(reader, "rx");
                                if (val.Length > 0)
                                {
                                    info.skipFields.Add(new FieldTester(new Regex(val), type, attrib));
                                }
                            }
                        }
                        break;

                        case "SkipProperty":
                        {
                            val = Helper.GetAttribute(reader, "name", vars);
                            string type   = Helper.GetAttribute(reader, "type", vars);
                            string attrib = Helper.GetAttribute(reader, "attrib", vars);

                            if (val.Length > 0)
                            {
                                info.skipProperties.Add(new PropertyTester(val, type, attrib));
                            }
                            else
                            {
                                val = Helper.GetAttribute(reader, "rx");
                                if (val.Length > 0)
                                {
                                    info.skipProperties.Add(new PropertyTester(new Regex(val), type, attrib));
                                }
                            }
                        }
                        break;

                        case "SkipEvent":
                        {
                            val = Helper.GetAttribute(reader, "name", vars);
                            string type   = Helper.GetAttribute(reader, "type", vars);
                            string attrib = Helper.GetAttribute(reader, "attrib", vars);

                            if (val.Length > 0)
                            {
                                info.skipEvents.Add(new EventTester(val, type, attrib));
                            }
                            else
                            {
                                val = Helper.GetAttribute(reader, "rx");
                                if (val.Length > 0)
                                {
                                    info.skipEvents.Add(new EventTester(new Regex(val), type, attrib));
                                }
                            }
                        }
                        break;
                        }
                    }
                    else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "Module")
                    {
                        // hit end of module element...stop reading
                        break;
                    }
                }
            }

            return(info);
        }