Skip to content

Commit c9ad3f6

Browse files
committed
8.1 compat for hook dll
1 parent 4a9441b commit c9ad3f6

3 files changed

Lines changed: 53 additions & 9 deletions

File tree

SecureUxTheme/avrf.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,24 @@ LdrGetProcedureAddress(
8989
_Out_ PVOID *ProcedureAddress
9090
);
9191

92+
NTSYSAPI
93+
PVOID
94+
NTAPI
95+
RtlPcToFileHeader(
96+
_In_ PVOID PcValue,
97+
_Out_ PVOID* BaseOfImage
98+
);
99+
100+
NTSYSAPI
101+
NTSTATUS
102+
NTAPI
103+
LdrGetDllHandle(
104+
_In_opt_ PWSTR DllPath,
105+
_In_opt_ PULONG DllCharacteristics,
106+
_In_ PUNICODE_STRING DllName,
107+
_Out_ PVOID* DllHandle
108+
);
109+
92110
NTSYSAPI
93111
ULONG
94112
DbgPrintEx(
@@ -271,11 +289,28 @@ void signal_loaded()
271289
if (!NT_SUCCESS(status))
272290
return; // whatever
273291

292+
const auto pRtlGetTokenNamedObjectPath = (decltype(&RtlGetTokenNamedObjectPath))[]
293+
{
294+
PVOID ntdll = nullptr;
295+
PVOID proc = nullptr;
296+
RtlPcToFileHeader((PVOID)&RtlPcToFileHeader, &ntdll);
297+
if (ntdll)
298+
{
299+
ANSI_STRING name = RTL_CONSTANT_STRING("RtlGetTokenNamedObjectPath");
300+
LdrGetProcedureAddress(ntdll, &name, 0, &proc);
301+
}
302+
return proc;
303+
}();
304+
305+
if (!pRtlGetTokenNamedObjectPath)
306+
return;
307+
274308
UNICODE_STRING named_objects{};
275-
309+
276310
// Let's call this totally undocumented function with no example code available anywhere, to get our session's BNO
277311
// hopefully kernel shit is set up already for this, since we're running before our own process is considered alive.
278-
status = RtlGetTokenNamedObjectPath(token, nullptr, &named_objects);
312+
status = pRtlGetTokenNamedObjectPath(token, nullptr, &named_objects);
313+
279314
if (!NT_SUCCESS(status))
280315
return;
281316

ThemeTool/MainDialog.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,15 @@ LR"(- For any custom themes to work SecureUxTheme or another patcher must be ins
5858
- or LogonUI must be hooked
5959
)";
6060

61-
// RegRenameKey is undocumented
62-
6361
static DWORD RenameDefaultColors()
6462
{
6563
const auto old_name = std::wstring{ kCurrentColorsPath } + kCurrentColorsName;
66-
//return RegRenameKey(HKEY_LOCAL_MACHINE, old_name.c_str(), kCurrentColorsBackup);
6764
return utl::rename_key(old_name.c_str(), kCurrentColorsBackup);
6865
}
6966

7067
static DWORD RestoreDefaultColors()
7168
{
7269
const auto old_name = std::wstring{ kCurrentColorsPath } + kCurrentColorsBackup;
73-
//return RegRenameKey(HKEY_LOCAL_MACHINE, old_name.c_str(), kCurrentColorsName);
7470
return utl::rename_key(old_name.c_str(), kCurrentColorsName);
7571
}
7672

@@ -92,6 +88,13 @@ static std::wstring GetPatcherDllPath()
9288
return path;
9389
}
9490

91+
static bool IsWin10()
92+
{
93+
ULONG major = 0, minor = 0, build = 0;
94+
RtlGetNtVersionNumbers(&major, &minor, &build);
95+
return major == 10;
96+
}
97+
9598
static bool IsLoadedInSession()
9699
{
97100
const auto h = OpenEventW(
@@ -506,7 +509,7 @@ void MainDialog::UpdatePatcherState()
506509
_is_loaded =
507510
is_loaded
508511
? PatcherState::Yes
509-
: (_is_installed == PatcherState::Outdated ? PatcherState::Probably : PatcherState::No);
512+
: (_is_installed == PatcherState::Outdated || (!IsWin10() && _is_installed == PatcherState::Yes) ? PatcherState::Probably : PatcherState::No);
510513
_is_logonui = reg_logonui ? PatcherState::Yes : PatcherState::No;
511514
_is_explorer = reg_explorer ? PatcherState::Yes : PatcherState::No;
512515
_is_systemsettings = reg_systemsettings ? PatcherState::Yes : PatcherState::No;
@@ -732,7 +735,7 @@ Are you sure you want to continue?)",
732735
%s
733736
The error encountered was: %s.
734737
Do you want to continue?)",
735-
_is_elevated
738+
!_is_elevated
736739
? L"Try executing the tool as administrator."
737740
: L"It seems like we're already elevated. Consider submitting a but report.",
738741
utl::ErrorToString(fix_result).c_str()
@@ -742,7 +745,7 @@ Do you want to continue?)",
742745
return;
743746
}
744747

745-
if(_is_installed == PatcherState::Yes && _is_loaded != PatcherState::Yes)
748+
if(_is_installed == PatcherState::Yes && _is_loaded == PatcherState::No)
746749
{
747750
const auto answer = utl::FormattedMessageBox(
748751
_hwnd,

ThemeTool/ThemeTool.vcxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
<EnableCOMDATFolding>true</EnableCOMDATFolding>
140140
<OptimizeReferences>true</OptimizeReferences>
141141
<GenerateDebugInformation>true</GenerateDebugInformation>
142+
<AdditionalDependencies>ntdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
142143
</Link>
143144
</ItemDefinitionGroup>
144145
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
@@ -159,6 +160,7 @@
159160
<EnableCOMDATFolding>true</EnableCOMDATFolding>
160161
<OptimizeReferences>true</OptimizeReferences>
161162
<GenerateDebugInformation>true</GenerateDebugInformation>
163+
<AdditionalDependencies>ntdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
162164
</Link>
163165
</ItemDefinitionGroup>
164166
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
@@ -174,6 +176,7 @@
174176
<Link>
175177
<SubSystem>Windows</SubSystem>
176178
<GenerateDebugInformation>true</GenerateDebugInformation>
179+
<AdditionalDependencies>ntdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
177180
</Link>
178181
</ItemDefinitionGroup>
179182
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -189,6 +192,7 @@
189192
<Link>
190193
<SubSystem>Windows</SubSystem>
191194
<GenerateDebugInformation>true</GenerateDebugInformation>
195+
<AdditionalDependencies>ntdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
192196
</Link>
193197
</ItemDefinitionGroup>
194198
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
@@ -204,6 +208,7 @@
204208
<Link>
205209
<SubSystem>Windows</SubSystem>
206210
<GenerateDebugInformation>true</GenerateDebugInformation>
211+
<AdditionalDependencies>ntdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
207212
</Link>
208213
</ItemDefinitionGroup>
209214
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -224,6 +229,7 @@
224229
<EnableCOMDATFolding>true</EnableCOMDATFolding>
225230
<OptimizeReferences>true</OptimizeReferences>
226231
<GenerateDebugInformation>true</GenerateDebugInformation>
232+
<AdditionalDependencies>ntdll.lib;%(AdditionalDependencies)</AdditionalDependencies>
227233
</Link>
228234
</ItemDefinitionGroup>
229235
<ItemGroup>

0 commit comments

Comments
 (0)