Skip to content

Commit df7d604

Browse files
committed
File Explorer: On TIFE-equipped builds, fix 7 command bar menu bar behavior and fix 10 ribbon window saving - ARM64 (#2243, #2676)
1 parent 75178ec commit df7d604

2 files changed

Lines changed: 73 additions & 4 deletions

File tree

ExplorerPatcher/dllmain.c

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8180,7 +8180,7 @@ void FixTIFEBreakagesForLegacyControlInterfaces(const MODULEINFO* pmi)
81808180
);
81818181
if (match)
81828182
{
8183-
match += 27; // Align to jump
8183+
match += 27; // Point to jump
81848184
}
81858185
else
81868186
{
@@ -8195,10 +8195,10 @@ void FixTIFEBreakagesForLegacyControlInterfaces(const MODULEINFO* pmi)
81958195
);
81968196
if (match)
81978197
{
8198-
match += 8; // Align to jump
8198+
match += 8; // Point to jump
81998199
}
82008200
}
8201-
if (match) // Should be aligned to jump at this point
8201+
if (match) // Should be pointed to jump at this point
82028202
{
82038203
PBYTE target = NULL;
82048204
DWORD jmpInstrSize = 0;
@@ -8239,7 +8239,58 @@ void FixTIFEBreakagesForLegacyControlInterfaces(const MODULEINFO* pmi)
82398239
}
82408240
}
82418241
#elif defined(_M_ARM64)
8242-
// ARM64 implementation not done yet
8242+
// No TIFE feature flag
8243+
// 69 ?? ?? B9 68 ?? ?? B9 69 ?? ?? 29 <TBZ/TBNZ>
8244+
// Ref: CInternetToolbar::_CreateBands()
8245+
PBYTE match = FindPattern(
8246+
pmi->lpBaseOfDll,
8247+
pmi->SizeOfImage,
8248+
"\x69\x00\x00\xB9\x68\x00\x00\xB9\x69\x00\x00\x29",
8249+
"x??xx??xx??x"
8250+
);
8251+
if (match)
8252+
{
8253+
match += 12; // Point to TBZ/TBNZ
8254+
}
8255+
else
8256+
{
8257+
// TIFE feature flag present
8258+
// 68 ?? ?? B9 68 00 20 36 08 79 1B 12 68 ?? ?? B9
8259+
// ^^^^^^^^^^^ <TBZ>
8260+
// Ref: CInternetToolbar::_CreateBands()
8261+
match = FindPattern(
8262+
pmi->lpBaseOfDll,
8263+
pmi->SizeOfImage,
8264+
"\x68\x00\x00\xB9\x68\x00\x20\x36\x08\x79\x1B\x12\x68\x00\x00\xB9",
8265+
"x??xxxxxxxxxx??x"
8266+
);
8267+
if (match)
8268+
{
8269+
match += 4; // Point to TBZ
8270+
}
8271+
}
8272+
if (match) // Should be pointed to TBZ/TBNZ at this point
8273+
{
8274+
DWORD insnCurrent = *(DWORD*)match;
8275+
DWORD insnNew = 0;
8276+
if (ARM64_IsTBZ(insnCurrent))
8277+
{
8278+
insnNew = ARM64_TBZToB(insnCurrent);
8279+
}
8280+
else if (ARM64_IsTBNZ(insnCurrent))
8281+
{
8282+
insnNew = 0xD503201F; // NOP
8283+
}
8284+
if (insnNew != 0)
8285+
{
8286+
DWORD dwOldProtect;
8287+
if (VirtualProtect(match, 4, PAGE_EXECUTE_READWRITE, &dwOldProtect))
8288+
{
8289+
*(DWORD*)match = insnNew;
8290+
VirtualProtect(match, 4, dwOldProtect, &dwOldProtect);
8291+
}
8292+
}
8293+
}
82438294
#endif
82448295
}
82458296
#pragma endregion

ExplorerPatcher/utility.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,8 @@ __forceinline UINT_PTR ARM64_Align(UINT_PTR value, UINT_PTR alignment)
709709

710710
__forceinline BOOL ARM64_IsCBZW(DWORD insn) { return ARM64_ReadBits(insn, 31, 24) == 0b00110100; }
711711
__forceinline BOOL ARM64_IsCBNZW(DWORD insn) { return ARM64_ReadBits(insn, 31, 24) == 0b00110101; }
712+
__forceinline BOOL ARM64_IsTBZ(DWORD insn) { return ARM64_ReadBits(insn, 31, 24) == 0b00110110; }
713+
__forceinline BOOL ARM64_IsTBNZ(DWORD insn) { return ARM64_ReadBits(insn, 31, 24) == 0b00110111; }
712714
__forceinline BOOL ARM64_IsBL(DWORD insn) { return ARM64_ReadBits(insn, 31, 26) == 0b100101; }
713715
__forceinline BOOL ARM64_IsADRP(DWORD insn) { return (ARM64_ReadBits(insn, 31, 24) & ~0b01100000) == 0b10010000; }
714716
__forceinline BOOL ARM64_IsMOVZW(DWORD insn) { return ARM64_ReadBits(insn, 31, 23) == 0b010100101; }
@@ -755,6 +757,22 @@ __forceinline DWORD ARM64_CBNZWToB(DWORD insnCBNZW)
755757
return ARM64_MakeB(imm19);
756758
}
757759

760+
__forceinline DWORD ARM64_TBZToB(DWORD insnTBZ)
761+
{
762+
if (!ARM64_IsTBZ(insnTBZ))
763+
return 0;
764+
int imm14 = ARM64_ReadBitsSignExtend(insnTBZ, 18, 5);
765+
return ARM64_MakeB(imm14);
766+
}
767+
768+
__forceinline DWORD ARM64_TBNZToB(DWORD insnTBNZ)
769+
{
770+
if (!ARM64_IsTBNZ(insnTBNZ))
771+
return 0;
772+
int imm14 = ARM64_ReadBitsSignExtend(insnTBNZ, 18, 5);
773+
return ARM64_MakeB(imm14);
774+
}
775+
758776
__forceinline DWORD ARM64_DecodeADD(DWORD insnADD)
759777
{
760778
DWORD imm12 = ARM64_ReadBits(insnADD, 21, 10);

0 commit comments

Comments
 (0)