Skip to content

Commit 41f830e

Browse files
committed
Fix token usage
1 parent 8112a24 commit 41f830e

File tree

6 files changed

+27
-23
lines changed

6 files changed

+27
-23
lines changed

ProcessHacker/memlists.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ INT_PTR CALLBACK PhpMemoryListsDlgProc(
170170
{
171171
case WM_INITDIALOG:
172172
{
173+
if (NT_SUCCESS(PhOpenProcessToken(NtCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &tokenHandle)))
174+
{
175+
PhSetTokenPrivilege(tokenHandle, L"SeProfileSingleProcessPrivilege", NULL, SE_PRIVILEGE_ENABLED);
176+
NtClose(tokenHandle);
177+
}
178+
173179
PhRegisterCallback(&PhProcessesUpdatedEvent, ProcessesUpdatedCallback, NULL, &ProcessesUpdatedRegistration);
174180
PhpUpdateMemoryListInfo(hwndDlg);
175181

@@ -237,9 +243,9 @@ INT_PTR CALLBACK PhpMemoryListsDlgProc(
237243
HANDLE tokenHandle;
238244
MEMORY_COMBINE_INFORMATION_EX combineInfo = { 0 };
239245

240-
if (NT_SUCCESS(NtOpenProcessToken(NtCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &tokenHandle)))
246+
if (NT_SUCCESS(PhOpenProcessToken(NtCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &tokenHandle)))
241247
{
242-
PhSetTokenPrivilege(tokenHandle, SE_PROF_SINGLE_PROCESS_NAME, NULL, SE_PRIVILEGE_ENABLED);
248+
PhSetTokenPrivilege(tokenHandle, L"SeProfileSingleProcessPrivilege", NULL, SE_PRIVILEGE_ENABLED);
243249
NtClose(tokenHandle);
244250
}
245251

ProcessHacker/tokprp.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,12 @@ INT_PTR CALLBACK PhpTokenPageProc(
669669

670670
if (appContainerName)
671671
{
672-
SetDlgItemText(hwndDlg, IDC_USER, appContainerName->Buffer);
672+
PPH_STRING packageFamilyName;
673+
674+
packageFamilyName = PhConcatStrings2(appContainerName->Buffer, L" (APP_PACKAGE)");
675+
SetDlgItemText(hwndDlg, IDC_USER, packageFamilyName->Buffer);
676+
677+
PhDereferenceObject(packageFamilyName);
673678
PhDereferenceObject(appContainerName);
674679
}
675680

phlib/appresolver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ PPH_STRING PhGetAppContainerPackageName(
167167

168168
if (SUCCEEDED(AppContainerLookupMoniker_I(AppContainerSid, &packageMonikerName)))
169169
{
170-
packageFamilyName = PhConcatStrings2(packageMonikerName, L" (APP_PACKAGE)");
170+
packageFamilyName = PhCreateString(packageMonikerName);
171171
AppContainerFreeMemory_I(packageMonikerName);
172172
}
173173

phlib/hndlinfo.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -371,16 +371,10 @@ PPH_STRING PhFormatNativeKeyName(
371371

372372
if (PhBeginInitOnce(&initOnce))
373373
{
374-
HANDLE currentTokenHandle;
375374
PTOKEN_USER tokenUser;
376375
PPH_STRING stringSid = NULL;
377376

378-
currentTokenHandle = PhGetOwnTokenAttributes().TokenHandle;
379-
380-
if (currentTokenHandle && NT_SUCCESS(PhGetTokenUser(
381-
currentTokenHandle,
382-
&tokenUser
383-
)))
377+
if (NT_SUCCESS(PhGetTokenUser(PhGetOwnTokenAttributes().TokenHandle, &tokenUser)))
384378
{
385379
stringSid = PhSidToStringSid(tokenUser->User.Sid);
386380
PhFree(tokenUser);

phlib/native.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,24 @@ PH_TOKEN_ATTRIBUTES PhGetOwnTokenAttributes(
7474
)
7575
{
7676
static PH_INITONCE initOnce = PH_INITONCE_INIT;
77-
static PH_TOKEN_ATTRIBUTES attributes;
77+
static PH_TOKEN_ATTRIBUTES attributes = { 0 };
7878

7979
if (PhBeginInitOnce(&initOnce))
8080
{
8181
BOOLEAN elevated = TRUE;
8282
TOKEN_ELEVATION_TYPE elevationType = TokenElevationTypeFull;
8383

8484
if (WindowsVersion >= WINDOWS_8)
85-
attributes.TokenHandle = NtCurrentProcessToken();
85+
{
86+
attributes.TokenHandle = NtCurrentProcessToken();
87+
}
8688
else
87-
PhOpenProcessToken(NtCurrentProcess(), TOKEN_QUERY, &attributes.TokenHandle);
89+
{
90+
HANDLE tokenHandle;
91+
92+
if (NT_SUCCESS(PhOpenProcessToken(NtCurrentProcess(), TOKEN_QUERY, &tokenHandle)))
93+
attributes.TokenHandle = tokenHandle;
94+
}
8895

8996
if (attributes.TokenHandle)
9097
{
@@ -312,14 +319,6 @@ NTSTATUS PhOpenProcessToken(
312319
{
313320
NTSTATUS status;
314321

315-
#ifdef _DEBUG
316-
if (WINDOWS_HAS_IMMERSIVE && ProcessHandle == NtCurrentProcess())
317-
{
318-
*TokenHandle = NtCurrentProcessToken();
319-
return STATUS_SUCCESS;
320-
}
321-
#endif
322-
323322
if (KphIsVerified() && (DesiredAccess & KPH_TOKEN_READ_ACCESS) == DesiredAccess)
324323
{
325324
status = KphOpenProcessToken(

plugins/DotNetTools/counters.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ BOOLEAN OpenDotNetPublicControlBlock_V4(
557557

558558
if (WINDOWS_HAS_IMMERSIVE && IsImmersive)
559559
{
560-
if (NT_SUCCESS(NtOpenProcessToken(&tokenHandle, TOKEN_QUERY, ProcessHandle)))
560+
if (NT_SUCCESS(NtOpenProcessToken(ProcessHandle, TOKEN_QUERY, &tokenHandle)))
561561
{
562562
ULONG returnLength = 0;
563563

0 commit comments

Comments
 (0)