Skip to content

Commit afd109f

Browse files
committed
Start10: Mitigate breakage caused by feature flag 58205615 (#4523)
1 parent 6d946bd commit afd109f

2 files changed

Lines changed: 93 additions & 21 deletions

File tree

ExplorerPatcher/utility.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,42 @@ inline BOOL IncrementDLLReferenceCount(HINSTANCE hinst)
605605
return TRUE;
606606
}
607607

608+
inline void SectionBeginAndSize(HMODULE hModule, const char* pszSectionName, PBYTE* beginSection, DWORD* sizeSection)
609+
{
610+
*beginSection = NULL;
611+
*sizeSection = 0;
612+
613+
PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER)hModule;
614+
if (dosHeader->e_magic == IMAGE_DOS_SIGNATURE)
615+
{
616+
PIMAGE_NT_HEADERS64 ntHeader = (PIMAGE_NT_HEADERS64)((BYTE*)dosHeader + dosHeader->e_lfanew);
617+
if (ntHeader->Signature == IMAGE_NT_SIGNATURE)
618+
{
619+
PIMAGE_SECTION_HEADER firstSection = IMAGE_FIRST_SECTION(ntHeader);
620+
for (unsigned int i = 0; i < ntHeader->FileHeader.NumberOfSections; ++i)
621+
{
622+
PIMAGE_SECTION_HEADER section = firstSection + i;
623+
if (strncmp((const char*)section->Name, pszSectionName, IMAGE_SIZEOF_SHORT_NAME) == 0)
624+
{
625+
*beginSection = (PBYTE)dosHeader + section->VirtualAddress;
626+
*sizeSection = section->SizeOfRawData;
627+
break;
628+
}
629+
}
630+
}
631+
}
632+
}
633+
634+
__forceinline void TextSectionBeginAndSize(HMODULE hModule, PBYTE* beginSection, DWORD* sizeSection)
635+
{
636+
SectionBeginAndSize(hModule, ".text", beginSection, sizeSection);
637+
}
638+
639+
__forceinline void RDataSectionBeginAndSize(HMODULE hModule, PBYTE* beginSection, DWORD* sizeSection)
640+
{
641+
SectionBeginAndSize(hModule, ".rdata", beginSection, sizeSection);
642+
}
643+
608644
PVOID FindPattern(PVOID pBase, SIZE_T dwSize, LPCSTR lpPattern, LPCSTR lpMask);
609645

610646
#if _M_X64

ep_startmenu/ep_sm_main.c

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,7 @@ void PatchXamlMetaDataProviderGuid()
7777

7878
PBYTE beginRData = NULL;
7979
DWORD sizeRData = 0;
80-
81-
// Our target is in .rdata
82-
PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER)GetModuleHandleW(NULL);
83-
if (dosHeader->e_magic == IMAGE_DOS_SIGNATURE)
84-
{
85-
PIMAGE_NT_HEADERS64 ntHeader = (PIMAGE_NT_HEADERS64)((u_char*)dosHeader + dosHeader->e_lfanew);
86-
if (ntHeader->Signature == IMAGE_NT_SIGNATURE)
87-
{
88-
PIMAGE_SECTION_HEADER firstSection = IMAGE_FIRST_SECTION(ntHeader);
89-
for (unsigned int i = 0; i < ntHeader->FileHeader.NumberOfSections; ++i)
90-
{
91-
PIMAGE_SECTION_HEADER section = firstSection + i;
92-
if (!strncmp(section->Name, ".rdata", 6))
93-
{
94-
beginRData = (PBYTE)dosHeader + section->VirtualAddress;
95-
sizeRData = section->SizeOfRawData;
96-
break;
97-
}
98-
}
99-
}
100-
}
80+
RDataSectionBeginAndSize(GetModuleHandleW(NULL), &beginRData, &sizeRData);
10181
if (!beginRData || !sizeRData)
10282
{
10383
return;
@@ -132,6 +112,62 @@ void Init()
132112
LoadLibraryW(L"JumpViewUI_.dll");
133113
g_bIsUsingOwnJumpViewUI = TRUE;
134114
}
115+
116+
PBYTE beginText = NULL;
117+
DWORD sizeText = 0;
118+
TextSectionBeginAndSize(GetModuleHandleW(NULL), &beginText, &sizeText);
119+
if (beginText && sizeText)
120+
{
121+
// Fix 0x800704DA (The service is already registered) exception when feature flag 58205615 is enabled
122+
// Feature flag introduced in:
123+
// - Germanium Client 26100.5742+
124+
// - Germanium Server 26461+
125+
// - Bromine Canary 27924+ (reworked in 27938)
126+
// Used to be inlined in StartMenuExperienceHost::App::OnLaunched(), the rework made it be called using
127+
// std::call_once, therefore we have a function that we can make it do nothing.
128+
129+
// StartMenuExperienceHost::App::SetExperienceManagerPropertiesAsync()
130+
// Early return that function
131+
#if defined(_M_X64)
132+
// TODO Improve pattern
133+
// 40 53 57 48 83 EC 28 E8 ?? ?? ?? ?? 48 8B D8 48 89 44 24 40 48 8B C8
134+
PBYTE match = FindPattern(
135+
beginText,
136+
sizeText,
137+
"\x40\x53\x57\x48\x83\xEC\x28\xE8\x00\x00\x00\x00\x48\x8B\xD8\x48\x89\x44\x24\x40\x48\x8B\xC8",
138+
"xxxxxxxx????xxxxxxxxxxx"
139+
);
140+
if (match)
141+
{
142+
DWORD dwOldProtect = 0;
143+
if (VirtualProtect(match, 1, PAGE_EXECUTE_READWRITE, &dwOldProtect))
144+
{
145+
match[0] = 0xC3; // ret
146+
VirtualProtect(match, 1, dwOldProtect, &dwOldProtect);
147+
}
148+
}
149+
#elif defined(_M_ARM64)
150+
// TODO Improve pattern
151+
// 7F 23 03 D5 F3 53 BF A9 FD 7B BC A9 FD 03 00 91 30 00 80 92
152+
// ----------- PACIBSP, don't scan for this because it's everywhere
153+
PBYTE match = FindPattern(
154+
beginText,
155+
sizeText,
156+
"\xF3\x53\xBF\xA9\xFD\x7B\xBC\xA9\xFD\x03\x00\x91\x30\x00\x80\x92",
157+
"xxxxxxxxxxxxxxxx"
158+
);
159+
if (match)
160+
{
161+
match -= 4; // include PACIBSP
162+
DWORD dwOldProtect = 0;
163+
if (VirtualProtect(match, 4, PAGE_EXECUTE_READWRITE, &dwOldProtect))
164+
{
165+
*(DWORD*)match = 0xD65F03C0; // RET
166+
VirtualProtect(match, 4, dwOldProtect, &dwOldProtect);
167+
}
168+
}
169+
#endif
170+
}
135171
}
136172
HMODULE hMod;
137173
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, hModule, &hMod);

0 commit comments

Comments
 (0)