![]() |
General Programming »
Programming Tips »
General
License: The Code Project Open License (CPOL)
How Can I Get the Address of KeServiceDescriptorTableShadowBy Try and tryExplain how to get the address of KeServiceDescriptorTableShadow |
C++/CLI, C, VC6, VC7, VC7.1, VC8.0Win2K, WinXP, Vista
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
This article shows how to get the address of KeServiceDescriptorTableShadow kernel variable. This variable is used to add new system services to kernel, or hook an existing system service. Unfortunately, it is not exported by ntoskrnl.exe, so we have to get its address manually.
Using KeServiceDescriptorTable variable exported by ntoskrnl.exe, we can get the address of KeServiceDescriptorTableShadow variable. KeServiceDescriptorTableShadow is an extension of KeServiceDescriptorTable variable. Please see the following section.
The type of two variables is SERVICE_DESCRIPTOR_TABLE structure. This structure is defined as follows:
typedef struct _SERVICE_DESCRIPTOR_TABLE
{
PULONG ServiceTable; // array of entry-points
PULONG puCounterTable; // array of counters
ULONG uTableSize; // number of table entries
PUCHAR pbArgumentTable; // array of byte counts
} SERVICE_DESCRIPTOR_TABLE, *PSERVICE_DESCRIPTOR_TABLE;
The first part of KeServiceDescriptorTableShadow is the same as KeServiceDescriptorTable. And so we could get the address of KeServiceDescriptorTableShadow by comparing memories around KeServiceDescriptorTable. In different version of Windows, this address is different.
This function retrieves its address in different version of Windows.
PSERVICE_DESCRIPTOR_TABLE QuerySDTShadow()
{
ULONG Index;
PUCHAR SDTShadow;
UONG MajorVersion, MinorVersion, BuildNumber;
UNICODE_STRING &CSDVersion;
PsGetVersion(&MajorVersion, &MinorVersion, &BuildNumber, &CSDVersion);
__try
{
if(MajorVersion == 5 && MinorVersion == 1) // Windows XP
SDTShadow = (PUCHAR)((ULONG)&KeServiceDescriptorTable - 0x40);
else // Windows 2000, or Windows Vista
SDTShadow = (PUCHAR)((ULONG)&KeServiceDescriptorTable + 0x40);
for(Index = 0; Index < 0x1000; Index ++, SDTShadow ++)
{
KeServiceDescriptorTableShadow = (PSERVICE_DESCRIPTOR_TABLE)SDTShadow;
if(KeServiceDescriptorTableShadow == &KeServiceDescriptorTable)
continue;
if(memcmp(KeServiceDescriptorTableShadow, &KeServiceDescriptorTable, 0x10) == 0
&& ((UCHAR)KeServiceDescriptorTableShadow->ServiceTable & 3) == 0)
{
return (PSERVICE_DESCRIPTOR_TABLE)SDTShadow;
}
}
return NULL;
}
__except(1)
{
return NULL;
}
}
This code was tested in various environments, but you must use it carefully.
| You must Sign In to use this message board. | ||||||||
|
||||||||
|
||||||||
|
||||||||
|
||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 26 May 2008 Editor: Deeksha Shenoy |
Copyright 2008 by Try and try Everything else Copyright © CodeProject, 1999-2009 Web20 | Advertise on the Code Project |