Ejemplo n.º 1
0
        public virtual bool Include(AssemblyMapping assembly)
        {
            if (assembly.Namespaces.Any() && Include(assembly.Difference))
                return true;

            return assembly.Namespaces.Any(Include);
        }
Ejemplo n.º 2
0
        public override void Visit(AssemblyMapping assembly)
        {
            _diffRecorder.CancellationToken.ThrowIfCancellationRequested();

            PushApi(assembly);
            base.Visit(assembly);
            PopApi();
        }
Ejemplo n.º 3
0
        public virtual bool Include(AssemblyMapping assembly)
        {
            if (assembly.Namespaces.Any() && Include(assembly.Difference))
            {
                return(true);
            }

            return(assembly.Namespaces.Any(Include));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Updates the member type references.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="memberReference">The member reference.</param>
        private static void UpdateMemberTypeReferences(ICloakContext 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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void RunTask()
        {
            //Go through the members and build up a mapping graph
            //If this is done then the members in the graph will be obfuscated, otherwise we'll
            //just obfuscate private members

            //Set up the mapping graph
            AssemblyMapping assemblyMapping = context.MappingGraph.AddAssembly(context.AssemblyDefinition);

            //Go through each module
            foreach (ModuleDefinition moduleDefinition in context.AssemblyDefinition.Modules)
            {
                //Go through each type
                foreach (TypeDefinition typeDefinition in moduleDefinition.GetAllTypes())
                {
                    //First of all - see if we've declared it already - if so get the existing reference
                    TypeMapping typeMapping = assemblyMapping.GetTypeMapping(typeDefinition);
                    if (typeMapping == null)
                    {
                        //We don't have it - get it
                        if (context.Settings.ObfuscateAllModifiers)
                        {
                            typeMapping = assemblyMapping.AddType(typeDefinition, context.NameManager.GenerateName(NamingTable.Type));
                        }
                        else
                        {
                            typeMapping = assemblyMapping.AddType(typeDefinition, null);
                        }
                    }

                    //Go through each method
                    foreach (MethodDefinition methodDefinition in typeDefinition.Methods)
                    {
                        MapMethod(assemblyMapping, typeDefinition, typeMapping, methodDefinition);
                    }

                    //Properties
                    foreach (PropertyDefinition propertyDefinition in typeDefinition.Properties)
                    {
                        MapProperty(assemblyMapping, typeDefinition, typeMapping, propertyDefinition);
                    }

                    //Fields
                    foreach (FieldDefinition fieldDefinition in typeDefinition.Fields)
                    {
                        MapField(typeMapping, fieldDefinition);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public static EntityManagerFactory getFactory(PersistenceContextConfig config)
        {
            AttributeConfigLoader configLoader = new AttributeConfigLoader();

            AssemblyMapping mappings = new AssemblyMapping();

            // convert names to assembly objects
            IEnumerable<Type> persistentTypes = AttributeUtils.GetTypesWithAttribute<Entity>(config.Assemblies);

            foreach (Type type in persistentTypes) {
                mappings.AddMapping (configLoader.createMapping(type));
            }

            return new EntityManagerFactory(config, mappings);
        }
Ejemplo n.º 7
0
        public override void Visit(AssemblyMapping mapping)
        {
            Debug.Assert(_differences.Count == 0);

            base.Visit(mapping);

            if (this.Settings.GroupByAssembly)
            {
                if (_differences.Count > 0)
                {
                    string header = string.Format("Compat issues with assembly {0}:", mapping.Representative.Name.Value);
                    OutputDifferences(header, _differences);
                    _totalDifferences += _differences.Count;
                    _differences.Clear();
                }
            }
        }
Ejemplo n.º 8
0
        public override void Visit(AssemblyMapping mapping)
        {
            Contract.Assert(_differences.Count == 0);

            base.Visit(mapping);

            if (this.Settings.GroupByAssembly)
            {
                if (_differences.Count > 0)
                {
                    string header = string.Format("Compat issues with assembly {0}:", mapping.Representative.Name.Value);
                    OutputDifferences(header, _differences);
                    _totalDifferences += _differences.Count;
                    _differences.Clear();
                }
            }
        }
Ejemplo n.º 9
0
        public virtual DifferenceType Diff <T>(IDifferences differences, ElementMapping <T> mapping) where T : class
        {
            if (mapping.ElementCount < 2)
            {
                return(DifferenceType.Unchanged);
            }

            MemberMapping member = mapping as MemberMapping;

            if (member != null)
            {
                return(Diff(differences, member));
            }

            TypeMapping type = mapping as TypeMapping;

            if (type != null)
            {
                return(Diff(differences, type));
            }

            NamespaceMapping ns = mapping as NamespaceMapping;

            if (ns != null)
            {
                return(Diff(differences, ns));
            }

            AssemblyMapping asm = mapping as AssemblyMapping;

            if (asm != null)
            {
                return(Diff(differences, asm));
            }

            AssemblySetMapping asmSet = mapping as AssemblySetMapping;

            if (asmSet != null)
            {
                return(Diff(differences, asmSet));
            }

            return(DifferenceType.Unknown);
        }
Ejemplo n.º 10
0
        public override void Visit(AssemblyMapping assembly)
        {
            Contract.Assert(this.Settings.GroupByAssembly);

            _syntaxWriter.WriteKeyword("assembly");
            _syntaxWriter.WriteSpace();
            _syntaxWriter.WriteIdentifier(assembly.Representative.Name.Value);
            using (_syntaxWriter.StartBraceBlock())
            {
                if (this.IncludeAssemblyProperties)
                {
                    var attributes = assembly.Attributes.Where(e => DiffFilter.Include(e.Difference));
                    var properties = assembly.Properties.Where(e => DiffFilter.Include(e.Difference));

                    Visit(properties);
                    Visit(attributes);
                }
                base.Visit(assembly);
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Updates the type references.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="typeReference">The type reference.</param>
 private static void UpdateTypeReferences(ICloakContext 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 virtual void Visit(AssemblyMapping assembly)
 {
     Visit(assembly.Namespaces);
 }
 public virtual string GetAssemblyKey(AssemblyMapping assembly)
 {
     return(assembly.Representative.Name.Value);
 }
Ejemplo n.º 14
0
 public override void Visit(AssemblyMapping mapping)
 {
     Visit(mapping.Differences);
     base.Visit(mapping);
 }
Ejemplo n.º 15
0
        private void MapMethod(AssemblyMapping assemblyMapping, TypeDefinition typeDefinition, TypeMapping typeMapping, MethodDefinition methodDefinition)
        {
            //First of all - check if we've obfuscated it already - if we have then don't bother
            if (typeMapping.HasMethodBeenObfuscated(methodDefinition.Name))
            {
                return;
            }

            //We won't do constructors - causes issues
            if (methodDefinition.IsConstructor)
            {
                return;
            }

            //We haven't - let's work out the obfuscated name
            if (context.Settings.ObfuscateAllModifiers)
            {
                //Take into account whether this is overriden, or an interface implementation
                if (methodDefinition.IsVirtual)
                {
                    //We handle this differently - rather than creating a new name each time we need to reuse any already generated names
                    //We do this by firstly finding the root interface or object
                    TypeDefinition baseType = FindBaseTypeDeclaration(typeDefinition, methodDefinition);
                    if (baseType != null)
                    {
                        //Find it in the mappings
                        TypeMapping baseTypeMapping = assemblyMapping.GetTypeMapping(baseType);
                        if (baseTypeMapping != null)
                        {
                            //We found the type mapping - look up the name it uses for this method and use that
                            if (baseTypeMapping.HasMethodMapping(methodDefinition))
                            {
                                typeMapping.AddMethodMapping(methodDefinition, baseTypeMapping.GetObfuscatedMethodName(methodDefinition));
                            }
                            else
                            {
                                //That's strange... we shouldn't get into here - but if we ever do then
                                //we'll add the type mapping into both
                                string obfuscatedName = context.NameManager.GenerateName(NamingTable.Method);
                                typeMapping.AddMethodMapping(methodDefinition, obfuscatedName);
                                baseTypeMapping.AddMethodMapping(methodDefinition, obfuscatedName);
                            }
                        }
                        else
                        {
                            //Otherwise add it into our list manually
                            //at the base level first off
                            baseTypeMapping = assemblyMapping.AddType(baseType,
                                                                      context.NameManager.GenerateName(NamingTable.Type));
                            string obfuscatedName = context.NameManager.GenerateName(NamingTable.Method);
                            baseTypeMapping.AddMethodMapping(methodDefinition, obfuscatedName);
                            //Now at our implemented level
                            typeMapping.AddMethodMapping(methodDefinition, obfuscatedName);
                        }
                    }
                    else
                    {
                        //We must be at the base already - add normally
                        typeMapping.AddMethodMapping(methodDefinition,
                                                     context.NameManager.GenerateName(NamingTable.Method));
                    }
                }
                else //Add normally
                {
                    typeMapping.AddMethodMapping(methodDefinition,
                                                 context.NameManager.GenerateName(NamingTable.Method));
                }
            }
            else if (methodDefinition.IsPrivate)
            {
                typeMapping.AddMethodMapping(methodDefinition, context.NameManager.GenerateName(NamingTable.Method));
            }
        }
Ejemplo n.º 16
0
 public virtual void Visit(AssemblyMapping assembly)
 {
     Visit(assembly.Namespaces);
 }
Ejemplo n.º 17
0
 public virtual string GetAssemblyKey(AssemblyMapping assembly)
 {
     return assembly.Representative.Name.Value;
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Processes the assembly - goes through each member and applies a mapping.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="definition">The assembly definition.</param>
        private static void ProcessAssembly(ICloakContext context, AssemblyDefinition definition)
        {
            //Store whether to obfuscate all members
            bool obfuscateAll = context.Settings.ObfuscateAllModifiers;

            //Set up the mapping graph
            AssemblyMapping assemblyMapping = context.MappingGraph.AddAssembly(definition);

            //Get a reference to the name manager
            NameManager nameManager = context.NameManager;

            //Go through each module
            foreach (ModuleDefinition moduleDefinition in definition.Modules)
            {
                //Go through each type
                foreach (TypeDefinition typeDefinition in moduleDefinition.GetAllTypes())
                {
                    //First of all - see if we've declared it already - if so get the existing reference
                    TypeMapping typeMapping = assemblyMapping.GetTypeMapping(typeDefinition);
                    if (typeMapping == null)
                    {
                        //We don't have it - get it
                        if (obfuscateAll)
                        {
                            typeMapping = assemblyMapping.AddType(typeDefinition,
                                                                  nameManager.GenerateName(NamingTable.Type));
                        }
                        else
                        {
                            typeMapping = assemblyMapping.AddType(typeDefinition, null);
                        }
                    }

                    //Go through each method
                    foreach (MethodDefinition methodDefinition in typeDefinition.Methods)
                    {
                        //First of all - check if we've obfuscated it already - if we have then don't bother
                        if (typeMapping.HasMethodBeenObfuscated(methodDefinition.Name))
                        {
                            continue;
                        }

                        //We won't do constructors - causes issues
                        if (methodDefinition.IsConstructor)
                        {
                            continue;
                        }

                        //We haven't - let's work out the obfuscated name
                        if (obfuscateAll)
                        {
                            //Take into account whether this is overriden, or an interface implementation
                            if (methodDefinition.IsVirtual)
                            {
                                //We handle this differently - rather than creating a new name each time we need to reuse any already generated names
                                //We do this by firstly finding the root interface or object
                                TypeDefinition baseType = FindBaseTypeDeclaration(typeDefinition, methodDefinition);
                                if (baseType != null)
                                {
                                    //Find it in the mappings
                                    TypeMapping baseTypeMapping = assemblyMapping.GetTypeMapping(baseType);
                                    if (baseTypeMapping != null)
                                    {
                                        //We found the type mapping - look up the name it uses for this method and use that
                                        if (baseTypeMapping.HasMethodMapping(methodDefinition))
                                        {
                                            typeMapping.AddMethodMapping(methodDefinition, baseTypeMapping.GetObfuscatedMethodName(methodDefinition));
                                        }
                                        else
                                        {
                                            //That's strange... we shouldn't get into here - but if we ever do then
                                            //we'll add the type mapping into both
                                            string obfuscatedName = nameManager.GenerateName(NamingTable.Method);
                                            typeMapping.AddMethodMapping(methodDefinition, obfuscatedName);
                                            baseTypeMapping.AddMethodMapping(methodDefinition, obfuscatedName);
                                        }
                                    }
                                    else
                                    {
                                        //Otherwise add it into our list manually
                                        //at the base level first off
                                        baseTypeMapping = assemblyMapping.AddType(baseType,
                                                                                  nameManager.GenerateName(NamingTable.Type));
                                        string obfuscatedName = nameManager.GenerateName(NamingTable.Method);
                                        baseTypeMapping.AddMethodMapping(methodDefinition, obfuscatedName);
                                        //Now at our implemented level
                                        typeMapping.AddMethodMapping(methodDefinition, obfuscatedName);
                                    }
                                }
                                else
                                {
                                    //We must be at the base already - add normally
                                    typeMapping.AddMethodMapping(methodDefinition,
                                                                 nameManager.GenerateName(NamingTable.Method));
                                }
                            }
                            else //Add normally
                            {
                                typeMapping.AddMethodMapping(methodDefinition,
                                                             nameManager.GenerateName(NamingTable.Method));
                            }
                        }
                        else if (methodDefinition.IsPrivate)
                        {
                            typeMapping.AddMethodMapping(methodDefinition, nameManager.GenerateName(NamingTable.Method));
                        }
                    }

                    //Properties
                    foreach (PropertyDefinition propertyDefinition in typeDefinition.Properties)
                    {
                        //First of all - check if we've obfuscated it already - if we have then don't bother
                        if (typeMapping.HasPropertyBeenObfuscated(propertyDefinition.Name))
                        {
                            continue;
                        }

                        //Go through the old fashioned way
                        if (obfuscateAll)
                        {
                            if ((propertyDefinition.GetMethod != null && propertyDefinition.GetMethod.IsVirtual) ||
                                (propertyDefinition.SetMethod != null && propertyDefinition.SetMethod.IsVirtual))
                            {
                                //We handle this differently - rather than creating a new name each time we need to reuse any already generated names
                                //We do this by firstly finding the root interface or object
                                TypeDefinition baseType = FindBaseTypeDeclaration(typeDefinition, propertyDefinition);
                                if (baseType != null)
                                {
                                    //Find it in the mappings
                                    TypeMapping baseTypeMapping = assemblyMapping.GetTypeMapping(baseType);
                                    if (baseTypeMapping != null)
                                    {
                                        //We found the type mapping - look up the name it uses for this property and use that
                                        if (baseTypeMapping.HasPropertyMapping(propertyDefinition))
                                        {
                                            typeMapping.AddPropertyMapping(propertyDefinition, baseTypeMapping.GetObfuscatedPropertyName(propertyDefinition));
                                        }
                                        else
                                        {
                                            //That's strange... we shouldn't get into here - but if we ever do then
                                            //we'll add the type mapping into both
                                            string obfuscatedName = nameManager.GenerateName(NamingTable.Property);
                                            typeMapping.AddPropertyMapping(propertyDefinition, obfuscatedName);
                                            baseTypeMapping.AddPropertyMapping(propertyDefinition, obfuscatedName);
                                        }
                                    }
                                    else
                                    {
                                        //Otherwise add it into our list manually
                                        //at the base level first off
                                        baseTypeMapping = assemblyMapping.AddType(baseType,
                                                                                  nameManager.GenerateName(NamingTable.Type));
                                        string obfuscatedName = nameManager.GenerateName(NamingTable.Property);
                                        baseTypeMapping.AddPropertyMapping(propertyDefinition, obfuscatedName);
                                        //Now at our implemented level
                                        typeMapping.AddPropertyMapping(propertyDefinition, obfuscatedName);
                                    }
                                }
                                else
                                {
                                    //We must be at the base already - add normally
                                    typeMapping.AddPropertyMapping(propertyDefinition,
                                                                   nameManager.GenerateName(NamingTable.Property));
                                }
                            }
                            else
                            {
                                typeMapping.AddPropertyMapping(propertyDefinition,
                                                               nameManager.GenerateName(NamingTable.Property));
                            }
                        }
                        else if (propertyDefinition.GetMethod != null && propertyDefinition.SetMethod != null)
                        {
                            //Both parts need to be private
                            if (propertyDefinition.GetMethod.IsPrivate && propertyDefinition.SetMethod.IsPrivate)
                            {
                                typeMapping.AddPropertyMapping(propertyDefinition, nameManager.GenerateName(NamingTable.Property));
                            }
                        }
                        else if (propertyDefinition.GetMethod != null)
                        {
                            //Only the get is present - make sure it is private
                            if (propertyDefinition.GetMethod.IsPrivate)
                            {
                                typeMapping.AddPropertyMapping(propertyDefinition, nameManager.GenerateName(NamingTable.Property));
                            }
                        }
                        else if (propertyDefinition.SetMethod != null)
                        {
                            //Only the set is present - make sure it is private
                            if (propertyDefinition.SetMethod.IsPrivate)
                            {
                                typeMapping.AddPropertyMapping(propertyDefinition, nameManager.GenerateName(NamingTable.Property));
                            }
                        }
                    }

                    //Fields
                    foreach (FieldDefinition fieldDefinition in typeDefinition.Fields)
                    {
                        //First of all - check if we've obfuscated it already - if we have then don't bother
                        if (typeMapping.HasFieldBeenObfuscated(fieldDefinition.Name))
                        {
                            continue;
                        }

                        if (obfuscateAll)
                        {
                            typeMapping.AddFieldMapping(fieldDefinition, nameManager.GenerateName(NamingTable.Field));
                        }
                        else if (fieldDefinition.IsPrivate)
                        {
                            //Rename if private
                            typeMapping.AddFieldMapping(fieldDefinition, nameManager.GenerateName(NamingTable.Field));
                        }
                    }
                }
            }
        }
Ejemplo n.º 19
0
        private void MapProperty(AssemblyMapping assemblyMapping, TypeDefinition typeDefinition, TypeMapping typeMapping, PropertyDefinition propertyDefinition)
        {
            //First of all - check if we've obfuscated it already - if we have then don't bother
            if (typeMapping.HasPropertyBeenObfuscated(propertyDefinition.Name))
            {
                return;
            }

            //Go through the old fashioned way
            if (context.Settings.ObfuscateAllModifiers)
            {
                if ((propertyDefinition.GetMethod != null && propertyDefinition.GetMethod.IsVirtual) ||
                    (propertyDefinition.SetMethod != null && propertyDefinition.SetMethod.IsVirtual))
                {
                    //We handle this differently - rather than creating a new name each time we need to reuse any already generated names
                    //We do this by firstly finding the root interface or object
                    TypeDefinition baseType = FindBaseTypeDeclaration(typeDefinition, propertyDefinition);
                    if (baseType != null)
                    {
                        //Find it in the mappings
                        TypeMapping baseTypeMapping = assemblyMapping.GetTypeMapping(baseType);
                        if (baseTypeMapping != null)
                        {
                            //We found the type mapping - look up the name it uses for this property and use that
                            if (baseTypeMapping.HasPropertyMapping(propertyDefinition))
                            {
                                typeMapping.AddPropertyMapping(propertyDefinition, baseTypeMapping.GetObfuscatedPropertyName(propertyDefinition));
                            }
                            else
                            {
                                //That's strange... we shouldn't get into here - but if we ever do then
                                //we'll add the type mapping into both
                                string obfuscatedName = context.NameManager.GenerateName(NamingTable.Property);
                                typeMapping.AddPropertyMapping(propertyDefinition, obfuscatedName);
                                baseTypeMapping.AddPropertyMapping(propertyDefinition, obfuscatedName);
                            }
                        }
                        else
                        {
                            //Otherwise add it into our list manually
                            //at the base level first off
                            baseTypeMapping = assemblyMapping.AddType(baseType,
                                                                      context.NameManager.GenerateName(NamingTable.Type));
                            string obfuscatedName = context.NameManager.GenerateName(NamingTable.Property);
                            baseTypeMapping.AddPropertyMapping(propertyDefinition, obfuscatedName);
                            //Now at our implemented level
                            typeMapping.AddPropertyMapping(propertyDefinition, obfuscatedName);
                        }
                    }
                    else
                    {
                        //We must be at the base already - add normally
                        typeMapping.AddPropertyMapping(propertyDefinition,
                                                       context.NameManager.GenerateName(NamingTable.Property));
                    }
                }
                else
                {
                    typeMapping.AddPropertyMapping(propertyDefinition,
                                                   context.NameManager.GenerateName(NamingTable.Property));
                }
            }
            else if (propertyDefinition.GetMethod != null && propertyDefinition.SetMethod != null)
            {
                //Both parts need to be private
                if (propertyDefinition.GetMethod.IsPrivate && propertyDefinition.SetMethod.IsPrivate)
                {
                    typeMapping.AddPropertyMapping(propertyDefinition, context.NameManager.GenerateName(NamingTable.Property));
                }
            }
            else if (propertyDefinition.GetMethod != null)
            {
                //Only the get is present - make sure it is private
                if (propertyDefinition.GetMethod.IsPrivate)
                {
                    typeMapping.AddPropertyMapping(propertyDefinition, context.NameManager.GenerateName(NamingTable.Property));
                }
            }
            else if (propertyDefinition.SetMethod != null)
            {
                //Only the set is present - make sure it is private
                if (propertyDefinition.SetMethod.IsPrivate)
                {
                    typeMapping.AddPropertyMapping(propertyDefinition, context.NameManager.GenerateName(NamingTable.Property));
                }
            }
        }
 public override void Visit(AssemblyMapping mapping)
 {
     Visit(mapping.Differences);
     base.Visit(mapping);
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Performs obfuscation on the specified assembly.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="definition">The assembly definition.</param>
        private static void Obfuscate(ICloakContext context, AssemblyDefinition definition)
        {
            //Get the assembly mapping information (if any)
            if (context.MappingGraph.IsAssemblyMappingDefined(definition))
            {
                //Get the mapping object
                AssemblyMapping assemblyMapping = context.MappingGraph.GetAssemblyMapping(definition);

                //Go through each module
                foreach (ModuleDefinition moduleDefinition in definition.Modules)
                {
                    //Go through each type
                    foreach (TypeDefinition typeDefinition in moduleDefinition.GetAllTypes())
                    {
                        //Get the type mapping
                        TypeMapping typeMapping = assemblyMapping.GetTypeMapping(typeDefinition);
                        if (typeMapping == null)
                        {
                            continue; //There is a problem....
                        }
                        //Rename if necessary
                        if (!String.IsNullOrEmpty(typeMapping.ObfuscatedTypeName))
                        {
                            typeDefinition.Name = typeMapping.ObfuscatedTypeName;
                        }

                        //Go through each method
                        foreach (MethodDefinition methodDefinition in typeDefinition.Methods)
                        {
                            //If this is an entry method then note it
                            //bool isEntry = false;
                            //if (definition.EntryPoint != null && definition.EntryPoint.Name == methodDefinition.Name)
                            //    isEntry = true;
                            if (typeMapping.HasMethodMapping(methodDefinition))
                            {
                                methodDefinition.Name = typeMapping.GetObfuscatedMethodName(methodDefinition);
                            }

                            //Dive into the method body
                            UpdateMethodReferences(context, methodDefinition);
                            //if (isEntry)
                            //    definition.EntryPoint = methodDefinition;
                        }

                        //Properties
                        foreach (PropertyDefinition propertyDefinition in typeDefinition.Properties)
                        {
                            if (typeMapping.HasPropertyMapping(propertyDefinition))
                            {
                                propertyDefinition.Name =
                                    typeMapping.GetObfuscatedPropertyName(propertyDefinition);
                            }

                            //Dive into the method body
                            if (propertyDefinition.GetMethod != null)
                            {
                                UpdateMethodReferences(context, propertyDefinition.GetMethod);
                            }
                            if (propertyDefinition.SetMethod != null)
                            {
                                UpdateMethodReferences(context, propertyDefinition.SetMethod);
                            }
                        }

                        //Fields
                        foreach (FieldDefinition fieldDefinition in typeDefinition.Fields)
                        {
                            if (typeMapping.HasFieldMapping(fieldDefinition))
                            {
                                fieldDefinition.Name = typeMapping.GetObfuscatedFieldName(fieldDefinition);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 22
0
        public override void Visit(AssemblyMapping mapping)
        {
            Contract.Assert(_differences.Count == 0);

            base.Visit(mapping);
        }
Ejemplo n.º 23
0
 public virtual DifferenceType Diff(IDifferences differences, AssemblyMapping mapping)
 {
     return(Diff(differences, mapping[0], mapping[1]));
 }
 public bool Include(AssemblyMapping assembly)
 {
     return _baseFilter.Include(assembly) && assembly.Namespaces.Any(Include);
 }
Ejemplo n.º 25
0
 public bool Include(AssemblyMapping assembly)
 {
     return(_baseFilter.Include(assembly) && assembly.Namespaces.Any(Include));
 }
Ejemplo n.º 26
0
 public EntityManagerFactory(PersistenceContextConfig config, AssemblyMapping mappings)
 {
     this.config = config;
     this.mappings = mappings;
 }