Beispiel #1
0
        public static void Obfuscate(params string[] assemblies)
        {
            if (assemblies == null || assemblies.Length == 0)
            {
                throw new ArgumentException("No assmemblies provided to obfuscate", "assemblies");
            }

            //Run the obfuscator
            CloakManager manager = new CloakManager();

            //Configure it (as necessary) - tasks etc
            manager.RegisterTask <CloakTasks.MappingTask>();
            manager.RegisterTask <CloakTasks.ObfuscationTask>();
            manager.RegisterTask <CloakTasks.OutputAssembliesTask>();
            //Create a cloaking context
            InitialisationSettings settings = new InitialisationSettings();

            settings.AssembliesToObfuscate.AddRange(assemblies);
            settings.ObfuscateAllModifiers = true;
            settings.OutputDirectory       = Path.Combine(Environment.CurrentDirectory,
                                                          "Obfuscated");
            if (!Directory.Exists(settings.OutputDirectory))
            {
                Directory.CreateDirectory(settings.OutputDirectory);
            }
            settings.Validate();
            ICloakContext cloakContext = new CloakContext(settings);

            //Run the manager
            manager.Run(cloakContext);
        }
        /// <summary>
        /// Updates the member type references.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="memberReference">The member reference.</param>
        private static void UpdateMemberTypeReferences(CloakContext context, MemberReference memberReference)
        {
            //Get the type reference for this
            TypeReference methodType = memberReference.DeclaringType;

            //Get the assembly for this
            if (methodType.Scope is AssemblyNameReference)
            {
                string assemblyName = ((AssemblyNameReference)methodType.Scope).FullName;
                //Check if this needs to be updated
                if (context.MappingGraph.IsAssemblyMappingDefined(assemblyName))
                {
                    AssemblyMapping assemblyMapping = context.MappingGraph.GetAssemblyMapping(assemblyName);
                    TypeMapping     t = assemblyMapping.GetTypeMapping(methodType);
                    if (t == null)
                    {
                        return; //No type defined
                    }
                    //Update the type name
                    if (!String.IsNullOrEmpty(t.ObfuscatedTypeName))
                    {
                        methodType.Name = t.ObfuscatedTypeName;
                    }

                    //We can't change method specifications....
                    if (memberReference is MethodSpecification)
                    {
                        MethodSpecification specification = (MethodSpecification)memberReference;
                        MethodReference     meth          = specification.GetElementMethod();
                        //Update the method name also if available
                        if (t.HasMethodMapping(meth))
                        {
                            meth.Name = t.GetObfuscatedMethodName(meth);
                        }
                    }
                    else if (memberReference is FieldReference)
                    {
                        FieldReference fr = (FieldReference)memberReference;
                        if (t.HasFieldMapping(fr))
                        {
                            memberReference.Name = t.GetObfuscatedFieldName(fr);
                        }
                    }
                    else if (memberReference is MethodReference) //Is this ever used?? Used to be just an else without if
                    {
                        MethodReference mr = (MethodReference)memberReference;
                        //Update the method name also if available
                        if (t.HasMethodMapping(mr))
                        {
                            memberReference.Name = t.GetObfuscatedMethodName(mr);
                        }
                    }
                }
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            //Basic parsing of arguments for now
            var parser = new CommandLineArgumentParser();
            parser.Parse(args);

            //Create a cloak manager
            var manager = new CloakManager();
            //Create a cloaking context
            var cloakContext = new CloakContext(parser.Settings);
            //Run the manager
            manager.Run(cloakContext);
        }
    public void Execute()
    {
        LoggerFactory.LogInfo  = LogInfo;
        LoggerFactory.LogWarn  = LogWarning;
        LoggerFactory.LogError = LogError;

        var settings = new InitialisationSettings(Config);

        var manager = new CloakManager();

        var cloakContext = new CloakContext(settings, ModuleDefinition);

        manager.Run(cloakContext);
    }
        private static void UpdateMethodReferences(CloakContext context, MethodDefinition methodDefinition)
        {
            if (methodDefinition.HasBody)
            {
                foreach (Instruction instruction in methodDefinition.Body.Instructions)
                {
                    //Find the call statement
                    switch (instruction.OpCode.Name)
                    {
                    case "call":
                    case "callvirt":
                    case "newobj":
                        Log.Debug("Discovered {0} {1} ({2})", instruction.OpCode.Name, instruction.Operand, instruction.Operand.GetType().Name);

                        //Look at the operand
                        if (instruction.Operand is GenericInstanceMethod)     //We do this one first due to inheritance
                        {
                            GenericInstanceMethod genericInstanceMethod =
                                (GenericInstanceMethod)instruction.Operand;
                            //Update the standard naming
                            UpdateMemberTypeReferences(context, genericInstanceMethod);
                            //Update the generic types
                            foreach (TypeReference tr in genericInstanceMethod.GenericArguments)
                            {
                                UpdateTypeReferences(context, tr);
                            }
                        }
                        else if (instruction.Operand is MethodReference)
                        {
                            MethodReference methodReference = (MethodReference)instruction.Operand;
                            //Update the standard naming
                            UpdateMemberTypeReferences(context, methodReference);
                        }

                        break;

                    case "stfld":
                    case "ldfld":
                        Log.Debug("Discovered {0} {1} ({2})", instruction.OpCode.Name, instruction.Operand, instruction.Operand.GetType().Name);
                        //Look at the operand
                        FieldReference fieldReference = instruction.Operand as FieldReference;
                        if (fieldReference != null)
                        {
                            UpdateMemberTypeReferences(context, fieldReference);
                        }
                        break;
                    }
                }
            }
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            //Basic parsing of arguments for now
            var parser = new CommandLineArgumentParser();

            parser.Parse(args);

            //Create a cloak manager
            var manager = new CloakManager();
            //Create a cloaking context
            var cloakContext = new CloakContext(parser.Settings);

            //Run the manager
            manager.Run(cloakContext);
        }
 /// <summary>
 /// Updates the type references.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="typeReference">The type reference.</param>
 private static void UpdateTypeReferences(CloakContext context, TypeReference typeReference)
 {
     //Get the assembly for this
     if (typeReference.Scope is AssemblyNameReference)
     {
         string assemblyName = ((AssemblyNameReference)typeReference.Scope).FullName;
         //Check if this needs to be updated
         if (context.MappingGraph.IsAssemblyMappingDefined(assemblyName))
         {
             AssemblyMapping assemblyMapping = context.MappingGraph.GetAssemblyMapping(assemblyName);
             TypeMapping     t = assemblyMapping.GetTypeMapping(typeReference);
             if (t == null)
             {
                 return; //No type defined
             }
             //Update the type name
             if (!String.IsNullOrEmpty(t.ObfuscatedTypeName))
             {
                 typeReference.Name = t.ObfuscatedTypeName;
             }
         }
     }
 }
        public static void Obfuscate(params string[] assemblies)
        {
            if (assemblies == null || assemblies.Length == 0)
                throw new ArgumentException("No assmemblies provided to obfuscate", "assemblies");

            //Run the obfuscator
            CloakManager manager = new CloakManager();
            //Configure it (as necessary) - tasks etc
            manager.RegisterTask<CloakTasks.MappingTask>();
            manager.RegisterTask<CloakTasks.ObfuscationTask>();
            //Create a cloaking context
            InitialisationSettings settings = new InitialisationSettings();
            settings.AssembliesToObfuscate.AddRange(assemblies);
            settings.ObfuscateAllModifiers = true;
            settings.OutputDirectory = Path.Combine(Environment.CurrentDirectory,
                                                    "Obfuscated");
            if (!Directory.Exists(settings.OutputDirectory))
                Directory.CreateDirectory(settings.OutputDirectory);
            settings.Validate();
            ICloakContext cloakContext = new CloakContext(settings);
            //Run the manager
            manager.Run(cloakContext);
        }
 public StringEncryptionTask(CloakContext context)
 {
     this.context = context;
     random       = new Random();
 }
Beispiel #10
0
 public ConfuseDecompilationTask(CloakContext context, ConfusionMethod method)
 {
     this.context = context;
     this.method  = method;
 }
Beispiel #11
0
 public ConfuseDecompilationTask(CloakContext context)
     : this(context, ConfusionMethod.InvalidIl)
 {
 }
Beispiel #12
0
 public SimplifyTask(CloakContext context)
 {
     this.context = context;
 }
 public SupressIldasmTask(CloakContext context)
 {
     this.context = context;
 }
 public ObfuscationTask(CloakContext context)
 {
     this.context = context;
 }
Beispiel #15
0
 public OptimizeTask(CloakContext context)
 {
     this.context = context;
 }
 public MappingTask(CloakContext context)
 {
     this.context = context;
 }