25-11-2010, 06:27 PM
كود :
PWCHAR *GetSsdtStrings(VOID)
{
LOADED_IMAGE LoadedImage;
PVOID PtrImage;
PWCHAR *Result;
PUSHORT Ordinals;
PULONG ExportRva;
PCHAR FunctionString, *StringRva;
ULONG ServiceId, FunctionId;
MapAndLoad("ntdll.dll", NULL, &LoadedImage, FALSE, TRUE);
PtrImage = calloc(LoadedImage.FileHeader->OptionalHeader.SizeOfImage, sizeof(UCHAR));
CopyMemory((PUCHAR)PtrImage, LoadedImage.MappedAddress, LoadedImage.FileHeader->OptionalHeader.SizeOfHeaders);
for (WORD Index = 0; Index < LoadedImage.FileHeader->FileHeader.NumberOfSections; Index++)
{
CopyMemory((PUCHAR)PtrImage + LoadedImage.Sections[Index].VirtualAddress,
LoadedImage.MappedAddress + LoadedImage.Sections[Index].PointerToRawData,
LoadedImage.Sections[Index].SizeOfRawData
);
}
UnMapAndLoad(&LoadedImage);
LoadedImage.FileHeader = (PIMAGE_NT_HEADERS)((ULONG_PTR)PtrImage + ((PIMAGE_DOS_HEADER)PtrImage)->e_lfanew);
PIMAGE_EXPORT_DIRECTORY ExportDirectory = (PIMAGE_EXPORT_DIRECTORY)(LoadedImage.FileHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress + (ULONG_PTR)PtrImage);
StringRva = (PCHAR *)(ExportDirectory->AddressOfNames + (ULONG_PTR)PtrImage);
Ordinals = (PUSHORT)(ExportDirectory->AddressOfNameOrdinals + (ULONG_PTR)PtrImage);
ExportRva = (PULONG)(ExportDirectory->AddressOfFunctions + (ULONG_PTR)PtrImage);
Result = (PWCHAR *)calloc(KiSsdtLimit, sizeof(PWCHAR));
for (ULONG Index = 0; Index < KiSsdtLimit; Index++)
{
Result[Index] = L"Unknown Entry";
}
for (ULONG Index = 0; Index < ExportDirectory->NumberOfNames; Index++)
{
FunctionId = ExportRva[Ordinals[Index]] + (ULONG_PTR)PtrImage;
FunctionString = StringRva[Index] + (ULONG_PTR)PtrImage;
if (*(PUCHAR)FunctionId == 0xb8 &&
*(PUCHAR)(FunctionId + 5) == 0xba &&
*(PUCHAR)(FunctionId + 10) == 0xff &&
(*(PUCHAR)(FunctionId + 12) & 0xc0) == 0xc0)
{
if (FunctionString[0] == 'N' && FunctionString[1] == 't')
{
ServiceId = *(PULONG)(FunctionId + 1);
if (ServiceId < KiSsdtLimit)
{
Result[ServiceId] = (PWCHAR)calloc(256, sizeof(WCHAR));
_snwprintf_s(Result[ServiceId], 256, _TRUNCATE, L"%S", FunctionString);
}
}
}
}
free(PtrImage);
return Result;
}
