summaryrefslogtreecommitdiff
path: root/src/burn/engine/baengine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/burn/engine/baengine.cpp')
-rw-r--r--src/burn/engine/baengine.cpp1532
1 files changed, 1532 insertions, 0 deletions
diff --git a/src/burn/engine/baengine.cpp b/src/burn/engine/baengine.cpp
new file mode 100644
index 00000000..e63836f4
--- /dev/null
+++ b/src/burn/engine/baengine.cpp
@@ -0,0 +1,1532 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3#include "precomp.h"
4
5
6static DWORD WINAPI BAEngineMessagePumpThreadProc(
7 __in LPVOID lpThreadParameter
8);
9static void CALLBACK FreeQueueItem(
10 __in void* pvValue,
11 __in void* /*pvContext*/
12);
13
14
15extern "C" HRESULT BAEngineCreateContext(
16 __in BURN_ENGINE_STATE *pEngineState,
17 __inout BAENGINE_CONTEXT** ppContext
18)
19{
20 HRESULT hr = S_OK;
21 BAENGINE_CONTEXT* pContext = NULL;
22
23 pContext = static_cast<BAENGINE_CONTEXT*>(MemAlloc(sizeof(BAENGINE_CONTEXT), TRUE));
24 ExitOnNull(pContext, hr, E_OUTOFMEMORY, "Failed to allocate bootstrapper application engine context.");
25
26 ::InitializeCriticalSection(&pContext->csQueue);
27
28 pContext->hQueueSemaphore = ::CreateSemaphoreW(NULL, 0, LONG_MAX, NULL);
29 ExitOnNullWithLastError(pContext->hQueueSemaphore, hr, "Failed to create semaphore for queue.");
30
31 hr = QueCreate(&pContext->hQueue);
32 ExitOnFailure(hr, "Failed to create queue for bootstrapper engine.");
33
34 pContext->pEngineState = pEngineState;
35
36 *ppContext = pContext;
37 pContext = NULL;
38
39LExit:
40 if (pContext)
41 {
42 BAEngineFreeContext(pContext);
43 pContext = NULL;
44 }
45
46 return hr;
47}
48
49extern "C" void BAEngineFreeContext(
50 __in BAENGINE_CONTEXT* pContext
51)
52{
53 PipeRpcUninitiailize(&pContext->hRpcPipe);
54 ReleaseQueue(pContext->hQueue, FreeQueueItem, pContext);
55 ReleaseHandle(pContext->hQueueSemaphore);
56 ::DeleteCriticalSection(&pContext->csQueue);
57}
58
59extern "C" void DAPI BAEngineFreeAction(
60 __in BAENGINE_ACTION * pAction
61)
62{
63 switch (pAction->dwMessage)
64 {
65 case WM_BURN_LAUNCH_APPROVED_EXE:
66 ApprovedExesUninitializeLaunch(&pAction->launchApprovedExe);
67 break;
68 }
69
70 MemFree(pAction);
71}
72
73extern "C" HRESULT BAEngineStartListening(
74 __in BAENGINE_CONTEXT *pContext,
75 __in HANDLE hBAEnginePipe
76)
77{
78 HRESULT hr = S_OK;
79
80 if (PipeRpcInitialized(&pContext->hRpcPipe))
81 {
82 ExitWithRootFailure(hr, E_INVALIDARG, "Bootstrapper application engine already listening on a pipe.");
83 }
84
85 PipeRpcInitialize(&pContext->hRpcPipe, hBAEnginePipe, TRUE);
86
87 pContext->hThread = ::CreateThread(NULL, 0, BAEngineMessagePumpThreadProc, pContext, 0, NULL);
88 ExitOnNullWithLastError(pContext->hThread, hr, "Failed to create bootstrapper application engine thread.");
89
90LExit:
91 return hr;
92}
93
94extern "C" HRESULT BAEngineStopListening(
95 __in BAENGINE_CONTEXT * pContext
96)
97{
98 HRESULT hr = S_OK;
99
100 // If the pipe was open, this should cause the bootstrapper application engine pipe thread to stop pumping messages and exit.
101 if (PipeRpcInitialized(&pContext->hRpcPipe))
102 {
103 PipeWriteDisconnect(pContext->hRpcPipe.hPipe);
104
105 PipeRpcUninitiailize(&pContext->hRpcPipe);
106 }
107
108 if (pContext->hThread)
109 {
110 hr = AppWaitForSingleObject(pContext->hThread, INFINITE);
111
112 ReleaseHandle(pContext->hThread); // always release the thread, no matter if we were able to wait for it to join or not.
113
114 ExitOnFailure(hr, "Failed to wait for bootstrapper application engine pipe thread.");
115 }
116
117LExit:
118 return hr;
119}
120
121static void CALLBACK FreeQueueItem(
122 __in void* pvValue,
123 __in void* /*pvContext*/
124)
125{
126 BAENGINE_ACTION* pAction = reinterpret_cast<BAENGINE_ACTION*>(pvValue);
127
128 LogId(REPORT_WARNING, MSG_IGNORE_OPERATION_AFTER_QUIT, LoggingBurnMessageToString(pAction->dwMessage));
129
130 BAEngineFreeAction(pAction);
131 MemFree(pAction);
132}
133
134static HRESULT BAEngineGetPackageCount(
135 __in BAENGINE_CONTEXT* pContext,
136 __in BUFF_READER* pReaderArgs,
137 __in BUFF_READER* pReaderResults,
138 __in BUFF_BUFFER* pBuffer
139 )
140{
141 HRESULT hr = S_OK;
142 BAENGINE_GETPACKAGECOUNT_ARGS args = { };
143 BAENGINE_GETPACKAGECOUNT_RESULTS results = { };
144
145 // Read args.
146 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
147 ExitOnFailure(hr, "Failed to read API version of BAEngineGetPackageCount args.");
148
149 // Read results.
150 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
151 ExitOnFailure(hr, "Failed to read API version of BAEngineGetPackageCount results.");
152
153 // Execute.
154 ExternalEngineGetPackageCount(pContext->pEngineState, &results.cPackages);
155
156 // Write results.
157 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
158 ExitOnFailure(hr, "Failed to write size of BAEngineGetPackageCount struct.");
159
160 hr = BuffWriteNumberToBuffer(pBuffer, results.cPackages);
161 ExitOnFailure(hr, "Failed to write length of value of BAEngineGetPackageCount struct.");
162
163LExit:
164 return hr;
165}
166
167static HRESULT BAEngineGetVariableNumeric(
168 __in BAENGINE_CONTEXT* pContext,
169 __in BUFF_READER* pReaderArgs,
170 __in BUFF_READER* pReaderResults,
171 __in BUFF_BUFFER* pBuffer
172 )
173{
174 HRESULT hr = S_OK;
175 BAENGINE_GETVARIABLENUMERIC_ARGS args = { };
176 BAENGINE_GETVARIABLENUMERIC_RESULTS results = { };
177 LPWSTR sczVariable = NULL;
178
179 // Read args.
180 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
181 ExitOnFailure(hr, "Failed to read API version of BAEngineGetVariableNumeric args.");
182
183 hr = BuffReaderReadString(pReaderArgs, &sczVariable);
184 ExitOnFailure(hr, "Failed to read variable name of BAEngineGetVariableNumeric args.");
185
186 args.wzVariable = sczVariable;
187
188 // Read results.
189 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
190 ExitOnFailure(hr, "Failed to read API version of BAEngineGetVariableNumeric results.");
191
192 // Execute.
193 hr = ExternalEngineGetVariableNumeric(pContext->pEngineState, args.wzVariable, &results.llValue);
194
195 // Write results.
196 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
197 ExitOnFailure(hr, "Failed to write size of BAEngineGetVariableNumeric struct.");
198
199 hr = BuffWriteNumber64ToBuffer(pBuffer, (DWORD64)results.llValue);
200 ExitOnFailure(hr, "Failed to write length of value of BAEngineGetVariableNumeric struct.");
201
202LExit:
203 ReleaseStr(sczVariable);
204 return hr;
205}
206
207static HRESULT BAEngineGetVariableString(
208 __in BAENGINE_CONTEXT* pContext,
209 __in BUFF_READER* pReaderArgs,
210 __in BUFF_READER* pReaderResults,
211 __in BUFF_BUFFER* pBuffer
212 )
213{
214 HRESULT hr = S_OK;
215 BAENGINE_GETVARIABLESTRING_ARGS args = { };
216 BAENGINE_GETVARIABLESTRING_RESULTS results = { };
217 LPWSTR sczVariable = NULL;
218 LPWSTR sczValue = NULL;
219 DWORD cchValue = 0;
220
221 // Read args.
222 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
223 ExitOnFailure(hr, "Failed to read API version of BAEngineGetVariableString args.");
224
225 hr = BuffReaderReadString(pReaderArgs, &sczVariable);
226 ExitOnFailure(hr, "Failed to read variable name of BAEngineGetVariableString args.");
227
228 args.wzVariable = sczVariable;
229
230 // Read results.
231 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
232 ExitOnFailure(hr, "Failed to read API version of BAEngineGetVariableString results.");
233
234 hr = BuffReaderReadNumber(pReaderResults, &cchValue);
235 ExitOnFailure(hr, "Failed to read API version of BAEngineGetVariableString results.");
236
237 results.cchValue = cchValue;
238
239 // Execute.
240 hr = VariableGetString(&pContext->pEngineState->variables, args.wzVariable, &sczValue);
241 if (E_NOTFOUND == hr)
242 {
243 ExitFunction();
244 }
245 ExitOnFailure(hr, "Failed to get string variable: %ls", sczVariable);
246
247 results.cchValue = lstrlenW(sczValue);
248 results.wzValue = sczValue;
249
250 // Write results.
251 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
252 ExitOnFailure(hr, "Failed to write size of BAEngineGetVariableString struct.");
253
254 hr = BuffWriteNumberToBuffer(pBuffer, results.cchValue);
255 ExitOnFailure(hr, "Failed to write length of value of BAEngineGetVariableString struct.");
256
257 hr = BuffWriteStringToBuffer(pBuffer, results.wzValue);
258 ExitOnFailure(hr, "Failed to write value of BAEngineGetVariableString struct.");
259
260LExit:
261 ReleaseStr(sczValue);
262 ReleaseStr(sczVariable);
263
264 return hr;
265}
266
267static HRESULT BAEngineGetVariableVersion(
268 __in BAENGINE_CONTEXT* pContext,
269 __in BUFF_READER* pReaderArgs,
270 __in BUFF_READER* pReaderResults,
271 __in BUFF_BUFFER* pBuffer
272 )
273{
274 HRESULT hr = S_OK;
275 BAENGINE_GETVARIABLEVERSION_ARGS args = { };
276 BAENGINE_GETVARIABLEVERSION_RESULTS results = { };
277 LPWSTR sczVariable = NULL;
278 VERUTIL_VERSION* pVersion = NULL;
279 DWORD cchValue = 0;
280
281 // Read args.
282 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
283 ExitOnFailure(hr, "Failed to read API version of BAEngineGetVariableVersion args.");
284
285 hr = BuffReaderReadString(pReaderArgs, &sczVariable);
286 ExitOnFailure(hr, "Failed to read variable name of BAEngineGetVariableVersion args.");
287
288 args.wzVariable = sczVariable;
289
290 // Read results.
291 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
292 ExitOnFailure(hr, "Failed to read API version of BAEngineGetVariableVersion results.");
293
294 hr = BuffReaderReadNumber(pReaderResults, &cchValue);
295 ExitOnFailure(hr, "Failed to read API version of BAEngineGetVariableVersion results.");
296
297 results.cchValue = cchValue;
298
299 // Execute.
300 hr = VariableGetVersion(&pContext->pEngineState->variables, args.wzVariable, &pVersion);
301 ExitOnFailure(hr, "Failed to get version variable: %ls", sczVariable);
302
303 results.cchValue = lstrlenW(pVersion->sczVersion);
304 results.wzValue = pVersion->sczVersion;
305
306 // Write results.
307 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
308 ExitOnFailure(hr, "Failed to write size of BAEngineGetVariableVersion struct.");
309
310 hr = BuffWriteNumberToBuffer(pBuffer, results.cchValue);
311 ExitOnFailure(hr, "Failed to write length of value of BAEngineGetVariableVersion struct.");
312
313 hr = BuffWriteStringToBuffer(pBuffer, results.wzValue);
314 ExitOnFailure(hr, "Failed to write value of BAEngineGetVariableVersion struct.");
315
316LExit:
317 ReleaseVerutilVersion(pVersion);
318 ReleaseStr(sczVariable);
319
320 return hr;
321}
322
323static HRESULT BAEngineGetRelatedBundleVariable(
324 __in BAENGINE_CONTEXT* /* pContext */,
325 __in BUFF_READER* pReaderArgs,
326 __in BUFF_READER* pReaderResults,
327 __in BUFF_BUFFER* pBuffer
328 )
329{
330 HRESULT hr = S_OK;
331 BAENGINE_GETRELATEDBUNDLEVARIABLE_ARGS args = { };
332 BAENGINE_GETRELATEDBUNDLEVARIABLE_RESULTS results = { };
333 LPWSTR sczBundleId = NULL;
334 LPWSTR sczVariable = NULL;
335 LPWSTR sczValue = NULL;
336
337 // Read args.
338 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
339 ExitOnFailure(hr, "Failed to read API version of BAEngineGetRelatedBundleVariable args.");
340
341 hr = BuffReaderReadString(pReaderArgs, &sczBundleId);
342 ExitOnFailure(hr, "Failed to read bundle id of BAEngineGetRelatedBundleVariable args.");
343
344 hr = BuffReaderReadString(pReaderArgs, &sczVariable);
345 ExitOnFailure(hr, "Failed to read variable name of BAEngineGetRelatedBundleVariable args.");
346
347 args.wzBundleId = sczBundleId;
348 args.wzVariable = sczVariable;
349
350 // Read results.
351 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
352 ExitOnFailure(hr, "Failed to read API version of BAEngineGetRelatedBundleVariable results.");
353
354 hr = BuffReaderReadNumber(pReaderResults, &results.cchValue); // ignored, overwritten below.
355 ExitOnFailure(hr, "Failed to read API version of BAEngineGetRelatedBundleVariable results.");
356
357 // Execute.
358 hr = BundleGetBundleVariable(args.wzBundleId, args.wzVariable, &sczValue);
359 ExitOnFailure(hr, "Failed to get related bundle variable: %ls", sczVariable);
360
361 results.cchValue = lstrlenW(sczValue);
362 results.wzValue = sczValue;
363
364 // Write results.
365 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
366 ExitOnFailure(hr, "Failed to write size of BAEngineGetRelatedBundleVariable struct.");
367
368 hr = BuffWriteNumberToBuffer(pBuffer, results.cchValue);
369 ExitOnFailure(hr, "Failed to write length of value of BAEngineGetRelatedBundleVariable struct.");
370
371 hr = BuffWriteStringToBuffer(pBuffer, results.wzValue);
372 ExitOnFailure(hr, "Failed to write value of BAEngineGetRelatedBundleVariable struct.");
373
374LExit:
375 ReleaseStr(sczValue);
376 ReleaseStr(sczVariable);
377 ReleaseStr(sczBundleId);
378
379 return hr;
380}
381
382static HRESULT BAEngineFormatString(
383 __in BAENGINE_CONTEXT* pContext,
384 __in BUFF_READER* pReaderArgs,
385 __in BUFF_READER* pReaderResults,
386 __in BUFF_BUFFER* pBuffer
387 )
388{
389 HRESULT hr = S_OK;
390 BAENGINE_FORMATSTRING_ARGS args = { };
391 BAENGINE_FORMATSTRING_RESULTS results = { };
392 LPWSTR sczIn = NULL;
393 LPWSTR sczOut = NULL;
394 SIZE_T cchOut = 0;
395
396 // Read args.
397 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
398 ExitOnFailure(hr, "Failed to read API version of BAEngineFormatString args.");
399
400 hr = BuffReaderReadString(pReaderArgs, &sczIn);
401 ExitOnFailure(hr, "Failed to read string to format of BAEngineFormatString args.");
402
403 args.wzIn = sczIn;
404
405 // Read results.
406 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
407 ExitOnFailure(hr, "Failed to read API version of BAEngineFormatString results.");
408
409 hr = BuffReaderReadNumber(pReaderResults, &results.cchOut); // ignored, overwritten below.
410 ExitOnFailure(hr, "Failed to read allowed length of formatted string of BAEngineFormatString results.");
411
412 // Execute.
413 hr = VariableFormatString(&pContext->pEngineState->variables, args.wzIn, &sczOut, &cchOut);
414 ExitOnFailure(hr, "Failed to format string");
415
416 results.cchOut = (cchOut > DWORD_MAX) ? DWORD_MAX : static_cast<DWORD>(cchOut);
417 results.wzOut = sczOut;
418
419 // Write results.
420 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
421 ExitOnFailure(hr, "Failed to write size of BAEngineFormatString struct.");
422
423 hr = BuffWriteNumberToBuffer(pBuffer, results.cchOut);
424 ExitOnFailure(hr, "Failed to write length of formatted string of BAEngineFormatString struct.");
425
426 hr = BuffWriteStringToBuffer(pBuffer, results.wzOut);
427 ExitOnFailure(hr, "Failed to write formatted string of BAEngineFormatString struct.");
428
429LExit:
430 ReleaseStr(sczOut);
431 ReleaseStr(sczIn);
432
433 return hr;
434}
435
436static HRESULT BAEngineEscapeString(
437 __in BAENGINE_CONTEXT* /* pContext */,
438 __in BUFF_READER* pReaderArgs,
439 __in BUFF_READER* pReaderResults,
440 __in BUFF_BUFFER* pBuffer
441 )
442{
443 HRESULT hr = S_OK;
444 BAENGINE_ESCAPESTRING_ARGS args = { };
445 BAENGINE_ESCAPESTRING_RESULTS results = { };
446 LPWSTR sczIn = NULL;
447 LPWSTR sczOut = NULL;
448
449 // Read args.
450 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
451 ExitOnFailure(hr, "Failed to read API version of BAEngineEscapeString args.");
452
453 hr = BuffReaderReadString(pReaderArgs, &sczIn);
454 ExitOnFailure(hr, "Failed to read string to escape of BAEngineEscapeString args.");
455
456 args.wzIn = sczIn;
457
458 // Read results.
459 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
460 ExitOnFailure(hr, "Failed to read API version of BAEngineEscapeString results.");
461
462 hr = BuffReaderReadNumber(pReaderResults, &results.cchOut); // ignored, overwritten below.
463 ExitOnFailure(hr, "Failed to read allowed length of escaped string of BAEngineEscapeString results.");
464
465 // Execute.
466 hr = VariableEscapeString(args.wzIn, &sczOut);
467 ExitOnFailure(hr, "Failed to format string");
468
469 results.cchOut = lstrlenW(sczOut);
470 results.wzOut = sczOut;
471
472 // Write results.
473 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
474 ExitOnFailure(hr, "Failed to write size of BAEngineEscapeString struct.");
475
476 hr = BuffWriteNumberToBuffer(pBuffer, results.cchOut);
477 ExitOnFailure(hr, "Failed to write length of formatted string of BAEngineEscapeString struct.");
478
479 hr = BuffWriteStringToBuffer(pBuffer, results.wzOut);
480 ExitOnFailure(hr, "Failed to write formatted string of BAEngineEscapeString struct.");
481
482LExit:
483 ReleaseStr(sczOut);
484 ReleaseStr(sczIn);
485
486 return hr;
487}
488
489static HRESULT BAEngineEvaluateCondition(
490 __in BAENGINE_CONTEXT* pContext,
491 __in BUFF_READER* pReaderArgs,
492 __in BUFF_READER* pReaderResults,
493 __in BUFF_BUFFER* pBuffer
494 )
495{
496 HRESULT hr = S_OK;
497 BAENGINE_EVALUATECONDITION_ARGS args = { };
498 BAENGINE_EVALUATECONDITION_RESULTS results = { };
499 LPWSTR sczCondition = NULL;
500
501 // Read args.
502 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
503 ExitOnFailure(hr, "Failed to read API version of BAEngineEvaluateCondition args.");
504
505 hr = BuffReaderReadString(pReaderArgs, &sczCondition);
506 ExitOnFailure(hr, "Failed to read condition of BAEngineEvaluateCondition args.");
507
508 args.wzCondition = sczCondition;
509
510 // Read results.
511 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
512 ExitOnFailure(hr, "Failed to read API version of BAEngineEvaluateCondition results.");
513
514 // Execute.
515 hr = ConditionEvaluate(&pContext->pEngineState->variables, args.wzCondition, &results.f);
516 ExitOnFailure(hr, "Failed to evalute condition.");
517
518 // Write results.
519 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
520 ExitOnFailure(hr, "Failed to write size of BAEngineEvaluateCondition struct.");
521
522 hr = BuffWriteNumberToBuffer(pBuffer, results.f);
523 ExitOnFailure(hr, "Failed to result of BAEngineEvaluateCondition struct.");
524
525LExit:
526 ReleaseStr(sczCondition);
527
528 return hr;
529}
530
531static HRESULT BAEngineLog(
532 __in BUFF_READER* pReaderArgs,
533 __in BUFF_READER* pReaderResults,
534 __in BUFF_BUFFER* pBuffer
535 )
536{
537 HRESULT hr = S_OK;
538 BAENGINE_LOG_ARGS args = { };
539 BAENGINE_LOG_RESULTS results = { };
540 LPWSTR sczMessage = NULL;
541 REPORT_LEVEL rl = REPORT_NONE;
542
543 // Read args.
544 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
545 ExitOnFailure(hr, "Failed to read API version of BAEngineLog args.");
546
547 hr = BuffReaderReadNumber(pReaderArgs, reinterpret_cast<DWORD*>(&args.level));
548 ExitOnFailure(hr, "Failed to read API version of BAEngineLog args.");
549
550 hr = BuffReaderReadString(pReaderArgs, &sczMessage);
551 ExitOnFailure(hr, "Failed to read variable name of BAEngineLog args.");
552
553 switch (args.level)
554 {
555 case BOOTSTRAPPER_LOG_LEVEL_STANDARD:
556 rl = REPORT_STANDARD;
557 break;
558
559 case BOOTSTRAPPER_LOG_LEVEL_VERBOSE:
560 rl = REPORT_VERBOSE;
561 break;
562
563 case BOOTSTRAPPER_LOG_LEVEL_DEBUG:
564 rl = REPORT_DEBUG;
565 break;
566
567 case BOOTSTRAPPER_LOG_LEVEL_ERROR:
568 rl = REPORT_ERROR;
569 break;
570
571 default:
572 ExitFunction1(hr = E_INVALIDARG);
573 }
574
575 args.wzMessage = sczMessage;
576
577 // Read results.
578 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
579 ExitOnFailure(hr, "Failed to read API version of BAEngineLog results.");
580
581 // Execute.
582 hr = ExternalEngineLog(rl, args.wzMessage);
583 ExitOnFailure(hr, "Failed to log BA message.");
584
585 // Write results.
586 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
587 ExitOnFailure(hr, "Failed to write size of BAEngineLog struct.");
588
589LExit:
590 ReleaseStr(sczMessage);
591 return hr;
592}
593
594static HRESULT BAEngineSendEmbeddedError(
595 __in BAENGINE_CONTEXT* pContext,
596 __in BUFF_READER* pReaderArgs,
597 __in BUFF_READER* pReaderResults,
598 __in BUFF_BUFFER* pBuffer
599 )
600{
601 HRESULT hr = S_OK;
602 BAENGINE_SENDEMBEDDEDERROR_ARGS args = { };
603 BAENGINE_SENDEMBEDDEDERROR_RESULTS results = { };
604 LPWSTR sczMessage = NULL;
605
606 // Read args.
607 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
608 ExitOnFailure(hr, "Failed to read API version of BAEngineSendEmbeddedError args.");
609
610 hr = BuffReaderReadNumber(pReaderArgs, &args.dwErrorCode);
611 ExitOnFailure(hr, "Failed to read error code of BAEngineSendEmbeddedError args.");
612
613 hr = BuffReaderReadString(pReaderArgs, &sczMessage);
614 ExitOnFailure(hr, "Failed to read condition of BAEngineSendEmbeddedError args.");
615
616 args.wzMessage = sczMessage;
617
618 hr = BuffReaderReadNumber(pReaderArgs, &args.dwUIHint);
619 ExitOnFailure(hr, "Failed to read UI hint of BAEngineSendEmbeddedError args.");
620
621 // Read results.
622 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
623 ExitOnFailure(hr, "Failed to read API version of BAEngineSendEmbeddedError results.");
624
625 // Execute.
626 hr = ExternalEngineSendEmbeddedError(pContext->pEngineState, args.dwErrorCode, args.wzMessage, args.dwUIHint, &results.nResult);
627 ExitOnFailure(hr, "Failed to send embedded error.");
628
629 // Write results.
630 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
631 ExitOnFailure(hr, "Failed to write size of BAEngineSendEmbeddedError struct.");
632
633 hr = BuffWriteNumberToBuffer(pBuffer, results.nResult);
634 ExitOnFailure(hr, "Failed to result of BAEngineSendEmbeddedError struct.");
635
636LExit:
637 ReleaseStr(sczMessage);
638 return hr;
639}
640
641static HRESULT BAEngineSendEmbeddedProgress(
642 __in BAENGINE_CONTEXT* pContext,
643 __in BUFF_READER* pReaderArgs,
644 __in BUFF_READER* pReaderResults,
645 __in BUFF_BUFFER* pBuffer
646 )
647{
648 HRESULT hr = S_OK;
649 BAENGINE_SENDEMBEDDEDPROGRESS_ARGS args = { };
650 BAENGINE_SENDEMBEDDEDPROGRESS_RESULTS results = { };
651
652 // Read args.
653 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
654 ExitOnFailure(hr, "Failed to read API version of BAEngineSendEmbeddedProgress args.");
655
656 hr = BuffReaderReadNumber(pReaderArgs, &args.dwProgressPercentage);
657 ExitOnFailure(hr, "Failed to read progress of BAEngineSendEmbeddedProgress args.");
658
659 hr = BuffReaderReadNumber(pReaderArgs, &args.dwOverallProgressPercentage);
660 ExitOnFailure(hr, "Failed to read overall progress of BAEngineSendEmbeddedProgress args.");
661
662 // Read results.
663 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
664 ExitOnFailure(hr, "Failed to read API version of BAEngineSendEmbeddedProgress results.");
665
666 // Execute.
667 hr = ExternalEngineSendEmbeddedProgress(pContext->pEngineState, args.dwProgressPercentage, args.dwOverallProgressPercentage, &results.nResult);
668 ExitOnFailure(hr, "Failed to send embedded error.");
669
670 // Write results.
671 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
672 ExitOnFailure(hr, "Failed to write size of BAEngineSendEmbeddedProgress struct.");
673
674 hr = BuffWriteNumberToBuffer(pBuffer, results.nResult);
675 ExitOnFailure(hr, "Failed to result of BAEngineSendEmbeddedProgress struct.");
676
677LExit:
678 return hr;
679}
680
681static HRESULT BAEngineSetUpdate(
682 __in BAENGINE_CONTEXT* pContext,
683 __in BUFF_READER* pReaderArgs,
684 __in BUFF_READER* pReaderResults,
685 __in BUFF_BUFFER* pBuffer
686 )
687{
688 HRESULT hr = S_OK;
689 BAENGINE_SETUPDATE_ARGS args = { };
690 BAENGINE_SETUPDATE_RESULTS results = { };
691 LPWSTR sczLocalSource = NULL;
692 LPWSTR sczDownloadSource = NULL;
693 LPWSTR sczHash = NULL;
694 LPWSTR sczUpdatePackageId = NULL;
695
696 // Read args.
697 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
698 ExitOnFailure(hr, "Failed to read API version of BAEngineSetUpdate args.");
699
700 hr = BuffReaderReadString(pReaderArgs, &sczLocalSource);
701 ExitOnFailure(hr, "Failed to read local source of BAEngineSetUpdate args.");
702
703 args.wzLocalSource = sczLocalSource;
704
705 hr = BuffReaderReadString(pReaderArgs, &sczDownloadSource);
706 ExitOnFailure(hr, "Failed to read download source of BAEngineSetUpdate args.");
707
708 args.wzDownloadSource = sczDownloadSource;
709
710 hr = BuffReaderReadNumber64(pReaderArgs, &args.qwSize);
711 ExitOnFailure(hr, "Failed to read update size of BAEngineSetUpdate args.");
712
713 hr = BuffReaderReadNumber(pReaderArgs, reinterpret_cast<DWORD*>(&args.hashType));
714 ExitOnFailure(hr, "Failed to read hash type of BAEngineSetUpdate args.");
715
716 hr = BuffReaderReadString(pReaderArgs, &sczHash);
717 ExitOnFailure(hr, "Failed to read hash of BAEngineSetUpdate args.");
718
719 args.wzHash = sczHash;
720
721 hr = BuffReaderReadString(pReaderArgs, &sczUpdatePackageId);
722 ExitOnFailure(hr, "Failed to read update package id of BAEngineSetUpdate args.");
723
724 args.wzUpdatePackageId = sczUpdatePackageId;
725
726 // Read results.
727 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
728 ExitOnFailure(hr, "Failed to read API version of BAEngineSetUpdate results.");
729
730 // Execute.
731 hr = ExternalEngineSetUpdate(pContext->pEngineState, args.wzLocalSource, args.wzDownloadSource, args.qwSize, args.hashType, args.wzHash, args.wzUpdatePackageId);
732 ExitOnFailure(hr, "Failed to set update.");
733
734 // Write results.
735 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
736 ExitOnFailure(hr, "Failed to write size of BAEngineSetUpdate struct.");
737
738LExit:
739 ReleaseStr(sczUpdatePackageId);
740 ReleaseStr(sczHash);
741 ReleaseStr(sczDownloadSource);
742 ReleaseStr(sczLocalSource);
743 return hr;
744}
745
746static HRESULT BAEngineSetLocalSource(
747 __in BAENGINE_CONTEXT* pContext,
748 __in BUFF_READER* pReaderArgs,
749 __in BUFF_READER* pReaderResults,
750 __in BUFF_BUFFER* pBuffer
751 )
752{
753 HRESULT hr = S_OK;
754 BAENGINE_SETLOCALSOURCE_ARGS args = { };
755 BAENGINE_SETLOCALSOURCE_RESULTS results = { };
756 LPWSTR sczPackageOrContainerId = NULL;
757 LPWSTR sczPayloadId = NULL;
758 LPWSTR sczPath = NULL;
759
760 // Read args.
761 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
762 ExitOnFailure(hr, "Failed to read API version of BAEngineSetLocalSource args.");
763
764 hr = BuffReaderReadString(pReaderArgs, &sczPackageOrContainerId);
765 ExitOnFailure(hr, "Failed to read package or container id of BAEngineSetLocalSource args.");
766
767 args.wzPackageOrContainerId = sczPackageOrContainerId;
768
769 hr = BuffReaderReadString(pReaderArgs, &sczPayloadId);
770 ExitOnFailure(hr, "Failed to read payload id of BAEngineSetLocalSource args.");
771
772 args.wzPayloadId = sczPayloadId;
773
774 hr = BuffReaderReadString(pReaderArgs, &sczPath);
775 ExitOnFailure(hr, "Failed to read path of BAEngineSetLocalSource args.");
776
777 args.wzPath = sczPath;
778
779 // Read results.
780 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
781 ExitOnFailure(hr, "Failed to read API version of BAEngineSetLocalSource results.");
782
783 // Execute.
784 hr = ExternalEngineSetLocalSource(pContext->pEngineState, args.wzPackageOrContainerId, args.wzPayloadId, args.wzPath);
785 ExitOnFailure(hr, "Failed to set local source.");
786
787 // Write results.
788 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
789 ExitOnFailure(hr, "Failed to write size of BAEngineSetLocalSource struct.");
790
791LExit:
792 ReleaseStr(sczPath);
793 ReleaseStr(sczPayloadId);
794 ReleaseStr(sczPackageOrContainerId);
795 return hr;
796}
797
798static HRESULT BAEngineSetDownloadSource(
799 __in BAENGINE_CONTEXT* pContext,
800 __in BUFF_READER* pReaderArgs,
801 __in BUFF_READER* pReaderResults,
802 __in BUFF_BUFFER* pBuffer
803 )
804{
805 HRESULT hr = S_OK;
806 BAENGINE_SETDOWNLOADSOURCE_ARGS args = { };
807 BAENGINE_SETDOWNLOADSOURCE_RESULTS results = { };
808 LPWSTR sczPackageOrContainerId = NULL;
809 LPWSTR sczPayloadId = NULL;
810 LPWSTR sczUrl = NULL;
811 LPWSTR sczUser = NULL;
812 LPWSTR sczPassword = NULL;
813 LPWSTR sczAuthorizationHeader = NULL;
814
815 // Read args.
816 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
817 ExitOnFailure(hr, "Failed to read API version of BAEngineSetDownloadSource args.");
818
819 hr = BuffReaderReadString(pReaderArgs, &sczPackageOrContainerId);
820 ExitOnFailure(hr, "Failed to read package or container id of BAEngineSetDownloadSource args.");
821
822 args.wzPackageOrContainerId = sczPackageOrContainerId;
823
824 hr = BuffReaderReadString(pReaderArgs, &sczPayloadId);
825 ExitOnFailure(hr, "Failed to read payload id of BAEngineSetDownloadSource args.");
826
827 args.wzPayloadId = sczPayloadId;
828
829 hr = BuffReaderReadString(pReaderArgs, &sczUrl);
830 ExitOnFailure(hr, "Failed to read url of BAEngineSetDownloadSource args.");
831
832 args.wzUrl = sczUrl;
833
834 hr = BuffReaderReadString(pReaderArgs, &sczUser);
835 ExitOnFailure(hr, "Failed to read user of BAEngineSetDownloadSource args.");
836
837 args.wzUser = sczUser;
838
839 hr = BuffReaderReadString(pReaderArgs, &sczPassword);
840 ExitOnFailure(hr, "Failed to read password of BAEngineSetDownloadSource args.");
841
842 args.wzPassword = sczPassword;
843
844 hr = BuffReaderReadString(pReaderArgs, &sczAuthorizationHeader);
845 ExitOnFailure(hr, "Failed to read authorization header of BAEngineSetDownloadSource args.");
846
847 args.wzAuthorizationHeader = sczAuthorizationHeader;
848
849 // Read results.
850 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
851 ExitOnFailure(hr, "Failed to read API version of BAEngineSetDownloadSource results.");
852
853 // Execute.
854 hr = ExternalEngineSetDownloadSource(pContext->pEngineState, args.wzPackageOrContainerId, args.wzPayloadId, args.wzUrl, args.wzUser, args.wzPassword, args.wzAuthorizationHeader);
855 ExitOnFailure(hr, "Failed to set download source.");
856
857 // Write results.
858 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
859 ExitOnFailure(hr, "Failed to write size of BAEngineSetDownloadSource struct.");
860
861LExit:
862 ReleaseStr(sczAuthorizationHeader);
863 ReleaseStr(sczPassword);
864 ReleaseStr(sczUser);
865 ReleaseStr(sczUrl);
866 ReleaseStr(sczPayloadId);
867 ReleaseStr(sczPackageOrContainerId);
868 return hr;
869}
870
871
872static HRESULT BAEngineSetVariableNumeric(
873 __in BAENGINE_CONTEXT* pContext,
874 __in BUFF_READER* pReaderArgs,
875 __in BUFF_READER* pReaderResults,
876 __in BUFF_BUFFER* pBuffer
877 )
878{
879 HRESULT hr = S_OK;
880 BAENGINE_SETVARIABLENUMERIC_ARGS args = { };
881 BAENGINE_SETVARIABLENUMERIC_RESULTS results = { };
882 LPWSTR sczVariable = NULL;
883
884 // Read args.
885 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
886 ExitOnFailure(hr, "Failed to read API version of BAEngineSetVariableNumeric args.");
887
888 hr = BuffReaderReadString(pReaderArgs, &sczVariable);
889 ExitOnFailure(hr, "Failed to read variable of BAEngineSetVariableNumeric args.");
890
891 args.wzVariable = sczVariable;
892
893 hr = BuffReaderReadNumber64(pReaderArgs, reinterpret_cast<DWORD64*>(&args.llValue));
894 ExitOnFailure(hr, "Failed to read formatted flag of BAEngineSetVariableNumeric results.");
895
896 // Read results.
897 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
898 ExitOnFailure(hr, "Failed to read API version of BAEngineSetVariableNumeric results.");
899
900 // Execute.
901 hr = ExternalEngineSetVariableNumeric(pContext->pEngineState, args.wzVariable, args.llValue);
902 ExitOnFailure(hr, "Failed to set numeric variable.");
903
904 // Write results.
905 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
906 ExitOnFailure(hr, "Failed to write size of BAEngineSetVariableNumeric struct.");
907
908LExit:
909 ReleaseStr(sczVariable);
910 return hr;
911}
912
913static HRESULT BAEngineSetVariableString(
914 __in BAENGINE_CONTEXT* pContext,
915 __in BUFF_READER* pReaderArgs,
916 __in BUFF_READER* pReaderResults,
917 __in BUFF_BUFFER* pBuffer
918 )
919{
920 HRESULT hr = S_OK;
921 BAENGINE_SETVARIABLESTRING_ARGS args = { };
922 BAENGINE_SETVARIABLESTRING_RESULTS results = { };
923 LPWSTR sczVariable = NULL;
924 LPWSTR sczValue = NULL;
925
926 // Read args.
927 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
928 ExitOnFailure(hr, "Failed to read API version of BAEngineSetVariableString args.");
929
930 hr = BuffReaderReadString(pReaderArgs, &sczVariable);
931 ExitOnFailure(hr, "Failed to read variable of BAEngineSetVariableString args.");
932
933 args.wzVariable = sczVariable;
934
935 hr = BuffReaderReadString(pReaderArgs, &sczValue);
936 ExitOnFailure(hr, "Failed to read value of BAEngineSetVariableString args.");
937
938 args.wzValue = sczValue;
939
940 hr = BuffReaderReadNumber(pReaderArgs, reinterpret_cast<DWORD*>(&args.fFormatted));
941 ExitOnFailure(hr, "Failed to read formatted flag of BAEngineSetVariableString results.");
942
943 // Read results.
944 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
945 ExitOnFailure(hr, "Failed to read API version of BAEngineSetVariableString results.");
946
947 // Execute.
948 hr = ExternalEngineSetVariableString(pContext->pEngineState, args.wzVariable, args.wzValue, args.fFormatted);
949 ExitOnFailure(hr, "Failed to set string variable.");
950
951 // Write results.
952 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
953 ExitOnFailure(hr, "Failed to write size of BAEngineSetVariableString struct.");
954
955LExit:
956 ReleaseStr(sczValue);
957 ReleaseStr(sczVariable);
958 return hr;
959}
960
961static HRESULT BAEngineSetVariableVersion(
962 __in BAENGINE_CONTEXT* pContext,
963 __in BUFF_READER* pReaderArgs,
964 __in BUFF_READER* pReaderResults,
965 __in BUFF_BUFFER* pBuffer
966 )
967{
968 HRESULT hr = S_OK;
969 BAENGINE_SETVARIABLEVERSION_ARGS args = { };
970 BAENGINE_SETVARIABLEVERSION_RESULTS results = { };
971 LPWSTR sczVariable = NULL;
972 LPWSTR sczValue = NULL;
973
974 // Read args.
975 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
976 ExitOnFailure(hr, "Failed to read API version of BAEngineSetVariableVersion args.");
977
978 hr = BuffReaderReadString(pReaderArgs, &sczVariable);
979 ExitOnFailure(hr, "Failed to read variable of BAEngineSetVariableVersion args.");
980
981 args.wzVariable = sczVariable;
982
983 hr = BuffReaderReadString(pReaderArgs, &sczValue);
984 ExitOnFailure(hr, "Failed to read value of BAEngineSetVariableVersion args.");
985
986 args.wzValue = sczValue;
987
988 // Read results.
989 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
990 ExitOnFailure(hr, "Failed to read API version of BAEngineSetVariableVersion results.");
991
992 // Execute.
993 hr = ExternalEngineSetVariableVersion(pContext->pEngineState, args.wzVariable, args.wzValue);
994 ExitOnFailure(hr, "Failed to set variable version.");
995
996 // Write results.
997 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
998 ExitOnFailure(hr, "Failed to write size of BAEngineSetVariableVersion struct.");
999
1000LExit:
1001 ReleaseStr(sczValue);
1002 ReleaseStr(sczVariable);
1003 return hr;
1004}
1005
1006static HRESULT BAEngineCloseSplashScreen(
1007 __in BAENGINE_CONTEXT* pContext,
1008 __in BUFF_READER* pReaderArgs,
1009 __in BUFF_READER* pReaderResults,
1010 __in BUFF_BUFFER* pBuffer
1011 )
1012{
1013 HRESULT hr = S_OK;
1014 BAENGINE_CLOSESPLASHSCREEN_ARGS args = { };
1015 BAENGINE_CLOSESPLASHSCREEN_RESULTS results = { };
1016
1017 // Read args.
1018 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
1019 ExitOnFailure(hr, "Failed to read API version of BAEngineCloseSplashScreen args.");
1020
1021 // Read results.
1022 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
1023 ExitOnFailure(hr, "Failed to read API version of BAEngineCloseSplashScreen results.");
1024
1025 // Execute.
1026 ExternalEngineCloseSplashScreen(pContext->pEngineState);
1027
1028 // Write results.
1029 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
1030 ExitOnFailure(hr, "Failed to write size of BAEngineCloseSplashScreen struct.");
1031
1032LExit:
1033 return hr;
1034}
1035
1036static HRESULT BAEngineCompareVersions(
1037 __in BAENGINE_CONTEXT* /* pContext */,
1038 __in BUFF_READER* pReaderArgs,
1039 __in BUFF_READER* pReaderResults,
1040 __in BUFF_BUFFER* pBuffer
1041 )
1042{
1043 HRESULT hr = S_OK;
1044 BAENGINE_COMPAREVERSIONS_ARGS args = { };
1045 BAENGINE_COMPAREVERSIONS_RESULTS results = { };
1046 LPWSTR sczVersion1 = NULL;
1047 LPWSTR sczVersion2 = NULL;
1048
1049 // Read args.
1050 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
1051 ExitOnFailure(hr, "Failed to read API version of BAEngineCompareVersions args.");
1052
1053 hr = BuffReaderReadString(pReaderArgs, &sczVersion1);
1054 ExitOnFailure(hr, "Failed to read first input of BAEngineCompareVersions args.");
1055
1056 args.wzVersion1 = sczVersion1;
1057
1058 hr = BuffReaderReadString(pReaderArgs, &sczVersion2);
1059 ExitOnFailure(hr, "Failed to read second input of BAEngineCompareVersions args.");
1060
1061 args.wzVersion2 = sczVersion2;
1062
1063 // Read results.
1064 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
1065 ExitOnFailure(hr, "Failed to read API version of BAEngineCompareVersions results.");
1066
1067 // Execute.
1068 hr = ExternalEngineCompareVersions(args.wzVersion1, args.wzVersion2, &results.nResult);
1069 ExitOnFailure(hr, "Failed to compare versions.");
1070
1071 // Write results.
1072 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
1073 ExitOnFailure(hr, "Failed to write size of BAEngineCompareVersions struct.");
1074
1075 hr = BuffWriteNumberToBuffer(pBuffer, results.nResult);
1076 ExitOnFailure(hr, "Failed to result of BAEngineCompareVersions struct.");
1077
1078LExit:
1079 ReleaseStr(sczVersion2);
1080 ReleaseStr(sczVersion1);
1081
1082 return hr;
1083}
1084
1085static HRESULT BAEngineDetect(
1086 __in BAENGINE_CONTEXT* pContext,
1087 __in BUFF_READER* pReaderArgs,
1088 __in BUFF_READER* pReaderResults,
1089 __in BUFF_BUFFER* pBuffer
1090 )
1091{
1092 HRESULT hr = S_OK;
1093 BAENGINE_DETECT_ARGS args = { };
1094 BAENGINE_DETECT_RESULTS results = { };
1095
1096 // Read args.
1097 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
1098 ExitOnFailure(hr, "Failed to read API version of BAEngineDetect args.");
1099
1100 hr = BuffReaderReadNumber64(pReaderArgs, &args.hwndParent);
1101 ExitOnFailure(hr, "Failed to read parent window of BAEngineDetect args.");
1102
1103 // Read results.
1104 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
1105 ExitOnFailure(hr, "Failed to read API version of BAEngineDetect results.");
1106
1107 // Execute.
1108 hr = ExternalEngineDetect(pContext, reinterpret_cast<HWND>(args.hwndParent));
1109 ExitOnFailure(hr, "Failed to detect in the engine.");
1110
1111 // Pack result.
1112 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
1113 ExitOnFailure(hr, "Failed to write size of BAEngineDetect struct.");
1114
1115LExit:
1116 return hr;
1117}
1118
1119static HRESULT BAEnginePlan(
1120 __in BAENGINE_CONTEXT* pContext,
1121 __in BUFF_READER* pReaderArgs,
1122 __in BUFF_READER* pReaderResults,
1123 __in BUFF_BUFFER* pBuffer
1124 )
1125{
1126 HRESULT hr = S_OK;
1127 BAENGINE_PLAN_ARGS args = { };
1128 BAENGINE_PLAN_RESULTS results = { };
1129
1130 // Read args.
1131 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
1132 ExitOnFailure(hr, "Failed to read API version of BAEnginePlan args.");
1133
1134 hr = BuffReaderReadNumber(pReaderArgs, reinterpret_cast<DWORD*>(&args.action));
1135 ExitOnFailure(hr, "Failed to read plan action of BAEnginePlan args.");
1136
1137 // Read results.
1138 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
1139 ExitOnFailure(hr, "Failed to read API version of BAEnginePlan results.");
1140
1141 // Execute.
1142 hr = ExternalEnginePlan(pContext, args.action);
1143 ExitOnFailure(hr, "Failed to plan in the engine.");
1144
1145 // Pack result.
1146 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
1147 ExitOnFailure(hr, "Failed to write size of BAEnginePlan struct.");
1148
1149LExit:
1150 return hr;
1151}
1152
1153static HRESULT BAEngineElevate(
1154 __in BAENGINE_CONTEXT* pContext,
1155 __in BUFF_READER* pReaderArgs,
1156 __in BUFF_READER* pReaderResults,
1157 __in BUFF_BUFFER* pBuffer
1158 )
1159{
1160 HRESULT hr = S_OK;
1161 BAENGINE_ELEVATE_ARGS args = { };
1162 BAENGINE_ELEVATE_RESULTS results = { };
1163
1164 // Read args.
1165 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
1166 ExitOnFailure(hr, "Failed to read API version of BAEngineElevate args.");
1167
1168 hr = BuffReaderReadNumber64(pReaderArgs, &args.hwndParent);
1169 ExitOnFailure(hr, "Failed to read parent window of BAEngineElevate args.");
1170
1171 // Read results.
1172 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
1173 ExitOnFailure(hr, "Failed to read API version of BAEngineElevate results.");
1174
1175 // Execute.
1176 hr = ExternalEngineElevate(pContext, reinterpret_cast<HWND>(args.hwndParent));
1177 ExitOnFailure(hr, "Failed to detect in the engine.");
1178
1179 // Pack result.
1180 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
1181 ExitOnFailure(hr, "Failed to write size of BAEngineElevate struct.");
1182
1183LExit:
1184 return hr;
1185}
1186
1187static HRESULT BAEngineApply(
1188 __in BAENGINE_CONTEXT* pContext,
1189 __in BUFF_READER* pReaderArgs,
1190 __in BUFF_READER* pReaderResults,
1191 __in BUFF_BUFFER* pBuffer
1192 )
1193{
1194 HRESULT hr = S_OK;
1195 BAENGINE_APPLY_ARGS args = { };
1196 BAENGINE_APPLY_RESULTS results = { };
1197
1198 // Read args.
1199 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
1200 ExitOnFailure(hr, "Failed to read API version of BAEngineApply args.");
1201
1202 hr = BuffReaderReadNumber64(pReaderArgs, &args.hwndParent);
1203 ExitOnFailure(hr, "Failed to read parent window of BAEngineApply args.");
1204
1205 // Read results.
1206 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
1207 ExitOnFailure(hr, "Failed to read API version of BAEngineApply results.");
1208
1209 // Execute.
1210 hr = ExternalEngineApply(pContext, reinterpret_cast<HWND>(args.hwndParent));
1211 ExitOnFailure(hr, "Failed to detect in the engine.");
1212
1213 // Pack result.
1214 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
1215 ExitOnFailure(hr, "Failed to write size of BAEngineApply struct.");
1216
1217LExit:
1218 return hr;
1219}
1220
1221static HRESULT BAEngineQuit(
1222 __in BAENGINE_CONTEXT* pContext,
1223 __in BUFF_READER* pReaderArgs,
1224 __in BUFF_READER* pReaderResults,
1225 __in BUFF_BUFFER* pBuffer
1226 )
1227{
1228 HRESULT hr = S_OK;
1229 BAENGINE_QUIT_ARGS args = { };
1230 BAENGINE_QUIT_RESULTS results = { };
1231
1232 // Read args.
1233 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
1234 ExitOnFailure(hr, "Failed to read API version of BAEngineQuit args.");
1235
1236 hr = BuffReaderReadNumber(pReaderArgs, &args.dwExitCode);
1237 ExitOnFailure(hr, "Failed to read API version of BAEngineQuit args.");
1238
1239 // Read results.
1240 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
1241 ExitOnFailure(hr, "Failed to read API version of BAEngineQuit results.");
1242
1243 // Execute.
1244 hr = ExternalEngineQuit(pContext, args.dwExitCode);
1245 ExitOnFailure(hr, "Failed to quit the engine.");
1246
1247 // Pack result.
1248 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
1249 ExitOnFailure(hr, "Failed to write size of BAEngineQuit struct.");
1250
1251LExit:
1252 return hr;
1253}
1254
1255static HRESULT BAEngineLaunchApprovedExe(
1256 __in BAENGINE_CONTEXT* pContext,
1257 __in BUFF_READER* pReaderArgs,
1258 __in BUFF_READER* pReaderResults,
1259 __in BUFF_BUFFER* pBuffer
1260 )
1261{
1262 HRESULT hr = S_OK;
1263 BAENGINE_LAUNCHAPPROVEDEXE_ARGS args = { };
1264 BAENGINE_LAUNCHAPPROVEDEXE_RESULTS results = { };
1265 LPWSTR sczApprovedExeForElevationId = NULL;
1266 LPWSTR sczArguments = NULL;
1267
1268 // Read args.
1269 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
1270 ExitOnFailure(hr, "Failed to read API version of BAEngineLaunchApprovedExe args.");
1271
1272 hr = BuffReaderReadNumber64(pReaderArgs, &args.hwndParent);
1273 ExitOnFailure(hr, "Failed to read parent window of BAEngineLaunchApprovedExe args.");
1274
1275 hr = BuffReaderReadString(pReaderArgs, &sczApprovedExeForElevationId);
1276 ExitOnFailure(hr, "Failed to read approved exe elevation id of BAEngineLaunchApprovedExe args.");
1277
1278 args.wzApprovedExeForElevationId = sczApprovedExeForElevationId;
1279
1280 hr = BuffReaderReadString(pReaderArgs, &sczArguments);
1281 ExitOnFailure(hr, "Failed to read arguments of BAEngineLaunchApprovedExe args.");
1282
1283 args.wzArguments = sczArguments;
1284
1285 hr = BuffReaderReadNumber(pReaderArgs, &args.dwWaitForInputIdleTimeout);
1286 ExitOnFailure(hr, "Failed to read wait for idle input timeout of BAEngineLaunchApprovedExe args.");
1287
1288 // Read results.
1289 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
1290 ExitOnFailure(hr, "Failed to read API version of BAEngineLaunchApprovedExe results.");
1291
1292 // Execute.
1293 hr = ExternalEngineLaunchApprovedExe(pContext, reinterpret_cast<HWND>(args.hwndParent), args.wzApprovedExeForElevationId, args.wzArguments, args.dwWaitForInputIdleTimeout);
1294 ExitOnFailure(hr, "Failed to quit the engine.");
1295
1296 // Pack result.
1297 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
1298 ExitOnFailure(hr, "Failed to write size of BAEngineLaunchApprovedExe struct.");
1299
1300LExit:
1301 ReleaseStr(sczArguments);
1302 ReleaseStr(sczApprovedExeForElevationId);
1303 return hr;
1304}
1305
1306static HRESULT BAEngineSetUpdateSource(
1307 __in BAENGINE_CONTEXT* pContext,
1308 __in BUFF_READER* pReaderArgs,
1309 __in BUFF_READER* pReaderResults,
1310 __in BUFF_BUFFER* pBuffer
1311 )
1312{
1313 HRESULT hr = S_OK;
1314 BAENGINE_SETUPDATESOURCE_ARGS args = { };
1315 BAENGINE_SETUPDATESOURCE_RESULTS results = { };
1316 LPWSTR sczUrl = NULL;
1317 LPWSTR sczAuthorizationHeader = NULL;
1318
1319 // Read args.
1320 hr = BuffReaderReadNumber(pReaderArgs, &args.dwApiVersion);
1321 ExitOnFailure(hr, "Failed to read API version of BAEngineSetUpdateSource args.");
1322
1323 hr = BuffReaderReadString(pReaderArgs, &sczUrl);
1324 ExitOnFailure(hr, "Failed to read url of BAEngineSetUpdateSource args.");
1325
1326 args.wzUrl = sczUrl;
1327
1328 hr = BuffReaderReadString(pReaderArgs, &sczAuthorizationHeader);
1329 ExitOnFailure(hr, "Failed to read authorization header of BAEngineSetUpdateSource args.");
1330
1331 args.wzAuthorizationHeader = sczAuthorizationHeader;
1332
1333 // Read results.
1334 hr = BuffReaderReadNumber(pReaderResults, &results.dwApiVersion);
1335 ExitOnFailure(hr, "Failed to read API version of BAEngineSetUpdateSource results.");
1336
1337 // Execute.
1338 hr = ExternalEngineSetUpdateSource(pContext->pEngineState, args.wzUrl, args.wzAuthorizationHeader);
1339 ExitOnFailure(hr, "Failed to set update source in the engine.");
1340
1341 // Pack result.
1342 hr = BuffWriteNumberToBuffer(pBuffer, sizeof(results));
1343 ExitOnFailure(hr, "Failed to write size of BAEngineSetUpdateSource struct.");
1344
1345LExit:
1346 ReleaseStr(sczAuthorizationHeader);
1347 ReleaseStr(sczUrl);
1348
1349 return hr;
1350}
1351
1352static HRESULT ParseArgsAndResults(
1353 __in_bcount(cbData) LPCBYTE pbData,
1354 __in SIZE_T cbData,
1355 __in BUFF_READER* pBufferArgs,
1356 __in BUFF_READER* pBufferResults
1357)
1358{
1359 HRESULT hr = S_OK;
1360 SIZE_T iData = 0;
1361 DWORD dw = 0;
1362
1363 // Get the args reader size and point to the data just after the size.
1364 hr = BuffReadNumber(pbData, cbData, &iData, &dw);
1365 ExitOnFailure(hr, "Failed to parse size of args");
1366
1367 pBufferArgs->pbData = pbData + iData;
1368 pBufferArgs->cbData = dw;
1369 pBufferArgs->iBuffer = 0;
1370
1371 // Get the results reader size and point to the data just after the size.
1372 hr = ::SIZETAdd(iData, dw, &iData);
1373 ExitOnFailure(hr, "Failed to advance index beyond args");
1374
1375 hr = BuffReadNumber(pbData, cbData, &iData, &dw);
1376 ExitOnFailure(hr, "Failed to parse size of results");
1377
1378 pBufferResults->pbData = pbData + iData;
1379 pBufferResults->cbData = dw;
1380 pBufferResults->iBuffer = 0;
1381
1382LExit:
1383 return hr;
1384}
1385
1386HRESULT WINAPI EngineForApplicationProc(
1387 __in BAENGINE_CONTEXT* pContext,
1388 __in BOOTSTRAPPER_ENGINE_MESSAGE message,
1389 __in_bcount(cbData) LPCBYTE pbData,
1390 __in SIZE_T cbData
1391 )
1392{
1393 HRESULT hr = S_OK;
1394 BUFF_READER readerArgs = { };
1395 BUFF_READER readerResults = { };
1396 BUFF_BUFFER bufferResponse = { };
1397
1398 hr = ParseArgsAndResults(pbData, cbData, &readerArgs, &readerResults);
1399 if (SUCCEEDED(hr))
1400 {
1401 switch (message)
1402 {
1403 case BOOTSTRAPPER_ENGINE_MESSAGE_GETPACKAGECOUNT:
1404 hr = BAEngineGetPackageCount(pContext, &readerArgs, &readerResults, &bufferResponse);
1405 break;
1406 case BOOTSTRAPPER_ENGINE_MESSAGE_GETVARIABLENUMERIC:
1407 hr = BAEngineGetVariableNumeric(pContext, &readerArgs, &readerResults, &bufferResponse);
1408 break;
1409 case BOOTSTRAPPER_ENGINE_MESSAGE_GETVARIABLESTRING:
1410 hr = BAEngineGetVariableString(pContext, &readerArgs, &readerResults, &bufferResponse);
1411 break;
1412 case BOOTSTRAPPER_ENGINE_MESSAGE_GETVARIABLEVERSION:
1413 hr = BAEngineGetVariableVersion(pContext, &readerArgs, &readerResults, &bufferResponse);
1414 break;
1415 case BOOTSTRAPPER_ENGINE_MESSAGE_FORMATSTRING:
1416 hr = BAEngineFormatString(pContext, &readerArgs, &readerResults, &bufferResponse);
1417 break;
1418 case BOOTSTRAPPER_ENGINE_MESSAGE_ESCAPESTRING:
1419 hr = BAEngineEscapeString(pContext, &readerArgs, &readerResults, &bufferResponse);
1420 break;
1421 case BOOTSTRAPPER_ENGINE_MESSAGE_EVALUATECONDITION:
1422 hr = BAEngineEvaluateCondition(pContext, &readerArgs, &readerResults, &bufferResponse);
1423 break;
1424 case BOOTSTRAPPER_ENGINE_MESSAGE_LOG:
1425 hr = BAEngineLog(&readerArgs, &readerResults, &bufferResponse);
1426 break;
1427 case BOOTSTRAPPER_ENGINE_MESSAGE_SENDEMBEDDEDERROR:
1428 hr = BAEngineSendEmbeddedError(pContext, &readerArgs, &readerResults, &bufferResponse);
1429 break;
1430 case BOOTSTRAPPER_ENGINE_MESSAGE_SENDEMBEDDEDPROGRESS:
1431 hr = BAEngineSendEmbeddedProgress(pContext, &readerArgs, &readerResults, &bufferResponse);
1432 break;
1433 case BOOTSTRAPPER_ENGINE_MESSAGE_SETUPDATE:
1434 hr = BAEngineSetUpdate(pContext, &readerArgs, &readerResults, &bufferResponse);
1435 break;
1436 case BOOTSTRAPPER_ENGINE_MESSAGE_SETLOCALSOURCE:
1437 hr = BAEngineSetLocalSource(pContext, &readerArgs, &readerResults, &bufferResponse);
1438 break;
1439 case BOOTSTRAPPER_ENGINE_MESSAGE_SETDOWNLOADSOURCE:
1440 hr = BAEngineSetDownloadSource(pContext, &readerArgs, &readerResults, &bufferResponse);
1441 break;
1442 case BOOTSTRAPPER_ENGINE_MESSAGE_SETVARIABLENUMERIC:
1443 hr = BAEngineSetVariableNumeric(pContext, &readerArgs, &readerResults, &bufferResponse);
1444 break;
1445 case BOOTSTRAPPER_ENGINE_MESSAGE_SETVARIABLESTRING:
1446 hr = BAEngineSetVariableString(pContext, &readerArgs, &readerResults, &bufferResponse);
1447 break;
1448 case BOOTSTRAPPER_ENGINE_MESSAGE_SETVARIABLEVERSION:
1449 hr = BAEngineSetVariableVersion(pContext, &readerArgs, &readerResults, &bufferResponse);
1450 break;
1451 case BOOTSTRAPPER_ENGINE_MESSAGE_CLOSESPLASHSCREEN:
1452 hr = BAEngineCloseSplashScreen(pContext, &readerArgs, &readerResults, &bufferResponse);
1453 break;
1454 case BOOTSTRAPPER_ENGINE_MESSAGE_DETECT:
1455 hr = BAEngineDetect(pContext, &readerArgs, &readerResults, &bufferResponse);
1456 break;
1457 case BOOTSTRAPPER_ENGINE_MESSAGE_PLAN:
1458 hr = BAEnginePlan(pContext, &readerArgs, &readerResults, &bufferResponse);
1459 break;
1460 case BOOTSTRAPPER_ENGINE_MESSAGE_ELEVATE:
1461 hr = BAEngineElevate(pContext, &readerArgs, &readerResults, &bufferResponse);
1462 break;
1463 case BOOTSTRAPPER_ENGINE_MESSAGE_APPLY:
1464 hr = BAEngineApply(pContext, &readerArgs, &readerResults, &bufferResponse);
1465 break;
1466 case BOOTSTRAPPER_ENGINE_MESSAGE_QUIT:
1467 hr = BAEngineQuit(pContext, &readerArgs, &readerResults, &bufferResponse);
1468 break;
1469 case BOOTSTRAPPER_ENGINE_MESSAGE_LAUNCHAPPROVEDEXE:
1470 hr = BAEngineLaunchApprovedExe(pContext, &readerArgs, &readerResults, &bufferResponse);
1471 break;
1472 case BOOTSTRAPPER_ENGINE_MESSAGE_SETUPDATESOURCE:
1473 hr = BAEngineSetUpdateSource(pContext, &readerArgs, &readerResults, &bufferResponse);
1474 break;
1475 case BOOTSTRAPPER_ENGINE_MESSAGE_COMPAREVERSIONS:
1476 hr = BAEngineCompareVersions(pContext, &readerArgs, &readerResults, &bufferResponse);
1477 break;
1478 case BOOTSTRAPPER_ENGINE_MESSAGE_GETRELATEDBUNDLEVARIABLE:
1479 hr = BAEngineGetRelatedBundleVariable(pContext, &readerArgs, &readerResults, &bufferResponse);
1480 break;
1481 default:
1482 hr = E_NOTIMPL;
1483 break;
1484 }
1485 }
1486
1487 hr = PipeRpcResponse(&pContext->hRpcPipe, message, hr, bufferResponse.pbData, bufferResponse.cbData);
1488 ExitOnFailure(hr, "Failed to send engine result to bootstrapper application.");
1489
1490LExit:
1491 ReleaseBuffer(bufferResponse);
1492 return hr;
1493}
1494
1495static DWORD WINAPI BAEngineMessagePumpThreadProc(
1496 __in LPVOID lpThreadParameter
1497)
1498{
1499 HRESULT hr = S_OK;
1500 BOOL fComInitialized = FALSE;
1501 BAENGINE_CONTEXT* pContext = reinterpret_cast<BAENGINE_CONTEXT*>(lpThreadParameter);
1502 PIPE_MESSAGE msg = { };
1503
1504 // initialize COM
1505 hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
1506 ExitOnFailure(hr, "Failed to initialize COM.");
1507 fComInitialized = TRUE;
1508
1509 // Pump messages from bootstrapper application for engine messages until the pipe is closed.
1510 while (S_OK == (hr = PipeRpcReadMessage(&pContext->hRpcPipe, &msg)))
1511 {
1512 EngineForApplicationProc(pContext, static_cast<BOOTSTRAPPER_ENGINE_MESSAGE>(msg.dwMessageType), reinterpret_cast<LPCBYTE>(msg.pvData), msg.cbData);
1513
1514 ReleasePipeMessage(&msg);
1515 }
1516 ExitOnFailure(hr, "Failed to get message over bootstrapper application pipe");
1517
1518 if (S_FALSE == hr)
1519 {
1520 hr = S_OK;
1521 }
1522
1523LExit:
1524 ReleasePipeMessage(&msg);
1525
1526 if (fComInitialized)
1527 {
1528 ::CoUninitialize();
1529 }
1530
1531 return (DWORD)hr;
1532}