aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2023-01-14 17:29:40 -0800
committerRob Mensching <rob@firegiant.com>2023-01-16 00:54:06 -0800
commit5f744a8c7da649721f7022dc174febd79e7e3e14 (patch)
tree643db84523bda1a2eae6dbeb02557e69f4e445e1
parentecbaffc08239e061a7dbaa92ff3c72acd53a0bae (diff)
downloadwix-5f744a8c7da649721f7022dc174febd79e7e3e14.tar.gz
wix-5f744a8c7da649721f7022dc174febd79e7e3e14.tar.bz2
wix-5f744a8c7da649721f7022dc174febd79e7e3e14.zip
Remove extension data after extensions get PreDecompileTables callback
Also update Util.wixext decompiler extension to handle the new elements that compile into CustomActions with no additional table data. These exposed the weakness in the decompiler where extension data was removed before extensions got a chance to pre-decompile. Fixes 7151
-rw-r--r--src/ext/Util/test/WixToolsetTest.Util/TestData/Queries/Package.wxs10
-rw-r--r--src/ext/Util/test/WixToolsetTest.Util/UtilExtensionFixture.cs43
-rw-r--r--src/ext/Util/wixext/UtilConstants.cs6
-rw-r--r--src/ext/Util/wixext/UtilDecompiler.cs58
-rw-r--r--src/wix/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs4
5 files changed, 104 insertions, 17 deletions
diff --git a/src/ext/Util/test/WixToolsetTest.Util/TestData/Queries/Package.wxs b/src/ext/Util/test/WixToolsetTest.Util/TestData/Queries/Package.wxs
index abf0dbb4..d85db478 100644
--- a/src/ext/Util/test/WixToolsetTest.Util/TestData/Queries/Package.wxs
+++ b/src/ext/Util/test/WixToolsetTest.Util/TestData/Queries/Package.wxs
@@ -1,4 +1,4 @@
1<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util"> 1<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">
2 <Package Name="MsiPackage" Language="1033" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a"> 2 <Package Name="MsiPackage" Language="1033" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
3 <MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeError)" /> 3 <MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeError)" />
4 4
@@ -13,10 +13,10 @@
13 </Package> 13 </Package>
14 14
15 <Fragment><util:BroadcastSettingChange /> 15 <Fragment><util:BroadcastSettingChange />
16 16 <util:QueryNativeMachine />
17 17
18 18
19 <StandardDirectory Id="ProgramFilesFolder"> 19 <StandardDirectory Id="ProgramFilesFolder">
20 <Directory Id="INSTALLFOLDER" Name="MsiPackage" /> 20 <Directory Id="INSTALLFOLDER" Name="MsiPackage" />
21 </StandardDirectory> 21 </StandardDirectory>
22 </Fragment> 22 </Fragment>
diff --git a/src/ext/Util/test/WixToolsetTest.Util/UtilExtensionFixture.cs b/src/ext/Util/test/WixToolsetTest.Util/UtilExtensionFixture.cs
index 2b59b2a9..a9b37870 100644
--- a/src/ext/Util/test/WixToolsetTest.Util/UtilExtensionFixture.cs
+++ b/src/ext/Util/test/WixToolsetTest.Util/UtilExtensionFixture.cs
@@ -9,6 +9,7 @@ namespace WixToolsetTest.Util
9 using WixInternal.Core.TestPackage; 9 using WixInternal.Core.TestPackage;
10 using WixToolset.Util; 10 using WixToolset.Util;
11 using Xunit; 11 using Xunit;
12 using System.Xml.Linq;
12 13
13 public class UtilExtensionFixture 14 public class UtilExtensionFixture
14 { 15 {
@@ -62,9 +63,20 @@ namespace WixToolsetTest.Util
62 var output = Path.Combine(folder, "decompile.xml"); 63 var output = Path.Combine(folder, "decompile.xml");
63 64
64 build.BuildAndDecompileAndBuild(Build, Decompile, output); 65 build.BuildAndDecompileAndBuild(Build, Decompile, output);
65 File.Exists(output);
66 }
67 66
67 var doc = XDocument.Load(output);
68 var utilElementNames = doc.Descendants()
69 .Where(e => e.Name.Namespace == "http://wixtoolset.org/schemas/v4/wxs/util")
70 .Select(e => e.Name.LocalName)
71 .OrderBy(s => s)
72 .ToArray();
73 WixAssert.CompareLineByLine(new[]
74 {
75 "FileShare",
76 "FileSharePermission",
77 "User",
78 }, utilElementNames);
79 }
68 80
69 [Fact] 81 [Fact]
70 public void CanBuildCloseApplication() 82 public void CanBuildCloseApplication()
@@ -225,12 +237,39 @@ namespace WixToolsetTest.Util
225 "CustomAction:Wix4BroadcastEnvironmentChange_A64\t65\tWix4UtilCA_A64\tWixBroadcastEnvironmentChange\t", 237 "CustomAction:Wix4BroadcastEnvironmentChange_A64\t65\tWix4UtilCA_A64\tWixBroadcastEnvironmentChange\t",
226 "CustomAction:Wix4BroadcastSettingChange_A64\t65\tWix4UtilCA_A64\tWixBroadcastSettingChange\t", 238 "CustomAction:Wix4BroadcastSettingChange_A64\t65\tWix4UtilCA_A64\tWixBroadcastSettingChange\t",
227 "CustomAction:Wix4CheckRebootRequired_A64\t65\tWix4UtilCA_A64\tWixCheckRebootRequired\t", 239 "CustomAction:Wix4CheckRebootRequired_A64\t65\tWix4UtilCA_A64\tWixCheckRebootRequired\t",
240 "CustomAction:Wix4QueryNativeMachine_A64\t257\tWix4UtilCA_A64\tWixQueryNativeMachine\t",
228 "CustomAction:Wix4QueryOsDriverInfo_A64\t257\tWix4UtilCA_A64\tWixQueryOsDriverInfo\t", 241 "CustomAction:Wix4QueryOsDriverInfo_A64\t257\tWix4UtilCA_A64\tWixQueryOsDriverInfo\t",
229 "CustomAction:Wix4QueryOsInfo_A64\t257\tWix4UtilCA_A64\tWixQueryOsInfo\t", 242 "CustomAction:Wix4QueryOsInfo_A64\t257\tWix4UtilCA_A64\tWixQueryOsInfo\t",
230 }, results.OrderBy(s => s).ToArray()); 243 }, results.OrderBy(s => s).ToArray());
231 } 244 }
232 245
233 [Fact] 246 [Fact]
247 public void CanBuildAndDecompiileQueries()
248 {
249 var folder = TestData.Get(@"TestData\Queries");
250 var build = new Builder(folder, typeof(UtilExtensionFactory), new[] { folder });
251 var output = Path.Combine(folder, "decompile.xml");
252
253 build.BuildAndDecompileAndBuild(Build, Decompile, output);
254
255 var doc = XDocument.Load(output);
256 var utilElementNames = doc.Descendants()
257 .Where(e => e.Name.Namespace == "http://wixtoolset.org/schemas/v4/wxs/util")
258 .Select(e => e.Name.LocalName)
259 .OrderBy(s => s)
260 .ToArray();
261 WixAssert.CompareLineByLine(new[]
262 {
263 "BroadcastEnvironmentChange",
264 "BroadcastSettingChange",
265 "CheckRebootRequired",
266 "QueryNativeMachine",
267 "QueryWindowsDriverInfo",
268 "QueryWindowsSuiteInfo",
269 }, utilElementNames);
270 }
271
272 [Fact]
234 public void CanBuildWithXmlConfig() 273 public void CanBuildWithXmlConfig()
235 { 274 {
236 var folder = TestData.Get(@"TestData", "XmlConfig"); 275 var folder = TestData.Get(@"TestData", "XmlConfig");
diff --git a/src/ext/Util/wixext/UtilConstants.cs b/src/ext/Util/wixext/UtilConstants.cs
index 93616e44..c1f5f820 100644
--- a/src/ext/Util/wixext/UtilConstants.cs
+++ b/src/ext/Util/wixext/UtilConstants.cs
@@ -11,6 +11,9 @@ namespace WixToolset.Util
11 { 11 {
12 internal static readonly XNamespace Namespace = "http://wixtoolset.org/schemas/v4/wxs/util"; 12 internal static readonly XNamespace Namespace = "http://wixtoolset.org/schemas/v4/wxs/util";
13 13
14 internal static readonly XName BroadcastEnvironmentChange = Namespace + "BroadcastEnvironmentChange";
15 internal static readonly XName BroadcastSettingChange = Namespace + "BroadcastSettingChange";
16 internal static readonly XName CheckRebootRequired = Namespace + "CheckRebootRequired";
14 internal static readonly XName CloseApplicationName = Namespace + "CloseApplication"; 17 internal static readonly XName CloseApplicationName = Namespace + "CloseApplication";
15 internal static readonly XName EventManifestName = Namespace + "EventManifest"; 18 internal static readonly XName EventManifestName = Namespace + "EventManifest";
16 internal static readonly XName FileShareName = Namespace + "FileShare"; 19 internal static readonly XName FileShareName = Namespace + "FileShare";
@@ -21,6 +24,9 @@ namespace WixToolset.Util
21 internal static readonly XName PerfCounterName = Namespace + "PerfCounter"; 24 internal static readonly XName PerfCounterName = Namespace + "PerfCounter";
22 internal static readonly XName PerfCounterManifestName = Namespace + "PerfCounterManifest"; 25 internal static readonly XName PerfCounterManifestName = Namespace + "PerfCounterManifest";
23 internal static readonly XName PermissionExName = Namespace + "PermissionEx"; 26 internal static readonly XName PermissionExName = Namespace + "PermissionEx";
27 internal static readonly XName QueryNativeMachine = Namespace + "QueryNativeMachine";
28 internal static readonly XName QueryWindowsDriverInfo = Namespace + "QueryWindowsDriverInfo";
29 internal static readonly XName QueryWindowsSuiteInfo = Namespace + "QueryWindowsSuiteInfo";
24 internal static readonly XName RemoveFolderExName = Namespace + "RemoveFolderEx"; 30 internal static readonly XName RemoveFolderExName = Namespace + "RemoveFolderEx";
25 internal static readonly XName RestartResourceName = Namespace + "RestartResource"; 31 internal static readonly XName RestartResourceName = Namespace + "RestartResource";
26 internal static readonly XName ServiceConfigName = Namespace + "ServiceConfig"; 32 internal static readonly XName ServiceConfigName = Namespace + "ServiceConfig";
diff --git a/src/ext/Util/wixext/UtilDecompiler.cs b/src/ext/Util/wixext/UtilDecompiler.cs
index 1201fdd5..0a78201e 100644
--- a/src/ext/Util/wixext/UtilDecompiler.cs
+++ b/src/ext/Util/wixext/UtilDecompiler.cs
@@ -3,16 +3,15 @@
3namespace WixToolset.Util 3namespace WixToolset.Util
4{ 4{
5 using System; 5 using System;
6 using System.Collections;
7 using System.Collections.Generic;
6 using System.IO; 8 using System.IO;
9 using System.Linq;
7 using System.Text; 10 using System.Text;
8 using System.Collections; 11 using System.Xml.Linq;
9 using System.Diagnostics;
10
11 using WixToolset.Data; 12 using WixToolset.Data;
12 using WixToolset.Extensibility;
13 using WixToolset.Data.WindowsInstaller; 13 using WixToolset.Data.WindowsInstaller;
14 using System.Collections.Generic; 14 using WixToolset.Extensibility;
15 using System.Xml.Linq;
16 using WixToolset.Util.Symbols; 15 using WixToolset.Util.Symbols;
17 16
18 /// <summary> 17 /// <summary>
@@ -22,16 +21,47 @@ namespace WixToolset.Util
22 { 21 {
23 public override IReadOnlyCollection<TableDefinition> TableDefinitions => UtilTableDefinitions.All; 22 public override IReadOnlyCollection<TableDefinition> TableDefinitions => UtilTableDefinitions.All;
24 23
24 private static readonly Dictionary<string, XName> CustomActionMapping = new Dictionary<string, XName>()
25 {
26 { "Wix4BroadcastEnvironmentChange_X86", UtilConstants.BroadcastEnvironmentChange },
27 { "Wix4BroadcastEnvironmentChange_X64", UtilConstants.BroadcastEnvironmentChange },
28 { "Wix4BroadcastEnvironmentChange_ARM64", UtilConstants.BroadcastEnvironmentChange },
29 { "Wix4BroadcastSettingChange_X86", UtilConstants.BroadcastSettingChange },
30 { "Wix4BroadcastSettingChange_X64", UtilConstants.BroadcastSettingChange },
31 { "Wix4BroadcastSettingChange_ARM64", UtilConstants.BroadcastSettingChange },
32 { "Wix4CheckRebootRequired_X86", UtilConstants.CheckRebootRequired },
33 { "Wix4CheckRebootRequired_X64", UtilConstants.CheckRebootRequired },
34 { "Wix4CheckRebootRequired_ARM64", UtilConstants.CheckRebootRequired },
35 { "Wix4QueryNativeMachine_X86", UtilConstants.QueryNativeMachine },
36 { "Wix4QueryNativeMachine_X64", UtilConstants.QueryNativeMachine },
37 { "Wix4QueryNativeMachine_ARM64", UtilConstants.QueryNativeMachine },
38 { "Wix4QueryOsDriverInfo_X86", UtilConstants.QueryWindowsDriverInfo },
39 { "Wix4QueryOsDriverInfo_X64", UtilConstants.QueryWindowsDriverInfo },
40 { "Wix4QueryOsDriverInfo_ARM64", UtilConstants.QueryWindowsDriverInfo },
41 { "Wix4QueryOsInfo_X86", UtilConstants.QueryWindowsSuiteInfo },
42 { "Wix4QueryOsInfo_X64", UtilConstants.QueryWindowsSuiteInfo },
43 { "Wix4QueryOsInfo_ARM64", UtilConstants.QueryWindowsSuiteInfo },
44 };
45
46 private IReadOnlyCollection<string> customActionNames;
47
25 /// <summary> 48 /// <summary>
26 /// Called at the beginning of the decompilation of a database. 49 /// Called at the beginning of the decompilation of a database.
27 /// </summary> 50 /// </summary>
28 /// <param name="tables">The collection of all tables.</param> 51 /// <param name="tables">The collection of all tables.</param>
29 public override void PreDecompileTables(TableIndexedCollection tables) 52 public override void PreDecompileTables(TableIndexedCollection tables)
30 { 53 {
54 this.RememberCustomActionNames(tables);
31 this.CleanupSecureCustomProperties(tables); 55 this.CleanupSecureCustomProperties(tables);
32 this.CleanupInternetShortcutRemoveFileTables(tables); 56 this.CleanupInternetShortcutRemoveFileTables(tables);
33 } 57 }
34 58
59 private void RememberCustomActionNames(TableIndexedCollection tables)
60 {
61 var customActionTable = tables["CustomAction"];
62 this.customActionNames = customActionTable?.Rows.Select(r => r.GetPrimaryKey()).Distinct().ToList() ?? (IReadOnlyCollection<string>)Array.Empty<string>();
63 }
64
35 /// <summary> 65 /// <summary>
36 /// Decompile the SecureCustomProperties field to PropertyRefs for known extension properties. 66 /// Decompile the SecureCustomProperties field to PropertyRefs for known extension properties.
37 /// </summary> 67 /// </summary>
@@ -195,6 +225,7 @@ namespace WixToolset.Util
195 /// <param name="tables">The collection of all tables.</param> 225 /// <param name="tables">The collection of all tables.</param>
196 public override void PostDecompileTables(TableIndexedCollection tables) 226 public override void PostDecompileTables(TableIndexedCollection tables)
197 { 227 {
228 this.FinalizeCustomActions();
198 this.FinalizePerfmonTable(tables); 229 this.FinalizePerfmonTable(tables);
199 this.FinalizePerfmonManifestTable(tables); 230 this.FinalizePerfmonManifestTable(tables);
200 this.FinalizeSecureObjectsTable(tables); 231 this.FinalizeSecureObjectsTable(tables);
@@ -223,7 +254,7 @@ namespace WixToolset.Util
223 AttributeIfNotNull("RebootPrompt", 0x2 == (attribute & 0x2)), 254 AttributeIfNotNull("RebootPrompt", 0x2 == (attribute & 0x2)),
224 AttributeIfNotNull("ElevatedCloseMessage", 0x4 == (attribute & 0x4)), 255 AttributeIfNotNull("ElevatedCloseMessage", 0x4 == (attribute & 0x4)),
225 NumericAttributeIfNotNull("Sequence", row, 5), 256 NumericAttributeIfNotNull("Sequence", row, 5),
226 NumericAttributeIfNotNull("Property", row, 6) 257 AttributeIfNotNull("Property", row, 6)
227 ); 258 );
228 } 259 }
229 } 260 }
@@ -379,7 +410,7 @@ namespace WixToolset.Util
379 if (this.DecompilerHelper.TryGetIndexedElement("Wix4FileShare", row.FieldAsString(0), out var fileShare) || 410 if (this.DecompilerHelper.TryGetIndexedElement("Wix4FileShare", row.FieldAsString(0), out var fileShare) ||
380 this.DecompilerHelper.TryGetIndexedElement("FileShare", row.FieldAsString(0), out fileShare)) 411 this.DecompilerHelper.TryGetIndexedElement("FileShare", row.FieldAsString(0), out fileShare))
381 { 412 {
382 fileShare.Add(fileSharePermission); 413 fileShare.Add(fileSharePermission);
383 } 414 }
384 else 415 else
385 { 416 {
@@ -695,6 +726,17 @@ namespace WixToolset.Util
695 } 726 }
696 } 727 }
697 728
729 private void FinalizeCustomActions()
730 {
731 foreach (var customActionName in this.customActionNames)
732 {
733 if (CustomActionMapping.TryGetValue(customActionName, out var elementName))
734 {
735 this.DecompilerHelper.AddElementToRoot(elementName);
736 }
737 }
738 }
739
698 /// <summary> 740 /// <summary>
699 /// Finalize the Perfmon table. 741 /// Finalize the Perfmon table.
700 /// </summary> 742 /// </summary>
diff --git a/src/wix/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs b/src/wix/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs
index e2a6750e..9fda8248 100644
--- a/src/wix/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs
+++ b/src/wix/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs
@@ -2384,12 +2384,12 @@ namespace WixToolset.Core.WindowsInstaller.Decompile
2384 this.DecompilerHelper.RootElement.SetAttributeValue("Guid", this.ModularizationGuid); 2384 this.DecompilerHelper.RootElement.SetAttributeValue("Guid", this.ModularizationGuid);
2385 } 2385 }
2386 2386
2387 this.RemoveExtensionDataFromTables(tables);
2388
2389 foreach (var extension in this.Extensions) 2387 foreach (var extension in this.Extensions)
2390 { 2388 {
2391 extension.PreDecompileTables(tables); 2389 extension.PreDecompileTables(tables);
2392 } 2390 }
2391
2392 this.RemoveExtensionDataFromTables(tables);
2393 } 2393 }
2394 2394
2395 private void RemoveExtensionDataFromTables(TableIndexedCollection tables) 2395 private void RemoveExtensionDataFromTables(TableIndexedCollection tables)