diff options
Diffstat (limited to 'src/engine/EngineForExtension.cpp')
| -rw-r--r-- | src/engine/EngineForExtension.cpp | 118 |
1 files changed, 60 insertions, 58 deletions
diff --git a/src/engine/EngineForExtension.cpp b/src/engine/EngineForExtension.cpp index fdfa59b1..6ec80a0f 100644 --- a/src/engine/EngineForExtension.cpp +++ b/src/engine/EngineForExtension.cpp | |||
| @@ -2,6 +2,13 @@ | |||
| 2 | 2 | ||
| 3 | #include "precomp.h" | 3 | #include "precomp.h" |
| 4 | 4 | ||
| 5 | |||
| 6 | static HRESULT CopyStringToBE( | ||
| 7 | __in LPWSTR wzValue, | ||
| 8 | __in LPWSTR wzBuffer, | ||
| 9 | __inout DWORD* pcchBuffer | ||
| 10 | ); | ||
| 11 | |||
| 5 | static HRESULT BEEngineEscapeString( | 12 | static HRESULT BEEngineEscapeString( |
| 6 | __in BURN_EXTENSION_ENGINE_CONTEXT* /*pContext*/, | 13 | __in BURN_EXTENSION_ENGINE_CONTEXT* /*pContext*/, |
| 7 | __in BUNDLE_EXTENSION_ENGINE_ESCAPESTRING_ARGS* pArgs, | 14 | __in BUNDLE_EXTENSION_ENGINE_ESCAPESTRING_ARGS* pArgs, |
| @@ -10,7 +17,6 @@ static HRESULT BEEngineEscapeString( | |||
| 10 | { | 17 | { |
| 11 | HRESULT hr = S_OK; | 18 | HRESULT hr = S_OK; |
| 12 | LPWSTR sczValue = NULL; | 19 | LPWSTR sczValue = NULL; |
| 13 | size_t cchRemaining = 0; | ||
| 14 | LPCWSTR wzIn = pArgs->wzIn; | 20 | LPCWSTR wzIn = pArgs->wzIn; |
| 15 | LPWSTR wzOut = pResults->wzOut; | 21 | LPWSTR wzOut = pResults->wzOut; |
| 16 | DWORD* pcchOut = &pResults->cchOut; | 22 | DWORD* pcchOut = &pResults->cchOut; |
| @@ -20,21 +26,7 @@ static HRESULT BEEngineEscapeString( | |||
| 20 | hr = VariableEscapeString(wzIn, &sczValue); | 26 | hr = VariableEscapeString(wzIn, &sczValue); |
| 21 | if (SUCCEEDED(hr)) | 27 | if (SUCCEEDED(hr)) |
| 22 | { | 28 | { |
| 23 | if (wzOut) | 29 | hr = CopyStringToBE(sczValue, wzOut, pcchOut); |
| 24 | { | ||
| 25 | hr = ::StringCchCopyExW(wzOut, *pcchOut, sczValue, NULL, &cchRemaining, STRSAFE_FILL_BEHIND_NULL); | ||
| 26 | if (STRSAFE_E_INSUFFICIENT_BUFFER == hr) | ||
| 27 | { | ||
| 28 | hr = E_MOREDATA; | ||
| 29 | ::StringCchLengthW(sczValue, STRSAFE_MAX_CCH, &cchRemaining); | ||
| 30 | *pcchOut = cchRemaining; | ||
| 31 | } | ||
| 32 | } | ||
| 33 | else | ||
| 34 | { | ||
| 35 | ::StringCchLengthW(sczValue, STRSAFE_MAX_CCH, &cchRemaining); | ||
| 36 | *pcchOut = cchRemaining; | ||
| 37 | } | ||
| 38 | } | 30 | } |
| 39 | } | 31 | } |
| 40 | else | 32 | else |
| @@ -76,33 +68,16 @@ static HRESULT BEEngineFormatString( | |||
| 76 | { | 68 | { |
| 77 | HRESULT hr = S_OK; | 69 | HRESULT hr = S_OK; |
| 78 | LPWSTR sczValue = NULL; | 70 | LPWSTR sczValue = NULL; |
| 79 | DWORD cchValue = 0; | ||
| 80 | LPCWSTR wzIn = pArgs->wzIn; | 71 | LPCWSTR wzIn = pArgs->wzIn; |
| 81 | LPWSTR wzOut = pResults->wzOut; | 72 | LPWSTR wzOut = pResults->wzOut; |
| 82 | DWORD* pcchOut = &pResults->cchOut; | 73 | DWORD* pcchOut = &pResults->cchOut; |
| 83 | 74 | ||
| 84 | if (wzIn && *wzIn) | 75 | if (wzIn && *wzIn) |
| 85 | { | 76 | { |
| 86 | hr = VariableFormatString(&pContext->pEngineState->variables, wzIn, &sczValue, &cchValue); | 77 | hr = VariableFormatString(&pContext->pEngineState->variables, wzIn, &sczValue, NULL); |
| 87 | if (SUCCEEDED(hr)) | 78 | if (SUCCEEDED(hr)) |
| 88 | { | 79 | { |
| 89 | if (wzOut) | 80 | hr = CopyStringToBE(sczValue, wzOut, pcchOut); |
| 90 | { | ||
| 91 | hr = ::StringCchCopyExW(wzOut, *pcchOut, sczValue, NULL, NULL, STRSAFE_FILL_BEHIND_NULL); | ||
| 92 | if (FAILED(hr)) | ||
| 93 | { | ||
| 94 | *pcchOut = cchValue; | ||
| 95 | if (STRSAFE_E_INSUFFICIENT_BUFFER == hr) | ||
| 96 | { | ||
| 97 | hr = E_MOREDATA; | ||
| 98 | } | ||
| 99 | } | ||
| 100 | } | ||
| 101 | else | ||
| 102 | { | ||
| 103 | hr = E_MOREDATA; | ||
| 104 | *pcchOut = cchValue; | ||
| 105 | } | ||
| 106 | } | 81 | } |
| 107 | } | 82 | } |
| 108 | else | 83 | else |
| @@ -144,7 +119,6 @@ static HRESULT BEEngineGetVariableString( | |||
| 144 | { | 119 | { |
| 145 | HRESULT hr = S_OK; | 120 | HRESULT hr = S_OK; |
| 146 | LPWSTR sczValue = NULL; | 121 | LPWSTR sczValue = NULL; |
| 147 | size_t cchRemaining = 0; | ||
| 148 | LPCWSTR wzVariable = pArgs->wzVariable; | 122 | LPCWSTR wzVariable = pArgs->wzVariable; |
| 149 | LPWSTR wzValue = pResults->wzValue; | 123 | LPWSTR wzValue = pResults->wzValue; |
| 150 | DWORD* pcchValue = &pResults->cchValue; | 124 | DWORD* pcchValue = &pResults->cchValue; |
| @@ -154,24 +128,7 @@ static HRESULT BEEngineGetVariableString( | |||
| 154 | hr = VariableGetString(&pContext->pEngineState->variables, wzVariable, &sczValue); | 128 | hr = VariableGetString(&pContext->pEngineState->variables, wzVariable, &sczValue); |
| 155 | if (SUCCEEDED(hr)) | 129 | if (SUCCEEDED(hr)) |
| 156 | { | 130 | { |
| 157 | if (wzValue) | 131 | hr = CopyStringToBE(sczValue, wzValue, pcchValue); |
| 158 | { | ||
| 159 | hr = ::StringCchCopyExW(wzValue, *pcchValue, sczValue, NULL, &cchRemaining, STRSAFE_FILL_BEHIND_NULL); | ||
| 160 | if (STRSAFE_E_INSUFFICIENT_BUFFER == hr) | ||
| 161 | { | ||
| 162 | hr = E_MOREDATA; | ||
| 163 | |||
| 164 | ::StringCchLengthW(sczValue, STRSAFE_MAX_CCH, &cchRemaining); | ||
| 165 | *pcchValue = cchRemaining + 1; | ||
| 166 | } | ||
| 167 | } | ||
| 168 | else | ||
| 169 | { | ||
| 170 | hr = E_MOREDATA; | ||
| 171 | |||
| 172 | ::StringCchLengthW(sczValue, STRSAFE_MAX_CCH, &cchRemaining); | ||
| 173 | *pcchValue = cchRemaining + 1; | ||
| 174 | } | ||
| 175 | } | 132 | } |
| 176 | } | 133 | } |
| 177 | else | 134 | else |
| @@ -190,18 +147,26 @@ static HRESULT BEEngineGetVariableVersion( | |||
| 190 | ) | 147 | ) |
| 191 | { | 148 | { |
| 192 | HRESULT hr = S_OK; | 149 | HRESULT hr = S_OK; |
| 150 | VERUTIL_VERSION* pVersion = NULL; | ||
| 193 | LPCWSTR wzVariable = pArgs->wzVariable; | 151 | LPCWSTR wzVariable = pArgs->wzVariable; |
| 194 | DWORD64* pqwValue = &pResults->qwValue; | 152 | LPWSTR wzValue = pResults->wzValue; |
| 153 | DWORD* pcchValue = &pResults->cchValue; | ||
| 195 | 154 | ||
| 196 | if (wzVariable && *wzVariable) | 155 | if (wzVariable && *wzVariable) |
| 197 | { | 156 | { |
| 198 | hr = VariableGetVersion(&pContext->pEngineState->variables, wzVariable, pqwValue); | 157 | hr = VariableGetVersion(&pContext->pEngineState->variables, wzVariable, &pVersion); |
| 158 | if (SUCCEEDED(hr)) | ||
| 159 | { | ||
| 160 | hr = CopyStringToBE(pVersion->sczVersion, wzValue, pcchValue); | ||
| 161 | } | ||
| 199 | } | 162 | } |
| 200 | else | 163 | else |
| 201 | { | 164 | { |
| 202 | hr = E_INVALIDARG; | 165 | hr = E_INVALIDARG; |
| 203 | } | 166 | } |
| 204 | 167 | ||
| 168 | ReleaseVerutilVersion(pVersion); | ||
| 169 | |||
| 205 | return hr; | 170 | return hr; |
| 206 | } | 171 | } |
| 207 | 172 | ||
| @@ -303,11 +268,15 @@ static HRESULT BEEngineSetVariableVersion( | |||
| 303 | { | 268 | { |
| 304 | HRESULT hr = S_OK; | 269 | HRESULT hr = S_OK; |
| 305 | LPCWSTR wzVariable = pArgs->wzVariable; | 270 | LPCWSTR wzVariable = pArgs->wzVariable; |
| 306 | DWORD64 qwValue = pArgs->qwValue; | 271 | LPCWSTR wzValue = pArgs->wzValue; |
| 272 | VERUTIL_VERSION* pVersion = NULL; | ||
| 307 | 273 | ||
| 308 | if (wzVariable && *wzVariable) | 274 | if (wzVariable && *wzVariable) |
| 309 | { | 275 | { |
| 310 | hr = VariableSetVersion(&pContext->pEngineState->variables, wzVariable, qwValue, FALSE); | 276 | hr = VerParseVersion(wzValue, 0, FALSE, &pVersion); |
| 277 | ExitOnFailure(hr, "Failed to parse new version value."); | ||
| 278 | |||
| 279 | hr = VariableSetVersion(&pContext->pEngineState->variables, wzVariable, pVersion, FALSE); | ||
| 311 | ExitOnFailure(hr, "Failed to set version variable."); | 280 | ExitOnFailure(hr, "Failed to set version variable."); |
| 312 | } | 281 | } |
| 313 | else | 282 | else |
| @@ -317,6 +286,8 @@ static HRESULT BEEngineSetVariableVersion( | |||
| 317 | } | 286 | } |
| 318 | 287 | ||
| 319 | LExit: | 288 | LExit: |
| 289 | ReleaseVerutilVersion(pVersion); | ||
| 290 | |||
| 320 | return hr; | 291 | return hr; |
| 321 | } | 292 | } |
| 322 | 293 | ||
| @@ -375,3 +346,34 @@ HRESULT WINAPI EngineForExtensionProc( | |||
| 375 | LExit: | 346 | LExit: |
| 376 | return hr; | 347 | return hr; |
| 377 | } | 348 | } |
| 349 | |||
| 350 | static HRESULT CopyStringToBE( | ||
| 351 | __in LPWSTR wzValue, | ||
| 352 | __in LPWSTR wzBuffer, | ||
| 353 | __inout DWORD* pcchBuffer | ||
| 354 | ) | ||
| 355 | { | ||
| 356 | HRESULT hr = S_OK; | ||
| 357 | BOOL fTooSmall = !wzBuffer; | ||
| 358 | |||
| 359 | if (!fTooSmall) | ||
| 360 | { | ||
| 361 | hr = ::StringCchCopyExW(wzBuffer, *pcchBuffer, wzValue, NULL, NULL, STRSAFE_FILL_BEHIND_NULL); | ||
| 362 | if (STRSAFE_E_INSUFFICIENT_BUFFER == hr) | ||
| 363 | { | ||
| 364 | fTooSmall = TRUE; | ||
| 365 | } | ||
| 366 | } | ||
| 367 | |||
| 368 | if (fTooSmall) | ||
| 369 | { | ||
| 370 | hr = ::StringCchLengthW(wzValue, STRSAFE_MAX_CCH, reinterpret_cast<size_t*>(pcchBuffer)); | ||
| 371 | if (SUCCEEDED(hr)) | ||
| 372 | { | ||
| 373 | hr = E_MOREDATA; | ||
| 374 | *pcchBuffer += 1; // null terminator. | ||
| 375 | } | ||
| 376 | } | ||
| 377 | |||
| 378 | return hr; | ||
| 379 | } | ||
