Esempio n. 1
0
        public TypeDef resolveOther(TypeReference type)
        {
            if (type == null)
            {
                return(null);
            }
            type = type.GetElementType();

            TypeDef typeDef;

            if (typeToTypeDefDict.tryGetValue(type, out typeDef))
            {
                return(typeDef);
            }

            var typeDefinition = deobfuscatorContext.resolve(type);

            if (typeDefinition == null)
            {
                typeToTypeDefDict.tryGetSimilarValue(type, out typeDef);
                typeToTypeDefDict[type] = typeDef;
                return(typeDef);
            }

            if (typeToTypeDefDict.tryGetValue(typeDefinition, out typeDef))
            {
                typeToTypeDefDict[type] = typeDef;
                return(typeDef);
            }

            typeToTypeDefDict[type]           = null;   // In case of a circular reference
            typeToTypeDefDict[typeDefinition] = null;

            typeDef = new TypeDef(typeDefinition, null, 0);
            typeDef.addMembers();
            foreach (var iface in typeDef.TypeDefinition.Interfaces)
            {
                var ifaceDef = resolveOther(iface);
                if (ifaceDef == null)
                {
                    continue;
                }
                typeDef.addInterface(ifaceDef, iface);
            }
            var baseDef = resolveOther(typeDef.TypeDefinition.BaseType);

            if (baseDef != null)
            {
                typeDef.addBaseType(baseDef, typeDef.TypeDefinition.BaseType);
            }

            typeToTypeDefDict[type] = typeDef;
            if (type != typeDefinition)
            {
                typeToTypeDefDict[typeDefinition] = typeDef;
            }
            return(typeDef);
        }
Esempio n. 2
0
        FieldReference fixLoadStoreFieldInstruction(Instruction instr, int token, OpCode staticInstr, OpCode instanceInstr)
        {
            var  fieldRef = (FieldReference)module.LookupToken(token);
            var  field    = deobfuscatorContext.resolve(fieldRef);
            bool isStatic;

            if (field == null)
            {
                Log.w("Could not resolve field {0:X8}. Assuming it's not static.", token);
                isStatic = false;
            }
            else
            {
                isStatic = field.IsStatic;
            }
            instr.OpCode = isStatic ? staticInstr : instanceInstr;
            return(fieldRef);
        }
Esempio n. 3
0
        TypeDefinition resolve(TypeReference type)
        {
            if (type is TypeDefinition)
            {
                return((TypeDefinition)type);
            }

            if (type.IsGenericInstance)
            {
                type = ((GenericInstanceType)type).ElementType;
            }

            if (type.Module == module && isModuleAssembly(type.Scope))
            {
                return(DotNetUtils.getType(module, type));
            }

            return(deobfuscatorContext.resolve(type));
        }