IUndoObject GetUndoObjectNoChecks(IDsDocument document) { var uo = document.Annotation <UndoObject>() ?? document.AddAnnotation(new UndoObject()); uo.Value = document; return(uo); }
IDsDocument TryLoadFromDir2(IAssembly asmName, bool checkVersion, bool checkPublicKeyToken, string filename) { if (!File.Exists(filename)) return null; IDsDocument document = null; bool error = true; try { document = documentService.TryCreateDocument(DsDocumentInfo.CreateDocument(filename)); if (document == null) return null; document.IsAutoLoaded = true; var asm = document.AssemblyDef; if (asm == null) return null; var flags = AssemblyNameComparerFlags.All & ~(AssemblyNameComparerFlags.Version | AssemblyNameComparerFlags.PublicKeyToken); if (checkVersion) flags |= AssemblyNameComparerFlags.Version; if (checkPublicKeyToken) flags |= AssemblyNameComparerFlags.PublicKeyToken; bool b = new AssemblyNameComparer(flags).Equals(asmName, asm); if (!b) return null; error = false; return document; } finally { if (error) { if (document is IDisposable) ((IDisposable)document).Dispose(); } } }
void Search(IDsDocument ownerModule, string nsOwner, TypeDef type) { var res = options.Filter.GetResult(type); if (res.FilterType == FilterType.Hide) { return; } CheckCustomAttributes(ownerModule, type, nsOwner); if (res.IsMatch && (IsMatch(type.FullName, type) || IsMatch(type.Name, type))) { options.OnMatch(new SearchResult { Context = options.Context, Object = type, NameObject = type, ObjectImageReference = options.DotNetImageService.GetImageReference(type), LocationObject = new NamespaceSearchResult(nsOwner), LocationImageReference = options.DotNetImageService.GetNamespaceImageReference(), Document = ownerModule, }); } SearchMembers(ownerModule, type); foreach (var subType in type.GetTypes()) { options.CancellationToken.ThrowIfCancellationRequested(); Search(ownerModule, subType); } }
void Search(IDsDocument ownerModule, TypeDef type) { var res = options.Filter.GetResult(type); if (res.FilterType == FilterType.Hide) { return; } CheckCustomAttributes(ownerModule, type, type.DeclaringType); if (res.IsMatch && (IsMatch(type.FullName, type) || IsMatch(type.Name, type))) { options.OnMatch(new SearchResult { Context = options.Context, Object = type, NameObject = type, ObjectImageReference = options.DotNetImageService.GetImageReference(type), LocationObject = type.DeclaringType, LocationImageReference = options.DotNetImageService.GetImageReference(type.DeclaringType), Document = ownerModule, }); } SearchMembers(ownerModule, type); }
void CheckCustomAttributes(IDsDocument file, IHasCustomAttribute hca, object parent) { var res = options.Filter.GetResultAttributes(hca); if (!res.IsMatch) { return; } foreach (var ca in hca.CustomAttributes) { options.CancellationToken.ThrowIfCancellationRequested(); foreach (var o in ca.ConstructorArguments) { options.CancellationToken.ThrowIfCancellationRequested(); if (CheckCA(file, hca, parent, o)) { return; } } foreach (var o in ca.NamedArguments) { options.CancellationToken.ThrowIfCancellationRequested(); if (CheckCA(file, hca, parent, o.Argument)) { return; } } } }
void Search(IDsDocument ownerModule, TypeDef type, FieldDef field) { var res = options.Filter.GetResult(field); if (res.FilterType == FilterType.Hide) { return; } CheckCustomAttributes(ownerModule, field, type); ImplMap im; if (res.IsMatch && (IsMatch(field.Name, field) || ((im = field.ImplMap) != null && (IsMatch(im.Name, im) || IsMatch(im.Module?.Name, null))))) { options.OnMatch(new SearchResult { Context = options.Context, Object = field, NameObject = field, ObjectImageReference = options.DotNetImageService.GetImageReference(field), LocationObject = type, LocationImageReference = options.DotNetImageService.GetImageReference(type), Document = ownerModule, }); } }
/// <summary> /// Gets all its children and their children /// </summary> /// <param name="self">This</param> /// <returns></returns> public static IEnumerable <IDsDocument> GetAllChildren(this IDsDocument self) { foreach (var c in GetAllChildren(self.Children)) { yield return(c); } }
public override DocumentTreeNodeFilterResult GetResult(IDsDocument document) { var thisFlag = VisibleMembersFlags.NonNetFile; var visibleFlags = thisFlag | VisibleMembersFlags.Other | VisibleMembersFlags.Attributes; return(FilterFile(thisFlag, visibleFlags)); }
void Search(IDsDocument ownerModule, string ns, List <TypeDef> types) { var res = options.Filter.GetResult(ns, ownerModule); if (res.FilterType == FilterType.Hide) { return; } if (res.IsMatch && IsMatch(ns, ns)) { options.OnMatch(new SearchResult { Context = options.Context, Object = ns, NameObject = new NamespaceSearchResult(ns), ObjectImageReference = options.DotNetImageService.GetNamespaceImageReference(), LocationObject = ownerModule.ModuleDef, LocationImageReference = options.DotNetImageService.GetImageReference(ownerModule.ModuleDef), Document = ownerModule, }); } foreach (var type in types) { options.CancellationToken.ThrowIfCancellationRequested(); Search(ownerModule, ns, type); } }
HashSet <IDsDocument> GetModifiedDocuments(IDsDocument document) { var documentsHash = new HashSet <IDsDocument>(); documentsHash.Add(document); var node = DocumentTreeView.FindNode(document); if (node is ModuleDocumentNode) { if (node.Document.AssemblyDef != null && node.Document.AssemblyDef.ManifestModule == node.Document.ModuleDef) { var asmNode = node.GetAssemblyNode(); Debug.Assert(asmNode != null); if (asmNode != null) { documentsHash.Add(asmNode.Document); } } } else if (node is AssemblyDocumentNode) { node.TreeNode.EnsureChildrenLoaded(); var manifestModNode = node.TreeNode.DataChildren.FirstOrDefault() as ModuleDocumentNode; Debug.Assert(manifestModNode != null); if (manifestModNode != null) { documentsHash.Add(manifestModNode.Document); } } return(documentsHash); }
public static bool GoToIL(IModuleIdProvider moduleIdProvider, IDocumentTabService documentTabService, IDsDocument document, uint token, uint ilOffset, bool newTab) { if (document == null) return false; var method = document.ModuleDef.ResolveToken(token) as MethodDef; if (method == null) return false; var modId = moduleIdProvider.Create(method.Module); var key = new ModuleTokenId(modId, method.MDToken); bool found = documentTabService.DocumentTreeView.FindNode(method.Module) != null; if (found) { documentTabService.FollowReference(method, newTab, true, e => { Debug.Assert(e.Tab.UIContext is IDocumentViewer); if (e.Success && !e.HasMovedCaret) { MoveCaretTo(e.Tab.UIContext as IDocumentViewer, key, ilOffset); e.HasMovedCaret = true; } }); return true; } Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { documentTabService.FollowReference(method, newTab, true, e => { Debug.Assert(e.Tab.UIContext is IDocumentViewer); if (e.Success && !e.HasMovedCaret) { MoveCaretTo(e.Tab.UIContext as IDocumentViewer, key, ilOffset); e.HasMovedCaret = true; } }); })); return true; }
void SearchNonNetFile(IDsDocument nonNetFile) { if (nonNetFile == null) { return; } var res = options.Filter.GetResult(nonNetFile); if (res.FilterType == FilterType.Hide) { return; } if (res.IsMatch && IsMatch(nonNetFile.GetShortName(), nonNetFile)) { options.OnMatch(new SearchResult { Context = options.Context, Object = nonNetFile, NameObject = nonNetFile, ObjectImageReference = options.DotNetImageService.GetImageReference(nonNetFile.PEImage), LocationObject = null, LocationImageReference = new ImageReference(), Document = nonNetFile, }); } }
public TabVM(TabsVM owner, IDocumentTab tab) { Owner = owner; Tab = tab; var node = tab.Content.Nodes.FirstOrDefault().GetTopNode(); document = node?.Document; }
public IDsDocumentNode FindNode(IDsDocument document) { if (document == null) { return(null); } return(Find(TopNodes, document)); }
/// <summary> /// Constructor /// </summary> /// <param name="document">Document</param> /// <param name="type">Type</param> public SearchTypeInfo(IDsDocument document, TypeDef type) { if (document == null) throw new ArgumentNullException(nameof(document)); if (type == null) throw new ArgumentNullException(nameof(type)); Document = document; Type = type; }
public override bool HandleAssemblyListChanged(IDsDocument[] removedAssemblies, IDsDocument[] addedAssemblies) { foreach (var asm in removedAssemblies) { if (Member.Module == asm.ModuleDef) return false; // remove this node } HandleAssemblyListChanged(TreeNode, removedAssemblies, addedAssemblies); return true; }
/// <summary> /// Writes a file /// </summary> /// <param name="output">Output</param> /// <param name="decompiler">Decompiler</param> /// <param name="document">Document</param> public void Write(ITextColorWriter output, IDecompiler decompiler, IDsDocument document) { var filename = GetFilename(document); var peImage = document.PEImage; if (peImage != null) output.Write(IsExe(peImage) ? BoxedTextColor.AssemblyExe : BoxedTextColor.Assembly, NameUtilities.CleanName(filename)); else output.Write(BoxedTextColor.Text, NameUtilities.CleanName(filename)); }
/// <summary> /// Disable memory mapped I/O /// </summary> /// <param name="document">Document</param> public static void DisableMemoryMappedIO(IDsDocument document) { if (document == null) { return; } DisableMemoryMappedIO(document.PEImage); }
/// <summary> /// Constructor /// </summary> /// <param name="document">Document</param> protected DsDocumentNode(IDsDocument document) { if (document == null) { throw new ArgumentNullException(nameof(document)); } this.Document = document; }
public override DocumentTreeNodeFilterResult GetResult(string ns, IDsDocument owner) { if (owner.ModuleDef != module) { return(new DocumentTreeNodeFilterResult(FilterType.Hide, false)); } return(new DocumentTreeNodeFilterResult(FilterType.Visible, false)); }
/// <summary> /// Creates a <see cref="NotifyDocumentCollectionType.Remove"/> instance /// </summary> /// <param name="document">Removed document</param> /// <param name="data">Data to send to listeners</param> /// <returns></returns> public static NotifyDocumentCollectionChangedEventArgs CreateRemove(IDsDocument document, object data) { if (document == null) { throw new ArgumentNullException(nameof(document)); } return(CreateRemove(new[] { document }, data)); }
public override bool HandleModelUpdated(IDsDocument[] documents) { if (Member.Module == null) return false; // remove this node if ((Member is IField || Member is IMethod || Member is PropertyDef || Member is EventDef) && Member.DeclaringType == null) return false; HandleModelUpdated(TreeNode, documents); return true; }
/// <summary> /// Creates a <see cref="NotifyDocumentCollectionType.Add"/> instance /// </summary> /// <param name="document">Added document</param> /// <param name="data">Data to send to listeners</param> /// <returns></returns> public static NotifyDocumentCollectionChangedEventArgs CreateAdd(IDsDocument document, object data) { if (document == null) throw new ArgumentNullException(nameof(document)); var e = new NotifyDocumentCollectionChangedEventArgs(); e.Type = NotifyDocumentCollectionType.Add; e.Documents = new IDsDocument[] { document }; e.Data = data; return e; }
/// <summary> /// Creates a <see cref="NotifyDocumentCollectionType.Clear"/> instance /// </summary> /// <param name="clearedDocuments">All cleared documents</param> /// <param name="data">Data to send to listeners</param> /// <returns></returns> public static NotifyDocumentCollectionChangedEventArgs CreateClear(IDsDocument[] clearedDocuments, object data) { if (clearedDocuments == null) throw new ArgumentNullException(nameof(clearedDocuments)); var e = new NotifyDocumentCollectionChangedEventArgs(); e.Type = NotifyDocumentCollectionType.Clear; e.Documents = clearedDocuments; e.Data = data; return e; }
/// <summary> /// Gets self and all its children /// </summary> /// <param name="self">This</param> /// <returns></returns> public static IEnumerable <IDsDocument> GetAllChildrenAndSelf(this IDsDocument self) { yield return(self); foreach (var c in self.GetAllChildren()) { yield return(c); } }
void Search(IDsDocument ownerModule, TypeDef type, MethodDef method) { var res = options.Filter.GetResult(method); if (res.FilterType == FilterType.Hide) { return; } CheckCustomAttributes(ownerModule, method, type); ImplMap im; if (res.IsMatch && (IsMatch(method.Name, method) || ((im = method.ImplMap) != null && (IsMatch(im.Name, im) || IsMatch(im.Module?.Name, null))))) { options.OnMatch(new SearchResult { Context = options.Context, Object = method, NameObject = method, ObjectImageReference = options.DotNetImageService.GetImageReference(method), LocationObject = type, LocationImageReference = options.DotNetImageService.GetImageReference(type), Document = ownerModule, }); return; } res = options.Filter.GetResultParamDefs(method); if (res.FilterType != FilterType.Hide) { foreach (var pd in method.ParamDefs) { options.CancellationToken.ThrowIfCancellationRequested(); CheckCustomAttributes(ownerModule, pd, method); res = options.Filter.GetResult(method, pd); if (res.FilterType == FilterType.Hide) { continue; } if (res.IsMatch && IsMatch(pd.Name, pd)) { options.OnMatch(new SearchResult { Context = options.Context, Object = method, NameObject = method, ObjectImageReference = options.DotNetImageService.GetImageReference(method), LocationObject = type, LocationImageReference = options.DotNetImageService.GetImageReference(type), Document = ownerModule, }); return; } } } SearchBody(ownerModule, type, method); }
public INamespaceNode FindNamespaceNode(IDsDocument module, string @namespace) { var modNode = FindNode(module) as IModuleDocumentNode; if (modNode != null) { return(modNode.FindNode(@namespace)); } return(null); }
/// <summary> /// Gets the short name of <paramref name="document"/>, which is usually the filename without /// the extension. /// </summary> /// <param name="document">Document</param> /// <returns></returns> public static string GetShortName(this IDsDocument document) { var shortName = GetShortName(document.Filename); if (string.IsNullOrEmpty(shortName)) { shortName = GetDefaultShortName(document) ?? string.Empty; } return(shortName); }
void SearchModAsmReferences(IDsDocument module) { var res = options.Filter.GetResult((IReferencesFolderNode)null); if (res.FilterType == FilterType.Hide) { return; } foreach (var asmRef in module.ModuleDef.GetAssemblyRefs()) { options.CancellationToken.ThrowIfCancellationRequested(); res = options.Filter.GetResult(asmRef); if (res.FilterType == FilterType.Hide) { continue; } if (res.IsMatch && (IsMatch(asmRef.FullName, asmRef) || IsMatch(asmRef.Name, null))) { options.OnMatch(new SearchResult { Context = options.Context, Object = asmRef, NameObject = asmRef, ObjectImageReference = options.DotNetImageService.GetImageReferenceAssemblyRef(), LocationObject = module.ModuleDef, LocationImageReference = options.DotNetImageService.GetImageReference(module.ModuleDef), Document = module, }); } } foreach (var modRef in module.ModuleDef.GetModuleRefs()) { options.CancellationToken.ThrowIfCancellationRequested(); res = options.Filter.GetResult(modRef); if (res.FilterType == FilterType.Hide) { continue; } if (res.IsMatch && IsMatch(modRef.FullName, modRef)) { options.OnMatch(new SearchResult { Context = options.Context, Object = modRef, NameObject = modRef, ObjectImageReference = options.DotNetImageService.GetImageReferenceModuleRef(), LocationObject = module.ModuleDef, LocationImageReference = options.DotNetImageService.GetImageReference(module.ModuleDef), Document = module, }); } } }
static string GetFilename(IDsDocument document) { string filename = null; try { filename = Path.GetFileName(document.Filename); } catch (ArgumentException) { } if (string.IsNullOrEmpty(filename)) filename = document.GetShortName(); return filename; }
internal static void GoToFile(IDocumentTabService documentTabService, IDsDocument document, bool newTab) { if (document == null) { return; } var obj = (object)document.ModuleDef ?? document; // The file could've been added lazily to the list so add a short delay before we select it Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => documentTabService.FollowReference(obj, newTab))); }
IDsDocument GetOrAdd_NoLock(IDsDocument document) { var existing = Find_NoLock(document.Key); if (existing != null) { return(existing); } documents.Add(document); return(document); }
/// <summary> /// Creates a <see cref="NotifyDocumentCollectionType.Add"/> instance /// </summary> /// <param name="document">Added document</param> /// <param name="data">Data to send to listeners</param> /// <returns></returns> public static NotifyDocumentCollectionChangedEventArgs CreateAdd(IDsDocument document, object?data) { if (document is null) { throw new ArgumentNullException(nameof(document)); } var e = new NotifyDocumentCollectionChangedEventArgs(new IDsDocument[] { document }); e.Type = NotifyDocumentCollectionType.Add; e.Data = data; return(e); }
public IDsDocument ForceAdd(IDsDocument document, bool delayLoad, object data) { if (document == null) { throw new ArgumentNullException(nameof(document)); } lock (lockObj) documents.Add(document); CallCollectionChanged(NotifyDocumentCollectionChangedEventArgs.CreateAdd(document, data), delayLoad); return(document); }
/// <summary> /// Constructor /// </summary> /// <param name="document">Document</param> /// <param name="type">Type</param> public SearchTypeInfo(IDsDocument document, TypeDef type) { if (document == null) { throw new ArgumentNullException(nameof(document)); } if (type == null) { throw new ArgumentNullException(nameof(type)); } Document = document; Type = type; }
public IDsDocumentNode CreateNode(IDsDocumentNode owner, IDsDocument document) { foreach (var provider in dsDocumentNodeProvider) { var result = provider.Value.Create(this, owner, document); if (result != null) { return(result); } } return(new UnknownDocumentNode(document)); }
IDsDocument AddTempCachedDocument(IDsDocument document) { // Disable mmap'd I/O before adding it to the temp cache to prevent another thread from // getting the same file while we're disabling mmap'd I/O. Could lead to crashes. DisableMMapdIO(document); lock (tempCache) { if (!AssemblyLoadEnabled) { tempCache.Add(document); } } return(document); }
/// <summary> /// Writes a file /// </summary> /// <param name="output">Output</param> /// <param name="decompiler">Decompiler</param> /// <param name="document">Document</param> public void Write(ITextColorWriter output, IDecompiler decompiler, IDsDocument document) { var filename = GetFilename(document); var peImage = document.PEImage; if (peImage != null) { output.Write(IsExe(peImage) ? BoxedTextColor.AssemblyExe : BoxedTextColor.Assembly, NameUtilities.CleanName(filename)); } else { output.Write(BoxedTextColor.Text, NameUtilities.CleanName(filename)); } }
public DsDocumentNode Create(IDocumentTreeView documentTreeView, DsDocumentNode owner, IDsDocument document) { var dnDocument = document as IDsDotNetDocument; if (dnDocument != null) { Debug.Assert(document.ModuleDef != null); if (document.AssemblyDef == null || owner != null) return new ModuleDocumentNodeImpl(dnDocument); return new AssemblyDocumentNodeImpl(dnDocument); } Debug.Assert(document.AssemblyDef == null && document.ModuleDef == null); if (document.PEImage != null) return new PEDocumentNodeImpl(document); return null; }
bool CheckCA(IDsDocument file, IHasCustomAttribute hca, object parent, CAArgument o) { var value = o.Value; var u = value as UTF8String; if (!ReferenceEquals(u, null)) value = u.String; if (!IsMatch(null, value)) return false; options.OnMatch(new SearchResult { Context = options.Context, Object = hca, NameObject = hca, ObjectImageReference = GetImageReference(hca), LocationObject = parent is string ? new NamespaceSearchResult((string)parent) : parent, LocationImageReference = GetImageReference(parent), Document = file, }); return true; }
void CheckCustomAttributes(IDsDocument file, IHasCustomAttribute hca, object parent) { var res = options.Filter.GetResultAttributes(hca); if (!res.IsMatch) return; foreach (var ca in hca.CustomAttributes) { options.CancellationToken.ThrowIfCancellationRequested(); foreach (var o in ca.ConstructorArguments) { options.CancellationToken.ThrowIfCancellationRequested(); if (CheckCA(file, hca, parent, o)) return; } foreach (var o in ca.NamedArguments) { options.CancellationToken.ThrowIfCancellationRequested(); if (CheckCA(file, hca, parent, o.Argument)) return; } } }
public virtual DocumentTreeNodeFilterResult GetResult(string ns, IDsDocument owner) => new DocumentTreeNodeFilterResult();
void SearchNonNetFile(IDsDocument nonNetFile) { if (nonNetFile == null) return; var res = options.Filter.GetResult(nonNetFile); if (res.FilterType == FilterType.Hide) return; if (res.IsMatch && IsMatch(nonNetFile.GetShortName(), nonNetFile)) { options.OnMatch(new SearchResult { Context = options.Context, Object = nonNetFile, NameObject = nonNetFile, ObjectImageReference = options.DotNetImageService.GetImageReference(nonNetFile.PEImage), LocationObject = null, LocationImageReference = new ImageReference(), Document = nonNetFile, }); } }
void Search(IDsDocument ownerModule, string ns, List<TypeDef> types) { var res = options.Filter.GetResult(ns, ownerModule); if (res.FilterType == FilterType.Hide) return; if (res.IsMatch && IsMatch(ns, ns)) { options.OnMatch(new SearchResult { Context = options.Context, Object = ns, NameObject = new NamespaceSearchResult(ns), ObjectImageReference = options.DotNetImageService.GetNamespaceImageReference(), LocationObject = ownerModule.ModuleDef, LocationImageReference = options.DotNetImageService.GetImageReference(ownerModule.ModuleDef), Document = ownerModule, }); } foreach (var type in types) { options.CancellationToken.ThrowIfCancellationRequested(); Search(ownerModule, ns, type); } }
void Search(IDsDocument ownerModule, string nsOwner, TypeDef type) { var res = options.Filter.GetResult(type); if (res.FilterType == FilterType.Hide) return; CheckCustomAttributes(ownerModule, type, nsOwner); if (res.IsMatch && (IsMatch(type.FullName, type) || IsMatch(type.Name, type))) { options.OnMatch(new SearchResult { Context = options.Context, Object = type, NameObject = type, ObjectImageReference = options.DotNetImageService.GetImageReference(type), LocationObject = new NamespaceSearchResult(nsOwner), LocationImageReference = options.DotNetImageService.GetNamespaceImageReference(), Document = ownerModule, }); } SearchMembers(ownerModule, type); foreach (var subType in type.GetTypes()) { options.CancellationToken.ThrowIfCancellationRequested(); Search(ownerModule, subType); } }
void Search(IDsDocument ownerModule, TypeDef type) { var res = options.Filter.GetResult(type); if (res.FilterType == FilterType.Hide) return; CheckCustomAttributes(ownerModule, type, type.DeclaringType); if (res.IsMatch && (IsMatch(type.FullName, type) || IsMatch(type.Name, type))) { options.OnMatch(new SearchResult { Context = options.Context, Object = type, NameObject = type, ObjectImageReference = options.DotNetImageService.GetImageReference(type), LocationObject = type.DeclaringType, LocationImageReference = options.DotNetImageService.GetImageReference(type.DeclaringType), Document = ownerModule, }); } SearchMembers(ownerModule, type); }
IUndoObject GetUndoObject(IDsDocument document) => GetUndoObjectNoChecks(GetDocumentFile(document));
void SearchBody(IDsDocument ownerModule, TypeDef type, MethodDef method) { CilBody body; var res = options.Filter.GetResultLocals(method); if (res.FilterType != FilterType.Hide) { body = method.Body; if (body == null) return; // Return immediately. All code here depends on a non-null body foreach (var local in body.Variables) { options.CancellationToken.ThrowIfCancellationRequested(); res = options.Filter.GetResult(method, local); if (res.FilterType == FilterType.Hide) continue; if (res.IsMatch && IsMatch(local.Name, local)) { options.OnMatch(new SearchResult { Context = options.Context, Object = method, NameObject = method, ObjectImageReference = options.DotNetImageService.GetImageReference(method), LocationObject = type, LocationImageReference = options.DotNetImageService.GetImageReference(type), Document = ownerModule, }); return; } } } res = options.Filter.GetResultBody(method); if (res.FilterType == FilterType.Hide) return; if (!res.IsMatch) return; body = method.Body; if (body == null) return; int counter = 0; foreach (var instr in body.Instructions) { if (counter++ > 1000) { options.CancellationToken.ThrowIfCancellationRequested(); counter = 0; } object operand; // Only check numbers and strings. Don't pass in any type of operand to IsMatch() switch (instr.OpCode.Code) { case Code.Ldc_I4_M1: operand = -1; break; case Code.Ldc_I4_0: operand = 0; break; case Code.Ldc_I4_1: operand = 1; break; case Code.Ldc_I4_2: operand = 2; break; case Code.Ldc_I4_3: operand = 3; break; case Code.Ldc_I4_4: operand = 4; break; case Code.Ldc_I4_5: operand = 5; break; case Code.Ldc_I4_6: operand = 6; break; case Code.Ldc_I4_7: operand = 7; break; case Code.Ldc_I4_8: operand = 8; break; case Code.Ldc_I4: case Code.Ldc_I4_S: case Code.Ldc_R4: case Code.Ldc_R8: case Code.Ldstr: operand = instr.Operand; break; default: operand = null; break; } if (operand != null && IsMatch(null, operand)) { options.OnMatch(new SearchResult { Context = options.Context, Object = method, NameObject = method, ObjectImageReference = options.DotNetImageService.GetImageReference(method), LocationObject = type, LocationImageReference = options.DotNetImageService.GetImageReference(type), Document = ownerModule, ObjectInfo = new BodyResult(instr.Offset), }); break; } } }
IDsDocument GetDocumentFile(IDsDocument document) { var dnDocument = document as IDsDotNetDocument; if (dnDocument != null) { // Assemblies and manifest modules don't share a IDsDocument instance, but we must // use the same IUndoObject instance since they're part of the same file. var module = document.ModuleDef; Debug.Assert(module != null); if (module == null) throw new InvalidOperationException(); var modFile = FindModule(module); // It could've been removed but some menu item handler could still have a reference // to the module. return modFile ?? document; } return document; }
void SearchModAsmReferences(IDsDocument module) { var res = options.Filter.GetResult((ReferencesFolderNode)null); if (res.FilterType == FilterType.Hide) return; foreach (var asmRef in module.ModuleDef.GetAssemblyRefs()) { options.CancellationToken.ThrowIfCancellationRequested(); res = options.Filter.GetResult(asmRef); if (res.FilterType == FilterType.Hide) continue; if (res.IsMatch && (IsMatch(asmRef.FullName, asmRef) || IsMatch(asmRef.Name, null))) { options.OnMatch(new SearchResult { Context = options.Context, Object = asmRef, NameObject = asmRef, ObjectImageReference = options.DotNetImageService.GetImageReferenceAssemblyRef(), LocationObject = module.ModuleDef, LocationImageReference = options.DotNetImageService.GetImageReference(module.ModuleDef), Document = module, }); } } foreach (var modRef in module.ModuleDef.GetModuleRefs()) { options.CancellationToken.ThrowIfCancellationRequested(); res = options.Filter.GetResult(modRef); if (res.FilterType == FilterType.Hide) continue; if (res.IsMatch && IsMatch(modRef.FullName, modRef)) { options.OnMatch(new SearchResult { Context = options.Context, Object = modRef, NameObject = modRef, ObjectImageReference = options.DotNetImageService.GetImageReferenceModuleRef(), LocationObject = module.ModuleDef, LocationImageReference = options.DotNetImageService.GetImageReference(module.ModuleDef), Document = module, }); } } }
void SearchResourceElementTreeNode(IDsDocument module, ResourceNode resTreeNode, ResourceElementNode resElNode) { var res = options.Filter.GetResult(resElNode); if (res.FilterType == FilterType.Hide) return; if (res.IsMatch) { bool m = IsMatch(resElNode.Name, resElNode); if (!m) { var builtin = resElNode.ResourceElement.ResourceData as BuiltInResourceData; if (builtin != null) { var val = builtin.Data; if (builtin.Code == ResourceTypeCode.TimeSpan) val = ((TimeSpan)val).Ticks; m = IsMatch(val as string, val); } } if (!m) m = IsMatch(ToString(resElNode), null); if (m) { options.OnMatch(new SearchResult { Context = options.Context, Object = resElNode, NameObject = resElNode, ObjectImageReference = resElNode.Icon, LocationObject = resTreeNode, LocationImageReference = resTreeNode.Icon, Document = module, }); } } }
void SearchMembers(IDsDocument ownerModule, TypeDef type) { foreach (var method in type.Methods) { options.CancellationToken.ThrowIfCancellationRequested(); Search(ownerModule, type, method); } foreach (var field in type.Fields) { options.CancellationToken.ThrowIfCancellationRequested(); Search(ownerModule, type, field); } foreach (var prop in type.Properties) { options.CancellationToken.ThrowIfCancellationRequested(); Search(ownerModule, type, prop); } foreach (var evt in type.Events) { options.CancellationToken.ThrowIfCancellationRequested(); Search(ownerModule, type, evt); } }
void Search(IDsDocument 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.DotNetImageService.GetImageReference(evt), LocationObject = type, LocationImageReference = options.DotNetImageService.GetImageReference(type), Document = ownerModule, }); } }
void Search(IDsDocument ownerModule, TypeDef type, FieldDef field) { var res = options.Filter.GetResult(field); if (res.FilterType == FilterType.Hide) return; CheckCustomAttributes(ownerModule, field, type); ImplMap im; if (res.IsMatch && (IsMatch(field.Name, field) || ((im = field.ImplMap) != null && (IsMatch(im.Name, im) || IsMatch(im.Module?.Name, null))))) { options.OnMatch(new SearchResult { Context = options.Context, Object = field, NameObject = field, ObjectImageReference = options.DotNetImageService.GetImageReference(field), LocationObject = type, LocationImageReference = options.DotNetImageService.GetImageReference(type), Document = ownerModule, }); } }
public virtual DocumentTreeNodeFilterResult GetResult(IDsDocument document) => new DocumentTreeNodeFilterResult();
IUndoObject GetUndoObjectNoChecks(IDsDocument document) { var uo = document.Annotation<UndoObject>() ?? document.AddAnnotation(new UndoObject()); uo.Value = document; return uo; }
void SearchResources(IDsDocument module) { var res = options.Filter.GetResult((ResourcesFolderNode)null); if (res.FilterType == FilterType.Hide) return; res = options.Filter.GetResult((ResourceNode)null); if (res.FilterType == FilterType.Hide) return; var resNodes = new List<ResourceNode>(); options.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { var modNode = options.DocumentTreeView.FindNode(module.ModuleDef); if (modNode == null) return; modNode.TreeNode.EnsureChildrenLoaded(); var resFolder = modNode.TreeNode.Children.FirstOrDefault(a => a.Data is ResourcesFolderNode); if (resFolder != null) { resFolder.EnsureChildrenLoaded(); resNodes.AddRange(resFolder.DataChildren.OfType<ResourceNode>()); } })); foreach (var node in resNodes) { options.CancellationToken.ThrowIfCancellationRequested(); SearchResourceTreeNodes(module, node); } }
void Search(IDsDocument ownerModule, TypeDef type, MethodDef method) { var res = options.Filter.GetResult(method); if (res.FilterType == FilterType.Hide) return; CheckCustomAttributes(ownerModule, method, type); ImplMap im; if (res.IsMatch && (IsMatch(method.Name, method) || ((im = method.ImplMap) != null && (IsMatch(im.Name, im) || IsMatch(im.Module?.Name, null))))) { options.OnMatch(new SearchResult { Context = options.Context, Object = method, NameObject = method, ObjectImageReference = options.DotNetImageService.GetImageReference(method), LocationObject = type, LocationImageReference = options.DotNetImageService.GetImageReference(type), Document = ownerModule, }); return; } res = options.Filter.GetResultParamDefs(method); if (res.FilterType != FilterType.Hide) { foreach (var pd in method.ParamDefs) { options.CancellationToken.ThrowIfCancellationRequested(); CheckCustomAttributes(ownerModule, pd, method); res = options.Filter.GetResult(method, pd); if (res.FilterType == FilterType.Hide) continue; if (res.IsMatch && IsMatch(pd.Name, pd)) { options.OnMatch(new SearchResult { Context = options.Context, Object = method, NameObject = method, ObjectImageReference = options.DotNetImageService.GetImageReference(method), LocationObject = type, LocationImageReference = options.DotNetImageService.GetImageReference(type), Document = ownerModule, }); return; } } } SearchBody(ownerModule, type, method); }
void SearchModule(IDsDocument module) { if (module == null) return; var mod = module.ModuleDef; if (mod == null) { SearchNonNetFile(module); return; } var res = options.Filter.GetResult(mod); if (res.FilterType == FilterType.Hide) return; CheckCustomAttributes(module, mod, mod.Assembly); if (res.IsMatch && IsMatch(mod.FullName, module)) { options.OnMatch(new SearchResult { Context = options.Context, Object = mod, NameObject = mod, ObjectImageReference = options.DotNetImageService.GetImageReference(mod), LocationObject = mod.Assembly, LocationImageReference = mod.Assembly != null ? options.DotNetImageService.GetImageReference(mod.Assembly.ManifestModule) : new ImageReference(), Document = module, }); } SearchModAsmReferences(module); SearchResources(module); foreach (var kv in GetNamespaces(mod)) { options.CancellationToken.ThrowIfCancellationRequested(); Search(module, kv.Key, kv.Value); } }
void SearchResourceTreeNodes(IDsDocument module, ResourceNode resTreeNode) { var res = options.Filter.GetResult(resTreeNode); if (res.FilterType == FilterType.Hide) return; if (res.IsMatch && (IsMatch(resTreeNode.Name, resTreeNode) || IsMatch(ToString(resTreeNode), null))) { options.OnMatch(new SearchResult { Context = options.Context, Object = resTreeNode, NameObject = resTreeNode, ObjectImageReference = resTreeNode.Icon, LocationObject = module.ModuleDef, LocationImageReference = options.DotNetImageService.GetImageReference(module.ModuleDef), Document = module, }); } res = options.Filter.GetResult((ResourceElementNode)null); if (res.FilterType == FilterType.Hide) return; var resNodes = new List<ResourceElementNode>(); options.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { resTreeNode.TreeNode.EnsureChildrenLoaded(); resNodes.AddRange(resTreeNode.TreeNode.DataChildren.OfType<ResourceElementNode>()); })); foreach (var resElNode in resNodes) { options.CancellationToken.ThrowIfCancellationRequested(); SearchResourceElementTreeNode(module, resTreeNode, resElNode); } }