aboutsummaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2022-03-30 10:35:02 -0700
committerRob Mensching <rob@firegiant.com>2022-03-30 14:12:12 -0700
commit5d08e0a4bbf4e4ba28300b8bace1089b64b198d7 (patch)
tree1cf7d1f79d45cc3acc32f19cabb1efedd7a4a3dc /src/api
parentc86a2148f6dd7bfcd6637b6e1c9e7b5a9b53a996 (diff)
downloadwix-5d08e0a4bbf4e4ba28300b8bace1089b64b198d7.tar.gz
wix-5d08e0a4bbf4e4ba28300b8bace1089b64b198d7.tar.bz2
wix-5d08e0a4bbf4e4ba28300b8bace1089b64b198d7.zip
Implement IWindowsInstallerDecompileExtensions
Update Util extension to validate extension model and fix some small issues in MSI decompiling. Fixes 6367
Diffstat (limited to 'src/api')
-rw-r--r--src/api/wix/WixToolset.Extensibility/BaseWindowsInstallerBackendBinderExtension.cs8
-rw-r--r--src/api/wix/WixToolset.Extensibility/BaseWindowsInstallerDecompilerExtension.cs77
-rw-r--r--src/api/wix/WixToolset.Extensibility/Data/IWindowsInstallerDecompileContext.cs12
-rw-r--r--src/api/wix/WixToolset.Extensibility/Data/IWindowsInstallerDecompileResult.cs15
-rw-r--r--src/api/wix/WixToolset.Extensibility/DecompilerExtension.cs61
-rw-r--r--src/api/wix/WixToolset.Extensibility/IWindowsInstallerDecompilerExtension.cs30
-rw-r--r--src/api/wix/WixToolset.Extensibility/Services/IWindowsInstallerDecompilerHelper.cs180
7 files changed, 313 insertions, 70 deletions
diff --git a/src/api/wix/WixToolset.Extensibility/BaseWindowsInstallerBackendBinderExtension.cs b/src/api/wix/WixToolset.Extensibility/BaseWindowsInstallerBackendBinderExtension.cs
index e48579d7..a54f05fc 100644
--- a/src/api/wix/WixToolset.Extensibility/BaseWindowsInstallerBackendBinderExtension.cs
+++ b/src/api/wix/WixToolset.Extensibility/BaseWindowsInstallerBackendBinderExtension.cs
@@ -4,7 +4,6 @@ namespace WixToolset.Extensibility
4{ 4{
5 using System; 5 using System;
6 using System.Collections.Generic; 6 using System.Collections.Generic;
7 using System.Linq;
8 using WixToolset.Data; 7 using WixToolset.Data;
9 using WixToolset.Data.Symbols; 8 using WixToolset.Data.Symbols;
10 using WixToolset.Data.WindowsInstaller; 9 using WixToolset.Data.WindowsInstaller;
@@ -12,7 +11,7 @@ namespace WixToolset.Extensibility
12 using WixToolset.Extensibility.Services; 11 using WixToolset.Extensibility.Services;
13 12
14 /// <summary> 13 /// <summary>
15 /// Base class for creating a preprocessor extension. 14 /// Base class for creating a windows installer backend extension.
16 /// </summary> 15 /// </summary>
17 public abstract class BaseWindowsInstallerBackendBinderExtension : IWindowsInstallerBackendBinderExtension 16 public abstract class BaseWindowsInstallerBackendBinderExtension : IWindowsInstallerBackendBinderExtension
18 { 17 {
@@ -39,7 +38,10 @@ namespace WixToolset.Extensibility
39 /// <summary> 38 /// <summary>
40 /// Creates a resolved cabinet result. 39 /// Creates a resolved cabinet result.
41 /// </summary> 40 /// </summary>
42 protected IResolvedCabinet CreateResolvedCabinet() => this.Context.ServiceProvider.GetService<IResolvedCabinet>(); 41 protected IResolvedCabinet CreateResolvedCabinet()
42 {
43 return this.Context.ServiceProvider.GetService<IResolvedCabinet>();
44 }
43 45
44 /// <summary> 46 /// <summary>
45 /// See <see cref="IWindowsInstallerBackendBinderExtension.PreBackendBind(IBindContext)"/> 47 /// See <see cref="IWindowsInstallerBackendBinderExtension.PreBackendBind(IBindContext)"/>
diff --git a/src/api/wix/WixToolset.Extensibility/BaseWindowsInstallerDecompilerExtension.cs b/src/api/wix/WixToolset.Extensibility/BaseWindowsInstallerDecompilerExtension.cs
new file mode 100644
index 00000000..8072cd88
--- /dev/null
+++ b/src/api/wix/WixToolset.Extensibility/BaseWindowsInstallerDecompilerExtension.cs
@@ -0,0 +1,77 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixToolset.Extensibility
4{
5 using System.Collections.Generic;
6 using WixToolset.Data;
7 using WixToolset.Data.WindowsInstaller;
8 using WixToolset.Extensibility.Data;
9 using WixToolset.Extensibility.Services;
10
11 /// <summary>
12 /// Base class for creating a windows installer decompiler extensions.
13 /// </summary>
14 public abstract class BaseWindowsInstallerDecompilerExtension : IWindowsInstallerDecompilerExtension
15 {
16 /// <summary>
17 /// Context for use by the extension.
18 /// </summary>
19 protected IWindowsInstallerDecompileContext Context { get; private set; }
20
21 /// <summary>
22 /// Messaging for use by the extension.
23 /// </summary>
24 protected IMessaging Messaging { get; private set; }
25
26 /// <summary>
27 /// Decompiler helper for use by the extension.
28 /// </summary>
29 protected IWindowsInstallerDecompilerHelper DecompilerHelper { get; private set; }
30
31 /// <summary>
32 /// See <see cref="IWindowsInstallerDecompilerExtension.TableDefinitions"/>
33 /// </summary>
34 public virtual IReadOnlyCollection<TableDefinition> TableDefinitions { get; }
35
36 /// <summary>
37 /// See <see cref="IWindowsInstallerDecompilerExtension.PostDecompile(IWindowsInstallerDecompileResult)"/>
38 /// </summary>
39 public virtual void PreDecompile(IWindowsInstallerDecompileContext context)
40 {
41 this.Context = context;
42
43 this.Messaging = context.ServiceProvider.GetService<IMessaging>();
44
45 this.DecompilerHelper = context.ServiceProvider.GetService<IWindowsInstallerDecompilerHelper>();
46 }
47
48 /// <summary>
49 /// See <see cref="IWindowsInstallerDecompilerExtension.PreDecompileTables(TableIndexedCollection)"/>
50 /// </summary>
51 public virtual void PreDecompileTables(TableIndexedCollection tables)
52 {
53 }
54
55 /// <summary>
56 /// See <see cref="IWindowsInstallerDecompilerExtension.TryDecompileTable(Table)"/>
57 /// </summary>
58 public virtual bool TryDecompileTable(Table table)
59 {
60 return false;
61 }
62
63 /// <summary>
64 /// See <see cref="IWindowsInstallerDecompilerExtension.PostDecompileTables(TableIndexedCollection)"/>
65 /// </summary>
66 public virtual void PostDecompileTables(TableIndexedCollection tables)
67 {
68 }
69
70 /// <summary>
71 /// See <see cref="IWindowsInstallerDecompilerExtension.PostDecompile(IWindowsInstallerDecompileResult)"/>
72 /// </summary>
73 public virtual void PostDecompile(IWindowsInstallerDecompileResult result)
74 {
75 }
76 }
77}
diff --git a/src/api/wix/WixToolset.Extensibility/Data/IWindowsInstallerDecompileContext.cs b/src/api/wix/WixToolset.Extensibility/Data/IWindowsInstallerDecompileContext.cs
index f744121a..27d30a5a 100644
--- a/src/api/wix/WixToolset.Extensibility/Data/IWindowsInstallerDecompileContext.cs
+++ b/src/api/wix/WixToolset.Extensibility/Data/IWindowsInstallerDecompileContext.cs
@@ -7,7 +7,7 @@ namespace WixToolset.Extensibility.Data
7 using WixToolset.Data; 7 using WixToolset.Data;
8 8
9 /// <summary> 9 /// <summary>
10 /// The context used to decompile Windows Installer packages. 10 /// The context used to decompile a Windows Installer database.
11 /// </summary> 11 /// </summary>
12 public interface IWindowsInstallerDecompileContext 12 public interface IWindowsInstallerDecompileContext
13 { 13 {
@@ -32,6 +32,16 @@ namespace WixToolset.Extensibility.Data
32 IReadOnlyCollection<IWindowsInstallerDecompilerExtension> Extensions { get; set; } 32 IReadOnlyCollection<IWindowsInstallerDecompilerExtension> Extensions { get; set; }
33 33
34 /// <summary> 34 /// <summary>
35 /// Collection of extension data to use during decompiling.
36 /// </summary>
37 IReadOnlyCollection<IExtensionData> ExtensionData { get; set; }
38
39 /// <summary>
40 /// Symbol definition creator used to load extension data.
41 /// </summary>
42 ISymbolDefinitionCreator SymbolDefinitionCreator { get; set; }
43
44 /// <summary>
35 /// Gets or sets the folder where content is extracted. 45 /// Gets or sets the folder where content is extracted.
36 /// </summary> 46 /// </summary>
37 string ExtractFolder { get; set; } 47 string ExtractFolder { get; set; }
diff --git a/src/api/wix/WixToolset.Extensibility/Data/IWindowsInstallerDecompileResult.cs b/src/api/wix/WixToolset.Extensibility/Data/IWindowsInstallerDecompileResult.cs
index 3b1dd815..724dd7fc 100644
--- a/src/api/wix/WixToolset.Extensibility/Data/IWindowsInstallerDecompileResult.cs
+++ b/src/api/wix/WixToolset.Extensibility/Data/IWindowsInstallerDecompileResult.cs
@@ -6,13 +6,24 @@ namespace WixToolset.Extensibility.Data
6 using System.Xml.Linq; 6 using System.Xml.Linq;
7 using WixToolset.Data; 7 using WixToolset.Data;
8 8
9#pragma warning disable 1591 // TODO: add documentation 9 /// <summary>
10 /// The result from decompiling a Windows Installer database.
11 /// </summary>
10 public interface IWindowsInstallerDecompileResult 12 public interface IWindowsInstallerDecompileResult
11 { 13 {
14 /// <summary>
15 /// Decompiled document.
16 /// </summary>
12 XDocument Document { get; set; } 17 XDocument Document { get; set; }
13 18
14 IReadOnlyCollection<string> ExtractedFilePaths { get; set; } 19 /// <summary>
20 /// Extracted paths.
21 /// </summary>
22 IList<string> ExtractedFilePaths { get; set; }
15 23
24 /// <summary>
25 /// Decompiled platform.
26 /// </summary>
16 Platform? Platform { get; set; } 27 Platform? Platform { get; set; }
17 } 28 }
18} 29}
diff --git a/src/api/wix/WixToolset.Extensibility/DecompilerExtension.cs b/src/api/wix/WixToolset.Extensibility/DecompilerExtension.cs
deleted file mode 100644
index b492cf3a..00000000
--- a/src/api/wix/WixToolset.Extensibility/DecompilerExtension.cs
+++ /dev/null
@@ -1,61 +0,0 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixToolset.Extensibility
4{
5 using WixToolset.Data;
6
7#if BRING_BACK_LATER
8 /// <summary>
9 /// Base class for creating a decompiler extension.
10 /// </summary>
11 public abstract class DecompilerExtension : IDecompilerExtension
12 {
13 /// <summary>
14 /// Gets or sets the decompiler core for the extension.
15 /// </summary>
16 /// <value>The decompiler core for the extension.</value>
17 public IDecompilerCore Core { get; set; }
18
19 /// <summary>
20 /// Gets the table definitions this extension decompiles.
21 /// </summary>
22 /// <value>Table definitions this extension decompiles.</value>
23 public virtual TableDefinitionCollection TableDefinitions { get; protected set; }
24
25 /// <summary>
26 /// Gets the library that this decompiler wants removed from the decomipiled output.
27 /// </summary>
28 /// <param name="tableDefinitions">The table definitions to use while loading the library.</param>
29 /// <returns>The library for this extension or null if there is no library to be removed.</returns>
30 public virtual Library GetLibraryToRemove(TableDefinitionCollection tableDefinitions)
31 {
32 return null;
33 }
34
35 /// <summary>
36 /// Called at the beginning of the decompilation of a database.
37 /// </summary>
38 /// <param name="tables">The collection of all tables.</param>
39 public virtual void Initialize(TableIndexedCollection tables)
40 {
41 }
42
43 /// <summary>
44 /// Decompiles an extension table.
45 /// </summary>
46 /// <param name="table">The table to decompile.</param>
47 public virtual void DecompileTable(Table table)
48 {
49 this.Core.UnexpectedTable(table);
50 }
51
52 /// <summary>
53 /// Finalize decompilation.
54 /// </summary>
55 /// <param name="tables">The collection of all tables.</param>
56 public virtual void Finish(TableIndexedCollection tables)
57 {
58 }
59 }
60#endif
61}
diff --git a/src/api/wix/WixToolset.Extensibility/IWindowsInstallerDecompilerExtension.cs b/src/api/wix/WixToolset.Extensibility/IWindowsInstallerDecompilerExtension.cs
index add5f886..f7d54799 100644
--- a/src/api/wix/WixToolset.Extensibility/IWindowsInstallerDecompilerExtension.cs
+++ b/src/api/wix/WixToolset.Extensibility/IWindowsInstallerDecompilerExtension.cs
@@ -2,21 +2,45 @@
2 2
3namespace WixToolset.Extensibility 3namespace WixToolset.Extensibility
4{ 4{
5 using WixToolset.Data; 5 using System.Collections.Generic;
6 using WixToolset.Data.WindowsInstaller; 6 using WixToolset.Data.WindowsInstaller;
7 using WixToolset.Extensibility.Data; 7 using WixToolset.Extensibility.Data;
8 8
9 /// <summary> 9 /// <summary>
10 /// Interface all binder extensions implement. 10 /// Interface all windows installer decompiler extensions implement.
11 /// </summary> 11 /// </summary>
12 public interface IWindowsInstallerDecompilerExtension 12 public interface IWindowsInstallerDecompilerExtension
13 { 13 {
14 /// <summary> 14 /// <summary>
15 /// Gets the table definitions this extension decompiles.
16 /// </summary>
17 /// <value>Table definitions this extension decompiles.</value>
18 IReadOnlyCollection<TableDefinition> TableDefinitions { get; }
19
20 /// <summary>
15 /// Called before decompiling occurs. 21 /// Called before decompiling occurs.
16 /// </summary> 22 /// </summary>
23 /// <param name="context">Decompile context.</param>
17 void PreDecompile(IWindowsInstallerDecompileContext context); 24 void PreDecompile(IWindowsInstallerDecompileContext context);
18 25
19 // TODO: Redesign this interface to be useful. 26 /// <summary>
27 /// Called before decompiling occurs.
28 /// </summary>
29 /// <param name="tables">The collection of all tables.</param>
30 void PreDecompileTables(TableIndexedCollection tables);
31
32 /// <summary>
33 /// Try to decompile an extension table.
34 /// </summary>
35 /// <param name="table">The table to decompile.</param>
36 /// <returns>True if the table was decompiled, false otherwise.</returns>
37 bool TryDecompileTable(Table table);
38
39 /// <summary>
40 /// After decompilation tables.
41 /// </summary>
42 /// <param name="tables">The collection of all tables.</param>
43 void PostDecompileTables(TableIndexedCollection tables);
20 44
21 /// <summary> 45 /// <summary>
22 /// Called after all output changes occur and right before the output is bound into its final format. 46 /// Called after all output changes occur and right before the output is bound into its final format.
diff --git a/src/api/wix/WixToolset.Extensibility/Services/IWindowsInstallerDecompilerHelper.cs b/src/api/wix/WixToolset.Extensibility/Services/IWindowsInstallerDecompilerHelper.cs
new file mode 100644
index 00000000..1f5ac47a
--- /dev/null
+++ b/src/api/wix/WixToolset.Extensibility/Services/IWindowsInstallerDecompilerHelper.cs
@@ -0,0 +1,180 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixToolset.Extensibility.Services
4{
5 using System.Xml.Linq;
6 using WixToolset.Data.WindowsInstaller;
7
8 /// <summary>
9 /// Interface provided to help Windows Installer decompiler extensions.
10 /// </summary>
11 public interface IWindowsInstallerDecompilerHelper
12 {
13 /// <summary>
14 /// Gets or sets the root element of the decompiled output.
15 /// </summary>
16 XElement RootElement { get; set; }
17
18 /// <summary>
19 /// Creates an element from the standard WiX Toolset namespace and adds it to the root document.
20 /// </summary>
21 /// <param name="name">Name of the element to create and add.</param>
22 /// <param name="content">Optional content to add to the new element.</param>
23 /// <returns>Element in the standard namespace.</returns>
24 XElement AddElementToRoot(string name, params object[] content);
25
26 /// <summary>
27 /// Creates an element with the specified name and adds it to the root document.
28 /// </summary>
29 /// <param name="name">Name of the element to create and add.</param>
30 /// <param name="content">Optional content to add to the new element.</param>
31 /// <returns>Element in the standard namespace.</returns>
32 XElement AddElementToRoot(XName name, params object[] content);
33
34 /// <summary>
35 /// Adds an existing element to the root document.
36 /// </summary>
37 /// <param name="element">Element to add.</param>
38 /// <returns>Same element provided.</returns>
39 XElement AddElementToRoot(XElement element);
40
41 /// <summary>
42 /// Creates an element from the standard WiX Toolset namespace.
43 /// </summary>
44 /// <param name="name">Name of the element to create.</param>
45 /// <param name="content">Optional content to add to the new element.</param>
46 /// <returns>Element in the standard namespace.</returns>
47 XElement CreateElement(string name, params object[] content);
48
49 /// <summary>
50 /// Get an element index by a row's table and primary keys.
51 /// </summary>
52 /// <param name="row">Row to get element.</param>
53 /// <returns>Element indexed for the row or null if not found.</returns>
54 XElement GetIndexedElement(Row row);
55
56 /// <summary>
57 /// Get an element index by table and primary key.
58 /// </summary>
59 /// <param name="table">Table name for indexed element.</param>
60 /// <param name="primaryKey">Primary key for indexed element.</param>
61 /// <returns>Element indexed for the table and primary key or null if not found.</returns>
62 XElement GetIndexedElement(string table, string primaryKey);
63
64 /// <summary>
65 /// Get an element index by table and primary keys.
66 /// </summary>
67 /// <param name="table">Table name for indexed element.</param>
68 /// <param name="primaryKey1">Primary key for first column indexed element.</param>
69 /// <param name="primaryKey2">Primary key for second column indexed element.</param>
70 /// <returns>Element indexed for the table and primary keys or null if not found.</returns>
71 XElement GetIndexedElement(string table, string primaryKey1, string primaryKey2);
72
73 /// <summary>
74 /// Get an element index by table and primary keys.
75 /// </summary>
76 /// <param name="table">Table name for indexed element.</param>
77 /// <param name="primaryKey1">Primary key for first column indexed element.</param>
78 /// <param name="primaryKey2">Primary key for second column indexed element.</param>
79 /// <param name="primaryKey3">Primary key for third column indexed element.</param>
80 /// <returns>Element indexed for the table and primary keys or null if not found.</returns>
81 XElement GetIndexedElement(string table, string primaryKey1, string primaryKey2, string primaryKey3);
82
83 /// <summary>
84 /// Get an element index by table and primary keys.
85 /// </summary>
86 /// <param name="table">Table name for indexed element.</param>
87 /// <param name="primaryKeys">Primary keys for indexed element.</param>
88 /// <returns>Element indexed for the table and primary keys or null if not found.</returns>
89 XElement GetIndexedElement(string table, string[] primaryKeys);
90
91 /// <summary>
92 /// Try to get an element index by a row's table and primary keys.
93 /// </summary>
94 /// <param name="row">Row to get element.</param>
95 /// <param name="element">Element indexed for the row.</param>
96 /// <returns>True if the element was index otherwise false.</returns>
97 bool TryGetIndexedElement(Row row, out XElement element);
98
99 /// <summary>
100 /// Try to get an element index by table name and primary key.
101 /// </summary>
102 /// <param name="table">Table name for indexed element.</param>
103 /// <param name="primaryKey">Primary key for indexed element.</param>
104 /// <param name="element">Element indexed for the table and primary key.</param>
105 /// <returns>True if the element was index otherwise false.</returns>
106 bool TryGetIndexedElement(string table, string primaryKey, out XElement element);
107
108 /// <summary>
109 /// Try to get an element index by table name and primary keys.
110 /// </summary>
111 /// <param name="table">Table name for indexed element.</param>
112 /// <param name="primaryKey1">First column's primary key for indexed element.</param>
113 /// <param name="primaryKey2">Second column's primary key for indexed element.</param>
114 /// <param name="element">Element indexed for the table and primary key.</param>
115 /// <returns>True if the element was index otherwise false.</returns>
116 bool TryGetIndexedElement(string table, string primaryKey1, string primaryKey2, out XElement element);
117
118 /// <summary>
119 /// Try to get an element index by table name and primary keys.
120 /// </summary>
121 /// <param name="table">Table name for indexed element.</param>
122 /// <param name="primaryKey1">First column's primary key for indexed element.</param>
123 /// <param name="primaryKey2">Second column's primary key for indexed element.</param>
124 /// <param name="primaryKey3">Third column's primary key for indexed element.</param>
125 /// <param name="element">Element indexed for the table and primary key.</param>
126 /// <returns>True if the element was index otherwise false.</returns>
127 bool TryGetIndexedElement(string table, string primaryKey1, string primaryKey2, string primaryKey3, out XElement element);
128
129 /// <summary>
130 /// Try to get an element index by table name and primary keys.
131 /// </summary>
132 /// <param name="table">Table name for indexed element.</param>
133 /// <param name="primaryKeys">Primary keys for indexed element.</param>
134 /// <param name="element">Element indexed for the table and primary key.</param>
135 /// <returns>True if the element was index otherwise false.</returns>
136 bool TryGetIndexedElement(string table, string[] primaryKeys, out XElement element);
137
138 /// <summary>
139 /// Index an element by a row's table and primary keys.
140 /// </summary>
141 /// <param name="row">Row to index element.</param>
142 /// <param name="element">Element to index.</param>
143 void IndexElement(Row row, XElement element);
144
145 /// <summary>
146 /// Index an element by table and primary key.
147 /// </summary>
148 /// <param name="table">Table name to index element.</param>
149 /// <param name="primaryKey">Primary key to index element.</param>
150 /// <param name="element">Element to index.</param>
151 void IndexElement(string table, string primaryKey, XElement element);
152
153 /// <summary>
154 /// Index an element by table and primary keys.
155 /// </summary>
156 /// <param name="table">Table name to index element.</param>
157 /// <param name="primaryKey1">First column's primary key to index element.</param>
158 /// <param name="primaryKey2">Second column's primary key to index element.</param>
159 /// <param name="element">Element to index.</param>
160 void IndexElement(string table, string primaryKey1, string primaryKey2, XElement element);
161
162 /// <summary>
163 /// Index an element by table and primary keys.
164 /// </summary>
165 /// <param name="table">Table name to index element.</param>
166 /// <param name="primaryKey1">First column's primary key to index element.</param>
167 /// <param name="primaryKey2">Second column's primary key to index element.</param>
168 /// <param name="primaryKey3">Third column's primary key to index element.</param>
169 /// <param name="element">Element to index.</param>
170 void IndexElement(string table, string primaryKey1, string primaryKey2, string primaryKey3, XElement element);
171
172 /// <summary>
173 /// Index an element by table and primary keys.
174 /// </summary>
175 /// <param name="table">Table name to index element.</param>
176 /// <param name="primaryKeys">Column's primary key to index element.</param>
177 /// <param name="element">Element to index.</param>
178 void IndexElement(string table, string[] primaryKeys, XElement element);
179 }
180}