[ADVAPI32_APITEST] If TEB SubProcessTag is set, query ADVAPI32 to validate its correctness

This is based on: https://wj32.org/wp/2010/03/30/howto-use-i_querytaginformation/
and properly works in W2K3 SP2.
Thanks to Joachim for his tests.
This commit is contained in:
Pierre Schweitzer 2018-12-11 23:39:00 +01:00
parent 7d18e36a31
commit dc65db7c13
No known key found for this signature in database
GPG key ID: 7545556C3D585B0B

View file

@ -106,6 +106,39 @@ service_main(DWORD dwArgc, LPWSTR* lpszArgv)
Teb = NtCurrentTeb();
service_ok(Teb->SubProcessTag != 0, "SubProcessTag is not defined!\n");
if (Teb->SubProcessTag != 0)
{
ULONG (NTAPI *_I_QueryTagInformation)(PVOID, DWORD, PVOID) = (PVOID)GetProcAddress(GetModuleHandle("advapi32.dll"), "I_QueryTagInformation");
if (_I_QueryTagInformation != NULL)
{
/* IN/OUT parameter structure for I_QueryTagInformation() function
* See: https://wj32.org/wp/2010/03/30/howto-use-i_querytaginformation/
*/
struct
{
ULONG ProcessId;
PVOID ServiceTag;
ULONG Unknown;
PWSTR Buffer;
} ServiceQuery;
/* Set our input parameters */
ServiceQuery.ProcessId = GetCurrentProcessId();
ServiceQuery.ServiceTag = Teb->SubProcessTag;
ServiceQuery.Unknown = 0;
ServiceQuery.Buffer = NULL;
/* Call ADVAPI32 to query the correctness of our tag */
_I_QueryTagInformation(NULL, 1, &ServiceQuery);
/* If buffer is not NULL, call succeed */
if (ServiceQuery.Buffer != NULL)
{
/* It should match our service name */
service_ok(wcscmp(lpszArgv[0], ServiceQuery.Buffer) == 0, "Mismatching info: %S - %S\n", lpszArgv[0], ServiceQuery.Buffer);
LocalFree(ServiceQuery.Buffer);
}
}
}
/* Work is done */
report_service_status(SERVICE_STOPPED, NO_ERROR, 0);