@joebigelow / wix / commits / 495370ff

Add NativeMachine to Burn and WIX_NATIVE_MACHINE to UtilExtension

Eric StJohn committed Aug 30, 2021 at 15:26 UTC 495370ff9311d406da9c043cd208ce836a0303ff
9 files changed +106 -8
src/burn/engine/variable.cpp
+25
@@ -97,6 +97,10 @@ static HRESULT InitializeVariableVersionNT(
97 __in DWORD_PTR dwpData,
98 __inout BURN_VARIANT* pValue
99 );
100 +static HRESULT InitializeVariableNativeMachine(
101 + __in DWORD_PTR dwpData,
102 + __inout BURN_VARIANT* pValue
103 + );
104 static HRESULT InitializeVariableOsInfo(
105 __in DWORD_PTR dwpData,
106 __inout BURN_VARIANT* pValue
@@ -223,6 +227,7 @@ extern "C" HRESULT VariableInitialize(
227 {L"LocalAppDataFolder", InitializeVariableCsidlFolder, CSIDL_LOCAL_APPDATA},
228 {VARIABLE_LOGONUSER, InitializeVariableLogonUser, 0},
229 {L"MyPicturesFolder", InitializeVariableCsidlFolder, CSIDL_MYPICTURES},
230 + {L"NativeMachine", InitializeVariableNativeMachine, 0},
231 {L"NTProductType", InitializeVariableOsInfo, OS_INFO_VARIABLE_NTProductType},
232 {L"NTSuiteBackOffice", InitializeVariableOsInfo, OS_INFO_VARIABLE_NTSuiteBackOffice},
233 {L"NTSuiteDataCenter", InitializeVariableOsInfo, OS_INFO_VARIABLE_NTSuiteDataCenter},
@@ -1827,6 +1832,26 @@ LExit:
1832 return hr;
1833 }
1834
1835 +static HRESULT InitializeVariableNativeMachine(
1836 + __in DWORD_PTR dwpData,
1837 + __inout BURN_VARIANT* pValue
1838 + )
1839 +{
1840 + UNREFERENCED_PARAMETER(dwpData);
1841 +
1842 + HRESULT hr = S_OK;
1843 + USHORT usNativeMachine = IMAGE_FILE_MACHINE_UNKNOWN;
1844 +
1845 + hr = ProcNativeMachine(::GetCurrentProcess(), &usNativeMachine);
1846 + ExitOnFailure(hr, "Failed to get native machine value.");
1847 +
1848 + hr = BVariantSetNumeric(pValue, usNativeMachine);
1849 + ExitOnFailure(hr, "Failed to set variant value.");
1850 +
1851 +LExit:
1852 + return hr;
1853 +}
1854 +
1855 static HRESULT InitializeVariableComputerName(
1856 __in DWORD_PTR dwpData,
1857 __inout BURN_VARIANT* pValue
src/burn/test/BurnUnitTest/VariableTest.cpp
+1
@@ -477,6 +477,7 @@ namespace Bootstrapper
477 Assert::Equal(E_INVALIDARG, hr);
478 Assert::False(EvaluateConditionHelper(&variables, L"VersionNT = \"VAL\""));
479
480 + VariableGetNumericHelper(&variables, L"NativeMachine");
481 VariableGetNumericHelper(&variables, L"NTProductType");
482 VariableGetNumericHelper(&variables, L"NTSuiteBackOffice");
483 VariableGetNumericHelper(&variables, L"NTSuiteDataCenter");
src/ext/Util/ca/OsInfo.cpp
+28
@@ -485,3 +485,31 @@ LExit:
485 }
486 return WcaFinalize(er);
487 }
488 +
489 +/********************************************************************
490 +WixQueryNativeMachine - entry point for WixQueryNativeMachine custom action
491 +
492 + Called as Type 1 custom action (DLL from the Binary table) from
493 + Windows Installer to set properties that indicates the native machine architecture
494 +********************************************************************/
495 +extern "C" UINT __stdcall WixQueryNativeMachine(
496 + __in MSIHANDLE hInstall
497 + )
498 +{
499 + HRESULT hr = S_OK;
500 + USHORT usNativeMachine = IMAGE_FILE_MACHINE_UNKNOWN;
501 + DWORD er = ERROR_SUCCESS;
502 +
503 + hr = WcaInitialize(hInstall, "WixQueryNativeMachine");
504 + ExitOnFailure(hr, "WixQueryNativeMachine failed to initialize");
505 +
506 + hr = ::ProcNativeMachine(::GetCurrentProcess(), &usNativeMachine);
507 + ExitOnFailure(hr, "Failed to get native machine value.");
508 +
509 + WcaSetIntProperty(L"WIX_NATIVE_MACHINE", usNativeMachine);
510 +
511 +LExit:
512 + if (FAILED(hr))
513 + er = ERROR_INSTALL_FAILURE;
514 + return WcaFinalize(er);
515 +}
\ No newline at end of file
src/ext/Util/ca/utilca.def
+1
@@ -22,6 +22,7 @@ EXPORTS
22 WixQueryOsDirs
23 WixQueryOsWellKnownSID
24 WixQueryOsDriverInfo
25 + WixQueryNativeMachine
26 ; netshortcuts.cpp
27 WixSchedInternetShortcuts
28 WixCreateInternetShortcuts
src/ext/Util/wixlib/UtilExtension_Platform.wxi
+12
@@ -353,6 +353,18 @@
353 <Custom Action="$(var.Prefix)QueryOsDriverInfo$(var.Suffix)" After="AppSearch" Overridable="yes" Condition="VersionNT &gt; 400 OR (VersionNT = 400 AND ServicePackLevel &gt; 3)" />
354 </InstallUISequence>
355 </Fragment>
356 +
357 + <Fragment>
358 + <CustomAction Id="$(var.Prefix)QueryNativeMachine$(var.Suffix)" DllEntry="WixQueryNativeMachine" Execute="firstSequence" Return="check" SuppressModularization="yes" BinaryRef="$(var.Prefix)UtilCA$(var.Suffix)" />
359 +
360 + <InstallExecuteSequence>
361 + <Custom Action="$(var.Prefix)QueryNativeMachine$(var.Suffix)" After="AppSearch" Overridable="yes" Condition="VersionNT &gt; 400 OR (VersionNT = 400 AND ServicePackLevel &gt; 3)" />
362 + </InstallExecuteSequence>
363 +
364 + <InstallUISequence>
365 + <Custom Action="$(var.Prefix)QueryNativeMachine$(var.Suffix)" After="AppSearch" Overridable="yes" Condition="VersionNT &gt; 400 OR (VersionNT = 400 AND ServicePackLevel &gt; 3)" />
366 + </InstallUISequence>
367 + </Fragment>
368
369 <Fragment>
370 <Binary Id="$(var.Prefix)UtilCA$(var.Suffix)" SourceFile="!(bindpath.$(var.platform))utilca.dll" />
src/libs/dutil/WixToolset.DUtil/inc/procutil.h
+4
@@ -22,6 +22,10 @@ HRESULT DAPI ProcWow64(
22 __in HANDLE hProcess,
23 __out BOOL* pfWow64
24 );
25 +HRESULT DAPI ProcNativeMachine(
26 + __in HANDLE hProcess,
27 + __out USHORT* pusNativeMachine
28 + );
29 HRESULT DAPI ProcDisableWowFileSystemRedirection(
30 __in PROC_FILESYSTEMREDIRECTION* pfsr
31 );
src/libs/dutil/WixToolset.DUtil/procutil.cpp
+31 -8
@@ -88,26 +88,26 @@ extern "C" HRESULT DAPI ProcWow64(
88
89 if (pfnIsWow64Process2)
90 {
91 - USHORT pProcessMachine = IMAGE_FILE_MACHINE_UNKNOWN;
92 - if (!pfnIsWow64Process2(hProcess, &pProcessMachine, nullptr))
91 + USHORT usProcessMachine = IMAGE_FILE_MACHINE_UNKNOWN;
92 + if (!pfnIsWow64Process2(hProcess, &usProcessMachine, nullptr))
93 {
94 ProcExitWithLastError(hr, "Failed to check WOW64 process - IsWow64Process2.");
95 }
96
97 - if (pProcessMachine != IMAGE_FILE_MACHINE_UNKNOWN)
97 + if (usProcessMachine != IMAGE_FILE_MACHINE_UNKNOWN)
98 {
99 fIsWow64 = TRUE;
100 }
101 }
102 else
103 {
104 - typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS)(HANDLE, PBOOL);
105 - LPFN_ISWOW64PROCESS pfnIsWow64Process = (LPFN_ISWOW64PROCESS)::GetProcAddress(::GetModuleHandleW(L"kernel32"), "IsWow64Process");
104 + typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS)(HANDLE, PBOOL);
105 + LPFN_ISWOW64PROCESS pfnIsWow64Process = (LPFN_ISWOW64PROCESS)::GetProcAddress(::GetModuleHandleW(L"kernel32"), "IsWow64Process");
106
107 - if (pfnIsWow64Process)
108 - {
109 - if (!pfnIsWow64Process(hProcess, &fIsWow64))
107 + if (pfnIsWow64Process)
108 {
109 + if (!pfnIsWow64Process(hProcess, &fIsWow64))
110 + {
111 ProcExitWithLastError(hr, "Failed to check WOW64 process - IsWow64Process.");
112 }
113 }
@@ -119,6 +119,29 @@ LExit:
119 return hr;
120 }
121
122 +extern "C" HRESULT DAPI ProcNativeMachine(
123 + __in HANDLE hProcess,
124 + __out USHORT* pusNativeMachine
125 + )
126 +{
127 + HRESULT hr = S_OK;
128 +
129 + typedef BOOL(WINAPI* LPFN_ISWOW64PROCESS2)(HANDLE, USHORT *, USHORT *);
130 + LPFN_ISWOW64PROCESS2 pfnIsWow64Process2 = (LPFN_ISWOW64PROCESS2)::GetProcAddress(::GetModuleHandleW(L"kernel32"), "IsWow64Process2");
131 +
132 + if (pfnIsWow64Process2)
133 + {
134 + USHORT usProcessMachineUnused = IMAGE_FILE_MACHINE_UNKNOWN;
135 + if (!pfnIsWow64Process2(hProcess, &usProcessMachineUnused, pusNativeMachine))
136 + {
137 + ExitWithLastError(hr, "Failed to check WOW64 process - IsWow64Process2.");
138 + }
139 + }
140 +
141 +LExit:
142 + return hr;
143 +}
144 +
145 extern "C" HRESULT DAPI ProcDisableWowFileSystemRedirection(
146 __in PROC_FILESYSTEMREDIRECTION* pfsr
147 )
src/wix/WixToolset.Converters/WixConverter.cs
+3
@@ -1374,6 +1374,9 @@ namespace WixToolset.Converters
1374 case "WIX_ACCOUNT_PERFLOGUSERS_NODOMAIN":
1375 newElementName = "QueryWindowsWellKnownSIDs";
1376 break;
1377 + case "WIX_NATIVE_MACHINE":
1378 + newElementName = "QueryNativeMachine";
1379 + break;
1380 }
1381
1382 if (!String.IsNullOrEmpty(newElementName)
src/wix/WixToolset.Core/CompilerCore.cs
+1
@@ -61,6 +61,7 @@ namespace WixToolset.Core
61 "LocalAppDataFolder",
62 "LogonUser",
63 "MyPicturesFolder",
64 + "NativeMachine",
65 "NTProductType",
66 "NTSuiteBackOffice",
67 "NTSuiteDataCenter",