From 0d3d54992104288e9ee0c834d0b96e8502fd2d42 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 11 Jan 2024 18:26:20 -0800 Subject: Move the BootstrapperApplication out of proc --- src/api/burn/balutil/BalBootstrapperEngine.cpp | 1148 +++++++++++++++++++++--- 1 file changed, 1035 insertions(+), 113 deletions(-) (limited to 'src/api/burn/balutil/BalBootstrapperEngine.cpp') diff --git a/src/api/burn/balutil/BalBootstrapperEngine.cpp b/src/api/burn/balutil/BalBootstrapperEngine.cpp index be53c6b9..b924906e 100644 --- a/src/api/burn/balutil/BalBootstrapperEngine.cpp +++ b/src/api/burn/balutil/BalBootstrapperEngine.cpp @@ -2,7 +2,6 @@ #include "precomp.h" - class CBalBootstrapperEngine : public IBootstrapperEngine { public: // IUnknown @@ -64,18 +63,44 @@ public: // IBootstrapperEngine HRESULT hr = S_OK; BAENGINE_GETPACKAGECOUNT_ARGS args = { }; BAENGINE_GETPACKAGECOUNT_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; + SIZE_T iBuffer = 0; ExitOnNull(pcPackages, hr, E_INVALIDARG, "pcPackages is required"); - args.cbSize = sizeof(args); + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of GetPackageCount args."); + + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of GetPackageCount results."); + + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_GETPACKAGECOUNT, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA GetPackageCount failed."); - results.cbSize = sizeof(results); + // Read results. + hr = BuffReadNumber(rpc.pbData, rpc.cbData, &iBuffer, &results.dwApiVersion); + ExitOnFailure(hr, "Failed to read value length from GetPackageCount results."); - hr = m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_GETPACKAGECOUNT, &args, &results, m_pvBAEngineProcContext); + hr = BuffReadNumber(rpc.pbData, rpc.cbData, &iBuffer, (DWORD*)&results.cPackages); + ExitOnFailure(hr, "Failed to read value length from GetPackageCount results."); *pcPackages = results.cPackages; LExit: + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + return hr; } @@ -87,20 +112,50 @@ public: // IBootstrapperEngine HRESULT hr = S_OK; BAENGINE_GETVARIABLENUMERIC_ARGS args = { }; BAENGINE_GETVARIABLENUMERIC_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; + SIZE_T iBuffer = 0; + LPWSTR sczValue = NULL; ExitOnNull(pllValue, hr, E_INVALIDARG, "pllValue is required"); - args.cbSize = sizeof(args); + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; args.wzVariable = wzVariable; - results.cbSize = sizeof(results); + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of GetVariableNumeric args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzVariable); + ExitOnFailure(hr, "Failed to write variable name of GetVariableNumeric args."); + + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of GetVariableNumeric results."); - hr = m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_GETVARIABLENUMERIC, &args, &results, m_pvBAEngineProcContext); + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_GETVARIABLENUMERIC, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA GetVariableNumeric failed."); + + // Read results. + hr = BuffReadNumber(rpc.pbData, rpc.cbData, &iBuffer, &results.dwApiVersion); + ExitOnFailure(hr, "Failed to read value length from GetVariableNumeric results."); + + hr = BuffReadNumber64(rpc.pbData, rpc.cbData, &iBuffer, (DWORD64*)&results.llValue); + ExitOnFailure(hr, "Failed to read value length from GetVariableNumeric results."); *pllValue = results.llValue; LExit: - SecureZeroMemory(&results, sizeof(results)); + ReleaseStr(sczValue); + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + return hr; } @@ -113,21 +168,69 @@ public: // IBootstrapperEngine HRESULT hr = S_OK; BAENGINE_GETVARIABLESTRING_ARGS args = { }; BAENGINE_GETVARIABLESTRING_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; + SIZE_T iBuffer = 0; + LPWSTR sczValue = NULL; ExitOnNull(pcchValue, hr, E_INVALIDARG, "pcchValue is required"); - args.cbSize = sizeof(args); + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; args.wzVariable = wzVariable; - results.cbSize = sizeof(results); - results.wzValue = wzValue; - results.cchValue = *pcchValue; + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + results.cchValue = static_cast(*pcchValue); + + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of GetVariableString args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzVariable); + ExitOnFailure(hr, "Failed to write variable name of GetVariableString args."); + + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of GetVariableString results."); + + hr = BuffWriteNumberToBuffer(&bufferResults, results.cchValue); + ExitOnFailure(hr, "Failed to write API version of GetVariableString results value."); + + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_GETVARIABLESTRING, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA GetVariableString failed."); + + // Read results. + hr = BuffReadNumber(rpc.pbData, rpc.cbData, &iBuffer, &results.dwApiVersion); + ExitOnFailure(hr, "Failed to read value length from GetVariableString results."); - hr = m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_GETVARIABLESTRING, &args, &results, m_pvBAEngineProcContext); + hr = BuffReadNumber(rpc.pbData, rpc.cbData, &iBuffer, &results.cchValue); + ExitOnFailure(hr, "Failed to read value length from GetVariableString results."); + + hr = BuffReadString(rpc.pbData, rpc.cbData, &iBuffer, &sczValue); + ExitOnFailure(hr, "Failed to read value from GetVariableString results."); + + results.wzValue = sczValue; + + if (wzValue) + { + hr = ::StringCchCopyW(wzValue, *pcchValue, results.wzValue); + } + else if (results.cchValue) + { + hr = E_MOREDATA; + } *pcchValue = results.cchValue; + ExitOnFailure(hr, "Failed to copy value from GetVariableString results."); LExit: + ReleaseStr(sczValue); + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + return hr; } @@ -140,21 +243,70 @@ public: // IBootstrapperEngine HRESULT hr = S_OK; BAENGINE_GETVARIABLEVERSION_ARGS args = { }; BAENGINE_GETVARIABLEVERSION_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; + SIZE_T iBuffer = 0; + LPWSTR sczValue = NULL; ExitOnNull(pcchValue, hr, E_INVALIDARG, "pcchValue is required"); - args.cbSize = sizeof(args); + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; args.wzVariable = wzVariable; - results.cbSize = sizeof(results); - results.wzValue = wzValue; - results.cchValue = *pcchValue; + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + hr = DutilSizetToDword(*pcchValue, &results.cchValue); + ExitOnFailure(hr, "Failed to convert pcchValue to DWORD."); + + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of GetVariableVersion args."); - hr = m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_GETVARIABLEVERSION, &args, &results, m_pvBAEngineProcContext); + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzVariable); + ExitOnFailure(hr, "Failed to write variable name of GetVariableVersion args."); + + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of GetVariableVersion results."); + + hr = BuffWriteNumberToBuffer(&bufferResults, results.cchValue); + ExitOnFailure(hr, "Failed to write API version of GetVariableVersion results value."); + + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_GETVARIABLEVERSION, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA GetVariableVersion failed."); + + // Read results. + hr = BuffReadNumber(rpc.pbData, rpc.cbData, &iBuffer, &results.dwApiVersion); + ExitOnFailure(hr, "Failed to read value length from GetVariableVersion results."); + + hr = BuffReadNumber(rpc.pbData, rpc.cbData, &iBuffer, &results.cchValue); + ExitOnFailure(hr, "Failed to read value length from GetVariableVersion results."); + + hr = BuffReadString(rpc.pbData, rpc.cbData, &iBuffer, &sczValue); + ExitOnFailure(hr, "Failed to read value from GetVariableVersion results."); + + results.wzValue = sczValue; + + if (wzValue) + { + hr = ::StringCchCopyW(wzValue, *pcchValue, results.wzValue); + } + else if (results.cchValue) + { + hr = E_MOREDATA; + } *pcchValue = results.cchValue; + ExitOnFailure(hr, "Failed to copy value from GetVariableVersion results."); LExit: + ReleaseStr(sczValue); + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + return hr; } @@ -168,21 +320,74 @@ public: // IBootstrapperEngine HRESULT hr = S_OK; BAENGINE_GETRELATEDBUNDLEVARIABLE_ARGS args = { }; BAENGINE_GETRELATEDBUNDLEVARIABLE_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; + SIZE_T iBuffer = 0; + LPWSTR sczValue = NULL; ExitOnNull(pcchValue, hr, E_INVALIDARG, "pcchValue is required"); - args.cbSize = sizeof(args); + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; args.wzBundleId = wzBundleId; args.wzVariable = wzVariable; - results.cbSize = sizeof(results); - results.wzValue = wzValue; - results.cchValue = *pcchValue; + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + hr = DutilSizetToDword(*pcchValue, &results.cchValue); + ExitOnFailure(hr, "Failed to convert pcchValue to DWORD."); + + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of GetRelatedBundleVariable args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzBundleId); + ExitOnFailure(hr, "Failed to write bundle id of GetRelatedBundleVariable args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzVariable); + ExitOnFailure(hr, "Failed to write variable name of GetRelatedBundleVariable args."); + + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of GetRelatedBundleVariable results."); + + hr = BuffWriteNumberToBuffer(&bufferResults, results.cchValue); + ExitOnFailure(hr, "Failed to write API version of GetRelatedBundleVariable results value."); - hr = m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_GETRELATEDBUNDLEVARIABLE, &args, &results, m_pvBAEngineProcContext); + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_GETRELATEDBUNDLEVARIABLE, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA GetRelatedBundleVariable failed."); + + // Read results. + hr = BuffReadNumber(rpc.pbData, rpc.cbData, &iBuffer, &results.dwApiVersion); + ExitOnFailure(hr, "Failed to read value length from GetRelatedBundleVariable results."); + + hr = BuffReadNumber(rpc.pbData, rpc.cbData, &iBuffer, &results.cchValue); + ExitOnFailure(hr, "Failed to read value length from GetRelatedBundleVariable results."); + + hr = BuffReadString(rpc.pbData, rpc.cbData, &iBuffer, &sczValue); + ExitOnFailure(hr, "Failed to read value from GetRelatedBundleVariable results."); + + results.wzValue = sczValue; + + if (wzValue) + { + hr = ::StringCchCopyW(wzValue, *pcchValue, results.wzValue); + } + else if (results.cchValue) + { + hr = E_MOREDATA; + } *pcchValue = results.cchValue; + ExitOnFailure(hr, "Failed to copy value from GetRelatedBundleVariable results."); + LExit: + ReleaseStr(sczValue); + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + return hr; } @@ -195,21 +400,70 @@ public: // IBootstrapperEngine HRESULT hr = S_OK; BAENGINE_FORMATSTRING_ARGS args = { }; BAENGINE_FORMATSTRING_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; + SIZE_T iBuffer = 0; + LPWSTR sczOut = NULL; ExitOnNull(pcchOut, hr, E_INVALIDARG, "pcchOut is required"); - args.cbSize = sizeof(args); + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; args.wzIn = wzIn; - results.cbSize = sizeof(results); - results.wzOut = wzOut; - results.cchOut = *pcchOut; + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + hr = DutilSizetToDword(*pcchOut, &results.cchOut); + ExitOnFailure(hr, "Failed to convert pcchOut to DWORD."); + + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of FormatString args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzIn); + ExitOnFailure(hr, "Failed to write string to format of FormatString args."); + + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of FormatString results."); + + hr = BuffWriteNumberToBuffer(&bufferResults, results.cchOut); + ExitOnFailure(hr, "Failed to write format string maximum size of FormatString results value."); + + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_FORMATSTRING, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA FormatString failed."); + + // Read results. + hr = BuffReadNumber(rpc.pbData, rpc.cbData, &iBuffer, &results.dwApiVersion); + ExitOnFailure(hr, "Failed to read size from FormatString results."); + + hr = BuffReadNumber(rpc.pbData, rpc.cbData, &iBuffer, &results.cchOut); + ExitOnFailure(hr, "Failed to read formatted string length from FormatString results."); - hr = m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_FORMATSTRING, &args, &results, m_pvBAEngineProcContext); + hr = BuffReadString(rpc.pbData, rpc.cbData, &iBuffer, &sczOut); + ExitOnFailure(hr, "Failed to read formatted string from FormatString results."); + + results.wzOut = sczOut; + + if (wzOut) + { + hr = ::StringCchCopyW(wzOut, *pcchOut, results.wzOut); + } + else if (results.cchOut) + { + hr = E_MOREDATA; + } *pcchOut = results.cchOut; + ExitOnFailure(hr, "Failed to copy formatted string from FormatString results."); LExit: + ReleaseStr(sczOut); + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + return hr; } @@ -222,21 +476,70 @@ public: // IBootstrapperEngine HRESULT hr = S_OK; BAENGINE_ESCAPESTRING_ARGS args = { }; BAENGINE_ESCAPESTRING_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; + SIZE_T iBuffer = 0; + LPWSTR sczOut = NULL; ExitOnNull(pcchOut, hr, E_INVALIDARG, "pcchOut is required"); - args.cbSize = sizeof(args); + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; args.wzIn = wzIn; - results.cbSize = sizeof(results); - results.wzOut = wzOut; - results.cchOut = *pcchOut; + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + hr = DutilSizetToDword(*pcchOut, &results.cchOut); + ExitOnFailure(hr, "Failed to convert pcchOut to DWORD."); + + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of EscapeString args."); - hr = m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_ESCAPESTRING, &args, &results, m_pvBAEngineProcContext); + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzIn); + ExitOnFailure(hr, "Failed to write string to escape of EscapeString args."); + + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of EscapeString results."); + + hr = BuffWriteNumberToBuffer(&bufferResults, results.cchOut); + ExitOnFailure(hr, "Failed to write escape string maximum size of EscapeString results value."); + + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_ESCAPESTRING, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA EscapeString failed."); + + // Read results. + hr = BuffReadNumber(rpc.pbData, rpc.cbData, &iBuffer, &results.dwApiVersion); + ExitOnFailure(hr, "Failed to read size from EscapeString results."); + + hr = BuffReadNumber(rpc.pbData, rpc.cbData, &iBuffer, &results.cchOut); + ExitOnFailure(hr, "Failed to read escaped string length from EscapeString results."); + + hr = BuffReadString(rpc.pbData, rpc.cbData, &iBuffer, &sczOut); + ExitOnFailure(hr, "Failed to read escaped string from EscapeString results."); + + results.wzOut = sczOut; + + if (wzOut) + { + hr = ::StringCchCopyW(wzOut, *pcchOut, results.wzOut); + } + else if (results.cchOut) + { + hr = E_MOREDATA; + } *pcchOut = results.cchOut; + ExitOnFailure(hr, "Failed to copy escaped string from EscapeString results."); LExit: + ReleaseStr(sczOut); + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + return hr; } @@ -248,19 +551,56 @@ public: // IBootstrapperEngine HRESULT hr = S_OK; BAENGINE_EVALUATECONDITION_ARGS args = { }; BAENGINE_EVALUATECONDITION_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; + SIZE_T iBuffer = 0; + ExitOnNull(wzCondition, hr, E_INVALIDARG, "wzCondition is required"); ExitOnNull(pf, hr, E_INVALIDARG, "pf is required"); - args.cbSize = sizeof(args); + // Empty condition evaluates to true. + if (!*wzCondition) + { + *pf = TRUE; + ExitFunction(); + } + + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; args.wzCondition = wzCondition; - results.cbSize = sizeof(results); + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of EvaluateCondition args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzCondition); + ExitOnFailure(hr, "Failed to write condition of EvaluateCondition args."); - hr = m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_EVALUATECONDITION, &args, &results, m_pvBAEngineProcContext); + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of EvaluateCondition results."); + + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_EVALUATECONDITION, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA EvaluateCondition failed."); + + // Read results. + hr = BuffReadNumber(rpc.pbData, rpc.cbData, &iBuffer, &results.dwApiVersion); + ExitOnFailure(hr, "Failed to read size from EvaluateCondition results."); + + hr = BuffReadNumber(rpc.pbData, rpc.cbData, &iBuffer, reinterpret_cast(&results.f)); + ExitOnFailure(hr, "Failed to read result from EvaluateCondition results."); *pf = results.f; LExit: + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + return hr; } @@ -269,16 +609,44 @@ public: // IBootstrapperEngine __in_z LPCWSTR wzMessage ) { + HRESULT hr = S_OK; BAENGINE_LOG_ARGS args = { }; BAENGINE_LOG_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; - args.cbSize = sizeof(args); + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; args.level = level; args.wzMessage = wzMessage; - results.cbSize = sizeof(results); + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of Log args."); + + hr = BuffWriteNumberToBuffer(&bufferArgs, args.level); + ExitOnFailure(hr, "Failed to write level of Log args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzMessage); + ExitOnFailure(hr, "Failed to write message of Log args."); + + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of Log results."); - return m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_LOG, &args, &results, m_pvBAEngineProcContext); + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_LOG, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA Log failed."); + + LExit: + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + + return hr; } virtual STDMETHODIMP SendEmbeddedError( @@ -291,21 +659,56 @@ public: // IBootstrapperEngine HRESULT hr = S_OK; BAENGINE_SENDEMBEDDEDERROR_ARGS args = { }; BAENGINE_SENDEMBEDDEDERROR_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; + SIZE_T iBuffer = 0; ExitOnNull(pnResult, hr, E_INVALIDARG, "pnResult is required"); - args.cbSize = sizeof(args); + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; args.dwErrorCode = dwErrorCode; args.wzMessage = wzMessage; args.dwUIHint = dwUIHint; - results.cbSize = sizeof(results); + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of SendEmbeddedError args."); + + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwErrorCode); + ExitOnFailure(hr, "Failed to write error code of SendEmbeddedError args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzMessage); + ExitOnFailure(hr, "Failed to write message of SendEmbeddedError args."); + + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwUIHint); + ExitOnFailure(hr, "Failed to write UI hint of SendEmbeddedError args."); + + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of SendEmbeddedError results."); - hr = m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_SENDEMBEDDEDERROR, &args, &results, m_pvBAEngineProcContext); + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_SENDEMBEDDEDERROR, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA SendEmbeddedError failed."); + + // Read results. + hr = BuffReadNumber(rpc.pbData, rpc.cbData, &iBuffer, &results.dwApiVersion); + ExitOnFailure(hr, "Failed to read size from SendEmbeddedError results."); + + hr = BuffReadNumber(rpc.pbData, rpc.cbData, &iBuffer, reinterpret_cast(&results.nResult)); + ExitOnFailure(hr, "Failed to read result from SendEmbeddedError results."); *pnResult = results.nResult; LExit: + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + return hr; } @@ -318,20 +721,52 @@ public: // IBootstrapperEngine HRESULT hr = S_OK; BAENGINE_SENDEMBEDDEDPROGRESS_ARGS args = { }; BAENGINE_SENDEMBEDDEDPROGRESS_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; + SIZE_T iBuffer = 0; ExitOnNull(pnResult, hr, E_INVALIDARG, "pnResult is required"); - args.cbSize = sizeof(args); + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; args.dwProgressPercentage = dwProgressPercentage; args.dwOverallProgressPercentage = dwOverallProgressPercentage; - results.cbSize = sizeof(results); + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of SendEmbeddedProgress args."); + + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwProgressPercentage); + ExitOnFailure(hr, "Failed to write progress of SendEmbeddedProgress args."); + + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwOverallProgressPercentage); + ExitOnFailure(hr, "Failed to write overall progress of SendEmbeddedProgress args."); + + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of SendEmbeddedProgress results."); + + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_SENDEMBEDDEDPROGRESS, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA SendEmbeddedProgress failed."); + + // Read results. + hr = BuffReadNumber(rpc.pbData, rpc.cbData, &iBuffer, &results.dwApiVersion); + ExitOnFailure(hr, "Failed to read size from SendEmbeddedProgress results."); - hr = m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_SENDEMBEDDEDPROGRESS, &args, &results, m_pvBAEngineProcContext); + hr = BuffReadNumber(rpc.pbData, rpc.cbData, &iBuffer, reinterpret_cast(&results.nResult)); + ExitOnFailure(hr, "Failed to read result from SendEmbeddedProgress results."); *pnResult = results.nResult; LExit: + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + return hr; } @@ -340,22 +775,67 @@ public: // IBootstrapperEngine __in_z_opt LPCWSTR wzDownloadSource, __in DWORD64 qwSize, __in BOOTSTRAPPER_UPDATE_HASH_TYPE hashType, - __in_z_opt LPCWSTR wzHash + __in_z_opt LPCWSTR wzHash, + __in_z_opt LPCWSTR wzUpdatePackageId ) { + HRESULT hr = S_OK; BAENGINE_SETUPDATE_ARGS args = { }; BAENGINE_SETUPDATE_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; - args.cbSize = sizeof(args); + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; args.wzLocalSource = wzLocalSource; args.wzDownloadSource = wzDownloadSource; args.qwSize = qwSize; args.hashType = hashType; args.wzHash = wzHash; + args.wzUpdatePackageId = wzUpdatePackageId; + + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of SetUpdate args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzLocalSource); + ExitOnFailure(hr, "Failed to write local source of SetUpdate args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzDownloadSource); + ExitOnFailure(hr, "Failed to write download source of SetUpdate args."); + + hr = BuffWriteNumber64ToBuffer(&bufferArgs, args.qwSize); + ExitOnFailure(hr, "Failed to write udpate size of SetUpdate args."); + + hr = BuffWriteNumberToBuffer(&bufferArgs, static_cast(args.hashType)); + ExitOnFailure(hr, "Failed to write hash type of SetUpdate args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzHash); + ExitOnFailure(hr, "Failed to write hash of SetUpdate args."); - results.cbSize = sizeof(results); + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzHash); + ExitOnFailure(hr, "Failed to write hash of SetUpdate args."); - return m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_SETUPDATE, &args, &results, m_pvBAEngineProcContext); + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzUpdatePackageId); + ExitOnFailure(hr, "Failed to write update package id to SetUpdate args."); + + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of SetUpdate results."); + + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_SETUPDATE, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA SetUpdate failed."); + + LExit: + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + + return hr; } virtual STDMETHODIMP SetLocalSource( @@ -364,17 +844,48 @@ public: // IBootstrapperEngine __in_z LPCWSTR wzPath ) { + HRESULT hr = S_OK; BAENGINE_SETLOCALSOURCE_ARGS args = { }; BAENGINE_SETLOCALSOURCE_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; - args.cbSize = sizeof(args); + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; args.wzPackageOrContainerId = wzPackageOrContainerId; args.wzPayloadId = wzPayloadId; args.wzPath = wzPath; - results.cbSize = sizeof(results); + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of SetLocalSource args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzPackageOrContainerId); + ExitOnFailure(hr, "Failed to write package or container id of SetLocalSource args."); - return m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_SETLOCALSOURCE, &args, &results, m_pvBAEngineProcContext); + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzPayloadId); + ExitOnFailure(hr, "Failed to write payload id of SetLocalSource args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzPath); + ExitOnFailure(hr, "Failed to write path of SetLocalSource args."); + + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of SetLocalSource results."); + + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_SETLOCALSOURCE, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA SetLocalSource failed."); + + LExit: + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + + return hr; } virtual STDMETHODIMP SetDownloadSource( @@ -382,22 +893,64 @@ public: // IBootstrapperEngine __in_z_opt LPCWSTR wzPayloadId, __in_z LPCWSTR wzUrl, __in_z_opt LPCWSTR wzUser, - __in_z_opt LPCWSTR wzPassword + __in_z_opt LPCWSTR wzPassword, + __in_z_opt LPCWSTR wzAuthorizationHeader ) { + HRESULT hr = S_OK; BAENGINE_SETDOWNLOADSOURCE_ARGS args = { }; BAENGINE_SETDOWNLOADSOURCE_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; - args.cbSize = sizeof(args); + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; args.wzPackageOrContainerId = wzPackageOrContainerId; args.wzPayloadId = wzPayloadId; args.wzUrl = wzUrl; args.wzUser = wzUser; args.wzPassword = wzPassword; + args.wzAuthorizationHeader = wzAuthorizationHeader; - results.cbSize = sizeof(results); + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; - return m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_SETDOWNLOADSOURCE, &args, &results, m_pvBAEngineProcContext); + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of SetDownloadSource args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzPackageOrContainerId); + ExitOnFailure(hr, "Failed to write package or container id of SetDownloadSource args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzPayloadId); + ExitOnFailure(hr, "Failed to write payload id of SetDownloadSource args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzUrl); + ExitOnFailure(hr, "Failed to write url of SetDownloadSource args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzUser); + ExitOnFailure(hr, "Failed to write user of SetDownloadSource args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzPassword); + ExitOnFailure(hr, "Failed to write password of SetDownloadSource args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzAuthorizationHeader); + ExitOnFailure(hr, "Failed to write authorization header of SetDownloadSource args."); + + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of SetDownloadSource results."); + + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_SETDOWNLOADSOURCE, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA SetDownloadSource failed."); + + LExit: + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + + return hr; } virtual STDMETHODIMP SetVariableNumeric( @@ -405,16 +958,44 @@ public: // IBootstrapperEngine __in LONGLONG llValue ) { + HRESULT hr = S_OK; BAENGINE_SETVARIABLENUMERIC_ARGS args = { }; BAENGINE_SETVARIABLENUMERIC_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; - args.cbSize = sizeof(args); + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; args.wzVariable = wzVariable; args.llValue = llValue; - results.cbSize = sizeof(results); + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of SetVariableNumeric args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzVariable); + ExitOnFailure(hr, "Failed to write variable of SetVariableNumeric args."); + + hr = BuffWriteNumber64ToBuffer(&bufferArgs, static_cast(args.llValue)); + ExitOnFailure(hr, "Failed to write value of SetVariableNumeric args."); + + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of SetVariableNumeric results."); + + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_SETVARIABLENUMERIC, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA SetVariableNumeric failed."); - return m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_SETVARIABLENUMERIC, &args, &results, m_pvBAEngineProcContext); + LExit: + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + + return hr; } virtual STDMETHODIMP SetVariableString( @@ -423,17 +1004,48 @@ public: // IBootstrapperEngine __in BOOL fFormatted ) { + HRESULT hr = S_OK; BAENGINE_SETVARIABLESTRING_ARGS args = { }; BAENGINE_SETVARIABLESTRING_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; - args.cbSize = sizeof(args); + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; args.wzVariable = wzVariable; args.wzValue = wzValue; args.fFormatted = fFormatted; - results.cbSize = sizeof(results); + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of SetVariableString args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzVariable); + ExitOnFailure(hr, "Failed to write variable of SetVariableString args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzValue); + ExitOnFailure(hr, "Failed to write value of SetVariableString args."); + + hr = BuffWriteNumberToBuffer(&bufferArgs, args.fFormatted); + ExitOnFailure(hr, "Failed to write formatted flag of SetVariableString args."); + + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of SetVariableString results."); - return m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_SETVARIABLESTRING, &args, &results, m_pvBAEngineProcContext); + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_SETVARIABLESTRING, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA SetVariableString failed."); + + LExit: + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + + return hr; } virtual STDMETHODIMP SetVariableVersion( @@ -441,103 +1053,278 @@ public: // IBootstrapperEngine __in_z_opt LPCWSTR wzValue ) { + HRESULT hr = S_OK; BAENGINE_SETVARIABLEVERSION_ARGS args = { }; BAENGINE_SETVARIABLEVERSION_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; - args.cbSize = sizeof(args); + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; args.wzVariable = wzVariable; args.wzValue = wzValue; - results.cbSize = sizeof(results); + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of SetVariableVersion args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzVariable); + ExitOnFailure(hr, "Failed to write variable of SetVariableVersion args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzValue); + ExitOnFailure(hr, "Failed to write value of SetVariableVersion args."); + + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of SetVariableVersion results."); - return m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_SETVARIABLEVERSION, &args, &results, m_pvBAEngineProcContext); + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_SETVARIABLEVERSION, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA SetVariableVersion failed."); + + LExit: + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + + return hr; } virtual STDMETHODIMP CloseSplashScreen() { + HRESULT hr = S_OK; BAENGINE_CLOSESPLASHSCREEN_ARGS args = { }; BAENGINE_CLOSESPLASHSCREEN_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; + + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of CloseSplashScreen args."); + + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of CloseSplashScreen results."); - args.cbSize = sizeof(args); + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_CLOSESPLASHSCREEN, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA CloseSplashScreen failed."); - results.cbSize = sizeof(results); + LExit: + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); - return m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_CLOSESPLASHSCREEN, &args, &results, m_pvBAEngineProcContext); + return hr; } virtual STDMETHODIMP Detect( __in_opt HWND hwndParent ) { + HRESULT hr = S_OK; BAENGINE_DETECT_ARGS args = { }; BAENGINE_DETECT_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; + + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + args.hwndParent = reinterpret_cast(hwndParent); + + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; - args.cbSize = sizeof(args); - args.hwndParent = hwndParent; + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of Detect args."); - results.cbSize = sizeof(results); + hr = BuffWriteNumber64ToBuffer(&bufferArgs, args.hwndParent); + ExitOnFailure(hr, "Failed to write parent window of Detect args."); + + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of Detect results."); + + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_DETECT, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA Detect failed."); + + LExit: + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); - return m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_DETECT, &args, &results, m_pvBAEngineProcContext); + return hr; } virtual STDMETHODIMP Plan( __in BOOTSTRAPPER_ACTION action ) { + HRESULT hr = S_OK; BAENGINE_PLAN_ARGS args = { }; BAENGINE_PLAN_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; - args.cbSize = sizeof(args); + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; args.action = action; - results.cbSize = sizeof(results); + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of Plan args."); + + hr = BuffWriteNumberToBuffer(&bufferArgs, static_cast(args.action)); + ExitOnFailure(hr, "Failed to write parent window of Plan args."); + + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of Plan results."); - return m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_PLAN, &args, &results, m_pvBAEngineProcContext); + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_PLAN, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA Plan failed."); + + LExit: + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + + return hr; } virtual STDMETHODIMP Elevate( __in_opt HWND hwndParent ) { + HRESULT hr = S_OK; BAENGINE_ELEVATE_ARGS args = { }; BAENGINE_ELEVATE_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; + + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + args.hwndParent = reinterpret_cast(hwndParent); + + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of Elevate args."); - args.cbSize = sizeof(args); - args.hwndParent = hwndParent; + hr = BuffWriteNumber64ToBuffer(&bufferArgs, args.hwndParent); + ExitOnFailure(hr, "Failed to write parent window of Elevate args."); - results.cbSize = sizeof(results); + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of Elevate results."); - return m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_ELEVATE, &args, &results, m_pvBAEngineProcContext); + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_ELEVATE, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA Elevate failed."); + + LExit: + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + + return hr; } virtual STDMETHODIMP Apply( __in HWND hwndParent ) { + HRESULT hr = S_OK; BAENGINE_APPLY_ARGS args = { }; BAENGINE_APPLY_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; + + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + args.hwndParent = reinterpret_cast(hwndParent); + + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of Apply args."); + + hr = BuffWriteNumber64ToBuffer(&bufferArgs, args.hwndParent); + ExitOnFailure(hr, "Failed to write parent window of Apply args."); - args.cbSize = sizeof(args); - args.hwndParent = hwndParent; + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of Apply results."); - results.cbSize = sizeof(results); + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_APPLY, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA Apply failed."); - return m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_APPLY, &args, &results, m_pvBAEngineProcContext); + LExit: + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + + return hr; } virtual STDMETHODIMP Quit( __in DWORD dwExitCode ) { + HRESULT hr = S_OK; BAENGINE_QUIT_ARGS args = { }; BAENGINE_QUIT_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; - args.cbSize = sizeof(args); + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; args.dwExitCode = dwExitCode; - results.cbSize = sizeof(results); + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; - return m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_QUIT, &args, &results, m_pvBAEngineProcContext); + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of Quit args."); + + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwExitCode); + ExitOnFailure(hr, "Failed to write exit code of Quit args."); + + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of Quit results."); + + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_QUIT, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA Quit failed."); + + LExit: + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + + return hr; } virtual STDMETHODIMP LaunchApprovedExe( @@ -547,33 +1334,101 @@ public: // IBootstrapperEngine __in DWORD dwWaitForInputIdleTimeout ) { + HRESULT hr = S_OK; BAENGINE_LAUNCHAPPROVEDEXE_ARGS args = { }; BAENGINE_LAUNCHAPPROVEDEXE_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; + + ExitOnNull(wzApprovedExeForElevationId, hr, E_INVALIDARG, "wzApprovedExeForElevationId is required"); - args.cbSize = sizeof(args); - args.hwndParent = hwndParent; + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + args.hwndParent = reinterpret_cast(hwndParent); args.wzApprovedExeForElevationId = wzApprovedExeForElevationId; args.wzArguments = wzArguments; args.dwWaitForInputIdleTimeout = dwWaitForInputIdleTimeout; - results.cbSize = sizeof(results); + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; - return m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_LAUNCHAPPROVEDEXE, &args, &results, m_pvBAEngineProcContext); + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of LaunchApprovedExe args."); + + hr = BuffWriteNumber64ToBuffer(&bufferArgs, args.hwndParent); + ExitOnFailure(hr, "Failed to write parent window of LaunchApprovedExe args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzApprovedExeForElevationId); + ExitOnFailure(hr, "Failed to write approved exe elevation id of LaunchApprovedExe args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzArguments); + ExitOnFailure(hr, "Failed to write arguments of LaunchApprovedExe args."); + + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwWaitForInputIdleTimeout); + ExitOnFailure(hr, "Failed to write wait for idle input timeout of LaunchApprovedExe args."); + + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of LaunchApprovedExe results."); + + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_LAUNCHAPPROVEDEXE, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA LaunchApprovedExe failed."); + + LExit: + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + + return hr; } virtual STDMETHODIMP SetUpdateSource( - __in_z LPCWSTR wzUrl + __in_z LPCWSTR wzUrl, + __in_z_opt LPCWSTR wzAuthorizationHeader ) { + HRESULT hr = S_OK; BAENGINE_SETUPDATESOURCE_ARGS args = { }; BAENGINE_SETUPDATESOURCE_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; + + ExitOnNull(wzUrl, hr, E_INVALIDARG, "wzUrl is required"); - args.cbSize = sizeof(args); + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; args.wzUrl = wzUrl; + args.wzAuthorizationHeader = wzAuthorizationHeader; + + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of SetUpdateSource args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzUrl); + ExitOnFailure(hr, "Failed to write url of SetUpdateSource args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzAuthorizationHeader); + ExitOnFailure(hr, "Failed to write authorization header of SetUpdateSource args."); - results.cbSize = sizeof(results); + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of SetUpdateSource results."); - return m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_SETUPDATESOURCE, &args, &results, m_pvBAEngineProcContext); + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_SETUPDATESOURCE, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA SetUpdateSource failed."); + + LExit: + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + + return hr; } virtual STDMETHODIMP CompareVersions( @@ -585,66 +1440,133 @@ public: // IBootstrapperEngine HRESULT hr = S_OK; BAENGINE_COMPAREVERSIONS_ARGS args = { }; BAENGINE_COMPAREVERSIONS_RESULTS results = { }; + BUFF_BUFFER bufferArgs = { }; + BUFF_BUFFER bufferResults = { }; + PIPE_RPC_RESULT rpc = { }; + SIZE_T iBuffer = 0; ExitOnNull(pnResult, hr, E_INVALIDARG, "pnResult is required"); - args.cbSize = sizeof(args); + // Init send structs. + args.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; args.wzVersion1 = wzVersion1; args.wzVersion2 = wzVersion2; - results.cbSize = sizeof(results); + results.dwApiVersion = WIX_5_BOOTSTRAPPER_APPLICATION_API_VERSION; + + // Send args. + hr = BuffWriteNumberToBuffer(&bufferArgs, args.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of CompareVersions args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzVersion1); + ExitOnFailure(hr, "Failed to write first input of CompareVersions args."); + + hr = BuffWriteStringToBuffer(&bufferArgs, args.wzVersion2); + ExitOnFailure(hr, "Failed to write second input of CompareVersions args."); + + // Send results. + hr = BuffWriteNumberToBuffer(&bufferResults, results.dwApiVersion); + ExitOnFailure(hr, "Failed to write API version of CompareVersions results."); + + // Get results. + hr = SendRequest(BOOTSTRAPPER_ENGINE_MESSAGE_COMPAREVERSIONS, &bufferArgs, &bufferResults, &rpc); + ExitOnFailure(hr, "BA CompareVersions failed."); - hr = m_pfnBAEngineProc(BOOTSTRAPPER_ENGINE_MESSAGE_COMPAREVERSIONS, &args, &results, m_pvBAEngineProcContext); + // Read results. + hr = BuffReadNumber(rpc.pbData, rpc.cbData, &iBuffer, &results.dwApiVersion); + ExitOnFailure(hr, "Failed to read size from CompareVersions results."); + + hr = BuffReadNumber(rpc.pbData, rpc.cbData, &iBuffer, reinterpret_cast(&results.nResult)); + ExitOnFailure(hr, "Failed to read result from CompareVersions results."); *pnResult = results.nResult; LExit: + PipeFreeRpcResult(&rpc); + ReleaseBuffer(bufferResults); + ReleaseBuffer(bufferArgs); + return hr; } -public: - HRESULT Init() +private: + HRESULT SendRequest( + __in DWORD dwMessageType, + __in BUFF_BUFFER* pBufferArgs, + __in BUFF_BUFFER* pBufferResults, + __in PIPE_RPC_RESULT* pRpc + ) { - return ::CoCreateFreeThreadedMarshaler(this, &m_pFreeThreadedMarshaler); + HRESULT hr = S_OK; + BUFF_BUFFER buffer = { }; + + hr = CombineArgsAndResults(pBufferArgs, pBufferResults, &buffer); + if (SUCCEEDED(hr)) + { + hr = PipeRpcRequest(&m_hRpcPipe, dwMessageType, buffer.pbData, buffer.cbData, pRpc); + } + + ReleaseBuffer(buffer); + return hr; } + HRESULT CombineArgsAndResults( + __in BUFF_BUFFER* pBufferArgs, + __in BUFF_BUFFER* pBufferResults, + __in BUFF_BUFFER* pBufferCombined + ) + { + HRESULT hr = S_OK; + + // Write args to buffer. + hr = BuffWriteStreamToBuffer(pBufferCombined, pBufferArgs->pbData, pBufferArgs->cbData); + ExitOnFailure(hr, "Failed to write args buffer."); + + // Write results to buffer. + hr = BuffWriteStreamToBuffer(pBufferCombined, pBufferResults->pbData, pBufferResults->cbData); + ExitOnFailure(hr, "Failed to write results buffer."); + + LExit: + return hr; + } + +public: CBalBootstrapperEngine( - __in PFN_BOOTSTRAPPER_ENGINE_PROC pfnBAEngineProc, - __in_opt LPVOID pvBAEngineProcContext + __in HANDLE hPipe, + __out HRESULT* phr ) { m_cReferences = 1; - m_pfnBAEngineProc = pfnBAEngineProc; - m_pvBAEngineProcContext = pvBAEngineProcContext; - m_pFreeThreadedMarshaler = NULL; + + PipeRpcInitialize(&m_hRpcPipe, hPipe, FALSE); + + *phr = ::CoCreateFreeThreadedMarshaler(this, &m_pFreeThreadedMarshaler); } ~CBalBootstrapperEngine() { + PipeRpcUninitiailize(&m_hRpcPipe); ReleaseObject(m_pFreeThreadedMarshaler); } private: long m_cReferences; - PFN_BOOTSTRAPPER_ENGINE_PROC m_pfnBAEngineProc; - LPVOID m_pvBAEngineProcContext; + PIPE_RPC_HANDLE m_hRpcPipe; IUnknown* m_pFreeThreadedMarshaler; }; + HRESULT BalBootstrapperEngineCreate( - __in PFN_BOOTSTRAPPER_ENGINE_PROC pfnBAEngineProc, - __in_opt LPVOID pvBAEngineProcContext, + __in HANDLE hPipe, __out IBootstrapperEngine** ppBootstrapperEngine ) { HRESULT hr = S_OK; CBalBootstrapperEngine* pBootstrapperEngine = NULL; - pBootstrapperEngine = new CBalBootstrapperEngine(pfnBAEngineProc, pvBAEngineProcContext); + pBootstrapperEngine = new CBalBootstrapperEngine(hPipe, &hr); ExitOnNull(pBootstrapperEngine, hr, E_OUTOFMEMORY, "Failed to allocate new BalBootstrapperEngine object."); - - hr = pBootstrapperEngine->Init(); - ExitOnFailure(hr, "Failed to initialize CBalBootstrapperEngine."); + ExitOnFailure(hr, "Failed to initialize BalBootstrapperEngine."); hr = pBootstrapperEngine->QueryInterface(IID_PPV_ARGS(ppBootstrapperEngine)); ExitOnFailure(hr, "Failed to QI for IBootstrapperEngine from BalBootstrapperEngine object."); -- cgit v1.2.3-55-g6feb