示例#1
0
		public EditClassVM(IRawModuleBytesProvider rawModuleBytesProvider, IOpenFromGAC openFromGAC, IOpenAssembly openAssembly, ILanguageCompiler languageCompiler, IDecompiler decompiler, IMemberDef defToEdit, IList<MethodSourceStatement> statementsInMethodToEdit)
			: base(rawModuleBytesProvider, openFromGAC, openAssembly, languageCompiler, decompiler, defToEdit.Module) {
			this.defToEdit = defToEdit;
			nonNestedTypeToEdit = defToEdit as TypeDef ?? defToEdit.DeclaringType;
			while (nonNestedTypeToEdit.DeclaringType != null)
				nonNestedTypeToEdit = nonNestedTypeToEdit.DeclaringType;
			methodSourceStatement = statementsInMethodToEdit.Count == 0 ? (MethodSourceStatement?)null : statementsInMethodToEdit[0];
			StartDecompile();
		}
示例#2
0
        BraceInfo StartKeywordBlock(IDecompilerOutput output, string keyword, IMemberDef member)
        {
            output.Write(keyword, BoxedTextColor.Keyword);
            output.Write(" ", BoxedTextColor.Text);
            output.Write(IdentifierEscaper.Escape(member.Name), member, DecompilerReferenceFlags.Definition, MetadataTextColorProvider.GetColor(member));
            output.Write(" ", BoxedTextColor.Text);
            var start = output.NextPosition;

            output.Write("{", BoxedTextColor.Punctuation);
            output.WriteLine();
            output.IncreaseIndent();
            return(new BraceInfo(start));
        }
示例#3
0
        private static MethodAttributes GetAccessAttributes(IMemberDef member)
        {
            var fld = member as FieldDef;

            if (fld != null)
            {
                return((MethodAttributes)fld.Attributes);
            }

            var method = member as MethodDef;

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

            var prop = member as PropertyDef;

            if (prop != null)
            {
                var accMeth = prop.GetMethod ?? prop.SetMethod;
                return(accMeth == null ? 0 : accMeth.Attributes);
            }

            var evnt = member as EventDef;

            if (evnt != null)
            {
                var m = evnt.AddMethod ?? evnt.RemoveMethod;
                return(m == null ? 0 : m.Attributes);
            }

            var nestedType = member as TypeDef;

            if (nestedType != null)
            {
                if (nestedType.IsNestedPrivate)
                {
                    return(MethodAttributes.Private);
                }
                if (nestedType.IsNestedAssembly || nestedType.IsNestedFamilyAndAssembly)
                {
                    return(MethodAttributes.Assembly);
                }
                return(MethodAttributes.Public);
            }

            return(0);
        }
示例#4
0
        static bool MoveCaretTo(IDocumentViewer documentViewer, IMemberDef def)
        {
            if (documentViewer == null)
            {
                return(false);
            }
            var data = documentViewer.ReferenceCollection.FirstOrNull(a => a.Data.IsDefinition && a.Data.Reference == def);

            if (data == null)
            {
                return(false);
            }
            documentViewer.MoveCaretToPosition(data.Value.Span.Start);
            return(true);
        }
        /// <summary>
        /// Determinates whether member of the base type is visible from a derived type.
        /// </summary>
        /// <param name="baseMember">The member which visibility is checked.</param>
        /// <param name="derivedType">The derived type.</param>
        /// <returns>true if the member is visible from derived type, othewise false.</returns>
        public static bool IsVisibleFromDerived(IMemberDef baseMember, TypeDef derivedType)
        {
            if (baseMember == null)
            {
                throw new ArgumentNullException("baseMember");
            }
            if (derivedType == null)
            {
                throw new ArgumentNullException("derivedType");
            }

            MethodAttributes attrs = GetAccessAttributes(baseMember) & MethodAttributes.MemberAccessMask;

            if (attrs == MethodAttributes.Private)
            {
                return(false);
            }

            if (baseMember.DeclaringType.Module == derivedType.Module)
            {
                return(true);
            }

            if (attrs == MethodAttributes.Assembly || attrs == MethodAttributes.FamANDAssem)
            {
                var derivedTypeAsm = derivedType.Module.Assembly;
                var asm            = baseMember.DeclaringType.Module.Assembly;

                if (asm.HasCustomAttributes)
                {
                    var attributes = asm.CustomAttributes
                                     .Where(attr => attr.AttributeType.FullName == "System.Runtime.CompilerServices.InternalsVisibleToAttribute");
                    foreach (var attribute in attributes)
                    {
                        string assemblyName = (UTF8String)attribute.ConstructorArguments[0].Value;
                        assemblyName = assemblyName.Split(',')[0];                         // strip off any public key info
                        if (assemblyName == derivedTypeAsm.Name)
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }

            return(true);
        }
示例#6
0
        static void UpdateOldestSiblingReference(IMemberDef oldestSiblingMemberDef, IMemberDef basePropDef, INameService service)
        {
            var reverseReference = service.GetReferences(oldestSiblingMemberDef).OfType <MemberOldestSiblingReference>()
                                   .SingleOrDefault();

            if (reverseReference is null)
            {
                service.AddReference(oldestSiblingMemberDef, new MemberOldestSiblingReference(oldestSiblingMemberDef, basePropDef));
                PropagateRenamingRestrictions(service, oldestSiblingMemberDef, basePropDef);
            }
            else if (!reverseReference.OtherSiblings.Contains(basePropDef))
            {
                reverseReference.OtherSiblings.Add(basePropDef);
                PropagateRenamingRestrictions(service, reverseReference.OtherSiblings);
            }
        }
示例#7
0
 public static bool IsCompilerGeneratedOrIsInCompilerGeneratedClass(this IMemberDef member)
 {
     for (int i = 0; i < 50; i++)
     {
         if (member == null)
         {
             break;
         }
         if (member.IsCompilerGenerated())
         {
             return(true);
         }
         member = member.DeclaringType;
     }
     return(false);
 }
        private static MethodAttributes GetAccessAttributes(IMemberDef member)
        {
            var fld = member as FieldDef;

            if (fld != null)
            {
                return((MethodAttributes)fld.Attributes);
            }

            var method = member as MethodDef;

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

            var prop = member as PropertyDef;

            if (prop != null)
            {
                return((prop.GetMethod ?? prop.SetMethod).Attributes);
            }

            var evnt = member as EventDef;

            if (evnt != null)
            {
                return((evnt.AddMethod ?? evnt.RemoveMethod).Attributes);
            }

            var nestedType = member as TypeDef;

            if (nestedType != null)
            {
                if (nestedType.IsNestedPrivate)
                {
                    return(MethodAttributes.Private);
                }
                if (nestedType.IsNestedAssembly || nestedType.IsNestedFamilyAndAssembly)
                {
                    return(MethodAttributes.Assembly);
                }
                return(MethodAttributes.Public);
            }

            throw new NotSupportedException();
        }
            public INsMember GetOrAddMember(IMemberDef source, Func <string> generator)
            {
                var name = source.Name;

                if (_byOld.TryGetValue(name, out var member))
                {
                    return(member);
                }
                var newName = generator?.Invoke();

                if (newName == null)
                {
                    return(null);
                }
                var result = new MetadataElement(this, newName);

                _byOld.Add(name, result);
                _byNew.Add(newName, result);
                return(result);
            }
示例#10
0
        public static bool GetRVA(this IMemberDef member, out uint rva, out long fileOffset)
        {
            rva        = 0;
            fileOffset = 0;

            if (member is MethodDef)
            {
                rva = (uint)(member as MethodDef).RVA;
            }
            else if (member is FieldDef)
            {
                rva = (uint)(member as FieldDef).RVA;
            }
            if (rva == 0)
            {
                return(false);
            }

            fileOffset = member.Module.ToFileOffset(rva);
            return(true);
        }
示例#11
0
        static void RedirectSiblingReferences(IMemberDef oldMemberDef, IMemberDef newMemberDef, INameService service)
        {
            if (ReferenceEquals(oldMemberDef, newMemberDef))
            {
                return;
            }

            var referencesToUpdate = service.GetReferences(oldMemberDef)
                                     .OfType <MemberOldestSiblingReference>()
                                     .SelectMany(r => r.OtherSiblings)
                                     .SelectMany(service.GetReferences)
                                     .OfType <MemberSiblingReference>()
                                     .Where(r => ReferenceEquals(r.OldestSiblingDef, oldMemberDef));

            foreach (var reference in referencesToUpdate)
            {
                reference.OldestSiblingDef = newMemberDef;
                UpdateOldestSiblingReference(newMemberDef, reference.ThisMemberDef, service);
            }
            UpdateOldestSiblingReference(newMemberDef, oldMemberDef, service);
        }
示例#12
0
		public void TryResolve() {
			if (ResolvedMember != null)
				return;

			var typeDef = DeclaringType.ResolvedType.ResolveTypeDef();
			if (typeDef == null)
				return;

			ResolvedMember = typeDef.FindPropertyCheckBaseType(PropertyName);
			if (ResolvedMember != null)
				return;

			ResolvedMember = typeDef.FindFieldCheckBaseType(PropertyName + "Property");
			if (ResolvedMember != null)
				return;

			ResolvedMember = typeDef.FindEventCheckBaseType(PropertyName);
			if (ResolvedMember != null)
				return;

			ResolvedMember = typeDef.FindFieldCheckBaseType(PropertyName + "Event");
		}
示例#13
0
        private static MethodAttributes GetAccessAttributes(IMemberDef member)
        {
            if (member is FieldDef fld)
            {
                return((MethodAttributes)fld.Attributes);
            }

            if (member is MethodDef method)
            {
                return(method.Attributes);
            }

            if (member is PropertyDef prop)
            {
                var accMeth = prop.GetMethod ?? prop.SetMethod;
                return(accMeth == null ? 0 : accMeth.Attributes);
            }

            if (member is EventDef evnt)
            {
                var m = evnt.AddMethod ?? evnt.RemoveMethod;
                return(m == null ? 0 : m.Attributes);
            }

            if (member is TypeDef nestedType)
            {
                if (nestedType.IsNestedPrivate)
                {
                    return(MethodAttributes.Private);
                }
                if (nestedType.IsNestedAssembly || nestedType.IsNestedFamilyAndAssembly)
                {
                    return(MethodAttributes.Assembly);
                }
                return(MethodAttributes.Public);
            }

            return(0);
        }
示例#14
0
            protected override void Execute(ConfuserContext context, ProtectionParameters parameters)
            {
                IMemberDef memberDef = parameters.Targets as IMemberDef;

                TypeDef typeDef;

                if ((typeDef = (memberDef as TypeDef)) != null && !this.IsTypePublic(typeDef))
                {
                    if (typeDef.IsEnum)
                    {
                        int num = 0;
                        while (typeDef.Fields.Count != 1)
                        {
                            if (typeDef.Fields[num].Name != "value__")
                            {
                                typeDef.Fields.RemoveAt(num);
                            }
                            else
                            {
                                num++;
                            }
                        }
                        return;
                    }
                }
                else if (memberDef is EventDef)
                {
                    if (memberDef.DeclaringType != null)
                    {
                        memberDef.DeclaringType.Events.Remove(memberDef as EventDef);
                        return;
                    }
                }
                else if (memberDef is PropertyDef && memberDef.DeclaringType != null)
                {
                    memberDef.DeclaringType.Properties.Remove(memberDef as PropertyDef);
                }
            }
示例#15
0
        internal static IMemberDef GetMemberDef(ContextMenuEntryContext context)
        {
            IMemberDef def = null;

            if (context.SelectedTreeNodes != null && context.SelectedTreeNodes.Length == 1 && context.SelectedTreeNodes[0] is IMemberTreeNode)
            {
                def = MainWindow.ResolveReference(((IMemberTreeNode)context.SelectedTreeNodes[0]).Member);
            }
            else
            {
                // Only allow declarations of the defs, i.e., right-clicking a method call with a method
                // def as reference should return null, not the method def.
                if (context.Reference != null && context.Reference.IsLocalTarget && context.Reference.Reference is IMemberRef)
                {
                    // Don't resolve it. It's confusing if we show the method body of a called method
                    // instead of the current method.
                    def = context.Reference.Reference as IMemberDef;
                }
            }
            var mod = def == null ? null : def.Module;

            return(mod is ModuleDefMD ? def : null);
        }
示例#16
0
 ReflectionDisassembler CreateReflectionDisassembler(ITextOutput output, DecompilationContext ctx, IMemberDef member)
 {
     return CreateReflectionDisassembler(output, ctx, member.Module);
 }
示例#17
0
文件: Language.cs 项目: nakijun/dnSpy
		public void WriteCommentLineDeclaringType(ITextOutput output, IMemberDef member)
		{
			WriteComment(output, string.Empty);
			output.WriteReference(TypeToString(member.DeclaringType, includeNamespace: true), member.DeclaringType, TextTokenType.Comment);
			output.WriteLine();
		}
示例#18
0
 public bool MemberEquals(IMemberDef md, MemberInfo mi)
 {
     return(TypeEquals(md.DeclaringType, mi.DeclaringType) && md.Name == mi.Name);
 }
示例#19
0
        public static void Analyze(INameService service, ICollection <ModuleDefMD> modules, MethodDef method)
        {
            if (!method.IsVirtual)
            {
                return;
            }

            var vTbl  = service.GetVTables()[method.DeclaringType];
            var slots = vTbl.FindSlots(method).ToArray();

            IMemberDef discoveredBaseMemberDef = null;
            MethodDef  discoveredBaseMethodDef = null;

            bool doesOverridePropertyOrEvent = false;
            var  methodProp = method.DeclaringType.Properties.Where(p => BelongsToProperty(p, method));

            foreach (var prop in methodProp)
            {
                foreach (var baseMethodDef in FindBaseDeclarations(service, method))
                {
                    var basePropDef = baseMethodDef.DeclaringType.Properties.
                                      FirstOrDefault(p => BelongsToProperty(p, baseMethodDef) && String.Equals(p.Name, prop.Name, StringComparison.Ordinal));

                    if (basePropDef is null)
                    {
                        continue;
                    }

                    // Name of property has to line up.
                    CreateOverrideReference(service, prop, basePropDef);
                    CreateSiblingReference(basePropDef, ref discoveredBaseMemberDef, service);

                    // Method names have to line up as well (otherwise inheriting attributes does not work).
                    CreateOverrideReference(service, method, baseMethodDef);
                    CreateSiblingReference(baseMethodDef, ref discoveredBaseMethodDef, service);

                    doesOverridePropertyOrEvent = true;
                }
            }

            discoveredBaseMemberDef = null;
            discoveredBaseMethodDef = null;

            var methodEvent = method.DeclaringType.Events.Where(e => BelongsToEvent(e, method));

            foreach (var evt in methodEvent)
            {
                foreach (var baseMethodDef in FindBaseDeclarations(service, method))
                {
                    var baseEventDef = baseMethodDef.DeclaringType.Events.
                                       FirstOrDefault(e => BelongsToEvent(e, baseMethodDef) && String.Equals(e.Name, evt.Name, StringComparison.Ordinal));

                    if (baseEventDef is null)
                    {
                        continue;
                    }

                    // Name of event has to line up.
                    CreateOverrideReference(service, evt, baseEventDef);
                    CreateSiblingReference(baseEventDef, ref discoveredBaseMemberDef, service);

                    // Method names have to line up as well (otherwise inheriting attributes does not work).
                    CreateOverrideReference(service, method, baseMethodDef);
                    CreateSiblingReference(baseMethodDef, ref discoveredBaseMethodDef, service);

                    doesOverridePropertyOrEvent = true;
                }
            }

            if (!method.IsAbstract)
            {
                foreach (var slot in slots)
                {
                    if (slot.Overrides == null)
                    {
                        continue;
                    }

                    SetupOverwriteReferences(service, modules, slot, method.Module);
                }
            }
            else if (!doesOverridePropertyOrEvent)
            {
                foreach (var baseMethodDef in FindBaseDeclarations(service, method))
                {
                    CreateOverrideReference(service, method, baseMethodDef);
                }
            }
        }
示例#20
0
 static SerializedDnModuleWithAssembly? GetSerializedDnModuleWithAssembly(IMemberDef md)
 {
     if (md == null)
         return null;
     //TODO: Method doesn't work with in-memory modules or assemblies
     var mod = md.Module;
     if (mod == null)
         return null;
     var asm = mod.Assembly;
     if (asm == null)
         return null;
     return new SerializedDnModuleWithAssembly(asm.ManifestModule.Location, new SerializedDnModule(mod.Location));
 }
 public bool MemberEquals(IMemberDef md, MemberInfo mi)
 {
     return TypeEquals(md.DeclaringType, mi.DeclaringType) && md.Name == mi.Name;
 }
示例#22
0
		public EditCodeVM CreateEditClass(IMemberDef def, IList<MethodSourceStatement> statements) {
			var info = GetLanguageCompilerProvider(CompilationKind.EditClass);
			if (info == null)
				throw new InvalidOperationException();
			return new EditClassVM(rawModuleBytesProvider, openFromGAC, openAssembly, info.Value.Value.Create(CompilationKind.EditClass), info.Value.Key, def, statements);
		}
示例#23
0
        static bool IsVisibleOutside(ConfuserContext context, ProtectionParameters parameters, IMemberDef def)
        {
            var type = def as TypeDef;
            if (type == null)
                type = def.DeclaringType;

            var renPublic = parameters.GetParameter<bool?>(context, type, "renPublic", null);
            if (renPublic == null)
                return type.IsVisibleOutside();
            else
                return type.IsVisibleOutside(false) && renPublic.Value;
        }
示例#24
0
		ReflectionDisassembler CreateReflectionDisassembler(IDecompilerOutput output, DecompilationContext ctx, IMemberDef member) =>
			CreateReflectionDisassembler(output, ctx, member.Module);
示例#25
0
 public MiscContent(IMemberDef method) : base(method.DeclaringType)
 {
     Method = method.Name;
 }
示例#26
0
 public EditClassVM(IRawModuleBytesProvider rawModuleBytesProvider, IOpenFromGAC openFromGAC, IOpenAssembly openAssembly, ILanguageCompiler languageCompiler, IDecompiler decompiler, IMemberDef defToEdit, IList <MethodSourceStatement> statementsInMethodToEdit)
     : base(rawModuleBytesProvider, openFromGAC, openAssembly, languageCompiler, decompiler, defToEdit.Module)
 {
     this.defToEdit      = defToEdit;
     nonNestedTypeToEdit = defToEdit as TypeDef ?? defToEdit.DeclaringType;
     while (nonNestedTypeToEdit.DeclaringType != null)
     {
         nonNestedTypeToEdit = nonNestedTypeToEdit.DeclaringType;
     }
     methodSourceStatement = statementsInMethodToEdit.Count == 0 ? (MethodSourceStatement?)null : statementsInMethodToEdit[0];
     StartDecompile();
 }
示例#27
0
 ReflectionDisassembler CreateReflectionDisassembler(ITextOutput output, DecompilationOptions options, IMemberDef member)
 {
     return(CreateReflectionDisassembler(output, options, member.Module));
 }
示例#28
0
 // Thanks to the AsStrongAsFuck project!
 public static void Rename(this IMemberDef member, string name)
 {
     member.Name = name;
 }
示例#29
0
 public static void GetRenamed(this IMemberDef member)
 {
     member.Rename(Randomizer.GenerateRandomString(StringLength()));
 }
示例#30
0
		protected void WriteCommentLineDeclaringType(IDecompilerOutput output, IMemberDef member) {
			WriteCommentBegin(output, true);
			output.Write(TypeToString(member.DeclaringType, includeNamespace: true), member.DeclaringType, DecompilerReferenceFlags.None, BoxedTextColor.Comment);
			WriteCommentEnd(output, true);
			output.WriteLine();
		}
示例#31
0
		protected void WriteCommentLineDeclaringType(ITextOutput output, IMemberDef member) {
			WriteCommentBegin(output, true);
			output.WriteReference(TypeToString(member.DeclaringType, includeNamespace: true), member.DeclaringType, TextTokenKind.Comment);
			WriteCommentEnd(output, true);
			output.WriteLine();
		}
示例#32
0
 public static void Rename(IMemberDef member, RenameMode mode, int depth = 1, int sublength = 10)
 {
     member.Name = GetEndName(mode, depth, sublength);
 }
示例#33
0
        /// <summary>
        /// Determinates whether member of the base type is visible from a derived type.
        /// </summary>
        /// <param name="baseMember">The member which visibility is checked.</param>
        /// <param name="derivedType">The derived type.</param>
        /// <returns>true if the member is visible from derived type, othewise false.</returns>
        public static bool IsVisibleFromDerived(IMemberDef baseMember, TypeDef derivedType)
        {
            if (baseMember == null)
                return false;
            if (derivedType == null)
                return false;

            MethodAttributes attrs = GetAccessAttributes(baseMember) & MethodAttributes.MemberAccessMask;
            if (attrs == MethodAttributes.Private)
                return false;

            if (baseMember.DeclaringType.Module == derivedType.Module)
                return true;

            if (attrs == MethodAttributes.Assembly || attrs == MethodAttributes.FamANDAssem) {
                var derivedTypeAsm = derivedType.Module.Assembly;
                var asm = baseMember.DeclaringType.Module.Assembly;

                if (derivedTypeAsm != null && asm != null && asm.HasCustomAttributes) {
                    var attributes = asm.CustomAttributes
                        .Where(attr => attr.TypeFullName == "System.Runtime.CompilerServices.InternalsVisibleToAttribute");
                    foreach (var attribute in attributes) {
                        if (attribute.ConstructorArguments.Count == 0)
                            continue;
                        string assemblyName = attribute.ConstructorArguments[0].Value as UTF8String;
                        if (assemblyName == null)
                            continue;
                        assemblyName = assemblyName.Split(',')[0]; // strip off any public key info
                        if (assemblyName == derivedTypeAsm.Name)
                            return true;
                    }
                }

                return false;
            }

            return true;
        }
		private static MethodAttributes GetAccessAttributes(IMemberDef member)
		{
			var fld = member as FieldDef;
			if (fld != null)
				return (MethodAttributes)fld.Attributes;

			var method = member as MethodDef;
			if (method != null)
				return method.Attributes;

			var prop = member as PropertyDef;
			if (prop != null) {
				return (prop.GetMethod ?? prop.SetMethod).Attributes;
		}

			var evnt = member as EventDef;
			if (evnt != null) {
				return (evnt.AddMethod ?? evnt.RemoveMethod).Attributes;
			}

			var nestedType = member as TypeDef;
			if (nestedType != null) {
				if (nestedType.IsNestedPrivate)
					return MethodAttributes.Private;
				if (nestedType.IsNestedAssembly || nestedType.IsNestedFamilyAndAssembly)
					return MethodAttributes.Assembly;
				return MethodAttributes.Public;
			}

			throw new NotSupportedException();
		}
示例#35
0
        private static MethodAttributes GetAccessAttributes(IMemberDef member)
        {
            var fld = member as FieldDef;
            if (fld != null)
                return (MethodAttributes)fld.Attributes;

            var method = member as MethodDef;
            if (method != null)
                return method.Attributes;

            var prop = member as PropertyDef;
            if (prop != null) {
                var accMeth = prop.GetMethod ?? prop.SetMethod;
                return accMeth == null ? 0 : accMeth.Attributes;
            }

            var evnt = member as EventDef;
            if (evnt != null) {
                var m = evnt.AddMethod ?? evnt.RemoveMethod;
                return m == null ? 0 : m.Attributes;
            }

            var nestedType = member as TypeDef;
            if (nestedType != null) {
                if (nestedType.IsNestedPrivate)
                    return MethodAttributes.Private;
                if (nestedType.IsNestedAssembly || nestedType.IsNestedFamilyAndAssembly)
                    return MethodAttributes.Assembly;
                return MethodAttributes.Public;
            }

            return 0;
        }
示例#36
0
        static void CreateOverrideReference(INameService service, IMemberDef thisMemberDef, IMemberDef baseMemberDef)
        {
            var overrideRef = new MemberOverrideReference(thisMemberDef, baseMemberDef);

            service.AddReference(thisMemberDef, overrideRef);

            PropagateRenamingRestrictions(service, thisMemberDef, baseMemberDef);
        }
示例#37
0
 ReflectionDisassembler CreateReflectionDisassembler(IDecompilerOutput output, DecompilationContext ctx, IMemberDef member) =>
 CreateReflectionDisassembler(output, ctx, member.Module);
示例#38
0
 public bool IsPreserved(TypeMapping tm, IMemberDef member) =>
 _nodes.TryGetValue(tm.Target, out var node) &&
 node.MembersByOldName.TryGetValue(member.Name, out var om) &&
 node.MembersByNewName.TryGetValue(member.Name, out var nm) && ReferenceEquals(nm, om);
        // Token: 0x06000009 RID: 9 RVA: 0x00003FD8 File Offset: 0x000021D8
        private static bool IsVisibleOutside(ConfuserContext context, ProtectionParameters parameters, IMemberDef def)
        {
            TypeDef type = def as TypeDef;

            if (type == null)
            {
                type = def.DeclaringType;
            }
            bool?renPublic = parameters.GetParameter <bool?>(context, type, "renPublic", null);

            if (!renPublic.HasValue)
            {
                return(type.IsVisibleOutside(true));
            }
            return(type.IsVisibleOutside(false) && renPublic.Value);
        }
示例#40
0
 public static SerializedDnModule ToSerializedDnModule(this IMemberDef md)
 {
     return(md.Module.ToSerializedDnSpyModule().ToSerializedDnModule());
 }
示例#41
0
        static bool IsVisibleOutside(ConfuserContext context, ProtectionParameters parameters, IMemberDef def)
        {
            var renPublic   = parameters.GetParameter <bool?>(context, def, "renPublic", null);
            var renInternal = parameters.GetParameter <bool?>(context, def, "renInternal", null);

            var type = def as TypeDef;

            if (type == null)
            {
                type = def.DeclaringType;
            }
            else
            {
                if (type.IsSerializable)
                {
                    return(true);
                }
            }

            var method = def as MethodDef;

            if (method != null)
            {
                if (renInternal == null || renInternal.Value)
                {
                    if (!method.IsFamily && !method.IsFamilyOrAssembly && !method.IsPublic)
                    {
                        return(false);
                    }
                }
                else
                {
                    if (method.HasPrivateFlags() && !method.IsFamily && !method.IsFamilyOrAssembly && !method.IsPublic)
                    {
                        return(false);
                    }
                }
            }

            var field = def as FieldDef;

            if (field != null)
            {
                if (renInternal == null || renInternal.Value)
                {
                    if (!field.IsFamily && !field.IsFamilyOrAssembly && !field.IsPublic)
                    {
                        return(false);
                    }
                }
                else
                {
                    if (field.HasPrivateFlags() && !field.IsFamily && !field.IsFamilyOrAssembly && !field.IsPublic)
                    {
                        return(false);
                    }
                }
            }

            var property = def as PropertyDef;

            if (property != null)
            {
                if (renInternal == null || renInternal.Value)
                {
                    if (!property.IsFamily() && !property.IsFamilyOrAssembly() && !property.IsPublic())
                    {
                        return(false);
                    }
                }
                else
                {
                    if (property.HasAllPrivateFlags() && !property.IsFamily() && !property.IsFamilyOrAssembly() && !property.IsPublic())
                    {
                        return(false);
                    }
                }
            }

            var evt = def as EventDef;

            if (evt != null)
            {
                if (renInternal == null || renInternal.Value)
                {
                    if (!evt.IsFamily() && !evt.IsFamilyOrAssembly() && !evt.IsPublic())
                    {
                        return(false);
                    }
                }
                else
                {
                    if (evt.HasAllPrivateFlags() && !evt.IsFamily() && !evt.IsFamilyOrAssembly() && !evt.IsPublic())
                    {
                        return(false);
                    }
                }
            }

            if (renPublic == null)
            {
                return(type.IsVisibleOutside());
            }
            else if (renInternal == null)
            {
                return(type.IsVisibleOutside(false) && !renPublic.Value);
            }
            else
            {
                return(type.IsVisibleOutside(false, renInternal.Value) && !renPublic.Value);
            }
        }
示例#42
0
 ReflectionDisassembler CreateReflectionDisassembler(ITextOutput output, DecompilationOptions options, IMemberDef member)
 {
     return CreateReflectionDisassembler(output, options, member.Module);
 }
示例#43
0
 public void WriteCommentLineDeclaringType(ITextOutput output, IMemberDef member)
 {
     WriteComment(output, string.Empty);
     output.WriteReference(TypeToString(member.DeclaringType, includeNamespace: true), member.DeclaringType, TextTokenType.Comment);
     output.WriteLine();
 }
示例#44
0
		void StartKeywordBlock(ITextOutput output, string keyword, IMemberDef member)
		{
			output.Write(keyword, TextTokenType.Keyword);
			output.WriteSpace();
			output.WriteDefinition(IdentifierEscaper.Escape(member.Name), member, TextTokenHelper.GetTextTokenType(member), false);
			output.WriteSpace();
			output.WriteLeftBrace();
			output.WriteLine();
			output.Indent();
		}
 public MemberOverrideReference(IMemberDef thisMemberDef, IMemberDef baseMemberDef)
 {
     this.thisMemberDef = thisMemberDef ?? throw new ArgumentNullException(nameof(thisMemberDef));
     BaseMemberDef      = baseMemberDef ?? throw new ArgumentNullException(nameof(baseMemberDef));
     Debug.Assert(thisMemberDef != baseMemberDef);
 }
示例#46
0
        static bool IsVisibleOutside(ConfuserContext context, ProtectionParameters parameters, IMemberDef def)
        {
            var type = def as TypeDef;

            if (type == null)
            {
                type = def.DeclaringType;
            }

            var renPublic = parameters.GetParameter <bool?>(context, def, "renPublic", null);

            if (renPublic == null)
            {
                return(type.IsVisibleOutside());
            }
            else
            {
                return(type.IsVisibleOutside(false) && !renPublic.Value);
            }
        }
示例#47
0
		void StartKeywordBlock(IDecompilerOutput output, string keyword, IMemberDef member) {
			output.Write(keyword, BoxedTextColor.Keyword);
			output.Write(" ", BoxedTextColor.Text);
			output.Write(IdentifierEscaper.Escape(member.Name), member, DecompilerReferenceFlags.Definition, MetadataTextColorProvider.GetColor(member));
			output.Write(" ", BoxedTextColor.Text);
			output.Write("{", BoxedTextColor.Punctuation);
			output.WriteLine();
			output.IncreaseIndent();
		}