From ac70afc7ec180ed192c54502035721446e831f49 Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Thu, 8 Oct 2020 15:12:30 -0400 Subject: Add the decompiled package's platform to the DecompileResult. --- .../Decompile/DecompileMsiOrMsmCommand.cs | 14 +++++- .../Decompile/Decompiler.cs | 55 ++++++++++++---------- src/WixToolset.Core/DecompileResult.cs | 3 ++ 3 files changed, 47 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/WixToolset.Core.WindowsInstaller/Decompile/DecompileMsiOrMsmCommand.cs b/src/WixToolset.Core.WindowsInstaller/Decompile/DecompileMsiOrMsmCommand.cs index 2ec39583..45b669b9 100644 --- a/src/WixToolset.Core.WindowsInstaller/Decompile/DecompileMsiOrMsmCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Decompile/DecompileMsiOrMsmCommand.cs @@ -6,8 +6,10 @@ namespace WixToolset.Core.WindowsInstaller.Unbind using System.Collections.Generic; using System.ComponentModel; using System.IO; + using System.Linq; using WixToolset.Core.WindowsInstaller.Msi; using WixToolset.Data; + using WixToolset.Data.WindowsInstaller; using WixToolset.Extensibility; using WixToolset.Extensibility.Data; using WixToolset.Extensibility.Services; @@ -41,13 +43,15 @@ namespace WixToolset.Core.WindowsInstaller.Unbind Directory.Delete(this.Context.ExtractFolder, true); } - var unbindCommand = new UnbindDatabaseCommand(this.Messaging, database, this.Context.DecompilePath, this.Context.DecompileType, this.Context.ExtractFolder, this.Context.IntermediateFolder, this.Context.IsAdminImage, false, skipSummaryInfo: false); + var unbindCommand = new UnbindDatabaseCommand(this.Messaging, database, this.Context.DecompilePath, this.Context.DecompileType, this.Context.ExtractFolder, this.Context.IntermediateFolder, this.Context.IsAdminImage, suppressDemodularization: false, skipSummaryInfo: false); var output = unbindCommand.Execute(); var extractedFilePaths = new List(unbindCommand.ExportedFiles); var decompiler = new Decompiler(this.Messaging, this.Extensions, this.Context.BaseSourcePath, this.Context.SuppressCustomTables, this.Context.SuppressDroppingEmptyTables, this.Context.SuppressUI, this.Context.TreatProductAsModule); result.Document = decompiler.Decompile(output); + result.Platform = GetPlatformFromOutput(output); + // extract the files from the cabinets if (!String.IsNullOrEmpty(this.Context.ExtractFolder) && !this.Context.SuppressExtractCabinets) { @@ -77,5 +81,13 @@ namespace WixToolset.Core.WindowsInstaller.Unbind return result; } + + private static Platform? GetPlatformFromOutput(WindowsInstallerData output) + { + var template = output.Tables["_SummaryInformation"]?.Rows.SingleOrDefault(row => row.FieldAsInteger(0) == 7)?.FieldAsString(1); + + return Decompiler.GetPlatformFromTemplateSummaryInformation(template?.Split(';')); + + } } } diff --git a/src/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs b/src/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs index 40643abd..a0146fda 100644 --- a/src/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs +++ b/src/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs @@ -93,7 +93,7 @@ namespace WixToolset.Core.WindowsInstaller private string ModularizationGuid { get; set; } - public XElement UIElement + private XElement UIElement { get { @@ -107,12 +107,11 @@ namespace WixToolset.Core.WindowsInstaller } } - public Dictionary Singletons { get; } = new Dictionary(); + private Dictionary Singletons { get; } = new Dictionary(); - public Dictionary IndexedElements { get; } = new Dictionary(); - - public Dictionary PatchTargetFiles { get; } = new Dictionary(); + private Dictionary IndexedElements { get; } = new Dictionary(); + private Dictionary PatchTargetFiles { get; } = new Dictionary(); /// /// Decompile the database file. @@ -215,12 +214,30 @@ namespace WixToolset.Core.WindowsInstaller } #endif + internal static Platform? GetPlatformFromTemplateSummaryInformation(string[] template) + { + if (null != template && 1 < template.Length && null != template[0] && 0 < template[0].Length) + { + switch (template[0]) + { + case "Intel": + return Platform.X86; + case "x64": + return Platform.X64; + case "Arm64": + return Platform.ARM64; + } + } + + return null; + } + /// /// Gets the element corresponding to the row it came from. /// /// The row corresponding to the element. /// The indexed element. - public XElement GetIndexedElement(WixToolset.Data.WindowsInstaller.Row row) => this.GetIndexedElement(row.TableDefinition.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter)); + private XElement GetIndexedElement(WixToolset.Data.WindowsInstaller.Row row) => this.GetIndexedElement(row.TableDefinition.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter)); /// /// Gets the element corresponding to the primary key of the given table. @@ -228,7 +245,7 @@ namespace WixToolset.Core.WindowsInstaller /// The table corresponding to the element. /// The primary key corresponding to the element. /// The indexed element. - public XElement GetIndexedElement(string table, params string[] primaryKey) => this.IndexedElements[String.Concat(table, ':', String.Join(DecompilerConstants.PrimaryKeyDelimiterString, primaryKey))]; + private XElement GetIndexedElement(string table, params string[] primaryKey) => this.IndexedElements[String.Concat(table, ':', String.Join(DecompilerConstants.PrimaryKeyDelimiterString, primaryKey))]; /// /// Gets the element corresponding to the primary key of the given table. @@ -236,7 +253,7 @@ namespace WixToolset.Core.WindowsInstaller /// The table corresponding to the element. /// The primary key corresponding to the element. /// The indexed element. - public bool TryGetIndexedElement(WixToolset.Data.WindowsInstaller.Row row, out XElement xElement) => this.TryGetIndexedElement(row.TableDefinition.Name, out xElement, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter)); + private bool TryGetIndexedElement(WixToolset.Data.WindowsInstaller.Row row, out XElement xElement) => this.TryGetIndexedElement(row.TableDefinition.Name, out xElement, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter)); /// /// Gets the element corresponding to the primary key of the given table. @@ -244,14 +261,14 @@ namespace WixToolset.Core.WindowsInstaller /// The table corresponding to the element. /// The primary key corresponding to the element. /// The indexed element. - public bool TryGetIndexedElement(string table, out XElement xElement, params string[] primaryKey) => this.IndexedElements.TryGetValue(String.Concat(table, ':', String.Join(DecompilerConstants.PrimaryKeyDelimiterString, primaryKey)), out xElement); + private bool TryGetIndexedElement(string table, out XElement xElement, params string[] primaryKey) => this.IndexedElements.TryGetValue(String.Concat(table, ':', String.Join(DecompilerConstants.PrimaryKeyDelimiterString, primaryKey)), out xElement); /// /// Index an element by its corresponding row. /// /// The row corresponding to the element. /// The element to index. - public void IndexElement(WixToolset.Data.WindowsInstaller.Row row, XElement element) + private void IndexElement(WixToolset.Data.WindowsInstaller.Row row, XElement element) { this.IndexedElements.Add(String.Concat(row.TableDefinition.Name, ':', row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter)), element); } @@ -261,7 +278,7 @@ namespace WixToolset.Core.WindowsInstaller /// /// The row corresponding to the element. /// The element to index. - public void IndexElement(XElement element, string table, params string[] primaryKey) + private void IndexElement(XElement element, string table, params string[] primaryKey) { this.IndexedElements.Add(String.Concat(table, ':', String.Join(DecompilerConstants.PrimaryKeyDelimiterString, primaryKey)), element); } @@ -3004,20 +3021,10 @@ namespace WixToolset.Core.WindowsInstaller xPackage.SetAttributeValue("Languages", template[template.Length - 1]); } - if (1 < template.Length && null != template[0] && 0 < template[0].Length) + var platform = GetPlatformFromTemplateSummaryInformation(template).ToString().ToLowerInvariant(); + if (!String.IsNullOrEmpty(platform)) { - switch (template[0]) - { - case "Intel": - xPackage.SetAttributeValue("Platform", "x86"); - break; - case "x64": - xPackage.SetAttributeValue("Platform", "x64"); - break; - case "Arm64": - xPackage.SetAttributeValue("Platform", "arm64"); - break; - } + xPackage.SetAttributeValue("Platform", platform); } break; case 9: diff --git a/src/WixToolset.Core/DecompileResult.cs b/src/WixToolset.Core/DecompileResult.cs index 120d099d..8c9285ba 100644 --- a/src/WixToolset.Core/DecompileResult.cs +++ b/src/WixToolset.Core/DecompileResult.cs @@ -4,6 +4,7 @@ namespace WixToolset.Core { using System.Collections.Generic; using System.Xml.Linq; + using WixToolset.Data; using WixToolset.Extensibility.Data; internal class DecompileResult : IDecompileResult @@ -11,5 +12,7 @@ namespace WixToolset.Core public XDocument Document { get; set; } public IEnumerable ExtractedFilePaths { get; set; } + + public Platform? Platform { get; set; } } } -- cgit v1.2.3-55-g6feb