2
2
3
3
#include " precomp.h"
4
4
5
+ static const HRESULT E_SUSPECTED_TAMPERING = MAKE_HRESULT(SEVERITY_ERROR, 500 /* FACILITY_WIX*/ , 2001 );
6
+
7
+ static void AvoidLocalDllRedirection (LPCWSTR wzPath);
8
+
5
9
6
10
int WINAPI wWinMain (
7
11
__in HINSTANCE hInstance,
@@ -52,6 +56,8 @@ int WINAPI wWinMain(
52
56
AppInitialize (rgsczSafelyLoadSystemDlls, countof (rgsczSafelyLoadSystemDlls));
53
57
}
54
58
59
+ AvoidLocalDllRedirection (sczPath);
60
+
55
61
// call run
56
62
hr = EngineRun (hInstance, hEngineFile, lpCmdLine, nCmdShow, &dwExitCode);
57
63
ExitOnFailure (hr, " Failed to run application." );
@@ -63,3 +69,23 @@ int WINAPI wWinMain(
63
69
64
70
return FAILED (hr) ? (int )hr : (int )dwExitCode;
65
71
}
72
+
73
+ static void AvoidLocalDllRedirection (LPCWSTR wzPath)
74
+ {
75
+ LPWSTR sczLocalPath = NULL ;
76
+ HMODULE hmodComCtl = NULL ;
77
+
78
+ // Bail if there's a <bundle>.exe.local directory, as it's a feature of
79
+ // DLL redirection that has no real use for a bundle and is a hole for
80
+ // DLL hijacking attacks.
81
+
82
+ if (FAILED (StrAllocFormatted (&sczLocalPath, L" %ls.local" , wzPath))
83
+ || DirExists (sczLocalPath, NULL )
84
+ || FileExistsEx (sczLocalPath, NULL )
85
+ || FAILED (LoadSystemLibrary (L" Comctl32.dll" , &hmodComCtl)))
86
+ {
87
+ ::ExitProcess ((UINT)E_SUSPECTED_TAMPERING);
88
+ }
89
+
90
+ ReleaseStr (sczLocalPath);
91
+ }
0 commit comments