@joebigelow / wix / commits / 088dc648

Initial commit

Rob Mensching committed Sep 3, 2017 at 16:51 UTC 088dc648a3478e2cacdbdab1cb1782556642ee69
13 files changed +757
WixToolset.Core.Native.sln new
+42
@@ -0,0 +1,42 @@
1 +
2 +Microsoft Visual Studio Solution File, Format Version 12.00
3 +# Visual Studio 15
4 +VisualStudioVersion = 15.0.26730.12
5 +MinimumVisualStudioVersion = 15.0.26124.0
6 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "winterop", "src\winterop\winterop.vcxproj", "{26D45E58-E703-431D-B67E-493C72C9DA0B}"
7 +EndProject
8 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixToolset.Core.Native", "src\WixToolset.Core.Native\WixToolset.Core.Native.csproj", "{C1F36B7C-6A5B-44CB-BD05-3C9CDEC2DD63}"
9 + ProjectSection(ProjectDependencies) = postProject
10 + {26D45E58-E703-431D-B67E-493C72C9DA0B} = {26D45E58-E703-431D-B67E-493C72C9DA0B}
11 + EndProjectSection
12 +EndProject
13 +Global
14 + GlobalSection(SolutionConfigurationPlatforms) = preSolution
15 + Debug|Any CPU = Debug|Any CPU
16 + Debug|x86 = Debug|x86
17 + Release|Any CPU = Release|Any CPU
18 + Release|x86 = Release|x86
19 + EndGlobalSection
20 + GlobalSection(ProjectConfigurationPlatforms) = postSolution
21 + {26D45E58-E703-431D-B67E-493C72C9DA0B}.Debug|Any CPU.ActiveCfg = Debug|Win32
22 + {26D45E58-E703-431D-B67E-493C72C9DA0B}.Debug|x86.ActiveCfg = Debug|Win32
23 + {26D45E58-E703-431D-B67E-493C72C9DA0B}.Debug|x86.Build.0 = Debug|Win32
24 + {26D45E58-E703-431D-B67E-493C72C9DA0B}.Release|Any CPU.ActiveCfg = Release|Win32
25 + {26D45E58-E703-431D-B67E-493C72C9DA0B}.Release|x86.ActiveCfg = Release|Win32
26 + {26D45E58-E703-431D-B67E-493C72C9DA0B}.Release|x86.Build.0 = Release|Win32
27 + {C1F36B7C-6A5B-44CB-BD05-3C9CDEC2DD63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28 + {C1F36B7C-6A5B-44CB-BD05-3C9CDEC2DD63}.Debug|Any CPU.Build.0 = Debug|Any CPU
29 + {C1F36B7C-6A5B-44CB-BD05-3C9CDEC2DD63}.Debug|x86.ActiveCfg = Debug|Any CPU
30 + {C1F36B7C-6A5B-44CB-BD05-3C9CDEC2DD63}.Debug|x86.Build.0 = Debug|Any CPU
31 + {C1F36B7C-6A5B-44CB-BD05-3C9CDEC2DD63}.Release|Any CPU.ActiveCfg = Release|Any CPU
32 + {C1F36B7C-6A5B-44CB-BD05-3C9CDEC2DD63}.Release|Any CPU.Build.0 = Release|Any CPU
33 + {C1F36B7C-6A5B-44CB-BD05-3C9CDEC2DD63}.Release|x86.ActiveCfg = Release|Any CPU
34 + {C1F36B7C-6A5B-44CB-BD05-3C9CDEC2DD63}.Release|x86.Build.0 = Release|Any CPU
35 + EndGlobalSection
36 + GlobalSection(SolutionProperties) = preSolution
37 + HideSolutionNode = FALSE
38 + EndGlobalSection
39 + GlobalSection(ExtensibilityGlobals) = postSolution
40 + SolutionGuid = {1E952530-A3ED-4E65-AF39-9025EFB85322}
41 + EndGlobalSection
42 +EndGlobal
appveyor.cmd
+5
@@ -1,5 +1,10 @@
1 @setlocal
2 @pushd %~dp0
3
4 +msbuild -p:Configuration=Release;Platform=Win32 -t:PackNativeNuget src\winterop\winterop.vcxproj
5 +msbuild -p:Configuration=Release;Platform=x64 -t:PackNativeNuget src\winterop\winterop.vcxproj
6 +
7 +dotnet pack -c Release .\src\WixToolset.Core.Native\WixToolset.Core.Native.csproj
8 +
9 @popd
10 @endlocal
\ No newline at end of file
src/Cpp.Build.props
+1
@@ -3,6 +3,7 @@
3
4 <Project>
5 <PropertyGroup>
6 + <Platform Condition=" '$(Platform)' == 'AnyCPU' ">Win32</Platform>
7 <BaseOutputPath>$(OutputPath)</BaseOutputPath>
8 <IntDir>$(BaseIntermediateOutputPath)$(Platform)\</IntDir>
9 <OutDir>$(OutputPath)$(Platform)\</OutDir>
src/Directory.Build.props
+1
@@ -4,6 +4,7 @@
4 <Project>
5 <PropertyGroup>
6 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7 + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8 <BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)..\build\obj\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
9 <OutputPath>$(MSBuildThisFileDirectory)..\build\$(Configuration)\</OutputPath>
10
src/WixToolset.Core.Native/CabInterop.cs new
+312
@@ -0,0 +1,312 @@
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 +
3 +namespace WixToolset.Core.Native
4 +{
5 + using System;
6 + using System.Diagnostics.CodeAnalysis;
7 + using System.Text;
8 + using System.Runtime.InteropServices;
9 + // using WixToolset.Msi;
10 + // using WixToolset.Msi.Interop;
11 +
12 + /// <summary>
13 + /// The native methods.
14 + /// </summary>
15 + public sealed class NativeMethods
16 + {
17 + /// <summary>
18 + /// Starts creating a cabinet.
19 + /// </summary>
20 + /// <param name="cabinetName">Name of cabinet to create.</param>
21 + /// <param name="cabinetDirectory">Directory to create cabinet in.</param>
22 + /// <param name="maxFiles">Maximum number of files that will be added to cabinet.</param>
23 + /// <param name="maxSize">Maximum size of the cabinet.</param>
24 + /// <param name="maxThreshold">Maximum threshold in the cabinet.</param>
25 + /// <param name="compressionType">Type of compression to use in the cabinet.</param>
26 + /// <param name="contextHandle">Handle to opened cabinet.</param>
27 + [DllImport("winterop.dll", EntryPoint = "CreateCabBegin", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false)]
28 + public static extern void CreateCabBegin(string cabinetName, string cabinetDirectory, uint maxFiles, uint maxSize, uint maxThreshold, uint compressionType, out IntPtr contextHandle);
29 +
30 + /// <summary>
31 + /// Adds a file to an open cabinet.
32 + /// </summary>
33 + /// <param name="file">Full path to file to add to cabinet.</param>
34 + /// <param name="token">Name of file in cabinet.</param>
35 + /// <param name="contextHandle">Handle to open cabinet.</param>
36 + // [DllImport("winterop.dll", EntryPoint = "CreateCabAddFile", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false)]
37 + // public static extern void CreateCabAddFile(string file, string token, MsiInterop.MSIFILEHASHINFO fileHash, IntPtr contextHandle);
38 +
39 + /// <summary>
40 + /// Closes a cabinet.
41 + /// </summary>
42 + /// <param name="contextHandle">Handle to open cabinet to close.</param>
43 + /// <param name="newCabNamesCallBackAddress">Address of Binder's cabinet split callback</param>
44 + [DllImport("winterop.dll", EntryPoint = "CreateCabFinish", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false)]
45 + public static extern void CreateCabFinish(IntPtr contextHandle, IntPtr newCabNamesCallBackAddress);
46 +
47 + /// <summary>
48 + /// Cancels cabinet creation.
49 + /// </summary>
50 + /// <param name="contextHandle">Handle to open cabinet to cancel.</param>
51 + [DllImport("winterop.dll", EntryPoint = "CreateCabCancel", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false)]
52 + public static extern void CreateCabCancel(IntPtr contextHandle);
53 +
54 + /// <summary>
55 + /// Initializes cabinet extraction.
56 + /// </summary>
57 + [DllImport("winterop.dll", EntryPoint = "ExtractCabBegin", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false)]
58 + public static extern void ExtractCabBegin();
59 +
60 + /// <summary>
61 + /// Extracts files from cabinet.
62 + /// </summary>
63 + /// <param name="cabinet">Path to cabinet to extract files from.</param>
64 + /// <param name="extractDirectory">Directory to extract files to.</param>
65 + [DllImport("winterop.dll", EntryPoint = "ExtractCab", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true, PreserveSig = false)]
66 + public static extern void ExtractCab(string cabinet, string extractDirectory);
67 +
68 + /// <summary>
69 + /// Cleans up after cabinet extraction.
70 + /// </summary>
71 + [DllImport("winterop.dll", EntryPoint = "ExtractCabFinish", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
72 + public static extern void ExtractCabFinish();
73 +
74 + /// <summary>
75 + /// Initializes cabinet enumeration.
76 + /// </summary>
77 + [DllImport("winterop.dll", EntryPoint = "EnumerateCabBegin", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false)]
78 + public static extern void EnumerateCabBegin();
79 +
80 + /// <summary>
81 + /// Enumerates files from cabinet.
82 + /// </summary>
83 + /// <param name="cabinet">Path to cabinet to enumerate files from.</param>
84 + /// <param name="notify">callback that gets each file.</param>
85 + [DllImport("winterop.dll", EntryPoint = "EnumerateCab", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true, PreserveSig = false)]
86 + public static extern void EnumerateCab(string cabinet, CabInterop.PFNNOTIFY notify);
87 +
88 + /// <summary>
89 + /// Cleans up after cabinet enumeration.
90 + /// </summary>
91 + [DllImport("winterop.dll", EntryPoint = "EnumerateCabFinish", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
92 + public static extern void EnumerateCabFinish();
93 +
94 + /// <summary>
95 + /// Resets the DACL on an array of files to "empty".
96 + /// </summary>
97 + /// <param name="files">Array of file reset ACL to "empty".</param>
98 + /// <param name="fileCount">Number of file paths in array.</param>
99 + [DllImport("winterop.dll", EntryPoint = "ResetAcls", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false)]
100 + public static extern void ResetAcls(string[] files, uint fileCount);
101 +
102 + /// <summary>
103 + /// Gets the hash of the pCertContext->pCertInfo->SubjectPublicKeyInfo using ::CryptHashPublicKeyInfo() which does not seem
104 + /// to be exposed by .NET Frameowkr.
105 + /// </summary>
106 + /// <param name="certContext">Pointer to a CERT_CONTEXT struct with public key information to hash.</param>
107 + /// <param name="fileCount">Number of file paths in array.</param>
108 + [DllImport("winterop.dll", EntryPoint = "HashPublicKeyInfo", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false)]
109 + public static extern void HashPublicKeyInfo(IntPtr certContext, byte[] publicKeyInfoHashed, ref uint sizePublicKeyInfoHashed);
110 +
111 + /// <summary>
112 + /// Converts file time to a local file time.
113 + /// </summary>
114 + /// <param name="fileTime">file time</param>
115 + /// <param name="localTime">local file time</param>
116 + /// <returns>true if successful, false otherwise</returns>
117 + [DllImport("kernel32.dll", SetLastError = true)]
118 + [return: MarshalAs(UnmanagedType.Bool)]
119 + public static extern bool FileTimeToLocalFileTime(ref long fileTime, ref long localTime);
120 +
121 + /// <summary>
122 + /// Converts file time to a MS-DOS time.
123 + /// </summary>
124 + /// <param name="fileTime">file time</param>
125 + /// <param name="wFatDate">MS-DOS date</param>
126 + /// <param name="wFatTime">MS-DOS time</param>
127 + /// <returns>true if successful, false otherwise</returns>
128 + [DllImport("kernel32.dll", SetLastError = true)]
129 + [return: MarshalAs(UnmanagedType.Bool)]
130 + public static extern bool FileTimeToDosDateTime(ref long fileTime, out ushort wFatDate, out ushort wFatTime);
131 + }
132 +
133 + /// <summary>
134 + /// Interop class for the winterop.dll.
135 + /// </summary>
136 + public static class CabInterop
137 + {
138 + /// <summary>
139 + /// Delegate type that's called by cabinet api for every file in cabinet.
140 + /// </summary>
141 + /// <param name="fdint">NOTIFICATIONTYPE</param>
142 + /// <param name="pfdin">NOTIFICATION</param>
143 + /// <returns>0 for success, -1 otherwise</returns>
144 + public delegate Int32 PFNNOTIFY(NOTIFICATIONTYPE fdint, NOTIFICATION pfdin);
145 +
146 + /// <summary>
147 + /// Wraps FDINOTIFICATIONTYPE.
148 + /// </summary>
149 + public enum NOTIFICATIONTYPE : int
150 + {
151 + /// <summary>Info about the cabinet.</summary>
152 + CABINET_INFO,
153 + /// <summary>One or more files are continued.</summary>
154 + PARTIAL_FILE,
155 + /// <summary>Called for each file in cabinet.</summary>
156 + COPY_FILE,
157 + /// <summary>Called after all of the data has been written to a target file.</summary>
158 + CLOSE_FILE_INFO,
159 + /// <summary>A file is continued to the next cabinet.</summary>
160 + NEXT_CABINET,
161 + /// <summary>Called once after a call to FDICopy() starts scanning a CAB's CFFILE entries, and again when there are no more CFFILE entries.</summary>
162 + ENUMERATE,
163 + }
164 +
165 + /// <summary>
166 + /// Converts DateTime to MS-DOS date and time which cabinet uses.
167 + /// </summary>
168 + /// <param name="dateTime">DateTime</param>
169 + /// <param name="cabDate">MS-DOS date</param>
170 + /// <param name="cabTime">MS-DOS time</param>
171 + public static void DateTimeToCabDateAndTime(DateTime dateTime, out ushort cabDate, out ushort cabTime)
172 + {
173 + // dateTime.ToLocalTime() does not match FileTimeToLocalFileTime() for some reason.
174 + // so we need to call FileTimeToLocalFileTime() from kernel32.dll.
175 + long filetime = dateTime.ToFileTime();
176 + long localTime = 0;
177 + NativeMethods.FileTimeToLocalFileTime(ref filetime, ref localTime);
178 + NativeMethods.FileTimeToDosDateTime(ref localTime, out cabDate, out cabTime);
179 + }
180 +
181 + /// <summary>
182 + /// Wraps FDINOTIFICATION.
183 + /// </summary>
184 + [SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")]
185 + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
186 + public class NOTIFICATION
187 + {
188 + private int cb;
189 + [MarshalAs(UnmanagedType.LPStr)]
190 + private string psz1;
191 + [MarshalAs(UnmanagedType.LPStr)]
192 + private string psz2;
193 + [MarshalAs(UnmanagedType.LPStr)]
194 + private string psz3;
195 + private IntPtr pv;
196 +
197 + private IntPtr hf;
198 +
199 + private ushort date;
200 + private ushort time;
201 + private ushort attribs;
202 + private ushort setID;
203 + private ushort cabinet;
204 + private ushort folder;
205 + private int fdie;
206 +
207 + /// <summary>
208 + /// Uncompressed size of file.
209 + /// </summary>
210 + public int Cb
211 + {
212 + get { return this.cb; }
213 + }
214 +
215 + /// <summary>
216 + /// File name in cabinet.
217 + /// </summary>
218 + public String Psz1
219 + {
220 + get { return this.psz1; }
221 + }
222 +
223 + /// <summary>
224 + /// Name of next disk.
225 + /// </summary>
226 + public string Psz2
227 + {
228 + get { return this.psz2; }
229 + }
230 +
231 + /// <summary>
232 + /// Points to a 256 character buffer.
233 + /// </summary>
234 + public string Psz3
235 + {
236 + get { return this.psz3; }
237 + }
238 +
239 + /// <summary>
240 + /// Value for client.
241 + /// </summary>
242 + public IntPtr Pv
243 + {
244 + get { return this.pv; }
245 + }
246 +
247 + /// <summary>
248 + /// Not used.
249 + /// </summary>
250 + public Int32 Hf
251 + {
252 + get { return (Int32)this.hf; }
253 + }
254 +
255 + /// <summary>
256 + /// Last modified MS-DOS date.
257 + /// </summary>
258 + public ushort Date
259 + {
260 + get { return this.date; }
261 + }
262 +
263 + /// <summary>
264 + /// Last modified MS-DOS time.
265 + /// </summary>
266 + public ushort Time
267 + {
268 + get { return this.time; }
269 + }
270 +
271 + /// <summary>
272 + /// File attributes.
273 + /// </summary>
274 + public ushort Attribs
275 + {
276 + get { return this.attribs; }
277 + }
278 +
279 + /// <summary>
280 + /// Cabinet set ID (a random 16-bit number).
281 + /// </summary>
282 + public ushort SetID
283 + {
284 + get { return this.setID; }
285 + }
286 +
287 + /// <summary>
288 + /// Cabinet number within cabinet set (0-based).
289 + /// </summary>
290 + public ushort Cabinet
291 + {
292 + get { return this.cabinet; }
293 + }
294 +
295 + /// <summary>
296 + /// File's folder index.
297 + /// </summary>
298 + public ushort Folder
299 + {
300 + get { return this.folder; }
301 + }
302 +
303 + /// <summary>
304 + /// Error code.
305 + /// </summary>
306 + public int Fdie
307 + {
308 + get { return this.fdie; }
309 + }
310 + }
311 + }
312 +}
src/WixToolset.Core.Native/WixToolset.Core.Native.csproj new
+23
@@ -0,0 +1,23 @@
1 +<Project Sdk="Microsoft.NET.Sdk">
2 +
3 + <PropertyGroup>
4 + <TargetFramework>netstandard2.0</TargetFramework>
5 + <NuspecFile>$(MSBuildThisFileName).nuspec</NuspecFile>
6 + <!-- <BeforePack>SetNuspecProperties</BeforePack> -->
7 + </PropertyGroup>
8 +
9 + <ItemGroup>
10 + <PackageReference Include="Nerdbank.GitVersioning" Version="2.0.37-beta" PrivateAssets="all" />
11 + </ItemGroup>
12 +
13 + <!-- <ItemGroup>
14 + <ProjectReference Include="..\winterop\winterop.vcxproj" ExcludeAssets="All" />
15 + </ItemGroup> -->
16 + <Target Name="SetNuspecProperties"
17 + AfterTargets="Build">
18 + <PropertyGroup>
19 + <NuspecBasePath>$(OutputPath)</NuspecBasePath>
20 + <NuspecProperties>Configuration=$(Configuration);Id=$(MSBuildThisFileName);Version=$(BuildVersionSimple);Authors=$(Authors);Copyright=$(Copyright);Description=$(Description)</NuspecProperties>
21 + </PropertyGroup>
22 + </Target>
23 +</Project>
src/WixToolset.Core.Native/WixToolset.Core.Native.nuspec new
+24
@@ -0,0 +1,24 @@
1 +<?xml version="1.0"?>
2 +<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
3 + <metadata minClientVersion="4.0">
4 + <id>$id$</id>
5 + <version>$version$</version>
6 + <authors>$authors$</authors>
7 + <owners>$authors$</owners>
8 + <licenseUrl>https://github.com/wixtoolset/Core.Native/blob/master/LICENSE.TXT</licenseUrl>
9 + <projectUrl>https://github.com/wixtoolset/Core.Native</projectUrl>
10 + <requireLicenseAcceptance>false</requireLicenseAcceptance>
11 + <description>$description$</description>
12 + <copyright>$copyright$</copyright>
13 +
14 + <dependencies>
15 + <dependency id="runtime.win-x86.WixToolset.Core.Native" version="$version$" />
16 + <dependency id="runtime.win-x64.WixToolset.Core.Native" version="$version$" />
17 + </dependencies>
18 + </metadata>
19 +
20 + <files>
21 + <file src="$id$.dll" target="lib\netstandard2.0" />
22 + <file src="$id$.pdb" target="lib\netstandard2.0" />
23 + </files>
24 +</package>
src/winterop/packages.config new
+5
@@ -0,0 +1,5 @@
1 +<?xml version="1.0" encoding="utf-8"?>
2 +<packages>
3 + <package id="Nerdbank.GitVersioning" version="2.0.37-beta" targetFramework="native" developmentDependency="true" />
4 + <package id="WixToolset.DUtil" version="4.0.3" targetFramework="native" />
5 +</packages>
\ No newline at end of file
src/winterop/precomp.h new
+12
@@ -0,0 +1,12 @@
1 +#pragma once
2 +// 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.
3 +
4 +#include <windows.h>
5 +#include <aclapi.h>
6 +
7 +#include "dutil.h"
8 +#include "fileutil.h"
9 +#include "memutil.h"
10 +#include "strutil.h"
11 +#include "cabcutil.h"
12 +#include "cabutil.h"
src/winterop/runtime.win-xxx.WixToolset.Core.Native.nuspec new
+19
@@ -0,0 +1,19 @@
1 +<?xml version="1.0"?>
2 +<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
3 + <metadata minClientVersion="4.0">
4 + <id>$id$</id>
5 + <version>$version$</version>
6 + <authors>$authors$</authors>
7 + <owners>$authors$</owners>
8 + <licenseUrl>https://github.com/wixtoolset/Core.Native/blob/master/LICENSE.TXT</licenseUrl>
9 + <projectUrl>https://github.com/wixtoolset/Core.Native</projectUrl>
10 + <requireLicenseAcceptance>false</requireLicenseAcceptance>
11 + <description>$description$</description>
12 + <copyright>$copyright$</copyright>
13 + </metadata>
14 +
15 + <files>
16 + <file src="winterop.dll" target="runtimes\win-$platform$\native" />
17 + <file src="winterop.pdb" target="runtimes\win-$platform$\native" />
18 + </files>
19 +</package>
src/winterop/winterop.cpp new
+216
@@ -0,0 +1,216 @@
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 +
3 +#include "precomp.h"
4 +
5 +
6 +HRESULT HashPublicKeyInfo(
7 + __in PCERT_CONTEXT pCertContext,
8 + __in_ecount(*pcbSubjectKeyIndentifier) BYTE* rgbSubjectKeyIdentifier,
9 + __inout DWORD* pcbSubjectKeyIndentifier
10 + )
11 +{
12 + HRESULT hr = S_OK;
13 +
14 + if (!::CryptHashPublicKeyInfo(NULL, CALG_SHA1, 0, X509_ASN_ENCODING, &pCertContext->pCertInfo->SubjectPublicKeyInfo, rgbSubjectKeyIdentifier, pcbSubjectKeyIndentifier))
15 + {
16 + ExitWithLastError(hr, "Failed to hash public key information.");
17 + }
18 +
19 +LExit:
20 + return hr;
21 +}
22 +
23 +HRESULT ResetAcls(
24 + __in LPCWSTR pwzFiles[],
25 + __in DWORD cFiles
26 + )
27 +{
28 + HRESULT hr = S_OK;
29 + ACL* pacl = NULL;
30 + DWORD cbAcl = sizeof(ACL);
31 +
32 + OSVERSIONINFO osvi;
33 +
34 + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
35 + if (!::GetVersionExA(&osvi))
36 + {
37 + ExitOnLastError(hr, "failed to get OS version");
38 + }
39 +
40 + // If we're running on NT 4 or earlier, or ME or earlier, don't reset ACLs.
41 + if (4 >= osvi.dwMajorVersion)
42 + {
43 + ExitFunction1(hr = S_FALSE);
44 + }
45 +
46 + // create an empty (not NULL!) ACL to use on all the files
47 + pacl = static_cast<ACL*>(MemAlloc(cbAcl, FALSE));
48 + ExitOnNull(pacl, hr, E_OUTOFMEMORY, "failed to allocate ACL");
49 +
50 +#pragma prefast(push)
51 +#pragma prefast(disable:25029)
52 + if (!::InitializeAcl(pacl, cbAcl, ACL_REVISION))
53 +#pragma prefast(op)
54 + {
55 + ExitOnLastError(hr, "failed to initialize ACL");
56 + }
57 +
58 + // reset the existing security permissions on each file
59 + for (DWORD i = 0; i < cFiles; ++i)
60 + {
61 + hr = ::SetNamedSecurityInfoW(const_cast<LPWSTR>(pwzFiles[i]), SE_FILE_OBJECT, DACL_SECURITY_INFORMATION | UNPROTECTED_DACL_SECURITY_INFORMATION, NULL, NULL, pacl, NULL);
62 + if (ERROR_FILE_NOT_FOUND != hr && ERROR_PATH_NOT_FOUND != hr)
63 + {
64 + ExitOnFailure(hr = HRESULT_FROM_WIN32(hr), "failed to set security descriptor for file: %S", pwzFiles[i]);
65 + }
66 + }
67 +
68 + // Setting to S_OK because we could end with ERROR_FILE_NOT_FOUND or ERROR_PATH_NOT_FOUND as valid return values.
69 + hr = S_OK;
70 +
71 + AssertSz(::IsValidAcl(pacl), "ResetAcls() - created invalid ACL");
72 +
73 +LExit:
74 + if (pacl)
75 + {
76 + MemFree(pacl);
77 + }
78 +
79 + return hr;
80 +}
81 +
82 +
83 +HRESULT CreateCabBegin(
84 + __in LPCWSTR wzCab,
85 + __in LPCWSTR wzCabDir,
86 + __in DWORD dwMaxFiles,
87 + __in DWORD dwMaxSize,
88 + __in DWORD dwMaxThresh,
89 + __in COMPRESSION_TYPE ct,
90 + __out HANDLE *phContext
91 + )
92 +{
93 + return CabCBegin(wzCab, wzCabDir, dwMaxFiles, dwMaxSize, dwMaxThresh, ct, phContext);
94 +}
95 +
96 +
97 +HRESULT CreateCabAddFile(
98 + __in LPCWSTR wzFile,
99 + __in_opt LPCWSTR wzToken,
100 + __in_opt PMSIFILEHASHINFO pmfHash,
101 + __in HANDLE hContext
102 + )
103 +{
104 + return CabCAddFile(wzFile, wzToken, pmfHash, hContext);
105 +}
106 +
107 +
108 +HRESULT CreateCabAddFiles(
109 + __in LPCWSTR pwzFiles[],
110 + __in LPCWSTR pwzTokens[],
111 + __in PMSIFILEHASHINFO pmfHash[],
112 + __in DWORD cFiles,
113 + __in HANDLE hContext
114 + )
115 +{
116 + HRESULT hr = S_OK;
117 + DWORD i;
118 +
119 + Assert(pwzFiles);
120 + Assert(hContext);
121 +
122 + for (i = 0; i < cFiles; i++)
123 + {
124 + hr = CreateCabAddFile(
125 + pwzFiles[i],
126 + pwzTokens ? pwzTokens[i] : NULL,
127 + pmfHash[i],
128 + hContext
129 + );
130 + ExitOnFailure(hr, "Failed to add file %S to cab", pwzFiles[i]);
131 + }
132 +
133 +LExit:
134 + return hr;
135 +}
136 +
137 +
138 +HRESULT CreateCabFinish(
139 + __in HANDLE hContext,
140 + __in_opt FileSplitCabNamesCallback newCabNamesCallBackAddress
141 + )
142 +{
143 + // Convert address into Binder callback function
144 + return CabCFinish(hContext, newCabNamesCallBackAddress);
145 +}
146 +
147 +
148 +void CreateCabCancel(
149 + __in HANDLE hContext
150 + )
151 +{
152 + CabCCancel(hContext);
153 +}
154 +
155 +
156 +HRESULT ExtractCabBegin()
157 +{
158 + return CabInitialize(FALSE);
159 +}
160 +
161 +
162 +HRESULT ExtractCab(
163 + __in LPCWSTR wzCabinet,
164 + __in LPCWSTR wzExtractDir
165 + )
166 +{
167 + return CabExtract(wzCabinet, L"*", wzExtractDir, NULL, NULL, 0);
168 +}
169 +
170 +
171 +void ExtractCabFinish()
172 +{
173 + CabUninitialize();
174 + return;
175 +}
176 +
177 +
178 +HRESULT EnumerateCabBegin()
179 +{
180 + return CabInitialize(FALSE);
181 +}
182 +
183 +
184 +HRESULT EnumerateCab(
185 + __in LPCWSTR wzCabinet,
186 + __in STDCALL_PFNFDINOTIFY pfnNotify
187 + )
188 +{
189 + return CabEnumerate(wzCabinet, L"*", pfnNotify, 0);
190 +}
191 +
192 +
193 +void EnumerateCabFinish()
194 +{
195 + CabUninitialize();
196 + return;
197 +}
198 +
199 +
200 +BOOL WINAPI DllMain(
201 + __in HINSTANCE /*hInstance*/,
202 + __in DWORD dwReason,
203 + __in LPVOID /*lpvReserved*/
204 + )
205 +{
206 + switch(dwReason)
207 + {
208 + case DLL_PROCESS_ATTACH:
209 + case DLL_PROCESS_DETACH:
210 + case DLL_THREAD_ATTACH:
211 + case DLL_THREAD_DETACH:
212 + break;
213 + }
214 +
215 + return TRUE;
216 +}
src/winterop/winterop.def new
+18
@@ -0,0 +1,18 @@
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 +
3 +LIBRARY "winterop.dll"
4 +
5 +EXPORTS
6 + CreateCabBegin
7 + CreateCabCancel
8 + CreateCabAddFile
9 + CreateCabAddFiles
10 + CreateCabFinish
11 + EnumerateCabBegin
12 + EnumerateCab
13 + EnumerateCabFinish
14 + ExtractCabBegin
15 + ExtractCab
16 + ExtractCabFinish
17 + ResetAcls
18 + HashPublicKeyInfo
src/winterop/winterop.vcxproj new
+79
@@ -0,0 +1,79 @@
1 +<?xml version="1.0" encoding="utf-8"?>
2 +<!-- 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. -->
3 +
4 +<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
5 + <Import Project="..\..\packages\WixToolset.DUtil.4.0.3\build\WixToolset.DUtil.props" Condition="Exists('..\..\packages\WixToolset.DUtil.4.0.3\build\WixToolset.DUtil.props')" />
6 +
7 + <ItemGroup Label="ProjectConfigurations">
8 + <ProjectConfiguration Include="Debug|Win32">
9 + <Configuration>Debug</Configuration>
10 + <Platform>Win32</Platform>
11 + </ProjectConfiguration>
12 + <ProjectConfiguration Include="Release|Win32">
13 + <Configuration>Release</Configuration>
14 + <Platform>Win32</Platform>
15 + </ProjectConfiguration>
16 + <ProjectConfiguration Include="Debug|x64">
17 + <Configuration>Debug</Configuration>
18 + <Platform>x64</Platform>
19 + </ProjectConfiguration>
20 + <ProjectConfiguration Include="Release|x64">
21 + <Configuration>Release</Configuration>
22 + <Platform>x64</Platform>
23 + </ProjectConfiguration>
24 + </ItemGroup>
25 +
26 + <PropertyGroup Label="Globals">
27 + <ProjectGuid>{26D45E58-E703-431D-B67E-493C72C9DA0B}</ProjectGuid>
28 + <ConfigurationType>DynamicLibrary</ConfigurationType>
29 + <TargetName>winterop</TargetName>
30 + <PlatformToolset>v141</PlatformToolset>
31 + <CharacterSet>MultiByte</CharacterSet>
32 + <ProjectModuleDefinitionFile>winterop.def</ProjectModuleDefinitionFile>
33 + <Description>Native component of WixToolset.Core</Description>
34 + </PropertyGroup>
35 +
36 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
37 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
38 +
39 + <ImportGroup Label="ExtensionSettings">
40 + </ImportGroup>
41 +
42 + <ImportGroup Label="Shared">
43 + </ImportGroup>
44 +
45 + <PropertyGroup>
46 + <ProjectAdditionalLinkLibraries>crypt32.lib;cabinet.lib;msi.lib</ProjectAdditionalLinkLibraries>
47 + </PropertyGroup>
48 +
49 + <ItemGroup>
50 + <ClCompile Include="winterop.cpp">
51 + <!-- turn off deprecation warning -->
52 + <DisableSpecificWarnings>4996</DisableSpecificWarnings>
53 + <PrecompiledHeader>Create</PrecompiledHeader>
54 + </ClCompile>
55 + </ItemGroup>
56 +
57 + <ItemGroup>
58 + <ClInclude Include="precomp.h" />
59 + </ItemGroup>
60 +
61 + <ItemGroup>
62 + <None Include="packages.config" />
63 + <None Include="winterop.def" />
64 + </ItemGroup>
65 +
66 + <Target Name="PackNativeNuget" DependsOnTargets="Build">
67 + <Exec Command="nuget pack runtime.win-xxx.WixToolset.Core.Native.nuspec -BasePath &quot;$(OutputPath)\&quot; -OutputDirectory &quot;$(BaseOutputPath)\&quot; -NoPackageAnalysis -Properties Configuration=$(Configuration);Id=runtime.win-$(PlatformTarget).WixToolset.Core.Native;Version=&quot;$(BuildVersionSimple)&quot;;Platform=$(PlatformTarget);Authors=&quot;$(Authors)&quot;;Copyright=&quot;$(Copyright)&quot;;Description=&quot;$(Description)&quot;;Title=&quot;$(Title)&quot;" />
68 + </Target>
69 +
70 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
71 + <Import Project="..\..\packages\Nerdbank.GitVersioning.2.0.37-beta\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\..\packages\Nerdbank.GitVersioning.2.0.37-beta\build\Nerdbank.GitVersioning.targets')" />
72 + <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
73 + <PropertyGroup>
74 + <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
75 + </PropertyGroup>
76 + <Error Condition="!Exists('..\..\packages\WixToolset.DUtil.4.0.3\build\WixToolset.DUtil.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\WixToolset.DUtil.4.0.3\build\WixToolset.DUtil.props'))" />
77 + <Error Condition="!Exists('..\..\packages\Nerdbank.GitVersioning.2.0.37-beta\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Nerdbank.GitVersioning.2.0.37-beta\build\Nerdbank.GitVersioning.targets'))" />
78 + </Target>
79 +</Project>