aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/Bind/Bundles/BurnReader.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core/Bind/Bundles/BurnReader.cs')
-rw-r--r--src/WixToolset.Core/Bind/Bundles/BurnReader.cs210
1 files changed, 0 insertions, 210 deletions
diff --git a/src/WixToolset.Core/Bind/Bundles/BurnReader.cs b/src/WixToolset.Core/Bind/Bundles/BurnReader.cs
deleted file mode 100644
index f6d7a197..00000000
--- a/src/WixToolset.Core/Bind/Bundles/BurnReader.cs
+++ /dev/null
@@ -1,210 +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.Bind.Bundles
4{
5 using System;
6 using System.Collections;
7 using System.Collections.Generic;
8 using System.IO;
9 using System.Xml;
10 using WixToolset.Cab;
11
12 /// <summary>
13 /// Burn PE reader for the WiX toolset.
14 /// </summary>
15 /// <remarks>This class encapsulates reading from a stub EXE with containers attached
16 /// for dissecting bundled/chained setup packages.</remarks>
17 /// <example>
18 /// using (BurnReader reader = BurnReader.Open(fileExe, this.core, guid))
19 /// {
20 /// reader.ExtractUXContainer(file1, tempFolder);
21 /// }
22 /// </example>
23 internal class BurnReader : BurnCommon
24 {
25 private bool disposed;
26
27 private bool invalidBundle;
28 private BinaryReader binaryReader;
29 private List<DictionaryEntry> attachedContainerPayloadNames;
30
31 /// <summary>
32 /// Creates a BurnReader for reading a PE file.
33 /// </summary>
34 /// <param name="fileExe">File to read.</param>
35 private BurnReader(string fileExe)
36 : base(fileExe)
37 {
38 this.attachedContainerPayloadNames = new List<DictionaryEntry>();
39 }
40
41 /// <summary>
42 /// Gets the underlying stream.
43 /// </summary>
44 public Stream Stream
45 {
46 get
47 {
48 return (null != this.binaryReader) ? this.binaryReader.BaseStream : null;
49 }
50 }
51
52 /// <summary>
53 /// Opens a Burn reader.
54 /// </summary>
55 /// <param name="fileExe">Path to file.</param>
56 /// <returns>Burn reader.</returns>
57 public static BurnReader Open(string fileExe)
58 {
59 BurnReader reader = new BurnReader(fileExe);
60
61 reader.binaryReader = new BinaryReader(File.Open(fileExe, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete));
62 if (!reader.Initialize(reader.binaryReader))
63 {
64 reader.invalidBundle = true;
65 }
66
67 return reader;
68 }
69
70 /// <summary>
71 /// Gets the UX container from the exe and extracts its contents to the output directory.
72 /// </summary>
73 /// <param name="outputDirectory">Directory to write extracted files to.</param>
74 /// <returns>True if successful, false otherwise</returns>
75 public bool ExtractUXContainer(string outputDirectory, string tempDirectory)
76 {
77 // No UX container to extract
78 if (this.UXAddress == 0 || this.UXSize == 0)
79 {
80 return false;
81 }
82
83 if (this.invalidBundle)
84 {
85 return false;
86 }
87
88 Directory.CreateDirectory(outputDirectory);
89 string tempCabPath = Path.Combine(tempDirectory, "ux.cab");
90 string manifestOriginalPath = Path.Combine(outputDirectory, "0");
91 string manifestPath = Path.Combine(outputDirectory, "manifest.xml");
92
93 this.binaryReader.BaseStream.Seek(this.UXAddress, SeekOrigin.Begin);
94 using (Stream tempCab = File.Open(tempCabPath, FileMode.Create, FileAccess.Write))
95 {
96 BurnCommon.CopyStream(this.binaryReader.BaseStream, tempCab, (int)this.UXSize);
97 }
98
99 using (WixExtractCab extract = new WixExtractCab())
100 {
101 extract.Extract(tempCabPath, outputDirectory);
102 }
103
104 Directory.CreateDirectory(Path.GetDirectoryName(manifestPath));
105 File.Delete(manifestPath);
106 File.Move(manifestOriginalPath, manifestPath);
107
108 XmlDocument document = new XmlDocument();
109 document.Load(manifestPath);
110 XmlNamespaceManager namespaceManager = new XmlNamespaceManager(document.NameTable);
111 namespaceManager.AddNamespace("burn", BurnCommon.BurnNamespace);
112 XmlNodeList uxPayloads = document.SelectNodes("/burn:BurnManifest/burn:UX/burn:Payload", namespaceManager);
113 XmlNodeList payloads = document.SelectNodes("/burn:BurnManifest/burn:Payload", namespaceManager);
114
115 foreach (XmlNode uxPayload in uxPayloads)
116 {
117 XmlNode sourcePathNode = uxPayload.Attributes.GetNamedItem("SourcePath");
118 XmlNode filePathNode = uxPayload.Attributes.GetNamedItem("FilePath");
119
120 string sourcePath = Path.Combine(outputDirectory, sourcePathNode.Value);
121 string destinationPath = Path.Combine(outputDirectory, filePathNode.Value);
122
123 Directory.CreateDirectory(Path.GetDirectoryName(destinationPath));
124 File.Delete(destinationPath);
125 File.Move(sourcePath, destinationPath);
126 }
127
128 foreach (XmlNode payload in payloads)
129 {
130 XmlNode sourcePathNode = payload.Attributes.GetNamedItem("SourcePath");
131 XmlNode filePathNode = payload.Attributes.GetNamedItem("FilePath");
132 XmlNode packagingNode = payload.Attributes.GetNamedItem("Packaging");
133
134 string sourcePath = sourcePathNode.Value;
135 string destinationPath = filePathNode.Value;
136 string packaging = packagingNode.Value;
137
138 if (packaging.Equals("embedded", StringComparison.OrdinalIgnoreCase))
139 {
140 this.attachedContainerPayloadNames.Add(new DictionaryEntry(sourcePath, destinationPath));
141 }
142 }
143
144 return true;
145 }
146
147 /// <summary>
148 /// Gets the attached container from the exe and extracts its contents to the output directory.
149 /// </summary>
150 /// <param name="outputDirectory">Directory to write extracted files to.</param>
151 /// <returns>True if successful, false otherwise</returns>
152 public bool ExtractAttachedContainer(string outputDirectory, string tempDirectory)
153 {
154 // No attached container to extract
155 if (this.AttachedContainerAddress == 0 || this.AttachedContainerSize == 0)
156 {
157 return false;
158 }
159
160 if (this.invalidBundle)
161 {
162 return false;
163 }
164
165 Directory.CreateDirectory(outputDirectory);
166 string tempCabPath = Path.Combine(tempDirectory, "attached.cab");
167
168 this.binaryReader.BaseStream.Seek(this.AttachedContainerAddress, SeekOrigin.Begin);
169 using (Stream tempCab = File.Open(tempCabPath, FileMode.Create, FileAccess.Write))
170 {
171 BurnCommon.CopyStream(this.binaryReader.BaseStream, tempCab, (int)this.AttachedContainerSize);
172 }
173
174 using (WixExtractCab extract = new WixExtractCab())
175 {
176 extract.Extract(tempCabPath, outputDirectory);
177 }
178
179 foreach (DictionaryEntry entry in this.attachedContainerPayloadNames)
180 {
181 string sourcePath = Path.Combine(outputDirectory, (string)entry.Key);
182 string destinationPath = Path.Combine(outputDirectory, (string)entry.Value);
183
184 Directory.CreateDirectory(Path.GetDirectoryName(destinationPath));
185 File.Delete(destinationPath);
186 File.Move(sourcePath, destinationPath);
187 }
188
189 return true;
190 }
191
192 /// <summary>
193 /// Dispose object.
194 /// </summary>
195 /// <param name="disposing">True when releasing managed objects.</param>
196 protected override void Dispose(bool disposing)
197 {
198 if (!this.disposed)
199 {
200 if (disposing && this.binaryReader != null)
201 {
202 this.binaryReader.Close();
203 this.binaryReader = null;
204 }
205
206 this.disposed = true;
207 }
208 }
209 }
210}