diff options
Diffstat (limited to 'src/engine/variable.cpp')
| -rw-r--r-- | src/engine/variable.cpp | 75 |
1 files changed, 45 insertions, 30 deletions
diff --git a/src/engine/variable.cpp b/src/engine/variable.cpp index fb4b74e2..3069ccf7 100644 --- a/src/engine/variable.cpp +++ b/src/engine/variable.cpp | |||
| @@ -268,7 +268,7 @@ extern "C" HRESULT VariableInitialize( | |||
| 268 | {BURN_BUNDLE_SOURCE_PROCESS_FOLDER, InitializeVariableString, NULL, FALSE, TRUE}, | 268 | {BURN_BUNDLE_SOURCE_PROCESS_FOLDER, InitializeVariableString, NULL, FALSE, TRUE}, |
| 269 | {BURN_BUNDLE_TAG, InitializeVariableString, (DWORD_PTR)L"", FALSE, TRUE}, | 269 | {BURN_BUNDLE_TAG, InitializeVariableString, (DWORD_PTR)L"", FALSE, TRUE}, |
| 270 | {BURN_BUNDLE_UILEVEL, InitializeVariableNumeric, 0, FALSE, TRUE}, | 270 | {BURN_BUNDLE_UILEVEL, InitializeVariableNumeric, 0, FALSE, TRUE}, |
| 271 | {BURN_BUNDLE_VERSION, InitializeVariableVersion, 0, FALSE, TRUE}, | 271 | {BURN_BUNDLE_VERSION, InitializeVariableVersion, (DWORD_PTR)L"0", FALSE, TRUE}, |
| 272 | }; | 272 | }; |
| 273 | 273 | ||
| 274 | for (DWORD i = 0; i < countof(vrgBuiltInVariables); ++i) | 274 | for (DWORD i = 0; i < countof(vrgBuiltInVariables); ++i) |
| @@ -561,11 +561,11 @@ LExit: | |||
| 561 | return hr; | 561 | return hr; |
| 562 | } | 562 | } |
| 563 | 563 | ||
| 564 | // The contents of pqwValue may be sensitive, if variable is hidden should keep value encrypted and SecureZeroMemory. | 564 | // The contents of ppValue may be sensitive, if variable is hidden should keep value encrypted and SecureZeroMemory. |
| 565 | extern "C" HRESULT VariableGetVersion( | 565 | extern "C" HRESULT VariableGetVersion( |
| 566 | __in BURN_VARIABLES* pVariables, | 566 | __in BURN_VARIABLES* pVariables, |
| 567 | __in_z LPCWSTR wzVariable, | 567 | __in_z LPCWSTR wzVariable, |
| 568 | __in DWORD64* pqwValue | 568 | __in VERUTIL_VERSION** ppValue |
| 569 | ) | 569 | ) |
| 570 | { | 570 | { |
| 571 | HRESULT hr = S_OK; | 571 | HRESULT hr = S_OK; |
| @@ -584,7 +584,7 @@ extern "C" HRESULT VariableGetVersion( | |||
| 584 | } | 584 | } |
| 585 | ExitOnFailure(hr, "Failed to get value of variable: %ls", wzVariable); | 585 | ExitOnFailure(hr, "Failed to get value of variable: %ls", wzVariable); |
| 586 | 586 | ||
| 587 | hr = BVariantGetVersion(&pVariable->Value, pqwValue); | 587 | hr = BVariantGetVersion(&pVariable->Value, ppValue); |
| 588 | ExitOnFailure(hr, "Failed to get value as version for variable: %ls", wzVariable); | 588 | ExitOnFailure(hr, "Failed to get value as version for variable: %ls", wzVariable); |
| 589 | 589 | ||
| 590 | LExit: | 590 | LExit: |
| @@ -701,14 +701,14 @@ extern "C" HRESULT VariableSetString( | |||
| 701 | extern "C" HRESULT VariableSetVersion( | 701 | extern "C" HRESULT VariableSetVersion( |
| 702 | __in BURN_VARIABLES* pVariables, | 702 | __in BURN_VARIABLES* pVariables, |
| 703 | __in_z LPCWSTR wzVariable, | 703 | __in_z LPCWSTR wzVariable, |
| 704 | __in DWORD64 qwValue, | 704 | __in VERUTIL_VERSION* pValue, |
| 705 | __in BOOL fOverwriteBuiltIn | 705 | __in BOOL fOverwriteBuiltIn |
| 706 | ) | 706 | ) |
| 707 | { | 707 | { |
| 708 | BURN_VARIANT variant = { }; | 708 | BURN_VARIANT variant = { }; |
| 709 | 709 | ||
| 710 | // We're not going to encrypt this value, so can access the value directly. | 710 | // We're not going to encrypt this value, so can access the value directly. |
| 711 | variant.qwValue = qwValue; | 711 | variant.pValue = pValue; |
| 712 | variant.Type = BURN_VARIANT_TYPE_VERSION; | 712 | variant.Type = BURN_VARIANT_TYPE_VERSION; |
| 713 | 713 | ||
| 714 | return SetVariableValue(pVariables, wzVariable, &variant, fOverwriteBuiltIn ? SET_VARIABLE_OVERRIDE_BUILTIN : SET_VARIABLE_NOT_BUILTIN, TRUE); | 714 | return SetVariableValue(pVariables, wzVariable, &variant, fOverwriteBuiltIn ? SET_VARIABLE_OVERRIDE_BUILTIN : SET_VARIABLE_NOT_BUILTIN, TRUE); |
| @@ -810,7 +810,6 @@ extern "C" HRESULT VariableSerialize( | |||
| 810 | BOOL fIncluded = FALSE; | 810 | BOOL fIncluded = FALSE; |
| 811 | LONGLONG ll = 0; | 811 | LONGLONG ll = 0; |
| 812 | LPWSTR scz = NULL; | 812 | LPWSTR scz = NULL; |
| 813 | DWORD64 qw = 0; | ||
| 814 | 813 | ||
| 815 | ::EnterCriticalSection(&pVariables->csAccess); | 814 | ::EnterCriticalSection(&pVariables->csAccess); |
| 816 | 815 | ||
| @@ -859,15 +858,7 @@ extern "C" HRESULT VariableSerialize( | |||
| 859 | 858 | ||
| 860 | SecureZeroMemory(&ll, sizeof(ll)); | 859 | SecureZeroMemory(&ll, sizeof(ll)); |
| 861 | break; | 860 | break; |
| 862 | case BURN_VARIANT_TYPE_VERSION: | 861 | case BURN_VARIANT_TYPE_VERSION: __fallthrough; |
| 863 | hr = BVariantGetVersion(&pVariable->Value, &qw); | ||
| 864 | ExitOnFailure(hr, "Failed to get version."); | ||
| 865 | |||
| 866 | hr = BuffWriteNumber64(ppbBuffer, piBuffer, qw); | ||
| 867 | ExitOnFailure(hr, "Failed to write variable value as number."); | ||
| 868 | |||
| 869 | SecureZeroMemory(&qw, sizeof(qw)); | ||
| 870 | break; | ||
| 871 | case BURN_VARIANT_TYPE_FORMATTED: __fallthrough; | 862 | case BURN_VARIANT_TYPE_FORMATTED: __fallthrough; |
| 872 | case BURN_VARIANT_TYPE_STRING: | 863 | case BURN_VARIANT_TYPE_STRING: |
| 873 | hr = BVariantGetString(&pVariable->Value, &scz); | 864 | hr = BVariantGetString(&pVariable->Value, &scz); |
| @@ -887,7 +878,6 @@ extern "C" HRESULT VariableSerialize( | |||
| 887 | LExit: | 878 | LExit: |
| 888 | ::LeaveCriticalSection(&pVariables->csAccess); | 879 | ::LeaveCriticalSection(&pVariables->csAccess); |
| 889 | SecureZeroMemory(&ll, sizeof(ll)); | 880 | SecureZeroMemory(&ll, sizeof(ll)); |
| 890 | SecureZeroMemory(&qw, sizeof(qw)); | ||
| 891 | StrSecureZeroFreeString(scz); | 881 | StrSecureZeroFreeString(scz); |
| 892 | 882 | ||
| 893 | return hr; | 883 | return hr; |
| @@ -908,6 +898,7 @@ extern "C" HRESULT VariableDeserialize( | |||
| 908 | BURN_VARIANT value = { }; | 898 | BURN_VARIANT value = { }; |
| 909 | LPWSTR scz = NULL; | 899 | LPWSTR scz = NULL; |
| 910 | DWORD64 qw = 0; | 900 | DWORD64 qw = 0; |
| 901 | VERUTIL_VERSION* pVersion = NULL; | ||
| 911 | 902 | ||
| 912 | ::EnterCriticalSection(&pVariables->csAccess); | 903 | ::EnterCriticalSection(&pVariables->csAccess); |
| 913 | 904 | ||
| @@ -950,10 +941,13 @@ extern "C" HRESULT VariableDeserialize( | |||
| 950 | SecureZeroMemory(&qw, sizeof(qw)); | 941 | SecureZeroMemory(&qw, sizeof(qw)); |
| 951 | break; | 942 | break; |
| 952 | case BURN_VARIANT_TYPE_VERSION: | 943 | case BURN_VARIANT_TYPE_VERSION: |
| 953 | hr = BuffReadNumber64(pbBuffer, cbBuffer, piBuffer, &qw); | 944 | hr = BuffReadString(pbBuffer, cbBuffer, piBuffer, &scz); |
| 954 | ExitOnFailure(hr, "Failed to read variable value as number."); | 945 | ExitOnFailure(hr, "Failed to read variable value as string."); |
| 946 | |||
| 947 | hr = VerParseVersion(scz, 0, FALSE, &pVersion); | ||
| 948 | ExitOnFailure(hr, "Failed to parse variable value as version."); | ||
| 955 | 949 | ||
| 956 | hr = BVariantSetVersion(&value, qw); | 950 | hr = BVariantSetVersion(&value, pVersion); |
| 957 | ExitOnFailure(hr, "Failed to set variable value."); | 951 | ExitOnFailure(hr, "Failed to set variable value."); |
| 958 | 952 | ||
| 959 | SecureZeroMemory(&qw, sizeof(qw)); | 953 | SecureZeroMemory(&qw, sizeof(qw)); |
| @@ -984,6 +978,7 @@ extern "C" HRESULT VariableDeserialize( | |||
| 984 | LExit: | 978 | LExit: |
| 985 | ::LeaveCriticalSection(&pVariables->csAccess); | 979 | ::LeaveCriticalSection(&pVariables->csAccess); |
| 986 | 980 | ||
| 981 | ReleaseVerutilVersion(pVersion); | ||
| 987 | ReleaseStr(sczName); | 982 | ReleaseStr(sczName); |
| 988 | BVariantUninitialize(&value); | 983 | BVariantUninitialize(&value); |
| 989 | SecureZeroMemory(&qw, sizeof(qw)); | 984 | SecureZeroMemory(&qw, sizeof(qw)); |
| @@ -1572,7 +1567,7 @@ static HRESULT SetVariableValue( | |||
| 1572 | break; | 1567 | break; |
| 1573 | 1568 | ||
| 1574 | case BURN_VARIANT_TYPE_VERSION: | 1569 | case BURN_VARIANT_TYPE_VERSION: |
| 1575 | LogStringLine(REPORT_STANDARD, "Setting version variable '%ls' to value '%hu.%hu.%hu.%hu'", wzVariable, (WORD)(pVariant->qwValue >> 48), (WORD)(pVariant->qwValue >> 32), (WORD)(pVariant->qwValue >> 16), (WORD)(pVariant->qwValue)); | 1570 | LogStringLine(REPORT_STANDARD, "Setting version variable '%ls' to value '%ls'", wzVariable, pVariant->pValue->sczVersion); |
| 1576 | break; | 1571 | break; |
| 1577 | 1572 | ||
| 1578 | default: | 1573 | default: |
| @@ -1609,6 +1604,7 @@ static HRESULT InitializeVariableVersionNT( | |||
| 1609 | RTL_GET_VERSION rtlGetVersion = NULL; | 1604 | RTL_GET_VERSION rtlGetVersion = NULL; |
| 1610 | RTL_OSVERSIONINFOEXW ovix = { }; | 1605 | RTL_OSVERSIONINFOEXW ovix = { }; |
| 1611 | BURN_VARIANT value = { }; | 1606 | BURN_VARIANT value = { }; |
| 1607 | VERUTIL_VERSION* pVersion = NULL; | ||
| 1612 | 1608 | ||
| 1613 | if (!::GetModuleHandleExW(0, L"ntdll", &ntdll)) | 1609 | if (!::GetModuleHandleExW(0, L"ntdll", &ntdll)) |
| 1614 | { | 1610 | { |
| @@ -1630,12 +1626,15 @@ static HRESULT InitializeVariableVersionNT( | |||
| 1630 | case OS_INFO_VARIABLE_ServicePackLevel: | 1626 | case OS_INFO_VARIABLE_ServicePackLevel: |
| 1631 | if (0 != ovix.wServicePackMajor) | 1627 | if (0 != ovix.wServicePackMajor) |
| 1632 | { | 1628 | { |
| 1633 | value.qwValue = static_cast<DWORD64>(ovix.wServicePackMajor); | 1629 | value.llValue = static_cast<LONGLONG>(ovix.wServicePackMajor); |
| 1634 | value.Type = BURN_VARIANT_TYPE_NUMERIC; | 1630 | value.Type = BURN_VARIANT_TYPE_NUMERIC; |
| 1635 | } | 1631 | } |
| 1636 | break; | 1632 | break; |
| 1637 | case OS_INFO_VARIABLE_VersionNT: | 1633 | case OS_INFO_VARIABLE_VersionNT: |
| 1638 | value.qwValue = MAKEQWORDVERSION(ovix.dwMajorVersion, ovix.dwMinorVersion, 0, 0); | 1634 | hr = VerVersionFromQword(MAKEQWORDVERSION(ovix.dwMajorVersion, ovix.dwMinorVersion, 0, 0), &pVersion); |
| 1635 | ExitOnFailure(hr, "Failed to create VersionNT from QWORD."); | ||
| 1636 | |||
| 1637 | value.pValue = pVersion; | ||
| 1639 | value.Type = BURN_VARIANT_TYPE_VERSION; | 1638 | value.Type = BURN_VARIANT_TYPE_VERSION; |
| 1640 | break; | 1639 | break; |
| 1641 | case OS_INFO_VARIABLE_VersionNT64: | 1640 | case OS_INFO_VARIABLE_VersionNT64: |
| @@ -1647,13 +1646,16 @@ static HRESULT InitializeVariableVersionNT( | |||
| 1647 | if (fIsWow64) | 1646 | if (fIsWow64) |
| 1648 | #endif | 1647 | #endif |
| 1649 | { | 1648 | { |
| 1650 | value.qwValue = MAKEQWORDVERSION(ovix.dwMajorVersion, ovix.dwMinorVersion, 0, 0); | 1649 | hr = VerVersionFromQword(MAKEQWORDVERSION(ovix.dwMajorVersion, ovix.dwMinorVersion, 0, 0), &pVersion); |
| 1650 | ExitOnFailure(hr, "Failed to create VersionNT64 from QWORD."); | ||
| 1651 | |||
| 1652 | value.pValue = pVersion; | ||
| 1651 | value.Type = BURN_VARIANT_TYPE_VERSION; | 1653 | value.Type = BURN_VARIANT_TYPE_VERSION; |
| 1652 | } | 1654 | } |
| 1653 | } | 1655 | } |
| 1654 | break; | 1656 | break; |
| 1655 | case OS_INFO_VARIABLE_WindowsBuildNumber: | 1657 | case OS_INFO_VARIABLE_WindowsBuildNumber: |
| 1656 | value.qwValue = static_cast<DWORD64>(ovix.dwBuildNumber); | 1658 | value.llValue = static_cast<LONGLONG>(ovix.dwBuildNumber); |
| 1657 | value.Type = BURN_VARIANT_TYPE_NUMERIC; | 1659 | value.Type = BURN_VARIANT_TYPE_NUMERIC; |
| 1658 | default: | 1660 | default: |
| 1659 | AssertSz(FALSE, "Unknown OS info type."); | 1661 | AssertSz(FALSE, "Unknown OS info type."); |
| @@ -1669,6 +1671,8 @@ LExit: | |||
| 1669 | FreeLibrary(ntdll); | 1671 | FreeLibrary(ntdll); |
| 1670 | } | 1672 | } |
| 1671 | 1673 | ||
| 1674 | ReleaseVerutilVersion(pVersion); | ||
| 1675 | |||
| 1672 | return hr; | 1676 | return hr; |
| 1673 | } | 1677 | } |
| 1674 | 1678 | ||
| @@ -1805,15 +1809,14 @@ LExit: | |||
| 1805 | } | 1809 | } |
| 1806 | 1810 | ||
| 1807 | static HRESULT InitializeVariableVersionMsi( | 1811 | static HRESULT InitializeVariableVersionMsi( |
| 1808 | __in DWORD_PTR dwpData, | 1812 | __in DWORD_PTR /*dwpData*/, |
| 1809 | __inout BURN_VARIANT* pValue | 1813 | __inout BURN_VARIANT* pValue |
| 1810 | ) | 1814 | ) |
| 1811 | { | 1815 | { |
| 1812 | UNREFERENCED_PARAMETER(dwpData); | ||
| 1813 | |||
| 1814 | HRESULT hr = S_OK; | 1816 | HRESULT hr = S_OK; |
| 1815 | DLLGETVERSIONPROC pfnMsiDllGetVersion = NULL; | 1817 | DLLGETVERSIONPROC pfnMsiDllGetVersion = NULL; |
| 1816 | DLLVERSIONINFO msiVersionInfo = { }; | 1818 | DLLVERSIONINFO msiVersionInfo = { }; |
| 1819 | VERUTIL_VERSION* pVersion = NULL; | ||
| 1817 | 1820 | ||
| 1818 | // get DllGetVersion proc address | 1821 | // get DllGetVersion proc address |
| 1819 | pfnMsiDllGetVersion = (DLLGETVERSIONPROC)::GetProcAddress(::GetModuleHandleW(L"msi"), "DllGetVersion"); | 1822 | pfnMsiDllGetVersion = (DLLGETVERSIONPROC)::GetProcAddress(::GetModuleHandleW(L"msi"), "DllGetVersion"); |
| @@ -1824,10 +1827,15 @@ static HRESULT InitializeVariableVersionMsi( | |||
| 1824 | hr = pfnMsiDllGetVersion(&msiVersionInfo); | 1827 | hr = pfnMsiDllGetVersion(&msiVersionInfo); |
| 1825 | ExitOnFailure(hr, "Failed to get msi.dll version info."); | 1828 | ExitOnFailure(hr, "Failed to get msi.dll version info."); |
| 1826 | 1829 | ||
| 1827 | hr = BVariantSetVersion(pValue, MAKEQWORDVERSION(msiVersionInfo.dwMajorVersion, msiVersionInfo.dwMinorVersion, 0, 0)); | 1830 | hr = VerVersionFromQword(MAKEQWORDVERSION(msiVersionInfo.dwMajorVersion, msiVersionInfo.dwMinorVersion, 0, 0), &pVersion); |
| 1831 | ExitOnFailure(hr, "Failed to create msi.dll version from QWORD."); | ||
| 1832 | |||
| 1833 | hr = BVariantSetVersion(pValue, pVersion); | ||
| 1828 | ExitOnFailure(hr, "Failed to set variant value."); | 1834 | ExitOnFailure(hr, "Failed to set variant value."); |
| 1829 | 1835 | ||
| 1830 | LExit: | 1836 | LExit: |
| 1837 | ReleaseVerutilVersion(pVersion); | ||
| 1838 | |||
| 1831 | return hr; | 1839 | return hr; |
| 1832 | } | 1840 | } |
| 1833 | 1841 | ||
| @@ -2270,12 +2278,19 @@ static HRESULT InitializeVariableVersion( | |||
| 2270 | ) | 2278 | ) |
| 2271 | { | 2279 | { |
| 2272 | HRESULT hr = S_OK; | 2280 | HRESULT hr = S_OK; |
| 2281 | LPCWSTR wzValue = (LPCWSTR)dwpData; | ||
| 2282 | VERUTIL_VERSION* pVersion = NULL; | ||
| 2283 | |||
| 2284 | hr = VerParseVersion(wzValue, 0, FALSE, &pVersion); | ||
| 2285 | ExitOnFailure(hr, "Failed to initialize version."); | ||
| 2273 | 2286 | ||
| 2274 | // set value | 2287 | // set value |
| 2275 | hr = BVariantSetVersion(pValue, static_cast<DWORD64>(dwpData)); | 2288 | hr = BVariantSetVersion(pValue, pVersion); |
| 2276 | ExitOnFailure(hr, "Failed to set variant value."); | 2289 | ExitOnFailure(hr, "Failed to set variant value."); |
| 2277 | 2290 | ||
| 2278 | LExit: | 2291 | LExit: |
| 2292 | ReleaseVerutilVersion(pVersion); | ||
| 2293 | |||
| 2279 | return hr; | 2294 | return hr; |
| 2280 | } | 2295 | } |
| 2281 | 2296 | ||
