public EventOverriddenNode(EventDef analyzedEvent) => this.analyzedEvent = analyzedEvent ?? throw new ArgumentNullException(nameof(analyzedEvent));
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); } }
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); } } } }
public EventInfo evt(EventDef evt) { return allEventInfos[evt]; }
public static bool CanShow(EventDef ev) { return(GetBackingField(ev) != null); }
public EventNode(ITreeNodeGroup treeNodeGroup, EventDef @event) { this.TreeNodeGroup = treeNodeGroup; this.EventDef = @event; }
/// <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; }
private static IEnumerable <MethodDef> AllMethods(this EventDef evt) { return(new[] { evt.AddMethod, evt.RemoveMethod, evt.InvokeMethod } .Concat(evt.OtherMethods) .Where(m => m != null)); }
public EventInfo evt(EventDef evt) { return memberInfos.evt(evt); }
/// <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)); }
/// <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)); }
/// <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())); }
public MEventDef findAny(EventDef er) { return events.findAny(er); }
public EventInfo(EventDef eventDef) : base(eventDef) { }
public virtual void Decompile(EventDef ev, IDecompilerOutput output, DecompilationContext ctx) => this.WriteCommentLine(output, TypeToString(ev.DeclaringType, true) + "." + ev.Name);
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); }
/// <summary> /// Constructor /// </summary> /// <param name="event">Event</param> protected EventNode(EventDef @event) => EventDef = @event ?? throw new ArgumentNullException(nameof(@event));
public virtual DocumentTreeNodeFilterResult GetResult(EventDef evt) => new DocumentTreeNodeFilterResult(FilterType.Hide, false);
public MEventDef FindAny(EventDef er) { return events.FindAny(er); }
public virtual FileTreeNodeFilterResult GetResult(EventDef evt) => this.filter.GetResult(evt);
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); }
public InterfaceEventImplementedByNode(EventDef analyzedEvent) { this.analyzedEvent = analyzedEvent ?? throw new ArgumentNullException(nameof(analyzedEvent)); analyzedMethod = this.analyzedEvent.AddMethod ?? this.analyzedEvent.RemoveMethod; }
public virtual TreeViewNodeFilterResult GetFilterResult(EventDef evt) { return(new TreeViewNodeFilterResult(FilterResult.Hidden, false)); }
public static bool CanShow(EventDef ev) => ev.DeclaringType.IsInterface;
public IEventNode Create(EventDef @event) => Context.FileTreeView.Create(@event);
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); } } } }
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); }
public ScopedWhereUsedAnalyzer(IDsDocumentService documentService, EventDef eventDef, Func <TypeDef, IEnumerable <T> > typeAnalysisFunction) : this(documentService, eventDef.DeclaringType, typeAnalysisFunction) =>
//------------------------------------------------------------------------- // 检查触发条件 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); } }
/// <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; }
public virtual TreeViewNodeFilterResult GetFilterResult(EventDef evt) { return(filter.GetFilterResult(evt)); }
public EventNode Create(EventDef @event) => (EventNode)TreeView.Create(new EventNodeImpl(DocumentTreeNodeGroups.GetGroup(DocumentTreeNodeGroupType.EventTreeNodeGroupType), @event)).Data;
/// <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; }
//------------------------------------------------------------------------- internal void _loadDefXml() { mNodeDef = mNodeSys.getNodeDef(mNodeId); Property pEvtType = mNodeDef.GetValue("Type"); mNodeType = pEvtType.Value.ToString(); }
public EventInfo evt(EventDef evt) { return(memberInfos.evt(evt)); }
public override DocumentTreeNodeFilterResult GetResult(EventDef evt) => new DocumentTreeNodeFilterResult(FilterType.Visible, false);
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; }
public EventNodeImpl(ITreeNodeGroup treeNodeGroup, EventDef @event) : base(@event) { this.TreeNodeGroup = treeNodeGroup; }
public MEventDef(EventDef eventDef, MTypeDef owner, int index) : base(eventDef, owner, index) { }
public IEventNode Create(EventDef @event) => (IEventNode)TreeView.Create(new EventNode(FileTreeNodeGroups.GetGroup(FileTreeNodeGroupType.EventTreeNodeGroupType), @event)).Data;
public void RemoveEventDef(EventDef ed) { if (!EventDefs.Remove(ed)) throw new ApplicationException(string.Format("Could not remove EventDef: {0}", ed)); }
public void add(EventDef evt) { allEventInfos[evt] = new EventInfo(evt); }