コード例 #1
0
ファイル: FieldsRestorer.cs プロジェクト: kidhudi/de4dot
        public void initialize()
        {
            foreach (var kv in getMovedTypes())
            {
                var structType = kv.Key;
                structToOwners.add(structType, kv.Value);

                foreach (var ownerType in kv.Value)
                {
                    foreach (var ownerField in ownerType.Fields)
                    {
                        if (DotNetUtils.getType(module, ownerField.FieldType) != structType)
                        {
                            continue;
                        }
                        structFieldsToFix.add(ownerField, true);
                        break;
                    }

                    var fieldsDict = new FieldDefinitionAndDeclaringTypeDict <FieldDefinition>();
                    typeToFieldsDict.add(ownerType, fieldsDict);
                    foreach (var structField in structType.Fields)
                    {
                        var newField = DotNetUtils.createFieldDefinition(structField.Name, structField.Attributes, structField.FieldType);
                        ownerType.Fields.Add(newField);
                        fieldsDict.add(structField, newField);
                    }
                }
            }
        }
コード例 #2
0
ファイル: FieldsRestorer.cs プロジェクト: kidhudi/de4dot
        IEnumerable <FieldDefinition> getPossibleFields(TypeDefinition type)
        {
            var typeToFields = new TypeDefinitionDict <List <FieldDefinition> >();

            foreach (var field in type.Fields)
            {
                if (field.Attributes != FieldAttributes.Private)
                {
                    continue;
                }
                var fieldType = DotNetUtils.getType(module, field.FieldType);
                if (fieldType == null)
                {
                    continue;
                }
                if (!checkBaseType(fieldType))
                {
                    continue;
                }
                var list = typeToFields.find(fieldType);
                if (list == null)
                {
                    typeToFields.add(fieldType, list = new List <FieldDefinition>());
                }
                list.Add(field);
            }

            foreach (var list in typeToFields.getValues())
            {
                if (list.Count == 1)
                {
                    yield return(list[0]);
                }
            }
        }
コード例 #3
0
 void initializeMethodsTypes()
 {
     foreach (var type in module.GetTypes())
     {
         if (checkMethodsType(type))
         {
             methodsTypes.add(type, true);
         }
     }
 }
コード例 #4
0
ファイル: MModule.cs プロジェクト: kidhudi/de4dot
 void initTokenToType()
 {
     moduleType = DotNetUtils.getModuleType(moduleDefinition);
     foreach (var typeDefinition in moduleDefinition.GetTypes())
     {
         int  token = typeDefinition.MetadataToken.ToInt32();
         Type type;
         try {
             type = module.ResolveType(token);
         }
         catch {
             tokenToType[token] = null;
             typeReferenceToType.add(typeDefinition, null);
             continue;
         }
         var mtype = new MType(type, typeDefinition);
         tokenToType[token] = mtype;
         typeReferenceToType.add(typeDefinition, mtype);
     }
 }
コード例 #5
0
        void initialize(TypeDefinition type)
        {
            if (type.HasEvents || type.HasProperties)
            {
                return;
            }

            if (!type.IsValueType)
            {
                return;
            }
            if (type.Methods.Count != 1)
            {
                return;
            }
            var ctor = type.Methods[0];

            if (ctor.Name != ".ctor" || ctor.Body == null || ctor.IsStatic)
            {
                return;
            }
            if (ctor.Parameters.Count != 1)
            {
                return;
            }
            var ctorParam = ctor.Parameters[0];

            if (type.Fields.Count != 1)
            {
                return;
            }
            var typeField = type.Fields[0];

            if (typeField.IsStatic)
            {
                return;
            }
            if (!MemberReferenceHelper.compareTypes(ctorParam.ParameterType, typeField.FieldType))
            {
                return;
            }

            typeToInfo.add(ctor.DeclaringType, new Info(ctor.DeclaringType, typeField.FieldType));
        }
コード例 #6
0
        public TypeDefinitionDict <bool> getInlinedTypes(IEnumerable <MethodDefinition> unusedMethods)
        {
            var unused = new MethodDefinitionAndDeclaringTypeDict <bool>();

            foreach (var method in unusedMethods)
            {
                unused.add(method, true);
            }

            var types = new TypeDefinitionDict <bool>();

            foreach (var type in methodsTypes.getKeys())
            {
                if (checkAllMethodsUnused(unused, type))
                {
                    types.add(type, true);
                }
            }
            return(types);
        }
コード例 #7
0
        public TypeDefinitionDict<bool> getInlinedTypes(IEnumerable<MethodDefinition> unusedMethods)
        {
            var unused = new MethodDefinitionAndDeclaringTypeDict<bool>();
            foreach (var method in unusedMethods)
                unused.add(method, true);

            var types = new TypeDefinitionDict<bool>();
            foreach (var type in methodsTypes.getKeys()) {
                if (checkAllMethodsUnused(unused, type))
                    types.add(type, true);
            }
            return types;
        }
コード例 #8
0
ファイル: FieldsRestorer.cs プロジェクト: ByteCatcher/de4dot
        IEnumerable<FieldDefinition> getPossibleFields(TypeDefinition type)
        {
            var typeToFields = new TypeDefinitionDict<List<FieldDefinition>>();
            foreach (var field in type.Fields) {
                if (field.Attributes != FieldAttributes.Private)
                    continue;
                var fieldType = DotNetUtils.getType(module, field.FieldType);
                if (fieldType == null || !fieldType.IsValueType)
                    continue;
                var list = typeToFields.find(fieldType);
                if (list == null)
                    typeToFields.add(fieldType, list = new List<FieldDefinition>());
                list.Add(field);
            }

            foreach (var list in typeToFields.getValues()) {
                if (list.Count == 1)
                    yield return list[0];
            }
        }
コード例 #9
0
ファイル: MethodCollection.cs プロジェクト: kidhudi/de4dot
 public void add(TypeDefinition type)
 {
     types.add(type, true);
 }