aboutsummaryrefslogtreecommitdiff
path: root/src/stub/stub.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/stub/stub.cpp')
-rw-r--r--src/stub/stub.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/stub/stub.cpp b/src/stub/stub.cpp
new file mode 100644
index 00000000..2f09eede
--- /dev/null
+++ b/src/stub/stub.cpp
@@ -0,0 +1,64 @@
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
6int WINAPI wWinMain(
7 __in HINSTANCE hInstance,
8 __in_opt HINSTANCE /* hPrevInstance */,
9 __in_z_opt LPWSTR lpCmdLine,
10 __in int nCmdShow
11 )
12{
13 HRESULT hr = S_OK;
14 DWORD dwExitCode = 0;
15 LPWSTR sczPath = NULL;
16 HANDLE hEngineFile = INVALID_HANDLE_VALUE;
17
18 LPCWSTR rgsczSafelyLoadSystemDlls[] =
19 {
20 L"cabinet.dll", // required by Burn.
21 L"msi.dll", // required by Burn.
22 L"version.dll", // required by Burn.
23 L"wininet.dll", // required by Burn.
24
25 L"comres.dll", // required by CLSIDFromProgID() when loading clbcatq.dll.
26 L"clbcatq.dll", // required by CLSIDFromProgID() when loading msxml?.dll.
27
28 L"msasn1.dll", // required by DecryptFile() when loading crypt32.dll.
29 L"crypt32.dll", // required by DecryptFile() when loading feclient.dll.
30 L"feclient.dll", // unsafely loaded by DecryptFile().
31 };
32
33 // Best effort attempt to get our file handle as soon as possible.
34 hr = PathForCurrentProcess(&sczPath, NULL);
35 if (SUCCEEDED(hr))
36 {
37 hEngineFile = ::CreateFileW(sczPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
38 }
39
40 // If the engine is in the clean room, we'll do the unsafe initialization
41 // because some systems in Windows (namely GDI+) will fail when run in
42 // a process that protects against DLL hijacking. Since we know the clean
43 // room is in a clean folder and not subject to DLL hijacking we won't
44 // make ourselves perfectly secure so that we can load BAs that still
45 // depend on those parts of Windows that are insecure to DLL hijacking.
46 if (EngineInCleanRoom(lpCmdLine))
47 {
48 AppInitializeUnsafe();
49 }
50 else
51 {
52 AppInitialize(rgsczSafelyLoadSystemDlls, countof(rgsczSafelyLoadSystemDlls));
53 }
54
55 // call run
56 hr = EngineRun(hInstance, hEngineFile, lpCmdLine, nCmdShow, &dwExitCode);
57 ExitOnFailure(hr, "Failed to run application.");
58
59LExit:
60 ReleaseFileHandle(hEngineFile);
61 ReleaseStr(sczPath);
62
63 return FAILED(hr) ? (int)hr : (int)dwExitCode;
64}