From 6d0f6095163c2b15506523ae804902b438757a86 Mon Sep 17 00:00:00 2001 From: ElektroKill Date: Sat, 30 Dec 2023 20:16:10 +0100 Subject: [PATCH] Add `IBundleEntryNode` interface --- .../TreeView/AssemblyDocumentNode.cs | 4 ++- .../Documents/TreeView/JsonBundleEntryNode.cs | 11 +++++-- .../Documents/TreeView/ModuleDocumentNode.cs | 4 ++- .../Documents/TreeView/PEDocumentNode.cs | 6 +++- .../TreeView/UnknownBundleEntryNode.cs | 11 +++++-- .../TreeView/IBundleEntryNode.cs | 32 +++++++++++++++++++ 6 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 dnSpy/dnSpy.Contracts.DnSpy/TreeView/IBundleEntryNode.cs diff --git a/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/AssemblyDocumentNode.cs b/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/AssemblyDocumentNode.cs index 6814e88f81..a4a150d897 100644 --- a/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/AssemblyDocumentNode.cs +++ b/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/AssemblyDocumentNode.cs @@ -19,13 +19,14 @@ You should have received a copy of the GNU General Public License using dnlib.DotNet; using dnlib.PE; +using dnSpy.Contracts.Bundles; using dnSpy.Contracts.TreeView; namespace dnSpy.Contracts.Documents.TreeView { /// /// A .NET assembly file /// - public abstract class AssemblyDocumentNode : DsDocumentNode, IMDTokenNode { + public abstract class AssemblyDocumentNode : DsDocumentNode, IMDTokenNode, IBundleEntryNode { /// /// Gets the instance /// @@ -37,6 +38,7 @@ public abstract class AssemblyDocumentNode : DsDocumentNode, IMDTokenNode { public bool IsExe => (Document.ModuleDef!.Characteristics & Characteristics.Dll) == 0; IMDTokenProvider? IMDTokenNode.Reference => Document.AssemblyDef; + BundleEntry? IBundleEntryNode.BundleEntry => Document.BundleEntry; /// /// Constructor diff --git a/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/JsonBundleEntryNode.cs b/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/JsonBundleEntryNode.cs index fe8c70f844..0d46eb5ba0 100644 --- a/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/JsonBundleEntryNode.cs +++ b/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/JsonBundleEntryNode.cs @@ -1,14 +1,21 @@ using System.Diagnostics; using dnSpy.Contracts.Bundles; +using dnSpy.Contracts.TreeView; namespace dnSpy.Contracts.Documents.TreeView { /// /// JSON bundle entry node /// - public abstract class JsonBundleEntryNode : DocumentTreeNodeData { + public abstract class JsonBundleEntryNode : DocumentTreeNodeData, IBundleEntryNode { + /// + public BundleEntry BundleEntry { get; } + /// /// Constructor /// - protected JsonBundleEntryNode(BundleEntry bundleEntry) => Debug2.Assert(bundleEntry is not null); + protected JsonBundleEntryNode(BundleEntry bundleEntry) { + Debug2.Assert(bundleEntry is not null); + BundleEntry = bundleEntry; + } } } diff --git a/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/ModuleDocumentNode.cs b/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/ModuleDocumentNode.cs index dd91cbc463..a2c0a32b55 100644 --- a/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/ModuleDocumentNode.cs +++ b/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/ModuleDocumentNode.cs @@ -19,19 +19,21 @@ You should have received a copy of the GNU General Public License using System.Diagnostics; using dnlib.DotNet; +using dnSpy.Contracts.Bundles; using dnSpy.Contracts.TreeView; namespace dnSpy.Contracts.Documents.TreeView { /// /// A .NET module file /// - public abstract class ModuleDocumentNode : DsDocumentNode, IMDTokenNode { + public abstract class ModuleDocumentNode : DsDocumentNode, IMDTokenNode, IBundleEntryNode { /// /// Gets the instance /// public new IDsDotNetDocument Document => (IDsDotNetDocument)base.Document; IMDTokenProvider? IMDTokenNode.Reference => Document.ModuleDef; + BundleEntry? IBundleEntryNode.BundleEntry => Document.BundleEntry; /// /// Constructor diff --git a/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/PEDocumentNode.cs b/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/PEDocumentNode.cs index b0f713e5d4..8697ff49d7 100644 --- a/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/PEDocumentNode.cs +++ b/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/PEDocumentNode.cs @@ -19,17 +19,21 @@ You should have received a copy of the GNU General Public License using System.Diagnostics; using dnlib.PE; +using dnSpy.Contracts.Bundles; +using dnSpy.Contracts.TreeView; namespace dnSpy.Contracts.Documents.TreeView { /// /// A PE file (but not a .NET file) /// - public abstract class PEDocumentNode : DsDocumentNode { + public abstract class PEDocumentNode : DsDocumentNode, IBundleEntryNode { /// /// true if it's an .exe file, false if it's a .dll file /// public bool IsExe => (Document.PEImage!.ImageNTHeaders.FileHeader.Characteristics & Characteristics.Dll) == 0; + BundleEntry? IBundleEntryNode.BundleEntry => Document.BundleEntry; + /// /// Constructor /// diff --git a/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/UnknownBundleEntryNode.cs b/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/UnknownBundleEntryNode.cs index c22f0de133..6b1af0a07b 100644 --- a/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/UnknownBundleEntryNode.cs +++ b/dnSpy/dnSpy.Contracts.DnSpy/Documents/TreeView/UnknownBundleEntryNode.cs @@ -1,14 +1,21 @@ using System.Diagnostics; using dnSpy.Contracts.Bundles; +using dnSpy.Contracts.TreeView; namespace dnSpy.Contracts.Documents.TreeView { /// /// Unknown bundle entry node /// - public abstract class UnknownBundleEntryNode : DocumentTreeNodeData { + public abstract class UnknownBundleEntryNode : DocumentTreeNodeData, IBundleEntryNode { + /// + public BundleEntry BundleEntry { get; } + /// /// Constructor /// - protected UnknownBundleEntryNode(BundleEntry bundleEntry) => Debug2.Assert(bundleEntry is not null); + protected UnknownBundleEntryNode(BundleEntry bundleEntry) { + Debug2.Assert(bundleEntry is not null); + BundleEntry = bundleEntry; + } } } diff --git a/dnSpy/dnSpy.Contracts.DnSpy/TreeView/IBundleEntryNode.cs b/dnSpy/dnSpy.Contracts.DnSpy/TreeView/IBundleEntryNode.cs new file mode 100644 index 0000000000..71f4aa1880 --- /dev/null +++ b/dnSpy/dnSpy.Contracts.DnSpy/TreeView/IBundleEntryNode.cs @@ -0,0 +1,32 @@ +/* + Copyright (C) 2023 ElektroKill + + This file is part of dnSpy + + dnSpy is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + dnSpy is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with dnSpy. If not, see . +*/ + +using dnSpy.Contracts.Bundles; + +namespace dnSpy.Contracts.TreeView { + /// + /// A node which can be a bundle entry + /// + public interface IBundleEntryNode { + /// + /// Gets the bundle entry for this node or null + /// + BundleEntry? BundleEntry { get; } + } +}