aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.Burn/Inscribe
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core.Burn/Inscribe')
-rw-r--r--src/WixToolset.Core.Burn/Inscribe/InscribeBundleCommand.cs53
-rw-r--r--src/WixToolset.Core.Burn/Inscribe/InscribeBundleEngineCommand.cs61
2 files changed, 114 insertions, 0 deletions
diff --git a/src/WixToolset.Core.Burn/Inscribe/InscribeBundleCommand.cs b/src/WixToolset.Core.Burn/Inscribe/InscribeBundleCommand.cs
new file mode 100644
index 00000000..5eb76479
--- /dev/null
+++ b/src/WixToolset.Core.Burn/Inscribe/InscribeBundleCommand.cs
@@ -0,0 +1,53 @@
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.Core.Burn.Inscribe
4{
5 using System.IO;
6 using WixToolset.Core.Burn.Bundles;
7 using WixToolset.Extensibility;
8
9 internal class InscribeBundleCommand
10 {
11 public InscribeBundleCommand(IInscribeContext context)
12 {
13 this.Context = context;
14 }
15
16 private IInscribeContext Context { get; }
17
18 public bool Execute()
19 {
20 bool inscribed = false;
21 string tempFile = Path.Combine(this.Context.IntermediateFolder, "bundle_engine_signed.exe");
22
23 using (BurnReader reader = BurnReader.Open(this.Context.InputFilePath))
24 {
25 File.Copy(this.Context.SignedEngineFile, tempFile, true);
26
27 // If there was an attached container on the original (unsigned) bundle, put it back.
28 if (reader.AttachedContainerSize > 0)
29 {
30 reader.Stream.Seek(reader.AttachedContainerAddress, SeekOrigin.Begin);
31
32 using (BurnWriter writer = BurnWriter.Open(tempFile))
33 {
34 writer.RememberThenResetSignature();
35 writer.AppendContainer(reader.Stream, reader.AttachedContainerSize, BurnCommon.Container.Attached);
36 inscribed = true;
37 }
38 }
39 }
40
41 Directory.CreateDirectory(Path.GetDirectoryName(this.Context.OutputFile));
42 if (File.Exists(this.Context.OutputFile))
43 {
44 File.Delete(this.Context.OutputFile);
45 }
46
47 File.Move(tempFile, this.Context.OutputFile);
48 WixToolset.Core.Native.NativeMethods.ResetAcls(new string[] { this.Context.OutputFile }, 1);
49
50 return inscribed;
51 }
52 }
53}
diff --git a/src/WixToolset.Core.Burn/Inscribe/InscribeBundleEngineCommand.cs b/src/WixToolset.Core.Burn/Inscribe/InscribeBundleEngineCommand.cs
new file mode 100644
index 00000000..26af056b
--- /dev/null
+++ b/src/WixToolset.Core.Burn/Inscribe/InscribeBundleEngineCommand.cs
@@ -0,0 +1,61 @@
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.Core.Burn.Inscribe
4{
5 using System;
6 using System.IO;
7 using WixToolset.Core.Burn.Bundles;
8 using WixToolset.Extensibility;
9
10 internal class InscribeBundleEngineCommand
11 {
12 public InscribeBundleEngineCommand(IInscribeContext context)
13 {
14 this.Context = context;
15 }
16
17 private IInscribeContext Context { get; }
18
19 public bool Execute()
20 {
21 string tempFile = Path.Combine(this.Context.IntermediateFolder, "bundle_engine_unsigned.exe");
22
23 using (BurnReader reader = BurnReader.Open(this.Context.InputFilePath))
24 using (FileStream writer = File.Open(tempFile, FileMode.Create, FileAccess.Write, FileShare.Read | FileShare.Delete))
25 {
26 reader.Stream.Seek(0, SeekOrigin.Begin);
27
28 byte[] buffer = new byte[4 * 1024];
29 int total = 0;
30 int read = 0;
31 do
32 {
33 read = Math.Min(buffer.Length, (int)reader.EngineSize - total);
34
35 read = reader.Stream.Read(buffer, 0, read);
36 writer.Write(buffer, 0, read);
37
38 total += read;
39 } while (total < reader.EngineSize && 0 < read);
40
41 if (total != reader.EngineSize)
42 {
43 throw new InvalidOperationException("Failed to copy engine out of bundle.");
44 }
45
46 // TODO: update writer with detached container signatures.
47 }
48
49 Directory.CreateDirectory(Path.GetDirectoryName(this.Context.OutputFile));
50 if (File.Exists(this.Context.OutputFile))
51 {
52 File.Delete(this.Context.OutputFile);
53 }
54
55 File.Move(tempFile, this.Context.OutputFile);
56 WixToolset.Core.Native.NativeMethods.ResetAcls(new string[] { this.Context.OutputFile }, 1);
57
58 return true;
59 }
60 }
61}