#include <ntddk.h>
#include <windef.h>
#define S_CODE _cdecl
typedef
NTSTATUS(S_CODE* t_NtQuerySystemInformation)(
ULONG
systemInformationClass,
PVOID
systemInformation,
ULONG
systemInformationLength,
PULONG
returnLength);
typedef
struct
_SYSTEM_SERVICE_TABLE
{
PVOID
* ServiceTable;
PULONG
CounterTable;
ULONG
ServiceLimit;
PVOID
ArgumentTable;
}SYSTEM_SERVICE_TABLE, * PSYSTEM_SERVICE_TABLE;
t_NtQuerySystemInformation NtQuerySystemInformation = NULL;
PSYSTEM_SERVICE_TABLE KeServiceDescriptorTable = NULL;
VOID
EnumSSDT()
{
PSYSTEM_SERVICE_TABLE SST = KeServiceDescriptorTable;
KIRQL irql;
ULONG
index;
PULONG
ptr;
PVOID
funptr;
irql = KeRaiseIrqlToDpcLevel();
for
(index = 0; index < SST->ServiceLimit; index++)
{
ptr = (
PULONG
)& SST->CounterTable[index];
funptr = (
PVOID
)ptr[index];
DbgPrint(
"SSDT[%d]: %p\n"
, index, funptr);
}
KeLowerIrql(irql);
}
NTSTATUS DriverEntry(_In_ PDRIVER_OBJECT pDriverObject, _In_ PUNICODE_STRING pRegistryPath)
{
NTSTATUS status;
ULONG
ReturnLength;
ULONG
i;
DbgPrint(
"DriverEntry start\n"
);
NtQuerySystemInformation = (t_NtQuerySystemInformation)MmGetSystemRoutineAddress(
&RTL_CONSTANT_STRING(
"NtQuerySystemInformation"
));
if
(!NtQuerySystemInformation)
{
DbgPrint(
"Failed to get system routine address\n"
);
return
STATUS_UNSUCCESSFUL;
}
status = NtQuerySystemInformation(SystemModuleInformation, NULL, 0, &ReturnLength);
if
(status != STATUS_INFO_LENGTH_MISMATCH)
{
DbgPrint(
"Failed to get system module information\n"
);
return
status;
}
PVOID
buffer = ExAllocatePoolWithTag(NonPagedPool, ReturnLength,
'NG'
);
status = NtQuerySystemInformation(SystemModuleInformation, buffer, ReturnLength, &ReturnLength);
if
(!NT_SUCCESS(status))
{
DbgPrint(
"failed to get system module information, status = %x\n"
, status);
return
status;
}
PRTL_PROCESS_MODULES pModules = (PRTL_PROCESS_MODULES)buffer;
PRTL_PROCESS_MODULE_INFORMATION pModule = &(pModules->Modules[0]);
KeServiceDescriptorTable = (PSYSTEM_SERVICE_TABLE)(
DWORD_PTR
)
((
PCHAR
)pModule->ImageBase + pModule->ExportDirectory->AddressOfNames);
EnumSSDT();
DbgPrint(
"DriverEntry end\n"
);
return
STATUS_SUCCESS;
}