From 1f3b7b5cfc7ca3bf335ed3fc062a0009e0a9dcb8 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 5 Aug 2022 17:47:29 +0300 Subject: =?UTF-8?q?fixes=20#3143=20(autoexec=5F*.ini=20=D0=BD=D0=B5=20?= =?UTF-8?q?=D1=81=D1=82=D0=B8=D1=80=D0=B0=D1=8E=D1=82=D1=81=D1=8F=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=81=D0=BB=D0=B5=20=D0=B8=D0=BC=D0=BF=D0=BE=D1=80=D1=82?= =?UTF-8?q?=D0=B0,=20=D1=85=D0=BE=D1=82=D1=8F=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D1=8D=D1=82=D0=BE=D0=B3=D0=BE=20=D0=B4=D0=BE=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BD=D0=BE=20=D0=BF=D1=80=D0=B0=D0=B2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/m_utils.h | 2 +- libs/win32/mir_app.lib | Bin 227550 -> 227570 bytes libs/win64/mir_app.lib | Bin 223646 -> 223672 bytes src/mir_app/src/db_ini.cpp | 6 +++--- src/mir_app/src/mir_app.def | 2 +- src/mir_app/src/mir_app64.def | 2 +- src/mir_app/src/pu_utils.cpp | 27 +++++++++++++++++---------- 7 files changed, 23 insertions(+), 16 deletions(-) diff --git a/include/m_utils.h b/include/m_utils.h index a9914f93f7..e7bff67f1a 100644 --- a/include/m_utils.h +++ b/include/m_utils.h @@ -486,7 +486,7 @@ namespace PU MIR_APP_DLL(bool) IsProcessElevated(); // Launches pu_stub.exe with elevated priviledges if needed - MIR_APP_DLL(bool) PrepareEscalation(); + MIR_APP_DLL(bool) PrepareEscalation(const wchar_t *pwszFile = nullptr); MIR_APP_DLL(int) SafeCopyFile(const wchar_t *pSrc, const wchar_t *pDst); MIR_APP_DLL(int) SafeMoveFile(const wchar_t *pSrc, const wchar_t *pDst); diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib index 6d2db7c7aa..649d08771d 100644 Binary files a/libs/win32/mir_app.lib and b/libs/win32/mir_app.lib differ diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib index 73e5cdf867..81024ccfa7 100644 Binary files a/libs/win64/mir_app.lib and b/libs/win64/mir_app.lib differ diff --git a/src/mir_app/src/db_ini.cpp b/src/mir_app/src/db_ini.cpp index 8c8ac9d1f4..8ce8f88385 100644 --- a/src/mir_app/src/db_ini.cpp +++ b/src/mir_app/src/db_ini.cpp @@ -30,19 +30,19 @@ static HANDLE hIniChangeNotification; static void MyMoveFile(const wchar_t *pwszFrom, const wchar_t *pwszTo) { - if (PU::PrepareEscalation()) + if (PU::PrepareEscalation(pwszTo)) PU::SafeMoveFile(pwszFrom, pwszTo); } static void MyDeleteFile(const wchar_t *pwszFileName) { - if (PU::PrepareEscalation()) + if (PU::PrepareEscalation(pwszFileName)) PU::SafeDeleteFile(pwszFileName); } static void ToRecycleBin(const wchar_t *pwszFileName) { - if (PU::PrepareEscalation()) + if (PU::PrepareEscalation(pwszFileName)) PU::SafeRecycleBin(pwszFileName); } diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index f49cd58964..3bb3706b0b 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -738,7 +738,7 @@ Chat_CreateMenu @824 NONAME _Netlib_GetTlsUnique@12 @831 NONAME ?IsDirect@PU@@YG_NXZ @832 NONAME ?IsProcessElevated@PU@@YG_NXZ @833 NONAME -?PrepareEscalation@PU@@YG_NXZ @834 NONAME +?PrepareEscalation@PU@@YG_NPB_W@Z @834 NONAME ?SafeCopyFile@PU@@YGHPB_W0@Z @835 NONAME ?SafeCreateDirectory@PU@@YGHPB_W@Z @836 NONAME ?SafeCreateFilePath@PU@@YGHPB_W@Z @837 NONAME diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 249613f8b9..3f49b78264 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -738,7 +738,7 @@ Chat_CreateMenu @824 NONAME Netlib_GetTlsUnique @831 NONAME ?IsDirect@PU@@YA_NXZ @832 NONAME ?IsProcessElevated@PU@@YA_NXZ @833 NONAME -?PrepareEscalation@PU@@YA_NXZ @834 NONAME +?PrepareEscalation@PU@@YA_NPEB_W@Z @834 NONAME ?SafeCopyFile@PU@@YAHPEB_W0@Z @835 NONAME ?SafeCreateDirectory@PU@@YAHPEB_W@Z @836 NONAME ?SafeCreateFilePath@PU@@YAHPEB_W@Z @837 NONAME diff --git a/src/mir_app/src/pu_utils.cpp b/src/mir_app/src/pu_utils.cpp index 622f483705..9495031fe7 100644 --- a/src/mir_app/src/pu_utils.cpp +++ b/src/mir_app/src/pu_utils.cpp @@ -133,21 +133,27 @@ Cleanup: ///////////////////////////////////////////////////////////////////////////////////////// // Launches pu_stub.exe with elevated priviledges if needed -MIR_APP_DLL(bool) PU::PrepareEscalation() +MIR_APP_DLL(bool) PU::PrepareEscalation(const wchar_t *pwszFile) { + CMStringW wszFilePath; // First try to create a file near Miranda32.exe - wchar_t szPath[MAX_PATH]; - GetModuleFileName(nullptr, szPath, _countof(szPath)); - wchar_t *ext = wcsrchr(szPath, '.'); - if (ext != nullptr) - *ext = '\0'; - wcscat(szPath, L".test"); + if (pwszFile == nullptr) { + wchar_t szPath[MAX_PATH]; + GetModuleFileName(nullptr, szPath, _countof(szPath)); + wchar_t *ext = wcsrchr(szPath, '.'); + if (ext != nullptr) + *ext = '\0'; + wszFilePath = szPath; + } + else wszFilePath = pwszFile; + + wszFilePath.Append(L".test"); - HANDLE hFile = CreateFile(szPath, GENERIC_WRITE, FILE_SHARE_READ, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + HANDLE hFile = CreateFileW(wszFilePath, GENERIC_WRITE, FILE_SHARE_READ, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); if (hFile != INVALID_HANDLE_VALUE) { // we are admins or UAC is disable, cool CloseHandle(hFile); - DeleteFileW(szPath); + DeleteFileW(wszFilePath); return true; } @@ -168,7 +174,8 @@ MIR_APP_DLL(bool) PU::PrepareEscalation() } else { wchar_t cmdLine[100], *p; - GetModuleFileName(nullptr, szPath, ARRAYSIZE(szPath)); + wchar_t szPath[MAX_PATH]; + GetModuleFileName(nullptr, szPath, _countof(szPath)); if ((p = wcsrchr(szPath, '\\')) != nullptr) wcscpy(p + 1, L"pu_stub.exe"); mir_snwprintf(cmdLine, L"%d", GetCurrentProcessId()); -- cgit v1.2.3