return 0;\r
}\r
\r
+\r
+\r
+//\r
+//copy from Rufus\r
+//\r
+#include <delayimp.h>\r
+// For delay-loaded DLLs, use LOAD_LIBRARY_SEARCH_SYSTEM32 to avoid DLL search order hijacking.\r
+FARPROC WINAPI dllDelayLoadHook(unsigned dliNotify, PDelayLoadInfo pdli)\r
+{\r
+ if (dliNotify == dliNotePreLoadLibrary) {\r
+ // Windows 7 without KB2533623 does not support the LOAD_LIBRARY_SEARCH_SYSTEM32 flag.\r
+ // That is is OK, because the delay load handler will interrupt the NULL return value\r
+ // to mean that it should perform a normal LoadLibrary.\r
+ return (FARPROC)LoadLibraryExA(pdli->szDll, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);\r
+ }\r
+ return NULL;\r
+}\r
+\r
+#if defined(_MSC_VER)\r
+// By default the Windows SDK headers have a `const` while MinGW does not.\r
+const\r
+#endif\r
+PfnDliHook __pfnDliNotifyHook2 = dllDelayLoadHook;\r
+\r
+typedef BOOL(WINAPI* SetDefaultDllDirectories_t)(DWORD);\r
+static void DllProtect(void)\r
+{\r
+ SetDefaultDllDirectories_t pfSetDefaultDllDirectories = NULL;\r
+\r
+ // Disable loading system DLLs from the current directory (sideloading mitigation)\r
+ // PS: You know that official MSDN documentation for SetDllDirectory() that explicitly\r
+ // indicates that "If the parameter is an empty string (""), the call removes the current\r
+ // directory from the default DLL search order"? Yeah, that doesn't work. At all.\r
+ // Still, we invoke it, for platforms where the following call might actually work...\r
+ SetDllDirectoryA("");\r
+\r
+ // For libraries on the KnownDLLs list, the system will always load them from System32.\r
+ // For other DLLs we link directly to, we can delay load the DLL and use a delay load\r
+ // hook to load them from System32. Note that, for this to work, something like:\r
+ // 'somelib.dll;%(DelayLoadDLLs)' must be added to the 'Delay Loaded Dlls' option of\r
+ // the linker properties in Visual Studio (which means this won't work with MinGW).\r
+ // For all other DLLs, use SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32).\r
+ // Finally, we need to perform the whole gymkhana below, where we can't call on\r
+ // SetDefaultDllDirectories() directly, because Windows 7 doesn't have the API exposed.\r
+ // Also, no, Coverity, we never need to care about freeing kernel32 as a library.\r
+ // coverity[leaked_storage]\r
+\r
+ pfSetDefaultDllDirectories = (SetDefaultDllDirectories_t)\r
+ GetProcAddress(LoadLibraryW(L"kernel32.dll"), "SetDefaultDllDirectories");\r
+ if (pfSetDefaultDllDirectories != NULL)\r
+ pfSetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32);\r
+}\r
+\r
+\r
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow)\r
{\r
int rc;\r
\r
UNREFERENCED_PARAMETER(hPrevInstance);\r
\r
+ DllProtect();\r
+\r
if (GetUserDefaultUILanguage() == 0x0804)\r
{\r
g_sysinfo.language = LANGUAGE_CN;\r
<ProjectGuid>{321D6EE2-2AB3-4103-9F05-EC4EC67A75E1}</ProjectGuid>\r
<Keyword>Win32Proj</Keyword>\r
<RootNamespace>VentoyPlugson</RootNamespace>\r
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>\r
</PropertyGroup>\r
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\r
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">\r
<ConfigurationType>Application</ConfigurationType>\r
<UseDebugLibraries>true</UseDebugLibraries>\r
- <PlatformToolset>v120</PlatformToolset>\r
+ <PlatformToolset>v142</PlatformToolset>\r
<CharacterSet>MultiByte</CharacterSet>\r
</PropertyGroup>\r
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">\r
<ConfigurationType>Application</ConfigurationType>\r
<UseDebugLibraries>false</UseDebugLibraries>\r
- <PlatformToolset>v120</PlatformToolset>\r
+ <PlatformToolset>v142</PlatformToolset>\r
<WholeProgramOptimization>true</WholeProgramOptimization>\r
<CharacterSet>MultiByte</CharacterSet>\r
</PropertyGroup>\r
<SubSystem>Windows</SubSystem>\r
<GenerateDebugInformation>true</GenerateDebugInformation>\r
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>\r
+ <DelayLoadDLLs>gdi32.dll;winspool.dll;comdlg32.dll;advapi32.dll;shell32.dll;ole32.dll;oleaut32.dll;uuid.dll;odbc32.dll;odbccp32.dll</DelayLoadDLLs>\r
</Link>\r
<Manifest>\r
<AdditionalManifestFiles>$(ProjectDir)\Res\Plugson32.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>\r
<EnableCOMDATFolding>true</EnableCOMDATFolding>\r
<OptimizeReferences>true</OptimizeReferences>\r
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>\r
+ <DelayLoadDLLs>gdi32.dll;winspool.dll;comdlg32.dll;advapi32.dll;shell32.dll;ole32.dll;oleaut32.dll;uuid.dll;odbc32.dll;odbccp32.dll</DelayLoadDLLs>\r
</Link>\r
<Manifest>\r
<AdditionalManifestFiles>$(ProjectDir)\Res\Plugson32.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>\r
<ItemGroup>\r
<ResourceCompile Include="VentoyPlugson.rc" />\r
</ItemGroup>\r
- <ItemGroup> \r
+ <ItemGroup>\r
<Image Include="Res\plugson.ico" />\r
</ItemGroup>\r
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\r
</ResourceCompile>\r
</ItemGroup>\r
<ItemGroup>\r
- <Image Include="Res\refresh.ico">\r
+ <Image Include="Res\plugson.ico">\r
<Filter>资源文件</Filter>\r
</Image>\r
</ItemGroup>\r
return argc;\r
}\r
\r
+\r
+//\r
+//copy from Rufus\r
+//\r
+#include <delayimp.h>\r
+// For delay-loaded DLLs, use LOAD_LIBRARY_SEARCH_SYSTEM32 to avoid DLL search order hijacking.\r
+FARPROC WINAPI dllDelayLoadHook(unsigned dliNotify, PDelayLoadInfo pdli)\r
+{\r
+ if (dliNotify == dliNotePreLoadLibrary) {\r
+ // Windows 7 without KB2533623 does not support the LOAD_LIBRARY_SEARCH_SYSTEM32 flag.\r
+ // That is is OK, because the delay load handler will interrupt the NULL return value\r
+ // to mean that it should perform a normal LoadLibrary.\r
+ return (FARPROC)LoadLibraryExA(pdli->szDll, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);\r
+ }\r
+ return NULL;\r
+}\r
+\r
+#if defined(_MSC_VER)\r
+// By default the Windows SDK headers have a `const` while MinGW does not.\r
+const\r
+#endif\r
+PfnDliHook __pfnDliNotifyHook2 = dllDelayLoadHook;\r
+\r
+typedef BOOL(WINAPI *SetDefaultDllDirectories_t)(DWORD);\r
+static void DllProtect(void)\r
+{\r
+ SetDefaultDllDirectories_t pfSetDefaultDllDirectories = NULL;\r
+\r
+ // Disable loading system DLLs from the current directory (sideloading mitigation)\r
+ // PS: You know that official MSDN documentation for SetDllDirectory() that explicitly\r
+ // indicates that "If the parameter is an empty string (""), the call removes the current\r
+ // directory from the default DLL search order"? Yeah, that doesn't work. At all.\r
+ // Still, we invoke it, for platforms where the following call might actually work...\r
+ SetDllDirectoryA("");\r
+\r
+ // For libraries on the KnownDLLs list, the system will always load them from System32.\r
+ // For other DLLs we link directly to, we can delay load the DLL and use a delay load\r
+ // hook to load them from System32. Note that, for this to work, something like:\r
+ // 'somelib.dll;%(DelayLoadDLLs)' must be added to the 'Delay Loaded Dlls' option of\r
+ // the linker properties in Visual Studio (which means this won't work with MinGW).\r
+ // For all other DLLs, use SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32).\r
+ // Finally, we need to perform the whole gymkhana below, where we can't call on\r
+ // SetDefaultDllDirectories() directly, because Windows 7 doesn't have the API exposed.\r
+ // Also, no, Coverity, we never need to care about freeing kernel32 as a library.\r
+ // coverity[leaked_storage]\r
+\r
+ pfSetDefaultDllDirectories = (SetDefaultDllDirectories_t)\r
+ GetProcAddress(LoadLibraryW(L"kernel32.dll"), "SetDefaultDllDirectories");\r
+ if (pfSetDefaultDllDirectories != NULL)\r
+ pfSetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32);\r
+}\r
+\r
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow)\r
{\r
DWORD dwAttrib;\r
\r
UNREFERENCED_PARAMETER(hPrevInstance);\r
\r
+ DllProtect();\r
+\r
if (GetUserDefaultUILanguage() == 0x0804)\r
{\r
g_msg_lang = g_msg_cn;\r
<ProjectGuid>{9987D9FE-1A40-4C5F-835C-D66B0FEADA26}</ProjectGuid>\r
<Keyword>Win32Proj</Keyword>\r
<RootNamespace>VentoyVlnk</RootNamespace>\r
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>\r
</PropertyGroup>\r
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\r
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">\r
<ConfigurationType>Application</ConfigurationType>\r
<UseDebugLibraries>true</UseDebugLibraries>\r
- <PlatformToolset>v120</PlatformToolset>\r
+ <PlatformToolset>v142</PlatformToolset>\r
<CharacterSet>Unicode</CharacterSet>\r
</PropertyGroup>\r
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">\r
<ConfigurationType>Application</ConfigurationType>\r
<UseDebugLibraries>false</UseDebugLibraries>\r
- <PlatformToolset>v120</PlatformToolset>\r
+ <PlatformToolset>v142</PlatformToolset>\r
<WholeProgramOptimization>true</WholeProgramOptimization>\r
<CharacterSet>Unicode</CharacterSet>\r
</PropertyGroup>\r
<SubSystem>Windows</SubSystem>\r
<GenerateDebugInformation>true</GenerateDebugInformation>\r
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>\r
+ <DelayLoadDLLs>gdi32.dll;winspool.dll;comdlg32.dll;advapi32.dll;shell32.dll;ole32.dll;oleaut32.dll;uuid.dll;odbc32.dll;odbccp32.dll</DelayLoadDLLs>\r
</Link>\r
<Manifest>\r
<AdditionalManifestFiles>$(ProjectDir)\Res\Vlnk32.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>\r
<EnableCOMDATFolding>true</EnableCOMDATFolding>\r
<OptimizeReferences>true</OptimizeReferences>\r
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>\r
+ <DelayLoadDLLs>gdi32.dll;winspool.dll;comdlg32.dll;advapi32.dll;shell32.dll;ole32.dll;oleaut32.dll;uuid.dll;odbc32.dll;odbccp32.dll</DelayLoadDLLs>\r
</Link>\r
<Manifest>\r
<AdditionalManifestFiles>$(ProjectDir)\Res\Vlnk32.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>\r