Skip to content
This repository was archived by the owner on Jan 4, 2025. It is now read-only.

Commit 993ee26

Browse files
committed
Update security measures for TranslucentFlyouts.Immersive
1 parent e6bd2bc commit 993ee26

File tree

6 files changed

+79
-4
lines changed

6 files changed

+79
-4
lines changed

TFMain/TFMain.aps

8 Bytes
Binary file not shown.

TFMain/TFMain.rc

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ BEGIN
6060
IDS_STRING106 "���ڴӱ��ػ�΢�����ŷ��������ط����ļ�����ȷ�����������������..."
6161
IDS_STRING107 "���ƺ�����һ������֧�ֵ�Windowsϵͳ������TranslucentFlyouts�������ļ��ѳɹ����ص�δ��������Ҫ����Ϣ���뽫���ϵͳ�汾����������ߣ�"
6262
IDS_STRING108 "�����Ľ���Ѿ������浽ע����С�"
63-
IDS_STRING109 "Windows ��Դ�������ڹ�ȥ30�����������������Σ��������ƺ�������һ�����صļ��������⣡���ڰ�ȫ������TranslucentFlyouts�����񽫻ᱻǿ����ֹ��\n���������������֣��뿼�DZ������ϵͳ�汾�������ߣ�"
64-
IDS_STRING110 "�Ѿ�������5���Ӷ�Windows ��Դ��������Ȼû�����������������������ƺ�������һ�����صļ��������⣡���ڰ�ȫ������TranslucentFlyouts�����񽫻ᱻǿ����ֹ��\n���������������֣��뿼�DZ������ϵͳ�汾�������ߣ�"
63+
IDS_STRING109 "Windows ��Դ�������ڹ�ȥ30�����������������Σ��������ƺ�������һ�����صļ��������⣡���ڰ�ȫ������TranslucentFlyouts.Win32���ᱻǿ����ֹ��\n���������������֣��뿼�DZ������ϵͳ�汾�������ߣ�"
64+
IDS_STRING110 "�Ѿ�������5���Ӷ�Windows ��Դ��������Ȼû�����������������������ƺ�������һ�����صļ��������⣡���ڰ�ȫ������TranslucentFlyouts.Win32���ᱻǿ����ֹ��\n���������������֣��뿼�DZ������ϵͳ�汾�������ߣ�"
6565
END
6666

6767
#endif // ����(���壬�й�) resources
@@ -90,8 +90,8 @@ BEGIN
9090
IDS_STRING106 "Loading symbol files from local disk or Microsoft symbol servers, please make sure your network connection is alright..."
9191
IDS_STRING107 "It appears that you are running TranslucentFlyouts on an UNSUPPORTED Windows system! The symbol file was loaded successfully but resolved failed, please report your OS information to the developer!"
9292
IDS_STRING108 "The results of resolved symbols have been saved into the registry."
93-
IDS_STRING109 "Windows Explorer crashed twice in the last 30 seconds! It seems like there is a severe compatibility issue! For security reasons, TranslucentFlyouts main service will now be terminated.\nPlease consider reporting your OS information to the developer if you encounter this situation again!"
94-
IDS_STRING110 "It's been more than 5 seconds and Windows Explorer still hasn't restarted properly! It seems like there is a severe compatibility issue! For security reasons, TranslucentFlyouts main service will now be terminated.\nPlease consider reporting your OS information to the developer if you keep encountering this situation!"
93+
IDS_STRING109 "Windows Explorer crashed twice in the last 30 seconds! It seems like there is a severe compatibility issue! For security reasons, TranslucentFlyouts.Win32 will now be terminated.\nPlease consider reporting your OS information to the developer if you encounter this situation again!"
94+
IDS_STRING110 "It's been more than 5 seconds and Windows Explorer still hasn't restarted properly! It seems like there is a severe compatibility issue! For security reasons, TranslucentFlyouts.Win32 main service will now be terminated.\nPlease consider reporting your OS information to the developer if you keep encountering this situation!"
9595
END
9696

9797
#endif // Ӣ��(����) resources

TFModern/Framework.cpp

+73
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include "pch.h"
2+
#include "resource.h"
23
#include "Api.hpp"
34
#include "Utils.hpp"
45
#include "RegHelper.hpp"
56
#include "Framework.hpp"
67
#include "HookHelper.hpp"
8+
#include "Application.hpp"
79
#include "CommonFlyoutsHandler.hpp"
810

911
using namespace TranslucentFlyouts;
@@ -23,6 +25,76 @@ namespace TranslucentFlyouts::Framework
2325

2426
void Update();
2527
DWORD WINAPI MessageThreadProc(LPVOID);
28+
void DoExplorerCrashCheck();
29+
}
30+
31+
void Framework::DoExplorerCrashCheck()
32+
{
33+
static std::chrono::steady_clock::time_point g_lastExplorerDied{ std::chrono::steady_clock::time_point{} - std::chrono::seconds(30) };
34+
static std::chrono::steady_clock::time_point g_lastExplorerDied2{ std::chrono::steady_clock::time_point{} - std::chrono::seconds(10) };
35+
static DWORD g_lastExplorerPid
36+
{
37+
[]
38+
{
39+
DWORD explorerPid{ 0 };
40+
GetWindowThreadProcessId(GetShellWindow(), &explorerPid);
41+
42+
return explorerPid;
43+
} ()
44+
};
45+
46+
auto terminate = [](UINT id)
47+
{
48+
Application::UninstallHook();
49+
50+
static WCHAR msg[32768 + 1]{};
51+
LoadStringW(wil::GetModuleInstanceHandle(), id, msg, 32768);
52+
MessageBoxW(
53+
nullptr,
54+
msg,
55+
nullptr,
56+
MB_ICONERROR | MB_SYSTEMMODAL | MB_SERVICE_NOTIFICATION | MB_SETFOREGROUND
57+
);
58+
59+
std::thread{ [&]
60+
{
61+
Application::StopService();
62+
} }.detach();
63+
};
64+
65+
DWORD explorerPid{ 0 };
66+
GetWindowThreadProcessId(GetShellWindow(), &explorerPid);
67+
68+
if (explorerPid)
69+
{
70+
g_lastExplorerDied2 = std::chrono::steady_clock::now();
71+
g_lastExplorerPid = explorerPid;
72+
}
73+
74+
// Being dead for too long!
75+
{
76+
const auto currentTimePoint{ std::chrono::steady_clock::now() };
77+
if (currentTimePoint >= g_lastExplorerDied2 + std::chrono::seconds(5))
78+
{
79+
terminate(IDS_STRING103);
80+
return;
81+
}
82+
}
83+
// Died twice in a short time!
84+
if (g_lastExplorerPid && explorerPid == 0)
85+
{
86+
const auto currentTimePoint{ std::chrono::steady_clock::now() };
87+
88+
if (currentTimePoint < g_lastExplorerDied + std::chrono::seconds(30)) [[unlikely]]
89+
{
90+
terminate(IDS_STRING102);
91+
return;
92+
}
93+
94+
g_lastExplorerDied = currentTimePoint;
95+
g_lastExplorerDied2 = currentTimePoint;
96+
g_lastExplorerPid = 0;
97+
}
2698
}
2799

28100
DWORD WINAPI Framework::MessageThreadProc(LPVOID)
@@ -339,6 +411,7 @@ void CALLBACK Framework::HandleWinEvent(
339411
DWORD dwEventThread, DWORD dwmsEventTime
340412
)
341413
{
414+
Framework::DoExplorerCrashCheck();
342415
if (Api::IsPartDisabled(L"ImmersiveFlyouts")) [[unlikely]]
343416
{
344417
return;

TFModern/TFModern.aps

1.7 KB
Binary file not shown.

TFModern/TFModern.rc

1.89 KB
Binary file not shown.

TFModern/resource.h

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// 供 TFModern.rc 使用
44
//
55
#define IDS_STRING101 101
6+
#define IDS_STRING102 102
7+
#define IDS_STRING103 103
68

79
// Next default values for new objects
810
//

0 commit comments

Comments
 (0)