Exemple #1
0
 public void MarkHelper(IDnlibDef def, IMarkerService marker, ConfuserComponent parentComp)
 {
     if (marker.IsMarked(def))
     {
         return;
     }
     if (def is MethodDef method)
     {
         method.Access = MethodAttributes.Assembly;
         if (!method.IsSpecialName && !method.IsRuntimeSpecialName && !method.DeclaringType.IsDelegate())
         {
             method.Name = this.RandomName();
         }
     }
     else if (def is FieldDef field)
     {
         field.Access = FieldAttributes.Assembly;
         if (!field.IsSpecialName && !field.IsRuntimeSpecialName)
         {
             field.Name = this.RandomName();
         }
     }
     else if (def is TypeDef type)
     {
         type.Visibility = type.DeclaringType == null ? TypeAttributes.NotPublic : TypeAttributes.NestedAssembly;
         type.Namespace  = this.RandomName();
         if (!type.IsSpecialName && !type.IsRuntimeSpecialName)
         {
             type.Name = this.RandomName();
         }
     }
     this.SetCanRename(def, false);
     this.Analyze(def);
     marker.Mark(def, parentComp);
 }
Exemple #2
0
		public void MarkHelper(IDnlibDef def, IMarkerService marker) {
			if (marker.IsMarked(def))
				return;
			if (def is MethodDef) {
				var method = (MethodDef)def;
				method.Access = MethodAttributes.Assembly;
				if (!method.IsSpecialName && !method.IsRuntimeSpecialName && !method.DeclaringType.IsDelegate())
					method.Name = RandomName();
			}
			else if (def is FieldDef) {
				var field = (FieldDef)def;
				field.Access = FieldAttributes.Assembly;
				field.Name = RandomName();
				if (!field.IsSpecialName && !field.IsRuntimeSpecialName)
					field.Name = RandomName();
			}
			else if (def is TypeDef) {
				var type = (TypeDef)def;
				type.Visibility = type.DeclaringType == null ? TypeAttributes.NotPublic : TypeAttributes.NestedAssembly;
				type.Namespace = "";
				if (!type.IsSpecialName && !type.IsRuntimeSpecialName)
					type.Name = RandomName();
			}
			SetCanRename(def, false);
			Analyze(def);
			marker.Mark(def);
		}
        private static void Inspection(ConfuserContext context)
        {
            foreach (Tuple <AssemblyRef, ModuleDefMD> dependency in context.Modules.SelectMany((ModuleDefMD module) => from asmRef in module.GetAssemblyRefs()
                                                                                               select Tuple.Create <AssemblyRef, ModuleDefMD>(asmRef, module)))
            {
                try
                {
                    context.Resolver.ResolveThrow(dependency.Item1, dependency.Item2);
                }
                catch (AssemblyResolveException ex)
                {
                    context.Logger.ErrorException("Failed to resolve dependency of '" + dependency.Item2.Name + "'.", ex);
                    throw new ConfuserException(ex);
                }
            }
            foreach (ModuleDefMD module4 in context.Modules)
            {
                StrongNameKey snKey = context.Annotations.Get <StrongNameKey>(module4, Marker.SNKey, null);
                if (snKey == null && module4.IsStrongNameSigned)
                {
                    context.Logger.LogFormat("[{0}] SN Key is not provided for a signed module, the output may not be working.", new object[]
                    {
                        module4.Name
                    });
                }
                else if (snKey != null && !module4.IsStrongNameSigned)
                {
                    context.Logger.LogFormat("[{0}] SN Key is provided for an unsigned module, the output may not be working.", new object[]
                    {
                        module4.Name
                    });
                }
                else if (snKey != null && module4.IsStrongNameSigned && !module4.Assembly.PublicKey.Data.SequenceEqual(snKey.PublicKey))
                {
                    context.Logger.LogFormat("[{0}] Provided SN Key and signed module's public key do not match, the output may not be working.", new object[]
                    {
                        module4.Name
                    });
                }
            }
            IMarkerService marker = context.Registry.GetService <IMarkerService>();

            foreach (ModuleDefMD module2 in context.Modules)
            {
                TypeDef modType = module2.GlobalType;
                if (modType == null)
                {
                    modType            = new TypeDefUser("", "<DarksProtector>", null);
                    modType.Attributes = dnlib.DotNet.TypeAttributes.NotPublic;
                    module2.Types.Add(modType);
                    marker.Mark(modType, null);
                }
                MethodDef cctor = modType.FindOrCreateStaticConstructor();
                if (!marker.IsMarked(cctor))
                {
                    marker.Mark(cctor, null);
                }
            }
        }
Exemple #4
0
        public static void MarkHelperStatic(IDnlibDef def, IMarkerService marker, ConfuserComponent parentComp)
        {
            if (marker.IsMarked(def))
            {
                return;
            }
            if (def is MethodDef)
            {
                var method = (MethodDef)def;
                method.Access = MethodAttributes.Assembly;
                if (!method.IsSpecialName && !method.IsRuntimeSpecialName && !method.DeclaringType.IsDelegate())
                {
                    method.Name = RandomNameStatic();
                }
            }
            else if (def is FieldDef)
            {
                var field = (FieldDef)def;
                field.Access = FieldAttributes.Assembly;
                if (!field.IsSpecialName && !field.IsRuntimeSpecialName)
                {
                    field.Name = RandomNameStatic();
                }
            }
            else if (def is TypeDef)
            {
                var type = (TypeDef)def;
                type.Visibility = type.DeclaringType == null ? TypeAttributes.NotPublic : TypeAttributes.NestedAssembly;
                type.Namespace  = RandomNameStatic();
                if (!type.IsSpecialName && !type.IsRuntimeSpecialName)
                {
                    type.Name = RandomNameStatic();
                }
            }

            marker.Mark(def, parentComp);
        }
        // Token: 0x0600010C RID: 268 RVA: 0x000093F8 File Offset: 0x000075F8
        private static void Inspection(ConfuserContext context)
        {
            context.Logger.Info("Resolving dependencies...");
            foreach (Tuple <AssemblyRef, ModuleDefMD> dependency in context.Modules.SelectMany((ModuleDefMD module) => from asmRef in module.GetAssemblyRefs()
                                                                                               select Tuple.Create <AssemblyRef, ModuleDefMD>(asmRef, module)))
            {
                try
                {
                    context.Resolver.ResolveThrow(dependency.Item1, dependency.Item2);
                }
                catch (AssemblyResolveException ex)
                {
                    context.Logger.ErrorException("Failed to resolve dependency of '" + dependency.Item2.Name + "'.", ex);
                    throw new ConfuserException(ex);
                }
            }
            context.Logger.Debug("Checking Strong Name...");
            foreach (ModuleDefMD module4 in context.Modules)
            {
                StrongNameKey snKey = context.Annotations.Get <StrongNameKey>(module4, Marker.SNKey, null);
                if (snKey == null && module4.IsStrongNameSigned)
                {
                    context.Logger.WarnFormat("[{0}] SN Key is not provided for a signed module, the output may not be working.", new object[]
                    {
                        module4.Name
                    });
                }
                else if (snKey != null && !module4.IsStrongNameSigned)
                {
                    context.Logger.WarnFormat("[{0}] SN Key is provided for an unsigned module, the output may not be working.", new object[]
                    {
                        module4.Name
                    });
                }
                else if (snKey != null && module4.IsStrongNameSigned && !module4.Assembly.PublicKey.Data.SequenceEqual(snKey.PublicKey))
                {
                    context.Logger.WarnFormat("[{0}] Provided SN Key and signed module's public key do not match, the output may not be working.", new object[]
                    {
                        module4.Name
                    });
                }
            }
            IMarkerService marker = context.Registry.GetService <IMarkerService>();

            context.Logger.Debug("Creating global .cctors...");
            foreach (ModuleDefMD module2 in context.Modules)
            {
                TypeDef modType = module2.GlobalType;
                if (modType == null)
                {
                    modType            = new TypeDefUser("", "<Bed>", null);
                    modType.Attributes = dnlib.DotNet.TypeAttributes.NotPublic;
                    module2.Types.Add(modType);
                    marker.Mark(modType, null);
                }
                MethodDef cctor = modType.FindOrCreateStaticConstructor();
                if (!marker.IsMarked(cctor))
                {
                    marker.Mark(cctor, null);
                }
            }
            context.Logger.Debug("Watermarking...");
            foreach (ModuleDefMD module3 in context.Modules)
            {
                TypeRef     attrRef  = module3.CorLibTypes.GetTypeRef("System", "Attribute");
                TypeDefUser attrType = new TypeDefUser("", "Beds-Protector", attrRef);
                module3.Types.Add(attrType);
                marker.Mark(attrType, null);
                MethodDefUser ctor = new MethodDefUser(".ctor", MethodSig.CreateInstance(module3.CorLibTypes.Void, module3.CorLibTypes.String), dnlib.DotNet.MethodImplAttributes.IL, dnlib.DotNet.MethodAttributes.FamANDAssem | dnlib.DotNet.MethodAttributes.Family | dnlib.DotNet.MethodAttributes.HideBySig | dnlib.DotNet.MethodAttributes.SpecialName | dnlib.DotNet.MethodAttributes.RTSpecialName);
                ctor.Body          = new CilBody();
                ctor.Body.MaxStack = 1;
                ctor.Body.Instructions.Add(OpCodes.Ldarg_0.ToInstruction());
                ctor.Body.Instructions.Add(OpCodes.Call.ToInstruction(new MemberRefUser(module3, ".ctor", MethodSig.CreateInstance(module3.CorLibTypes.Void), attrRef)));
                ctor.Body.Instructions.Add(OpCodes.Ret.ToInstruction());
                attrType.Methods.Add(ctor);
                marker.Mark(ctor, null);
                CustomAttribute attr = new CustomAttribute(ctor);
                attr.ConstructorArguments.Add(new CAArgument(module3.CorLibTypes.String, ConfuserEngine.Version));
                module3.CustomAttributes.Add(attr);
            }
        }