예제 #1
0
 public EventOverriddenNode(EventDef analyzedEvent) =>
 this.analyzedEvent = analyzedEvent ?? throw new ArgumentNullException(nameof(analyzedEvent));
예제 #2
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);
            }
        }
예제 #3
0
        void AnalyzeMethod(ConfuserContext context, INameService service, MethodDef method)
        {
            var dpRegInstrs        = new List <Tuple <bool, Instruction> >();
            var routedEvtRegInstrs = new List <Instruction>();

            foreach (Instruction instr in method.Body.Instructions)
            {
                if ((instr.OpCode.Code == Code.Call || instr.OpCode.Code == Code.Callvirt))
                {
                    var regMethod = (IMethod)instr.Operand;

                    if (regMethod.DeclaringType.FullName == "System.Windows.DependencyProperty" &&
                        regMethod.Name.String.StartsWith("Register"))
                    {
                        dpRegInstrs.Add(Tuple.Create(regMethod.Name.String.StartsWith("RegisterAttached"), instr));
                    }
                    else if (regMethod.DeclaringType.FullName == "System.Windows.EventManager" &&
                             regMethod.Name.String == "RegisterRoutedEvent")
                    {
                        routedEvtRegInstrs.Add(instr);
                    }
                }
                else if (instr.OpCode == OpCodes.Ldstr)
                {
                    var operand = ((string)instr.Operand).ToUpperInvariant();
                    if (operand.EndsWith(".BAML") || operand.EndsWith(".XAML"))
                    {
                        var match = UriPattern.Match(operand);
                        if (match.Success)
                        {
                            operand = match.Groups[1].Value;
                        }
                        else if (operand.Contains("/"))
                        {
                            context.Logger.WarnFormat("Fail to extract XAML name from '{0}'.", instr.Operand);
                        }

                        var reference = new BAMLStringReference(instr);
                        operand = operand.TrimStart('/');
                        var baml = operand.Substring(0, operand.Length - 5) + ".BAML";
                        var xaml = operand.Substring(0, operand.Length - 5) + ".XAML";
                        bamlRefs.AddListEntry(baml, reference);
                        bamlRefs.AddListEntry(xaml, reference);
                    }
                }
            }

            if (dpRegInstrs.Count == 0)
            {
                return;
            }

            var         traceSrv = context.Registry.GetService <ITraceService>();
            MethodTrace trace    = traceSrv.Trace(method);

            bool erred = false;

            foreach (var instrInfo in dpRegInstrs)
            {
                int[] args = trace.TraceArguments(instrInfo.Item2);
                if (args == null)
                {
                    if (!erred)
                    {
                        context.Logger.WarnFormat("Failed to extract dependency property name in '{0}'.", method.FullName);
                    }
                    erred = true;
                    continue;
                }
                Instruction ldstr = method.Body.Instructions[args[0]];
                if (ldstr.OpCode.Code != Code.Ldstr)
                {
                    if (!erred)
                    {
                        context.Logger.WarnFormat("Failed to extract dependency property name in '{0}'.", method.FullName);
                    }
                    erred = true;
                    continue;
                }

                var     name     = (string)ldstr.Operand;
                TypeDef declType = method.DeclaringType;
                bool    found    = false;
                if (instrInfo.Item1)                 // Attached DP
                {
                    MethodDef accessor;
                    if ((accessor = declType.FindMethod("Get" + name)) != null && accessor.IsStatic)
                    {
                        service.SetCanRename(accessor, false);
                        found = true;
                    }
                    if ((accessor = declType.FindMethod("Set" + name)) != null && accessor.IsStatic)
                    {
                        service.SetCanRename(accessor, false);
                        found = true;
                    }
                }

                // Normal DP
                // Find CLR property for attached DP as well, because it seems attached DP can be use as normal DP as well.
                PropertyDef property = null;
                if ((property = declType.FindProperty(name)) != null)
                {
                    service.SetCanRename(property, false);

                    found = true;
                    if (property.GetMethod != null)
                    {
                        service.SetCanRename(property.GetMethod, false);
                    }

                    if (property.SetMethod != null)
                    {
                        service.SetCanRename(property.SetMethod, false);
                    }

                    if (property.HasOtherMethods)
                    {
                        foreach (MethodDef accessor in property.OtherMethods)
                        {
                            service.SetCanRename(accessor, false);
                        }
                    }
                }
                if (!found)
                {
                    if (instrInfo.Item1)
                    {
                        context.Logger.WarnFormat("Failed to find the accessors of attached dependency property '{0}' in type '{1}'.",
                                                  name, declType.FullName);
                    }
                    else
                    {
                        context.Logger.WarnFormat("Failed to find the CLR property of normal dependency property '{0}' in type '{1}'.",
                                                  name, declType.FullName);
                    }
                }
            }

            erred = false;
            foreach (Instruction instr in routedEvtRegInstrs)
            {
                int[] args = trace.TraceArguments(instr);
                if (args == null)
                {
                    if (!erred)
                    {
                        context.Logger.WarnFormat("Failed to extract routed event name in '{0}'.", method.FullName);
                    }
                    erred = true;
                    continue;
                }
                Instruction ldstr = method.Body.Instructions[args[0]];
                if (ldstr.OpCode.Code != Code.Ldstr)
                {
                    if (!erred)
                    {
                        context.Logger.WarnFormat("Failed to extract routed event name in '{0}'.", method.FullName);
                    }
                    erred = true;
                    continue;
                }

                var     name     = (string)ldstr.Operand;
                TypeDef declType = method.DeclaringType;

                EventDef eventDef = null;
                if ((eventDef = declType.FindEvent(name)) == null)
                {
                    context.Logger.WarnFormat("Failed to find the CLR event of routed event '{0}' in type '{1}'.",
                                              name, declType.FullName);
                    continue;
                }
                service.SetCanRename(eventDef, false);

                if (eventDef.AddMethod != null)
                {
                    service.SetCanRename(eventDef.AddMethod, false);
                }

                if (eventDef.RemoveMethod != null)
                {
                    service.SetCanRename(eventDef.RemoveMethod, false);
                }

                if (eventDef.InvokeMethod != null)
                {
                    service.SetCanRename(eventDef.InvokeMethod, false);
                }

                if (eventDef.HasOtherMethods)
                {
                    foreach (MethodDef accessor in eventDef.OtherMethods)
                    {
                        service.SetCanRename(accessor, false);
                    }
                }
            }
        }
예제 #4
0
 public EventInfo evt(EventDef evt)
 {
     return allEventInfos[evt];
 }
예제 #5
0
 public static bool CanShow(EventDef ev)
 {
     return(GetBackingField(ev) != null);
 }
예제 #6
0
 public EventNode(ITreeNodeGroup treeNodeGroup, EventDef @event)
 {
     this.TreeNodeGroup = treeNodeGroup;
     this.EventDef      = @event;
 }
예제 #7
0
		/// <inheritdoc/>
		public override uint GetRid(EventDef ed) {
			uint rid;
			if (eventDefInfos.TryGetRid(ed, out rid))
				return rid;
			if (ed == null)
				Error("Event is null");
			else
				Error("Event {0} ({1:X8}) is not defined in this module ({2}). An event was removed that is still referenced by this module.", ed, ed.MDToken.Raw, module);
			return 0;
		}
예제 #8
0
 private static IEnumerable <MethodDef> AllMethods(this EventDef evt)
 {
     return(new[] { evt.AddMethod, evt.RemoveMethod, evt.InvokeMethod }
            .Concat(evt.OtherMethods)
            .Where(m => m != null));
 }
예제 #9
0
파일: TypeInfo.cs 프로젝트: ldh0227/de4dot
 public EventInfo evt(EventDef evt)
 {
     return memberInfos.evt(evt);
 }
예제 #10
0
 /// <summary>
 ///     Determines whether the specified event is static.
 /// </summary>
 /// <param name="evt">The event.</param>
 /// <returns><c>true</c> if the specified event is static; otherwise, <c>false</c>.</returns>
 public static bool IsStatic(this EventDef evt)
 {
     return(evt.AllMethods().Any(method => method.IsStatic));
 }
예제 #11
0
 /// <summary>
 ///     Determines whether the specified event is an explictly implemented interface member.
 /// </summary>
 /// <param name="evt">The event.</param>
 /// <returns><c>true</c> if the specified eve is an explictly implemented interface member; otherwise, <c>false</c>.</returns>
 public static bool IsExplicitlyImplementedInterfaceMember(this EventDef evt)
 {
     return(evt.AllMethods().Any(IsExplicitlyImplementedInterfaceMember));
 }
예제 #12
0
 /// <summary>
 /// Determines whether this specified event has private flags for all event methods.
 /// </summary>
 /// <param name="evt">The event.</param>
 /// <returns>
 ///   <c>true</c> if the specified property is family; otherwise, <c>false</c>.
 /// </returns>
 public static bool HasAllPrivateFlags(this EventDef evt)
 {
     return(evt.AllMethods().All(method => method.HasPrivateFlags()));
 }
예제 #13
0
 public MEventDef findAny(EventDef er)
 {
     return events.findAny(er);
 }
예제 #14
0
 public EventInfo(EventDef eventDef)
     : base(eventDef)
 {
 }
예제 #15
0
 public virtual void Decompile(EventDef ev, IDecompilerOutput output, DecompilationContext ctx) =>
 this.WriteCommentLine(output, TypeToString(ev.DeclaringType, true) + "." + ev.Name);
예제 #16
0
파일: TypeInfo.cs 프로젝트: ldh0227/de4dot
        void prepareRenameEvent(EventDef eventDef)
        {
            if (eventDef.isVirtual())
                throw new ApplicationException("Can't rename virtual events here");
            var eventInfo = evt(eventDef);
            if (eventInfo.renamed)
                return;

            string eventName = eventInfo.oldName;
            if (!NameChecker.isValidEventName(eventName))
                eventName = eventInfo.suggestedName;
            if (!NameChecker.isValidEventName(eventName))
                eventName = variableNameState.getNewEventName(eventDef.EventDefinition);
            variableNameState.addEventName(eventName);
            eventInfo.rename(eventName);

            renameSpecialMethod(eventDef.AddMethod, "add_" + eventName);
            renameSpecialMethod(eventDef.RemoveMethod, "remove_" + eventName);
            renameSpecialMethod(eventDef.RaiseMethod, "raise_" + eventName);
        }
예제 #17
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="event">Event</param>
 protected EventNode(EventDef @event) => EventDef = @event ?? throw new ArgumentNullException(nameof(@event));
예제 #18
0
 public virtual DocumentTreeNodeFilterResult GetResult(EventDef evt) => new DocumentTreeNodeFilterResult(FilterType.Hide, false);
예제 #19
0
		public MEventDef FindAny(EventDef er) {
			return events.FindAny(er);
		}
 public virtual FileTreeNodeFilterResult GetResult(EventDef evt) => this.filter.GetResult(evt);
예제 #21
0
 void Add(EventDef ed)
 {
     if (ed == null || eventDefs.ContainsKey(ed))
         return;
     if (ed.DeclaringType != null && ed.DeclaringType.Module != validModule)
         return;
     eventDefs[ed] = true;
     Push(ed.EventType);
     Add(ed.CustomAttributes);
     Add(ed.AddMethod);
     Add(ed.InvokeMethod);
     Add(ed.RemoveMethod);
     Add(ed.OtherMethods);
     Add(ed.DeclaringType);
 }
예제 #22
0
 public InterfaceEventImplementedByNode(EventDef analyzedEvent)
 {
     this.analyzedEvent = analyzedEvent ?? throw new ArgumentNullException(nameof(analyzedEvent));
     analyzedMethod     = this.analyzedEvent.AddMethod ?? this.analyzedEvent.RemoveMethod;
 }
예제 #23
0
 public virtual TreeViewNodeFilterResult GetFilterResult(EventDef evt)
 {
     return(new TreeViewNodeFilterResult(FilterResult.Hidden, false));
 }
예제 #24
0
 public static bool CanShow(EventDef ev) => ev.DeclaringType.IsInterface;
예제 #25
0
파일: TypeNode.cs 프로젝트: net10010/dnSpy
 public IEventNode Create(EventDef @event) => Context.FileTreeView.Create(@event);
예제 #26
0
        void AnalyzeMethod(ConfuserContext context, INameService service, MethodDef method)
        {
            var dpRegInstrs        = new List <Tuple <bool, Instruction> >();
            var routedEvtRegInstrs = new List <Instruction>();

            for (int i = 0; i < method.Body.Instructions.Count; i++)
            {
                Instruction instr = method.Body.Instructions[i];
                if ((instr.OpCode.Code == Code.Call || instr.OpCode.Code == Code.Callvirt))
                {
                    var regMethod = (IMethod)instr.Operand;

                    if (regMethod.DeclaringType.FullName == "System.Windows.DependencyProperty" &&
                        regMethod.Name.String.StartsWith("Register"))
                    {
                        dpRegInstrs.Add(Tuple.Create(regMethod.Name.String.StartsWith("RegisterAttached"), instr));
                    }
                    else if (regMethod.DeclaringType.FullName == "System.Windows.EventManager" &&
                             regMethod.Name.String == "RegisterRoutedEvent")
                    {
                        routedEvtRegInstrs.Add(instr);
                    }
                }
                else if (instr.OpCode.Code == Code.Newobj)
                {
                    var methodRef = (IMethod)instr.Operand;

                    if (methodRef.DeclaringType.FullName == "System.Windows.Data.PropertyGroupDescription" &&
                        methodRef.Name == ".ctor" && i - 1 >= 0 && method.Body.Instructions[i - 1].OpCode.Code == Code.Ldstr)
                    {
                        foreach (var property in analyzer.LookupProperty((string)method.Body.Instructions[i - 1].Operand))
                        {
                            service.SetCanRename(property, false);
                        }
                    }
                }
                else if (instr.OpCode == OpCodes.Ldstr)
                {
                    var operand = ((string)instr.Operand).ToUpperInvariant();
                    if (operand.EndsWith(".BAML") || operand.EndsWith(".XAML"))
                    {
                        var match = UriPattern.Match(operand);
                        if (match.Success)
                        {
                            var resourceAssemblyName = match.Groups[1].Success ? match.Groups[1].Value : string.Empty;
                            // Check if the expression contains a resource name (group 1)
                            // If it does, check if it is this assembly.
                            if (!string.IsNullOrWhiteSpace(resourceAssemblyName) &&
                                !resourceAssemblyName.Equals(method.Module.Assembly.Name.String, StringComparison.OrdinalIgnoreCase))
                            {
                                // This resource points to another assembly.
                                // Leave it alone!
                                return;
                            }
                            operand = match.Groups[2].Value;
                        }
                        else if (operand.Contains("/"))
                        {
                            context.Logger.WarnFormat("Fail to extract XAML name from '{0}'.", instr.Operand);
                        }

                        var reference = new BAMLStringReference(instr);
                        operand = WebUtility.UrlDecode(operand.TrimStart('/'));
                        var baml = operand.Substring(0, operand.Length - 5) + ".BAML";
                        var xaml = operand.Substring(0, operand.Length - 5) + ".XAML";
                        bamlRefs.AddListEntry(baml, reference);
                        bamlRefs.AddListEntry(xaml, reference);
                    }
                }
            }

            if (dpRegInstrs.Count == 0)
            {
                return;
            }

            var         traceSrv = context.Registry.GetService <ITraceService>();
            MethodTrace trace    = traceSrv.Trace(method);

            bool erred = false;

            foreach (var instrInfo in dpRegInstrs)
            {
                int[] args = trace.TraceArguments(instrInfo.Item2);
                if (args == null)
                {
                    if (!erred)
                    {
                        context.Logger.WarnFormat("Failed to extract dependency property name in '{0}'.", method.FullName);
                    }
                    erred = true;
                    continue;
                }
                Instruction ldstr = method.Body.Instructions[args[0]];
                if (ldstr.OpCode.Code != Code.Ldstr)
                {
                    if (!erred)
                    {
                        context.Logger.WarnFormat("Failed to extract dependency property name in '{0}'.", method.FullName);
                    }
                    erred = true;
                    continue;
                }

                var     name     = (string)ldstr.Operand;
                TypeDef declType = method.DeclaringType;
                bool    found    = false;
                if (instrInfo.Item1)                 // Attached DP
                {
                    MethodDef accessor;
                    if ((accessor = declType.FindMethod("Get" + name)) != null && accessor.IsStatic)
                    {
                        service.SetCanRename(accessor, false);
                        found = true;
                    }
                    if ((accessor = declType.FindMethod("Set" + name)) != null && accessor.IsStatic)
                    {
                        service.SetCanRename(accessor, false);
                        found = true;
                    }
                }

                // Normal DP
                // Find CLR property for attached DP as well, because it seems attached DP can be use as normal DP as well.
                PropertyDef property = null;
                if ((property = declType.FindProperty(name)) != null)
                {
                    service.SetCanRename(property, false);

                    found = true;
                    if (property.GetMethod != null)
                    {
                        service.SetCanRename(property.GetMethod, false);
                    }

                    if (property.SetMethod != null)
                    {
                        service.SetCanRename(property.SetMethod, false);
                    }

                    if (property.HasOtherMethods)
                    {
                        foreach (MethodDef accessor in property.OtherMethods)
                        {
                            service.SetCanRename(accessor, false);
                        }
                    }
                }
                if (!found)
                {
                    if (instrInfo.Item1)
                    {
                        context.Logger.WarnFormat("Failed to find the accessors of attached dependency property '{0}' in type '{1}'.",
                                                  name, declType.FullName);
                    }
                    else
                    {
                        context.Logger.WarnFormat("Failed to find the CLR property of normal dependency property '{0}' in type '{1}'.",
                                                  name, declType.FullName);
                    }
                }
            }

            erred = false;
            foreach (Instruction instr in routedEvtRegInstrs)
            {
                int[] args = trace.TraceArguments(instr);
                if (args == null)
                {
                    if (!erred)
                    {
                        context.Logger.WarnFormat("Failed to extract routed event name in '{0}'.", method.FullName);
                    }
                    erred = true;
                    continue;
                }
                Instruction ldstr = method.Body.Instructions[args[0]];
                if (ldstr.OpCode.Code != Code.Ldstr)
                {
                    if (!erred)
                    {
                        context.Logger.WarnFormat("Failed to extract routed event name in '{0}'.", method.FullName);
                    }
                    erred = true;
                    continue;
                }

                var     name     = (string)ldstr.Operand;
                TypeDef declType = method.DeclaringType;

                EventDef eventDef = null;
                if ((eventDef = declType.FindEvent(name)) == null)
                {
                    context.Logger.WarnFormat("Failed to find the CLR event of routed event '{0}' in type '{1}'.",
                                              name, declType.FullName);
                    continue;
                }
                service.SetCanRename(eventDef, false);

                if (eventDef.AddMethod != null)
                {
                    service.SetCanRename(eventDef.AddMethod, false);
                }

                if (eventDef.RemoveMethod != null)
                {
                    service.SetCanRename(eventDef.RemoveMethod, false);
                }

                if (eventDef.InvokeMethod != null)
                {
                    service.SetCanRename(eventDef.InvokeMethod, false);
                }

                if (eventDef.HasOtherMethods)
                {
                    foreach (MethodDef accessor in eventDef.OtherMethods)
                    {
                        service.SetCanRename(accessor, false);
                    }
                }
            }
        }
예제 #27
0
 public EditedEvent(EventDef originalEvent, EventDefOptions eventDefOptions)
 {
     OriginalEvent   = originalEvent;
     EventDefOptions = eventDefOptions;
 }
 public override TreeViewNodeFilterResult GetFilterResult(EventDef evt)
 {
     return(new TreeViewNodeFilterResult(FilterResult.Match, false));
 }
        public static bool CanShow(EventDef property)
        {
            var accessor = property.AddMethod ?? property.RemoveMethod;

            return(accessor != null && accessor.IsVirtual && !accessor.IsFinal && !accessor.DeclaringType.IsInterface);
        }
예제 #30
0
 public ScopedWhereUsedAnalyzer(IDsDocumentService documentService, EventDef eventDef, Func <TypeDef, IEnumerable <T> > typeAnalysisFunction)
     : this(documentService, eventDef.DeclaringType, typeAnalysisFunction) =>
예제 #31
0
    //-------------------------------------------------------------------------
    // 检查触发条件
    private bool _checkTriggerCondition()
    {
        EventDef entity_def    = mNode.getDefXml();
        var      trigger_group = entity_def.GetGroup("TrigCondition");

        if (trigger_group == null)
        {
            return(true);
        }
        if (trigger_group.Groups.Count == 0)
        {
            return(true);
        }

        bool blank = true;
        bool and   = true;

        {
            Property p = trigger_group.GetValue("Conjunction");
            if (p.Value == "2")
            {
                and = false;
            }
        }

        foreach (Group g in trigger_group.Groups)
        {
            INodeTriggerCondition tc = mNode.getNodeSys().getEntityTriggerCondition(g.Key);
            if (tc != null)
            {
                tc.setEntity(mNode);
                bool result = tc.excute(g);
                if (and)
                {
                    if (!result)
                    {
                        return(false);
                    }
                }
                else
                {
                    if (result)
                    {
                        return(true);
                    }
                }
                blank = false;
            }
        }

        if (blank)
        {
            return(true);
        }

        if (and)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
예제 #32
0
 /// <summary>
 /// Initialises a new instance of the EventPage class.
 /// </summary>
 /// <param name="eventDef">The event to be documented.</param>
 /// <param name="xmlComments">The xml comments associated with the defining library.</param>
 public EventPage(EventDef eventDef, ICommentSource xmlComments)
 {
     this.eventDef    = eventDef;
     this.xmlComments = xmlComments;
 }
예제 #33
0
 public virtual TreeViewNodeFilterResult GetFilterResult(EventDef evt)
 {
     return(filter.GetFilterResult(evt));
 }
예제 #34
0
 public EventNode Create(EventDef @event) =>
 (EventNode)TreeView.Create(new EventNodeImpl(DocumentTreeNodeGroups.GetGroup(DocumentTreeNodeGroupType.EventTreeNodeGroupType), @event)).Data;
예제 #35
0
		/// <inheritdoc/>
		public override uint GetRid(EventDef ed) {
			uint rid;
			if (eventDefInfos.TryGetRid(ed, out rid))
				return rid;
			if (ed == null)
				Error("Event is null");
			else
				Error("Event {0} ({1:X8}) is not defined in this module ({2})", ed, ed.MDToken.Raw, module);
			return 0;
		}
예제 #36
0
파일: Node.cs 프로젝트: yinlei/Fishing
    //-------------------------------------------------------------------------
    internal void _loadDefXml()
    {
        mNodeDef = mNodeSys.getNodeDef(mNodeId);

        Property pEvtType = mNodeDef.GetValue("Type");
        mNodeType = pEvtType.Value.ToString();
    }
예제 #37
0
 public EventInfo evt(EventDef evt)
 {
     return(memberInfos.evt(evt));
 }
 public override DocumentTreeNodeFilterResult GetResult(EventDef evt) => new DocumentTreeNodeFilterResult(FilterType.Visible, false);
예제 #39
0
		public MEventDef Create(EventDef newEvent) {
			if (FindAny(newEvent) != null)
				throw new ApplicationException("Can't add an event when it's already been added");

			var eventDef = new MEventDef(newEvent, this, events.Count);
			Add(eventDef);
			TypeDef.Events.Add(newEvent);
			return eventDef;
		}
예제 #40
0
 public EventNodeImpl(ITreeNodeGroup treeNodeGroup, EventDef @event)
     : base(@event)
 {
     this.TreeNodeGroup = treeNodeGroup;
 }
예제 #41
0
파일: EventDef.cs 프로젝트: GodLesZ/de4dot
		public MEventDef(EventDef eventDef, MTypeDef owner, int index)
			: base(eventDef, owner, index) {
		}
예제 #42
0
 public IEventNode Create(EventDef @event) =>
 (IEventNode)TreeView.Create(new EventNode(FileTreeNodeGroups.GetGroup(FileTreeNodeGroupType.EventTreeNodeGroupType), @event)).Data;
예제 #43
0
		public void RemoveEventDef(EventDef ed) {
			if (!EventDefs.Remove(ed))
				throw new ApplicationException(string.Format("Could not remove EventDef: {0}", ed));
		}
예제 #44
0
 public void add(EventDef evt)
 {
     allEventInfos[evt] = new EventInfo(evt);
 }