Example #1
0
 void ProcessMember(IDnlibDef member, Rules rules, ProtectionSettingsStack stack)
 {
     stack.Push(ProcessAttributes(ReadObfuscationAttributes(member)));
     ApplySettings(member, rules, stack.GetInfos());
     ProcessBody(member as MethodDef, rules, stack);
     stack.Pop();
 }
Example #2
0
        void ProcessModule(ModuleDefMD module, Rules rules, string snKeyPath, string snKeyPass,
                           List <ObfuscationAttributeInfo> settingAttrs,
                           Dictionary <Regex, List <ObfuscationAttributeInfo> > namespaceAttrs)
        {
            context.Annotations.Set(module, SNKey, LoadSNKey(context, snKeyPath == null ? null : Path.Combine(project.BaseDirectory, snKeyPath), snKeyPass));

            var moduleStack = new ProtectionSettingsStack();

            moduleStack.Push(ProcessAttributes(settingAttrs));
            ApplySettings(module, rules, moduleStack.GetInfos());

            var nsSettings = namespaceAttrs.ToDictionary(kvp => kvp.Key, kvp => {
                var nsStack = new ProtectionSettingsStack(moduleStack);
                nsStack.Push(ProcessAttributes(kvp.Value));
                return(nsStack);
            });

            foreach (var type in module.Types)
            {
                var typeStack = MatchNamespace(nsSettings, type.Namespace) ?? moduleStack;
                typeStack.Push(ProcessAttributes(ReadObfuscationAttributes(type)));

                ApplySettings(type, rules, typeStack.GetInfos());
                ProcessTypeMembers(type, rules, typeStack);

                typeStack.Pop();
            }
        }
        void ProcessTypeMembers(TypeDef type, ProtectionSettingsStack stack)
        {
            foreach (var nestedType in type.NestedTypes) {
                stack.Push(ProcessAttributes(ReadObfuscationAttributes(nestedType)));

                ApplySettings(nestedType, stack.GetInfos());
                ProcessTypeMembers(nestedType, stack);

                stack.Pop();
            }

            foreach (var prop in type.Properties) {
                stack.Push(ProcessAttributes(ReadObfuscationAttributes(prop)));

                ApplySettings(prop, stack.GetInfos());
                if (prop.GetMethod != null) {
                    ProcessMember(prop.GetMethod, stack);
                }
                if (prop.SetMethod != null) {
                    ProcessMember(prop.SetMethod, stack);
                }
                foreach (var m in prop.OtherMethods)
                    ProcessMember(m, stack);

                stack.Pop();
            }

            foreach (var evt in type.Events) {
                stack.Push(ProcessAttributes(ReadObfuscationAttributes(evt)));

                ApplySettings(evt, stack.GetInfos());
                if (evt.AddMethod != null) {
                    ProcessMember(evt.AddMethod, stack);
                }
                if (evt.RemoveMethod != null) {
                    ProcessMember(evt.RemoveMethod, stack);
                }
                if (evt.InvokeMethod != null) {
                    ProcessMember(evt.InvokeMethod, stack);
                }
                foreach (var m in evt.OtherMethods)
                    ProcessMember(m, stack);

                stack.Pop();
            }

            foreach (var method in type.Methods) {
                if (method.SemanticsAttributes == 0)
                    ProcessMember(method, stack);
            }

            foreach (var field in type.Fields) {
                ProcessMember(field, stack);
            }
        }
        void ProcessModule(ModuleDefMD module, string snKeyPath, string snKeyPass,
		                   List<ObfuscationAttributeInfo> settingAttrs,
		                   Dictionary<Regex, List<ObfuscationAttributeInfo>> namespaceAttrs)
        {
            context.Annotations.Set(module, SNKey, LoadSNKey(context, snKeyPath, snKeyPass));

            var moduleStack = new ProtectionSettingsStack();
            moduleStack.Push(ProcessAttributes(settingAttrs));
            ApplySettings(module, moduleStack.GetInfos());

            var nsSettings = namespaceAttrs.ToDictionary(kvp => kvp.Key, kvp => {
                var nsStack = new ProtectionSettingsStack(moduleStack);
                nsStack.Push(ProcessAttributes(kvp.Value));
                return nsStack;
            });

            foreach (var type in module.Types) {
                var typeStack = MatchNamespace(nsSettings, type.Namespace) ?? moduleStack;
                typeStack.Push(ProcessAttributes(ReadObfuscationAttributes(type)));

                ApplySettings(type, typeStack.GetInfos());
                ProcessTypeMembers(type, typeStack);

                typeStack.Pop();
            }
        }
 void ProcessMember(IDnlibDef member, ProtectionSettingsStack stack)
 {
     stack.Push(ProcessAttributes(ReadObfuscationAttributes(member)));
     ApplySettings(member, stack.GetInfos());
     stack.Pop();
 }
Example #6
0
        void ProcessTypeMembers(TypeDef type, Rules rules, ProtectionSettingsStack stack)
        {
            foreach (var nestedType in type.NestedTypes)
            {
                stack.Push(ProcessAttributes(ReadObfuscationAttributes(nestedType)));

                ApplySettings(nestedType, rules, stack.GetInfos());
                ProcessTypeMembers(nestedType, rules, stack);

                stack.Pop();
            }

            foreach (var prop in type.Properties)
            {
                stack.Push(ProcessAttributes(ReadObfuscationAttributes(prop)));

                ApplySettings(prop, rules, stack.GetInfos());
                if (prop.GetMethod != null)
                {
                    ProcessMember(prop.GetMethod, rules, stack);
                }
                if (prop.SetMethod != null)
                {
                    ProcessMember(prop.SetMethod, rules, stack);
                }
                foreach (var m in prop.OtherMethods)
                {
                    ProcessMember(m, rules, stack);
                }

                stack.Pop();
            }

            foreach (var evt in type.Events)
            {
                stack.Push(ProcessAttributes(ReadObfuscationAttributes(evt)));

                ApplySettings(evt, rules, stack.GetInfos());
                if (evt.AddMethod != null)
                {
                    ProcessMember(evt.AddMethod, rules, stack);
                }
                if (evt.RemoveMethod != null)
                {
                    ProcessMember(evt.RemoveMethod, rules, stack);
                }
                if (evt.InvokeMethod != null)
                {
                    ProcessMember(evt.InvokeMethod, rules, stack);
                }
                foreach (var m in evt.OtherMethods)
                {
                    ProcessMember(m, rules, stack);
                }

                stack.Pop();
            }

            foreach (var method in type.Methods)
            {
                if (method.SemanticsAttributes == 0)
                {
                    ProcessMember(method, rules, stack);
                }
            }

            foreach (var field in type.Fields)
            {
                ProcessMember(field, rules, stack);
            }
        }
Example #7
0
 void ProcessMember(IDnlibDef member, ProtectionSettingsStack stack)
 {
     stack.Push(ProcessAttributes(ReadObfuscationAttributes(member)));
     ApplySettings(member, stack.GetInfos());
     stack.Pop();
 }