コード例 #1
0
        IEnumerable <FieldDef> getPossibleFields(TypeDef type)
        {
            var typeToFields = new TypeDefDict <List <FieldDef> >();

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

            foreach (var list in typeToFields.getValues())
            {
                if (list.Count == 1)
                {
                    yield return(list[0]);
                }
            }
        }
コード例 #2
0
 public bool exists(IMethod method)
 {
     if (method == null)
     {
         return(false);
     }
     if (method.DeclaringType != null && types.find(method.DeclaringType))
     {
         return(true);
     }
     return(methods.find(method));
 }
コード例 #3
0
        FieldDef getNewField(IField structField, IField oldFieldRef)
        {
            var fieldsDict = typeToFieldsDict.find(structField.DeclaringType);

            if (fieldsDict == null)
            {
                throw new ApplicationException("Could not find structField declaringType");
            }
            var newField = fieldsDict.find(oldFieldRef);

            if (newField == null)
            {
                throw new ApplicationException("Could not find new field");
            }
            return(newField);
        }
コード例 #4
0
 public MType getType(IType typeRef)
 {
     return(typeRefToType.find(typeRef));
 }
コード例 #5
0
        public void deobfuscate(Blocks blocks)
        {
            var instrsToRemove = new List <int>();

            foreach (var block in blocks.MethodBlocks.getAllBlocks())
            {
                instrsToRemove.Clear();
                var instrs = block.Instructions;
                for (int i = 0; i < instrs.Count; i++)
                {
                    var           instr = instrs[i];
                    int           indexToRemove;
                    ITypeDefOrRef type;
                    Local         local = null;

                    if (instr.OpCode.Code == Code.Newobj)
                    {
                        if (i + 1 >= instrs.Count)
                        {
                            continue;
                        }
                        var ctor = instr.Operand as IMethod;
                        if (ctor == null || ctor.DeclaringType == null)
                        {
                            continue;
                        }
                        if (ctor.Name != ".ctor")
                        {
                            continue;
                        }

                        var next = instrs[i + 1];
                        if (!next.isStloc() && !next.isLeave() && next.OpCode.Code != Code.Pop)
                        {
                            continue;
                        }

                        indexToRemove = i;
                        type          = ctor.DeclaringType;
                        if (next.isStloc())
                        {
                            local = Instr.getLocalVar(blocks.Locals, next);
                        }
                    }
                    else if (instr.OpCode.Code == Code.Ldfld)
                    {
                        if (i == 0)
                        {
                            continue;
                        }
                        var ldloc = instrs[i - 1];
                        if (!ldloc.isLdloc())
                        {
                            continue;
                        }

                        var field = instr.Operand as IField;
                        if (field == null || field.DeclaringType == null)
                        {
                            continue;
                        }

                        indexToRemove = i;
                        type          = field.DeclaringType;
                        local         = Instr.getLocalVar(blocks.Locals, ldloc);
                    }
                    else
                    {
                        continue;
                    }

                    if (type == null)
                    {
                        continue;
                    }
                    var info = typeToInfo.find(type);
                    if (info == null)
                    {
                        continue;
                    }

                    info.referenced = true;
                    instrsToRemove.Add(indexToRemove);
                    if (local != null)
                    {
                        local.Type = info.localType;
                    }
                }
                if (instrsToRemove.Count > 0)
                {
                    block.remove(instrsToRemove);
                }
            }
        }
コード例 #6
0
        IEnumerable<FieldDef> getPossibleFields(TypeDef type)
        {
            var typeToFields = new TypeDefDict<List<FieldDef>>();
            foreach (var field in type.Fields) {
                if (field.Attributes != FieldAttributes.Private)
                    continue;
                var fieldType = DotNetUtils.getType(module, field.FieldSig.GetFieldType());
                if (fieldType == null)
                    continue;
                if (!checkBaseType(fieldType))
                    continue;
                var list = typeToFields.find(fieldType);
                if (list == null)
                    typeToFields.add(fieldType, list = new List<FieldDef>());
                list.Add(field);
            }

            foreach (var list in typeToFields.getValues()) {
                if (list.Count == 1)
                    yield return list[0];
            }
        }
コード例 #7
0
 public bool checkCanInline(MethodDef method)
 {
     return(methodsTypes.find(method.DeclaringType));
 }