From af10c45d7b3a44af0b461a557847fe03263dcc10 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 22 Apr 2021 17:06:54 -0700 Subject: Move burn into burn --- src/burn/stub/stub.cpp | 106 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/burn/stub/stub.cpp (limited to 'src/burn/stub/stub.cpp') diff --git a/src/burn/stub/stub.cpp b/src/burn/stub/stub.cpp new file mode 100644 index 00000000..0cb202e0 --- /dev/null +++ b/src/burn/stub/stub.cpp @@ -0,0 +1,106 @@ +// 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. + +#include "precomp.h" + + +static void CALLBACK BurnTraceError( + __in_z LPCSTR szFile, + __in int iLine, + __in REPORT_LEVEL rl, + __in UINT source, + __in HRESULT hrError, + __in_z __format_string LPCSTR szFormat, + __in va_list args + ); + +int WINAPI wWinMain( + __in HINSTANCE hInstance, + __in_opt HINSTANCE /* hPrevInstance */, + __in_z_opt LPWSTR lpCmdLine, + __in int nCmdShow + ) +{ + HRESULT hr = S_OK; + DWORD dwExitCode = 0; + LPWSTR sczPath = NULL; + HANDLE hEngineFile = INVALID_HANDLE_VALUE; + + LPCWSTR rgsczSafelyLoadSystemDlls[] = + { + L"cabinet.dll", // required by Burn. + L"msi.dll", // required by Burn. + L"version.dll", // required by Burn. + L"wininet.dll", // required by Burn. + + L"comres.dll", // required by CLSIDFromProgID() when loading clbcatq.dll. + L"clbcatq.dll", // required by CLSIDFromProgID() when loading msxml?.dll. + + L"msasn1.dll", // required by DecryptFile() when loading crypt32.dll. + L"crypt32.dll", // required by DecryptFile() when loading feclient.dll. + L"feclient.dll", // unsafely loaded by DecryptFile(). + }; + + DutilInitialize(&BurnTraceError); + + // Best effort attempt to get our file handle as soon as possible. + hr = PathForCurrentProcess(&sczPath, NULL); + if (SUCCEEDED(hr)) + { + hEngineFile = ::CreateFileW(sczPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + } + + // If the engine is in the clean room, we'll do the unsafe initialization + // because some systems in Windows (namely GDI+) will fail when run in + // a process that protects against DLL hijacking. Since we know the clean + // room is in a clean folder and not subject to DLL hijacking we won't + // make ourselves perfectly secure so that we can load BAs that still + // depend on those parts of Windows that are insecure to DLL hijacking. + if (EngineInCleanRoom(lpCmdLine)) + { + AppInitializeUnsafe(); + } + else + { + AppInitialize(rgsczSafelyLoadSystemDlls, countof(rgsczSafelyLoadSystemDlls)); + } + + // call run + hr = EngineRun(hInstance, hEngineFile, lpCmdLine, nCmdShow, &dwExitCode); + ExitOnFailure(hr, "Failed to run application."); + +LExit: + ReleaseFileHandle(hEngineFile); + ReleaseStr(sczPath); + + DutilUninitialize(); + + return FAILED(hr) ? (int)hr : (int)dwExitCode; +} + +static void CALLBACK BurnTraceError( + __in_z LPCSTR /*szFile*/, + __in int /*iLine*/, + __in REPORT_LEVEL /*rl*/, + __in UINT source, + __in HRESULT hrError, + __in_z __format_string LPCSTR szFormat, + __in va_list args + ) +{ + BOOL fLog = FALSE; + + switch (source) + { + case DUTIL_SOURCE_DEFAULT: + fLog = TRUE; + break; + default: + fLog = REPORT_VERBOSE < LogGetLevel(); + break; + } + + if (fLog) + { + LogErrorStringArgs(hrError, szFormat, args); + } +} -- cgit v1.2.3-55-g6feb