Exemplo n.º 1
0
 void CopyImplMap(IMemberForwarded source, IMemberForwarded dest)
 {
     if (source.HasImplMap)
     {
         dest.ImplMap = new ImplMapUser(source.ImplMap.Module, source.ImplMap.Name, source.ImplMap.Attributes);
     }
 }
Exemplo n.º 2
0
 internal static void SetPInvokeMap(this IMemberForwarded owner, LazyValue <ImplementationMap> container, ImplementationMap newValue)
 {
     if (newValue != null && newValue.MemberForwarded != null)
     {
         throw new InvalidOperationException("Implementation map is already added to another member.");
     }
     if (container.Value != null)
     {
         container.Value.MemberForwarded = null;
     }
     container.Value = newValue;
     if (newValue != null)
     {
         newValue.MemberForwarded = owner;
     }
 }
        public void Analyze(ConfuserContext context, INameService service, ProtectionParameters parameters, IDnlibDef def)
        {
            var method = def as MethodDef;

            if (method == null || !method.HasBody)
            {
                return;
            }

            // When a ldtoken instruction reference a definition,
            // most likely it would be used in reflection and thus probably should not be renamed.
            // Also, when ToString is invoked on enum,
            // the enum should not be renamed.
            for (int i = 0; i < method.Body.Instructions.Count; i++)
            {
                Instruction instr = method.Body.Instructions[i];
                if (instr.OpCode.Code == Code.Ldtoken)
                {
                    if (instr.Operand is MemberRef)
                    {
                        IMemberForwarded member = ((MemberRef)instr.Operand).ResolveThrow();
                        if (context.Modules.Contains((ModuleDefMD)member.Module))
                        {
                            service.SetCanRename(member, false);
                        }
                    }
                    else if (instr.Operand is IField)
                    {
                        FieldDef field = ((IField)instr.Operand).ResolveThrow();
                        if (context.Modules.Contains((ModuleDefMD)field.Module))
                        {
                            service.SetCanRename(field, false);
                        }
                    }
                    else if (instr.Operand is IMethod)
                    {
                        var im = (IMethod)instr.Operand;
                        if (!im.IsArrayAccessors())
                        {
                            MethodDef m = im.ResolveThrow();
                            if (context.Modules.Contains((ModuleDefMD)m.Module))
                            {
                                service.SetCanRename(method, false);
                            }
                        }
                    }
                    else if (instr.Operand is ITypeDefOrRef)
                    {
                        if (!(instr.Operand is TypeSpec))
                        {
                            TypeDef type = ((ITypeDefOrRef)instr.Operand).ResolveTypeDefThrow();
                            if (context.Modules.Contains((ModuleDefMD)type.Module) &&
                                HandleTypeOf(context, service, method, i))
                            {
                                var t = type;
                                do
                                {
                                    DisableRename(service, t, false);
                                    t = t.DeclaringType;
                                } while (t != null);
                            }
                        }
                    }
                    else
                    {
                        throw new UnreachableException();
                    }
                }
                else if ((instr.OpCode.Code == Code.Call || instr.OpCode.Code == Code.Callvirt) &&
                         ((IMethod)instr.Operand).Name == "ToString")
                {
                    HandleEnum(context, service, method, i);
                }
                else if (instr.OpCode.Code == Code.Ldstr)
                {
                    TypeDef typeDef = method.Module.FindReflection((string)instr.Operand);
                    if (typeDef != null)
                    {
                        service.AddReference(typeDef, new StringTypeReference(instr, typeDef));
                    }
                }
            }
        }
        // Token: 0x0600001F RID: 31 RVA: 0x00002FC4 File Offset: 0x000011C4
        public void Analyze(ConfuserContext context, INameService service, ProtectionParameters parameters, IDnlibDef def)
        {
            MethodDef method = def as MethodDef;

            if (method == null || !method.HasBody)
            {
                return;
            }
            for (int i = 0; i < method.Body.Instructions.Count; i++)
            {
                Instruction instr = method.Body.Instructions[i];
                if (instr.OpCode.Code == Code.Ldtoken)
                {
                    if (instr.Operand is MemberRef)
                    {
                        IMemberForwarded member = ((MemberRef)instr.Operand).ResolveThrow();
                        if (context.Modules.Contains((ModuleDefMD)member.Module))
                        {
                            service.SetCanRename(member, false);
                        }
                    }
                    else if (instr.Operand is IField)
                    {
                        FieldDef field = ((IField)instr.Operand).ResolveThrow();
                        if (context.Modules.Contains((ModuleDefMD)field.Module))
                        {
                            service.SetCanRename(field, false);
                        }
                    }
                    else if (instr.Operand is IMethod)
                    {
                        IMethod im = (IMethod)instr.Operand;
                        if (!im.IsArrayAccessors())
                        {
                            MethodDef j = im.ResolveThrow();
                            if (context.Modules.Contains((ModuleDefMD)j.Module))
                            {
                                service.SetCanRename(method, false);
                            }
                        }
                    }
                    else
                    {
                        if (!(instr.Operand is ITypeDefOrRef))
                        {
                            throw new UnreachableException();
                        }
                        if (!(instr.Operand is TypeSpec))
                        {
                            TypeDef type = ((ITypeDefOrRef)instr.Operand).ResolveTypeDefThrow();
                            if (context.Modules.Contains((ModuleDefMD)type.Module) && this.HandleTypeOf(context, service, method, i))
                            {
                                TypeDef t = type;
                                do
                                {
                                    this.DisableRename(service, t, false);
                                    t = t.DeclaringType;
                                }while (t != null);
                            }
                        }
                    }
                }
                else if ((instr.OpCode.Code == Code.Call || instr.OpCode.Code == Code.Callvirt) && ((IMethod)instr.Operand).Name == "ToString")
                {
                    this.HandleEnum(context, service, method, i);
                }
                else if (instr.OpCode.Code == Code.Ldstr)
                {
                    TypeDef typeDef = method.Module.FindReflection((string)instr.Operand);
                    if (typeDef != null)
                    {
                        service.AddReference <TypeDef>(typeDef, new StringTypeReference(instr, typeDef));
                    }
                }
            }
        }