#ifndef _NTRTL_H
#if (PHNT_VERSION >= PHNT_WINDOWS_8_1)
NTSYSAPI
NTSTATUS
NTAPI
RtlQueryPackageIdentityEx(
_In_ HANDLE TokenHandle,
_Out_writes_bytes_to_(*PackageSize, *PackageSize) PWSTR PackageFullName,
_Inout_ PSIZE_T PackageSize,
_Out_writes_bytes_to_opt_(*AppIdSize, *AppIdSize) PWSTR AppId,
_Inout_opt_ PSIZE_T AppIdSize,
_Out_opt_ PGUID DynamicId,
_Out_opt_ PULONG64 Flags
);
View code on GitHub
// ntifs.h
NTSYSAPI NTSTATUS RtlQueryPackageIdentityEx(
PVOID TokenObject,
PWSTR PackageFullName,
PSIZE_T PackageSize,
PWSTR AppId,
PSIZE_T AppIdSize,
LPGUID DynamicId,
PULONG64 Flags
);
View the official Windows Driver Kit DDI reference
Queries package identity information for a token. This function is documented in Windows Driver Kit.
TokenHandle
- a handle to a token or one of the supported pseudo-handles (see below). The handle must grant TOKEN_QUERY
access.PackageFullName
- an optional pointer to user-allocated buffer that receives the full name of the package.PackageSize
- an optional pointer to a variable that specifies the size of the PackageFullName
buffer in bytes and receives the number of bytes written.AppId
- an optional pointer to user-allocated buffer that receives the relative application user model ID of the package.AppIdSize
- an optional pointer to a variable that specifies the size of the AppId
buffer in bytes and receives the number of bytes written.DynamicId
- an optional pointer to a variable that receives the dynamic ID of the application.Flags
- an optional pointer to a variable that receives package claim flags. To interpret this value, cast it to PS_PKG_CLAIM
.This function supports the following pseudo-handle values:
NtCurrentProcessToken
- performs the query on the primary token of the calling process.NtCurrentThreadToken
- performs the query on the impersonation token of the calling thread. The function fails if the thread is not impersonating.NtCurrentThreadEffectiveToken
- performs the query on the impersonation token of the calling thread, if present. Otherwise, the function uses the primary token of the calling process.STATUS_NOT_FOUND
- the token doesn't have package identity attributes.This function calls NtQuerySecurityAttributesToken
and reads the values of the WIN://SYSAPPID
and WIN://PKG
attributes.
Alternatively to using NtQuerySecurityAttributesToken
, you can also enumerate all security attributes via NtQueryInformationToken
with TokenSecurityAttributes
and retrieve the values from there.
This function was introduced in Windows 8.1.
RtlQueryPackageIdentityEx returns the associated full package name. It can optionally also return the package relative application name, and whether an application is considered packaged.
TokenObject
Handle to a token object (user mode) that was opened with TOKEN_QUERY access, or to a raw token object (kernel mode).
PackageFullName
Pointer to a wide character buffer that will receive the unique package key. The buffer will be null terminated upon success.
PackageSize
Pointer to the value that defines the size of the buffer that PackageFullName points to. On output, it will contain the written size including the terminating null.
AppId
Pointer to a wide character buffer that may receive the package relative application identifier. AppId is optional and can be NULL.
AppIdSize
Pointer to the value that defines the size of the buffer that AppId points to. On output, it will contain the written size including the terminating null. If AppId is not NULL, AppIdSize must point to a valid value; otherwise AppIdSize should set to NULL.
DynamicId
Pointer to a value that receives a dynamic ID for the application. DynamicId is optional and can be NULL.
Flags
Pointer to a value that receives a bitmask of values for the package attribute.
RtlQueryPackageIdentityEx returns STATUS_SUCCESS upon successful completion; otherwise it returns a code such as one of the following.
Error Code | Meaning |
---|---|
STATUS_INVALID_PARAMETER | A parameter contains an invalid value; for example, a size value was not provided for a non-NULL buffer. This is an error code. |
STATUS_NOT_FOUND | A package identity does not exist. |