mirror of
https://github.com/Qz3rK/tdesktop.git
synced 2026-07-03 14:15:08 +02:00
Use a safer way to load system libraries.
This commit is contained in:
@@ -7,26 +7,43 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "platform/win/windows_dlls.h"
|
||||
|
||||
#include "base/platform/win/base_windows_safe_library.h"
|
||||
|
||||
#include <VersionHelpers.h>
|
||||
#include <QtCore/QSysInfo>
|
||||
|
||||
namespace Platform {
|
||||
namespace Dlls {
|
||||
|
||||
f_SetDllDirectory SetDllDirectory;
|
||||
|
||||
HINSTANCE LibKernel32;
|
||||
using base::Platform::SafeLoadLibrary;
|
||||
using base::Platform::LoadMethod;
|
||||
|
||||
void init() {
|
||||
static bool inited = false;
|
||||
if (inited) return;
|
||||
inited = true;
|
||||
|
||||
LibKernel32 = LoadLibrary(L"KERNEL32.DLL");
|
||||
load(LibKernel32, "SetDllDirectoryW", SetDllDirectory);
|
||||
if (SetDllDirectory) {
|
||||
// Remove the current directory from the DLL search order.
|
||||
SetDllDirectory(L"");
|
||||
// Remove the current directory from the DLL search order.
|
||||
::SetDllDirectory(L"");
|
||||
|
||||
const auto list = {
|
||||
u"dbghelp.dll"_q,
|
||||
u"dbgcore.dll"_q,
|
||||
u"propsys.dll"_q,
|
||||
u"winsta.dll"_q,
|
||||
u"textinputframework.dll"_q,
|
||||
u"uxtheme.dll"_q,
|
||||
u"igdumdim32.dll"_q,
|
||||
u"amdhdl32.dll"_q,
|
||||
u"wtsapi32.dll"_q,
|
||||
u"propsys.dll"_q,
|
||||
u"combase.dll"_q,
|
||||
u"dwmapi.dll"_q,
|
||||
u"rstrtmgr.dll"_q,
|
||||
u"psapi.dll"_q,
|
||||
};
|
||||
for (const auto &lib : list) {
|
||||
SafeLoadLibrary(lib);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,59 +70,50 @@ f_RmShutdown RmShutdown;
|
||||
f_RmEndSession RmEndSession;
|
||||
f_GetProcessMemoryInfo GetProcessMemoryInfo;
|
||||
|
||||
HINSTANCE LibUxTheme;
|
||||
HINSTANCE LibShell32;
|
||||
HINSTANCE LibWtsApi32;
|
||||
HINSTANCE LibPropSys;
|
||||
HINSTANCE LibComBase;
|
||||
HINSTANCE LibDwmApi;
|
||||
HINSTANCE LibRstrtMgr;
|
||||
HINSTANCE LibPsApi;
|
||||
|
||||
void start() {
|
||||
init();
|
||||
|
||||
LibShell32 = LoadLibrary(L"SHELL32.DLL");
|
||||
load(LibShell32, "SHAssocEnumHandlers", SHAssocEnumHandlers);
|
||||
load(LibShell32, "SHCreateItemFromParsingName", SHCreateItemFromParsingName);
|
||||
load(LibShell32, "SHOpenWithDialog", SHOpenWithDialog);
|
||||
load(LibShell32, "OpenAs_RunDLLW", OpenAs_RunDLL);
|
||||
load(LibShell32, "SHQueryUserNotificationState", SHQueryUserNotificationState);
|
||||
load(LibShell32, "SHChangeNotify", SHChangeNotify);
|
||||
load(LibShell32, "SetCurrentProcessExplicitAppUserModelID", SetCurrentProcessExplicitAppUserModelID);
|
||||
const auto LibShell32 = SafeLoadLibrary(u"shell32.dll"_q);
|
||||
LoadMethod(LibShell32, "SHAssocEnumHandlers", SHAssocEnumHandlers);
|
||||
LoadMethod(LibShell32, "SHCreateItemFromParsingName", SHCreateItemFromParsingName);
|
||||
LoadMethod(LibShell32, "SHOpenWithDialog", SHOpenWithDialog);
|
||||
LoadMethod(LibShell32, "OpenAs_RunDLLW", OpenAs_RunDLL);
|
||||
LoadMethod(LibShell32, "SHQueryUserNotificationState", SHQueryUserNotificationState);
|
||||
LoadMethod(LibShell32, "SHChangeNotify", SHChangeNotify);
|
||||
LoadMethod(LibShell32, "SetCurrentProcessExplicitAppUserModelID", SetCurrentProcessExplicitAppUserModelID);
|
||||
|
||||
LibUxTheme = LoadLibrary(L"UXTHEME.DLL");
|
||||
load(LibUxTheme, "SetWindowTheme", SetWindowTheme);
|
||||
const auto LibUxTheme = SafeLoadLibrary(u"uxtheme.dll"_q);
|
||||
LoadMethod(LibUxTheme, "SetWindowTheme", SetWindowTheme);
|
||||
|
||||
if (IsWindowsVistaOrGreater()) {
|
||||
LibWtsApi32 = LoadLibrary(L"WTSAPI32.DLL");
|
||||
load(LibWtsApi32, "WTSRegisterSessionNotification", WTSRegisterSessionNotification);
|
||||
load(LibWtsApi32, "WTSUnRegisterSessionNotification", WTSUnRegisterSessionNotification);
|
||||
const auto LibWtsApi32 = SafeLoadLibrary(u"wtsapi32.dll"_q);
|
||||
LoadMethod(LibWtsApi32, "WTSRegisterSessionNotification", WTSRegisterSessionNotification);
|
||||
LoadMethod(LibWtsApi32, "WTSUnRegisterSessionNotification", WTSUnRegisterSessionNotification);
|
||||
|
||||
LibPropSys = LoadLibrary(L"PROPSYS.DLL");
|
||||
load(LibPropSys, "PropVariantToString", PropVariantToString);
|
||||
load(LibPropSys, "PSStringFromPropertyKey", PSStringFromPropertyKey);
|
||||
const auto LibPropSys = SafeLoadLibrary(u"propsys.dll"_q);
|
||||
LoadMethod(LibPropSys, "PropVariantToString", PropVariantToString);
|
||||
LoadMethod(LibPropSys, "PSStringFromPropertyKey", PSStringFromPropertyKey);
|
||||
|
||||
if (IsWindows8OrGreater()) {
|
||||
LibComBase = LoadLibrary(L"COMBASE.DLL");
|
||||
load(LibComBase, "RoGetActivationFactory", RoGetActivationFactory);
|
||||
load(LibComBase, "WindowsCreateStringReference", WindowsCreateStringReference);
|
||||
load(LibComBase, "WindowsDeleteString", WindowsDeleteString);
|
||||
const auto LibComBase = SafeLoadLibrary(u"combase.dll"_q);
|
||||
LoadMethod(LibComBase, "RoGetActivationFactory", RoGetActivationFactory);
|
||||
LoadMethod(LibComBase, "WindowsCreateStringReference", WindowsCreateStringReference);
|
||||
LoadMethod(LibComBase, "WindowsDeleteString", WindowsDeleteString);
|
||||
}
|
||||
|
||||
LibDwmApi = LoadLibrary(L"DWMAPI.DLL");
|
||||
load(LibDwmApi, "DwmIsCompositionEnabled", DwmIsCompositionEnabled);
|
||||
const auto LibDwmApi = SafeLoadLibrary(u"dwmapi.dll"_q);
|
||||
LoadMethod(LibDwmApi, "DwmIsCompositionEnabled", DwmIsCompositionEnabled);
|
||||
|
||||
LibRstrtMgr = LoadLibrary(L"RSTRTMGR.DLL");
|
||||
load(LibRstrtMgr, "RmStartSession", RmStartSession);
|
||||
load(LibRstrtMgr, "RmRegisterResources", RmRegisterResources);
|
||||
load(LibRstrtMgr, "RmGetList", RmGetList);
|
||||
load(LibRstrtMgr, "RmShutdown", RmShutdown);
|
||||
load(LibRstrtMgr, "RmEndSession", RmEndSession);
|
||||
const auto LibRstrtMgr = SafeLoadLibrary(u"rstrtmgr.dll"_q);
|
||||
LoadMethod(LibRstrtMgr, "RmStartSession", RmStartSession);
|
||||
LoadMethod(LibRstrtMgr, "RmRegisterResources", RmRegisterResources);
|
||||
LoadMethod(LibRstrtMgr, "RmGetList", RmGetList);
|
||||
LoadMethod(LibRstrtMgr, "RmShutdown", RmShutdown);
|
||||
LoadMethod(LibRstrtMgr, "RmEndSession", RmEndSession);
|
||||
}
|
||||
|
||||
LibPsApi = LoadLibrary(L"PSAPI.DLL");
|
||||
load(LibPsApi, "GetProcessMemoryInfo", GetProcessMemoryInfo);
|
||||
const auto LibPsApi = SafeLoadLibrary(u"psapi.dll"_q);
|
||||
LoadMethod(LibPsApi, "GetProcessMemoryInfo", GetProcessMemoryInfo);
|
||||
}
|
||||
|
||||
} // namespace Dlls
|
||||
|
||||
@@ -30,14 +30,6 @@ extern f_SetDllDirectory SetDllDirectory;
|
||||
|
||||
void start();
|
||||
|
||||
template <typename Function>
|
||||
bool load(HINSTANCE library, LPCSTR name, Function &func) {
|
||||
if (!library) return false;
|
||||
|
||||
func = reinterpret_cast<Function>(GetProcAddress(library, name));
|
||||
return (func != nullptr);
|
||||
}
|
||||
|
||||
// UXTHEME.DLL
|
||||
using f_SetWindowTheme = HRESULT(FAR STDAPICALLTYPE*)(
|
||||
HWND hWnd,
|
||||
|
||||
+1
-1
Submodule Telegram/lib_base updated: 3017da83c1...01ca681ab3
+1
-1
Submodule Telegram/lib_ui updated: 262b3eb335...09918f0133
+1
-1
Submodule cmake updated: 6b36a649dc...9346d5f895
Reference in New Issue
Block a user