From 47bca2dc51525fcad86f325278b14953ac5b137e Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Sat, 15 Jan 2022 21:40:54 -0500 Subject: Fix 32/64-bit bitness handling in Burn and BUtil. - Take advantage of RegOpenEx. - Always look for related bundles in both 32 and 64 hives. - BundleEnumRelatedBundle requires caller to specify bitness. --- src/burn/engine/elevation.cpp | 8 +------- src/burn/engine/relatedbundle.cpp | 24 +++++++++++------------- src/burn/engine/search.cpp | 16 ++-------------- src/burn/engine/variable.cpp | 2 +- src/burn/test/BurnUnitTest/RegistrationTest.cpp | 2 +- 5 files changed, 16 insertions(+), 36 deletions(-) (limited to 'src/burn') diff --git a/src/burn/engine/elevation.cpp b/src/burn/engine/elevation.cpp index 355b4a34..221d8b6d 100644 --- a/src/burn/engine/elevation.cpp +++ b/src/burn/engine/elevation.cpp @@ -3299,7 +3299,6 @@ static HRESULT OnLaunchApprovedExe( SIZE_T iData = 0; BURN_LAUNCH_APPROVED_EXE* pLaunchApprovedExe = NULL; BURN_APPROVED_EXE* pApprovedExe = NULL; - REGSAM samDesired = KEY_QUERY_VALUE; HKEY hKey = NULL; DWORD dwProcessId = 0; BYTE* pbSendData = NULL; @@ -3323,12 +3322,7 @@ static HRESULT OnLaunchApprovedExe( LogId(REPORT_STANDARD, MSG_LAUNCH_APPROVED_EXE_SEARCH, pApprovedExe->sczKey, pApprovedExe->sczValueName ? pApprovedExe->sczValueName : L"", pApprovedExe->fWin64 ? L"yes" : L"no"); - if (pApprovedExe->fWin64) - { - samDesired |= KEY_WOW64_64KEY; - } - - hr = RegOpen(HKEY_LOCAL_MACHINE, pApprovedExe->sczKey, samDesired, &hKey); + hr = RegOpenEx(HKEY_LOCAL_MACHINE, pApprovedExe->sczKey, KEY_QUERY_VALUE, pApprovedExe->fWin64 ? REG_KEY_64BIT : REG_KEY_32BIT, &hKey); ExitOnFailure(hr, "Failed to open the registry key for the approved exe path."); hr = RegReadString(hKey, pApprovedExe->sczValueName, &pLaunchApprovedExe->sczExecutablePath); diff --git a/src/burn/engine/relatedbundle.cpp b/src/burn/engine/relatedbundle.cpp index 99ed8553..619fa8dd 100644 --- a/src/burn/engine/relatedbundle.cpp +++ b/src/burn/engine/relatedbundle.cpp @@ -11,13 +11,13 @@ static __callback int __cdecl CompareRelatedBundles( ); static HRESULT InitializeForScopeAndBitness( __in BOOL fPerMachine, - __in BOOL fWow6432, + __in REG_KEY_BITNESS regBitness, __in BURN_REGISTRATION* pRegistration, __in BURN_RELATED_BUNDLES* pRelatedBundles ); static HRESULT LoadIfRelatedBundle( __in BOOL fPerMachine, - __in BOOL fWow6432, + __in REG_KEY_BITNESS regBitness, __in HKEY hkUninstallKey, __in_z LPCWSTR sczRelatedBundleId, __in BURN_REGISTRATION* pRegistration, @@ -47,13 +47,11 @@ extern "C" HRESULT RelatedBundlesInitializeForScope( { HRESULT hr = S_OK; - hr = InitializeForScopeAndBitness(fPerMachine, /*fWow6432*/FALSE, pRegistration, pRelatedBundles); - ExitOnFailure(hr, "Failed to open platform-native uninstall registry key."); - -#if defined(_WIN64) - hr = InitializeForScopeAndBitness(fPerMachine, /*fWow6432*/TRUE, pRegistration, pRelatedBundles); + hr = InitializeForScopeAndBitness(fPerMachine, REG_KEY_32BIT, pRegistration, pRelatedBundles); ExitOnFailure(hr, "Failed to open 32-bit uninstall registry key."); -#endif + + hr = InitializeForScopeAndBitness(fPerMachine, REG_KEY_64BIT, pRegistration, pRelatedBundles); + ExitOnFailure(hr, "Failed to open 64-bit uninstall registry key."); LExit: return hr; @@ -170,7 +168,7 @@ static __callback int __cdecl CompareRelatedBundles( static HRESULT InitializeForScopeAndBitness( __in BOOL fPerMachine, - __in BOOL fWow6432, + __in REG_KEY_BITNESS regBitness, __in BURN_REGISTRATION * pRegistration, __in BURN_RELATED_BUNDLES * pRelatedBundles ) @@ -180,7 +178,7 @@ static HRESULT InitializeForScopeAndBitness( HKEY hkUninstallKey = NULL; LPWSTR sczRelatedBundleId = NULL; - hr = RegOpen(hkRoot, BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY, KEY_READ | (fWow6432 ? KEY_WOW64_32KEY : 0), &hkUninstallKey); + hr = RegOpenEx(hkRoot, BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY, KEY_READ, regBitness, &hkUninstallKey); if (HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) == hr || HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == hr) { ExitFunction1(hr = S_OK); @@ -202,7 +200,7 @@ static HRESULT InitializeForScopeAndBitness( { // Ignore failures here since we'll often find products that aren't actually // related bundles (or even bundles at all). - HRESULT hrRelatedBundle = LoadIfRelatedBundle(fPerMachine, fWow6432, hkUninstallKey, sczRelatedBundleId, pRegistration, pRelatedBundles); + HRESULT hrRelatedBundle = LoadIfRelatedBundle(fPerMachine, regBitness, hkUninstallKey, sczRelatedBundleId, pRegistration, pRelatedBundles); UNREFERENCED_PARAMETER(hrRelatedBundle); } } @@ -216,7 +214,7 @@ LExit: static HRESULT LoadIfRelatedBundle( __in BOOL fPerMachine, - __in BOOL fWow6432, + __in REG_KEY_BITNESS regBitness, __in HKEY hkUninstallKey, __in_z LPCWSTR sczRelatedBundleId, __in BURN_REGISTRATION* pRegistration, @@ -227,7 +225,7 @@ static HRESULT LoadIfRelatedBundle( HKEY hkBundleId = NULL; BOOTSTRAPPER_RELATION_TYPE relationType = BOOTSTRAPPER_RELATION_NONE; - hr = RegOpen(hkUninstallKey, sczRelatedBundleId, KEY_READ | (fWow6432 ? KEY_WOW64_32KEY : 0), &hkBundleId); + hr = RegOpenEx(hkUninstallKey, sczRelatedBundleId, KEY_READ, regBitness, &hkBundleId); ExitOnFailure(hr, "Failed to open uninstall key for potential related bundle: %ls", sczRelatedBundleId); hr = DetermineRelationType(hkBundleId, pRegistration, &relationType); diff --git a/src/burn/engine/search.cpp b/src/burn/engine/search.cpp index 6d5f8d49..4505e1a2 100644 --- a/src/burn/engine/search.cpp +++ b/src/burn/engine/search.cpp @@ -836,19 +836,13 @@ static HRESULT RegistrySearchExists( HKEY hKey = NULL; DWORD dwType = 0; BOOL fExists = FALSE; - REGSAM samDesired = KEY_QUERY_VALUE; - - if (pSearch->RegistrySearch.fWin64) - { - samDesired = samDesired | KEY_WOW64_64KEY; - } // format key string hr = VariableFormatString(pVariables, pSearch->RegistrySearch.sczKey, &sczKey, NULL); ExitOnFailure(hr, "Failed to format key string."); // open key - hr = RegOpen(pSearch->RegistrySearch.hRoot, sczKey, samDesired, &hKey); + hr = RegOpenEx(pSearch->RegistrySearch.hRoot, sczKey, KEY_QUERY_VALUE, pSearch->RegistrySearch.fWin64 ? REG_KEY_64BIT : REG_KEY_32BIT, &hKey); if (SUCCEEDED(hr)) { fExists = TRUE; @@ -922,12 +916,6 @@ static HRESULT RegistrySearchValue( LPBYTE pData = NULL; DWORD cch = 0; BURN_VARIANT value = { }; - REGSAM samDesired = KEY_QUERY_VALUE; - - if (pSearch->RegistrySearch.fWin64) - { - samDesired = samDesired | KEY_WOW64_64KEY; - } // format key string hr = VariableFormatString(pVariables, pSearch->RegistrySearch.sczKey, &sczKey, NULL); @@ -941,7 +929,7 @@ static HRESULT RegistrySearchValue( } // open key - hr = RegOpen(pSearch->RegistrySearch.hRoot, sczKey, samDesired, &hKey); + hr = RegOpenEx(pSearch->RegistrySearch.hRoot, sczKey, KEY_QUERY_VALUE, pSearch->RegistrySearch.fWin64 ? REG_KEY_64BIT : REG_KEY_32BIT, &hKey); if (E_FILENOTFOUND == hr) { // What if there is a hidden variable in sczKey? diff --git a/src/burn/engine/variable.cpp b/src/burn/engine/variable.cpp index fa6190dd..b3dcdb7d 100644 --- a/src/burn/engine/variable.cpp +++ b/src/burn/engine/variable.cpp @@ -2361,7 +2361,7 @@ static HRESULT Get64bitFolderFromRegistry( AssertSz(CSIDL_PROGRAM_FILES == nFolder || CSIDL_PROGRAM_FILES_COMMON == nFolder, "Unknown folder CSIDL."); LPCWSTR wzFolderValue = CSIDL_PROGRAM_FILES_COMMON == nFolder ? L"CommonFilesDir" : L"ProgramFilesDir"; - hr = RegOpen(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion", KEY_READ | KEY_WOW64_64KEY, &hkFolders); + hr = RegOpenEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion", KEY_READ, REG_KEY_64BIT, &hkFolders); ExitOnFailure(hr, "Failed to open Windows folder key."); hr = RegReadString(hkFolders, wzFolderValue, psczPath); diff --git a/src/burn/test/BurnUnitTest/RegistrationTest.cpp b/src/burn/test/BurnUnitTest/RegistrationTest.cpp index dbcd2613..d2ec0a82 100644 --- a/src/burn/test/BurnUnitTest/RegistrationTest.cpp +++ b/src/burn/test/BurnUnitTest/RegistrationTest.cpp @@ -645,7 +645,7 @@ namespace Bootstrapper NativeAssert::Succeeded(hr, "Failed to allocate buffer for related bundle id."); // Verify we can find ourself via the UpgradeCode - hr = BundleEnumRelatedBundleFixed(TEST_BUNDLE_UPGRADE_CODE, BUNDLE_INSTALL_CONTEXT_USER, &dwRelatedBundleIndex, sczRelatedBundleId); + hr = BundleEnumRelatedBundleFixed(TEST_BUNDLE_UPGRADE_CODE, BUNDLE_INSTALL_CONTEXT_USER, REG_KEY_DEFAULT, &dwRelatedBundleIndex, sczRelatedBundleId); TestThrowOnFailure(hr, L"Failed to enumerate related bundle."); NativeAssert::StringEqual(TEST_BUNDLE_ID, sczRelatedBundleId); -- cgit v1.2.3-55-g6feb