public InterfaceEventImplementedByNode(EventDef analyzedEvent) {
			if (analyzedEvent == null)
				throw new ArgumentNullException("analyzedEvent");

			this.analyzedEvent = analyzedEvent;
			this.analyzedMethod = this.analyzedEvent.AddMethod ?? this.analyzedEvent.RemoveMethod;
		}
예제 #2
0
		public AnalyzedEventTreeNode(EventDef analyzedEvent, bool hidesParent = false) {
			if (analyzedEvent == null)
				throw new ArgumentNullException("analyzedEvent");
			this.analyzedEvent = analyzedEvent;
			this.hidesParent = hidesParent;
			this.LazyLoading = true;
		}
        public AnalyzedEventOverridesTreeNode(EventDef analyzedEvent)
        {
            if (analyzedEvent == null)
                throw new ArgumentNullException("analyzedEvent");

            this.analyzedEvent = analyzedEvent;
        }
 public AnalyzedEventTreeNode(EventDef analyzedEvent, string prefix = "")
 {
     if (analyzedEvent == null)
         throw new ArgumentNullException("analyzedEvent");
     this.analyzedEvent = analyzedEvent;
     this.prefix = prefix;
     this.LazyLoading = true;
 }
예제 #5
0
		public DeletedEventUpdater(ModuleDocumentNode modNode, EventDef originalEvent) {
			ownerNode = modNode.Context.DocumentTreeView.FindNode(originalEvent);
			if (ownerNode == null)
				throw new InvalidOperationException();
			parentNode = ownerNode.TreeNode.Parent.Data;
			ownerType = originalEvent.DeclaringType;
			@event = originalEvent;
		}
예제 #6
0
        private static string ResolveRawName(dnlib.DotNet.EventDef source)
        {
            var rawName = source.FullName.AsSpan(source.FullName.IndexOf(' ', StringComparison.InvariantCultureIgnoreCase) + 1);

            return(rawName.ToString()
                   .Replace("::", ".", StringComparison.InvariantCultureIgnoreCase)
                   .Replace("/", ".", StringComparison.InvariantCultureIgnoreCase));
        }
예제 #7
0
		public EditedEventUpdater(ModuleDocumentNode modNode, EventDef originalEvent, EventDefOptions eventDefOptions) {
			ownerNode = modNode.Context.DocumentTreeView.FindNode(originalEvent);
			if (ownerNode == null)
				throw new InvalidOperationException();
			@event = originalEvent;
			originalEventDefOptions = new EventDefOptions(originalEvent);
			newEventDefOptions = eventDefOptions;
		}
예제 #8
0
		public static ITextOutput Write(ITextOutput output, EventDef ev, Language language) {
			output.Write(UIUtils.CleanUpIdentifier(ev.Name), TextTokenHelper.GetTextTokenType(ev));
			output.WriteSpace();
			output.Write(':', TextTokenType.Operator);
			output.WriteSpace();
			language.TypeToString(output, ev.EventType, false, ev);
			ev.MDToken.WriteSuffixString(output);
			return output;
		}
예제 #9
0
		public EventDefOptions(EventDef evt) {
			Attributes = evt.Attributes;
			Name = evt.Name;
			EventType = evt.EventType;
			AddMethod = evt.AddMethod;
			InvokeMethod = evt.InvokeMethod;
			RemoveMethod = evt.RemoveMethod;
			OtherMethods.AddRange(evt.OtherMethods);
			CustomAttributes.AddRange(evt.CustomAttributes);
		}
        public AnalyzedEventFiredByTreeNode(EventDef analyzedEvent)
        {
            if (analyzedEvent == null)
                throw new ArgumentNullException("analyzedEvent");

            this.analyzedEvent = analyzedEvent;

            this.eventBackingField = GetBackingField(analyzedEvent);
            this.eventFiringMethod = analyzedEvent.EventType.ResolveTypeDef().Methods.First(md => md.Name == "Invoke");
        }
예제 #11
0
		public EventDefOptions(EventDef evt) {
			this.Attributes = evt.Attributes;
			this.Name = evt.Name;
			this.EventType = evt.EventType;
			this.AddMethod = evt.AddMethod;
			this.InvokeMethod = evt.InvokeMethod;
			this.RemoveMethod = evt.RemoveMethod;
			this.OtherMethods.AddRange(evt.OtherMethods);
			this.CustomAttributes.AddRange(evt.CustomAttributes);
		}
예제 #12
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="resolver">Type resolver instance</param>
 /// <param name="source">Member source</param>
 internal EventDef(Resolver resolver, dnlib.DotNet.EventDef source)
     : base(resolver, source)
 {
     Name        = source.Name.String;
     Type        = ResolveType(source);
     IsStatic    = source.AddMethod.IsStatic;
     Inheritance = ResolveInheritance(source.RemoveMethod);
     Accessor    = ResolveAccessor(source.AddMethod);
     RawName     = ResolveRawName(source);
 }
예제 #13
0
		public EventFiredByNode(EventDef analyzedEvent) {
			if (analyzedEvent == null)
				throw new ArgumentNullException(nameof(analyzedEvent));

			this.analyzedEvent = analyzedEvent;

			eventBackingField = GetBackingField(analyzedEvent);
			var eventType = analyzedEvent.EventType.ResolveTypeDef();
			if (eventType != null)
				eventFiringMethod = eventType.Methods.First(md => md.Name == "Invoke");
		}
예제 #14
0
		public EventDef CopyTo(EventDef evt) {
			evt.Attributes = this.Attributes;
			evt.Name = this.Name ?? UTF8String.Empty;
			evt.EventType = this.EventType;
			evt.AddMethod = this.AddMethod;
			evt.InvokeMethod = this.InvokeMethod;
			evt.RemoveMethod = this.RemoveMethod;
			evt.OtherMethods.Clear();
			evt.OtherMethods.AddRange(this.OtherMethods);
			evt.CustomAttributes.Clear();
			evt.CustomAttributes.AddRange(CustomAttributes);
			return evt;
		}
예제 #15
0
		public EventTreeNode(EventDef ev) {
			if (ev == null)
				throw new ArgumentNullException("ev");
			this.ev = ev;

			if (ev.AddMethod != null)
				this.Children.Add(new MethodTreeNode(ev.AddMethod));
			if (ev.RemoveMethod != null)
				this.Children.Add(new MethodTreeNode(ev.RemoveMethod));
			if (ev.InvokeMethod != null)
				this.Children.Add(new MethodTreeNode(ev.InvokeMethod));
			if (ev.HasOtherMethods) {
				foreach (var m in ev.OtherMethods)
					this.Children.Add(new MethodTreeNode(m));
			}
		}
예제 #16
0
		static MemberIcon GetMemberIcon(EventDef eventDef) {
			MethodDef method = eventDef.AddMethod ?? eventDef.RemoveMethod;
			if (method == null)
				return MemberIcon.Event;

			var access = MethodTreeNode.GetMemberAccess(method);
			if (method.IsStatic) {
				switch (access) {
				case MemberAccess.Public: return MemberIcon.StaticEvent;
				case MemberAccess.Private: return MemberIcon.StaticEventPrivate;
				case MemberAccess.Protected: return MemberIcon.StaticEventProtected;
				case MemberAccess.Internal: return MemberIcon.StaticEventInternal;
				case MemberAccess.CompilerControlled: return MemberIcon.StaticEventCompilerControlled;
				case MemberAccess.ProtectedInternal: return MemberIcon.StaticEventProtectedInternal;
				default:
					Debug.Fail("Invalid MemberAccess");
					goto case MemberAccess.Public;
				}
			}

			if (method.IsVirtual) {
				switch (access) {
				case MemberAccess.Public: return MemberIcon.VirtualEvent;
				case MemberAccess.Private: return MemberIcon.VirtualEventPrivate;
				case MemberAccess.Protected: return MemberIcon.VirtualEventProtected;
				case MemberAccess.Internal: return MemberIcon.VirtualEventInternal;
				case MemberAccess.CompilerControlled: return MemberIcon.VirtualEventCompilerControlled;
				case MemberAccess.ProtectedInternal: return MemberIcon.VirtualEventProtectedInternal;
				default:
					Debug.Fail("Invalid MemberAccess");
					goto case MemberAccess.Public;
				}
			}

			switch (access) {
			case MemberAccess.Public: return MemberIcon.Event;
			case MemberAccess.Private: return MemberIcon.EventPrivate;
			case MemberAccess.Protected: return MemberIcon.EventProtected;
			case MemberAccess.Internal: return MemberIcon.EventInternal;
			case MemberAccess.CompilerControlled: return MemberIcon.EventCompilerControlled;
			case MemberAccess.ProtectedInternal: return MemberIcon.EventProtectedInternal;
			default:
				Debug.Fail("Invalid MemberAccess");
				goto case MemberAccess.Public;
			}
		}
예제 #17
0
        public override void DecompileEvent(EventDef ev, ITextOutput output, DecompilationOptions options)
        {
            StartKeywordBlock(output, ".event", ev);

            if (ev.AddMethod != null) {
                StartKeywordBlock(output, ".add", ev.AddMethod);
                EndKeywordBlock(output);
            }

            if (ev.InvokeMethod != null) {
                StartKeywordBlock(output, ".invoke", ev.InvokeMethod);
                EndKeywordBlock(output);
            }

            if (ev.RemoveMethod != null) {
                StartKeywordBlock(output, ".remove", ev.RemoveMethod);
                EndKeywordBlock(output);
            }

            EndKeywordBlock(output);
        }
예제 #18
0
        public static IEnumerable<EventDef> FindBaseEvents(EventDef eventDef)
        {
            if (eventDef == null)
                yield break;

            var eventType = eventDef.EventType.ToTypeSig();

            foreach (var baseType in BaseTypes(eventDef.DeclaringType)) {
                var baseTypeDef = baseType.Resolve();
                if (baseTypeDef == null)
                    continue;
                foreach (var baseEvent in baseTypeDef.Events) {
                    if (MatchEvent(baseEvent, Resolve(baseEvent.EventType.ToTypeSig(), baseType), eventDef, eventType) &&
                        IsVisibleFromDerived(baseEvent, eventDef.DeclaringType)) {
                        yield return baseEvent;
                        var anyEventAccessor = baseEvent.AddMethod ?? baseEvent.RemoveMethod;
                        if (anyEventAccessor != null && anyEventAccessor.IsNewSlot == anyEventAccessor.IsVirtual)
                            yield break;
                    }
                }
            }
        }
예제 #19
0
 public override void DecompileEvent(EventDef ev, ITextOutput output, DecompilationOptions options)
 {
     ReflectionDisassembler rd = CreateReflectionDisassembler(output, options, ev);
     rd.DisassembleEvent(ev);
     if (ev.AddMethod != null) {
         output.WriteLine();
         rd.DisassembleMethod(ev.AddMethod);
     }
     if (ev.RemoveMethod != null) {
         output.WriteLine();
         rd.DisassembleMethod(ev.RemoveMethod);
     }
     foreach (var m in ev.OtherMethods) {
         output.WriteLine();
         rd.DisassembleMethod(m);
     }
 }
예제 #20
0
        void Analyze(NameService service, ConfuserContext context, ProtectionParameters parameters, EventDef evt)
        {
            if (evt.DeclaringType.IsVisibleOutside() &&
                !IsVisibleOutside(context, parameters, evt))
                service.SetCanRename(evt, false);

            else if (evt.IsRuntimeSpecialName)
                service.SetCanRename(evt, false);
        }
 public static bool CanShow(EventDef ev)
 {
     return ev.DeclaringType.IsInterface;
 }
예제 #22
0
 public override TreeViewNodeFilterResult GetFilterResult(EventDef evt)
 {
     var visibleFlags = VisibleMembersFlags.EventDef | VisibleMembersFlags.MethodDef |
                         VisibleMembersFlags.MethodBody | VisibleMembersFlags.ParamDefs |
                         VisibleMembersFlags.ParamDef | VisibleMembersFlags.Locals |
                         VisibleMembersFlags.Local;
     bool isMatch = (flags & VisibleMembersFlags.EventDef) != 0;
     if ((flags & visibleFlags) == 0)
         return new TreeViewNodeFilterResult(FilterResult.Hidden, isMatch);
     if (isMatch)
         return new TreeViewNodeFilterResult(FilterResult.Match, isMatch);	// Make sure it's not hidden
     return new TreeViewNodeFilterResult(FilterResult.Recurse, isMatch);
 }
예제 #23
0
        void Search(IDnSpyFile ownerModule, TypeDef type, EventDef evt)
        {
            var res = options.Filter.GetResult(evt);
            if (res.FilterType == FilterType.Hide)
                return;
            CheckCustomAttributes(ownerModule, evt, type);

            if (res.IsMatch && IsMatch(evt.Name, evt)) {
                options.OnMatch(new SearchResult {
                    Context = options.Context,
                    Object = evt,
                    NameObject = evt,
                    ObjectImageReference = options.DotNetImageManager.GetImageReference(evt),
                    LocationObject = type,
                    LocationImageReference = options.DotNetImageManager.GetImageReference(type),
                    DnSpyFile = ownerModule,
                });
            }
        }
예제 #24
0
        public TreeNode NewEvent(EventDef @event)
        {
            TreeNode node = NewNode(String.Format("{0}: {1}", @event.Name, "EventHandler"));

            node.Tag = @event;
            node.ImageIndex = node.SelectedImageIndex = 15;

            if (@event.AddMethod != null)
            {
                node.Nodes.Add(NewMethod(@event.AddMethod));
            }

            if (@event.RemoveMethod != null)
            {
                node.Nodes.Add(NewMethod(@event.RemoveMethod));
            }

            if (@event.InvokeMethod != null)
            {
                node.Nodes.Add(NewMethod(@event.InvokeMethod));
            }

            foreach (MethodDef method in @event.OtherMethods)
            {
                node.Nodes.Add(NewMethod(method));
            }

            return node;
        }
		public static bool CanShow(EventDef ev) {
			return GetBackingField(ev) != null;
		}
예제 #26
0
 /// <summary>
 /// Looks up the event node corresponding to the event definition.
 /// Returns null if no matching node is found.
 /// </summary>
 public EventTreeNode FindEventNode(EventDef def)
 {
     if (def == null)
         return null;
     TypeTreeNode typeNode = FindTypeNode(def.DeclaringType);
     if (typeNode == null)
         return null;
     typeNode.EnsureChildrenFiltered();
     return typeNode.Children.OfType<EventTreeNode>().FirstOrDefault(m => m.EventDefinition == def);
 }
		public virtual DocumentTreeNodeFilterResult GetResult(EventDef evt) => new DocumentTreeNodeFilterResult();
		// HACK: we should probably examine add/remove methods to determine this
		private static FieldDef GetBackingField(EventDef ev) {
			var fieldName = ev.Name;
			var vbStyleFieldName = fieldName + "Event";
			var fieldType = ev.EventType;
			if (fieldType == null)
				return null;

			foreach (var fd in ev.DeclaringType.Fields) {
				if (fd.Name == fieldName || fd.Name == vbStyleFieldName)
					if (new SigComparer().Equals(fd.FieldType, fieldType))
						return fd;
			}

			return null;
		}
예제 #29
0
		public virtual void Decompile(EventDef ev, IDecompilerOutput output, DecompilationContext ctx) =>
			this.WriteCommentLine(output, TypeToString(ev.DeclaringType, true) + "." + ev.Name);
예제 #30
0
 static IEnumerable<MethodDef> GetMethods(EventDef evt)
 {
     if (evt.AddMethod != null) yield return evt.AddMethod;
     if (evt.InvokeMethod != null) yield return evt.InvokeMethod;
     if (evt.RemoveMethod != null) yield return evt.RemoveMethod;
     foreach (var m in evt.OtherMethods) yield return m;
 }
예제 #31
0
 public ModelInfo(EventDef evt)
 {
     this.OwnerType = evt.DeclaringType;
     this.EventIndex = this.OwnerType.Events.IndexOf(evt);
     Debug.Assert(this.EventIndex >= 0);
     this.Methods = new HashSet<MethodDef>(GetMethods(evt)).ToArray();
     this.MethodIndexes = new int[this.Methods.Length];
 }
예제 #32
0
 private IResType ResolveType(dnlib.DotNet.EventDef source)
 => Resolver.Resolve(source.EventType.ToTypeSig());
		public virtual TreeViewNodeFilterResult GetFilterResult(EventDef evt) {
			return new TreeViewNodeFilterResult(FilterResult.Hidden, false);
		}