Implemented system module Information

Got rid of cryptic driver names

svn path=/trunk/; revision=1542
This commit is contained in:
Eric Kohl 2001-01-18 16:55:00 +00:00
parent fd4c82a289
commit e443f083f2
5 changed files with 129 additions and 77 deletions

View file

@ -430,16 +430,15 @@ struct _SYSTEM_FLAGS_INFORMATION
typedef typedef
struct _SYSTEM_MODULE_ENTRY struct _SYSTEM_MODULE_ENTRY
{ {
ULONG Unused; ULONG Unknown1;
ULONG Always0; ULONG Unknown2;
ULONG ModuleBaseAddress; PVOID BaseAddress;
ULONG ModuleSize; ULONG Size;
ULONG Unknown; ULONG Unknown3;
ULONG ModuleEntryIndex; ULONG EntryIndex;
USHORT ModuleNameLength; /* Length of module name not including the path, this field contains valid value only for NTOSKRNL module*/ USHORT NameLength; /* Length of module name not including the path, this field contains valid value only for NTOSKRNL module*/
USHORT ModulePathLength; /* Length of 'directory path' part of modulename*/ USHORT PathLength; /* Length of 'directory path' part of modulename*/
CHAR ModuleName [256]; CHAR Name [256];
} SYSTEM_MODULE_ENTRY, * PSYSTEM_MODULE_ENTRY; } SYSTEM_MODULE_ENTRY, * PSYSTEM_MODULE_ENTRY;
typedef typedef
@ -447,7 +446,6 @@ struct _SYSTEM_MODULE_INFORMATION
{ {
ULONG Count; ULONG Count;
SYSTEM_MODULE_ENTRY Module [1]; SYSTEM_MODULE_ENTRY Module [1];
} SYSTEM_MODULE_INFORMATION, *PSYSTEM_MODULE_INFORMATION; } SYSTEM_MODULE_INFORMATION, *PSYSTEM_MODULE_INFORMATION;
// SystemLocksInformation (12) // SystemLocksInformation (12)

View file

@ -1,4 +1,4 @@
/* $Id: sysinfo.c,v 1.9 2001/01/17 02:02:39 ekohl Exp $ /* $Id: sysinfo.c,v 1.10 2001/01/18 16:53:50 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -317,11 +317,10 @@ QSI_DEF(SystemCallTimeInformation)
return (STATUS_NOT_IMPLEMENTED); return (STATUS_NOT_IMPLEMENTED);
} }
/* Class 11 - Modules Information */ /* Class 11 - Module Information */
QSI_DEF(SystemModuleInformation) QSI_DEF(SystemModuleInformation)
{ {
/* FIXME */ return LdrpQueryModuleInformation(Buffer, Size, ReqSize);
return (STATUS_NOT_IMPLEMENTED);
} }
/* Class 12 - Locks Information */ /* Class 12 - Locks Information */

View file

@ -28,7 +28,8 @@ LdrInitModuleManagement (
); );
NTSTATUS NTSTATUS
LdrProcessDriver ( LdrProcessDriver (
IN PVOID ModuleLoadBase IN PVOID ModuleLoadBase,
IN PCHAR FileName
); );
NTSTATUS NTSTATUS
LdrpMapSystemDll ( LdrpMapSystemDll (
@ -59,6 +60,11 @@ NTSTATUS LdrLoadGdiDriver (PUNICODE_STRING DriverName,
PVOID *EntryPoint, PVOID *EntryPoint,
PVOID *ExportSectionPointer); PVOID *ExportSectionPointer);
NTSTATUS
LdrpQueryModuleInformation(PVOID Buffer,
ULONG Size,
PULONG ReqSize);
PVOID STDCALL PVOID STDCALL
RtlImageDirectoryEntryToData ( RtlImageDirectoryEntryToData (
IN PVOID BaseAddress, IN PVOID BaseAddress,
@ -67,4 +73,5 @@ RtlImageDirectoryEntryToData (
OUT PULONG Size); OUT PULONG Size);
#endif /* __INCLUDE_INTERNAL_LDR_H */ #endif /* __INCLUDE_INTERNAL_LDR_H */

View file

@ -1,4 +1,4 @@
/* $Id: main.c,v 1.75 2001/01/17 19:07:13 ea Exp $ /* $Id: main.c,v 1.76 2001/01/18 16:54:22 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -565,7 +565,7 @@ _main (ULONG MultiBootMagic, PLOADER_PARAMETER_BLOCK _LoaderBlock)
if (strcmp ((PCHAR) start, "REGEDIT4") != 0) if (strcmp ((PCHAR) start, "REGEDIT4") != 0)
{ {
DPRINT1("process module '%s' at %08lx\n", name, start); DPRINT1("process module '%s' at %08lx\n", name, start);
LdrProcessDriver((PVOID)start); LdrProcessDriver((PVOID)start, name);
} }
} }

View file

@ -1,4 +1,4 @@
/* $Id: loader.c,v 1.65 2000/10/22 16:36:51 ekohl Exp $ /* $Id: loader.c,v 1.66 2001/01/18 16:55:00 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -28,6 +28,7 @@
#include <internal/mmhal.h> #include <internal/mmhal.h>
#include <internal/ob.h> #include <internal/ob.h>
#include <internal/ps.h> #include <internal/ps.h>
#include <internal/ldr.h>
#define NDEBUG #define NDEBUG
#include <internal/debug.h> #include <internal/debug.h>
@ -47,9 +48,6 @@ POBJECT_TYPE EXPORTED IoDriverObjectType = NULL;
/* FORWARD DECLARATIONS ******************************************************/ /* FORWARD DECLARATIONS ******************************************************/
NTSTATUS LdrLoadDriver(PUNICODE_STRING Filename);
NTSTATUS LdrProcessDriver(PVOID ModuleLoadBase);
PMODULE_OBJECT LdrLoadModule(PUNICODE_STRING Filename); PMODULE_OBJECT LdrLoadModule(PUNICODE_STRING Filename);
PMODULE_OBJECT LdrProcessModule(PVOID ModuleLoadBase, PUNICODE_STRING ModuleName); PMODULE_OBJECT LdrProcessModule(PVOID ModuleLoadBase, PUNICODE_STRING ModuleName);
PVOID LdrGetExportAddress(PMODULE_OBJECT ModuleObject, char *Name, unsigned short Hint); PVOID LdrGetExportAddress(PMODULE_OBJECT ModuleObject, char *Name, unsigned short Hint);
@ -60,7 +58,7 @@ static NTSTATUS LdrCreateModule(PVOID ObjectBody,
POBJECT_ATTRIBUTES ObjectAttributes); POBJECT_ATTRIBUTES ObjectAttributes);
/* PE Driver load support */ /* PE Driver load support */
static PMODULE_OBJECT LdrPEProcessModule(PVOID ModuleLoadBase, PUNICODE_STRING ModuleName); static PMODULE_OBJECT LdrPEProcessModule(PVOID ModuleLoadBase, PUNICODE_STRING FileName);
static PVOID LdrPEGetExportAddress(PMODULE_OBJECT ModuleObject, static PVOID LdrPEGetExportAddress(PMODULE_OBJECT ModuleObject,
char *Name, char *Name,
unsigned short Hint); unsigned short Hint);
@ -99,7 +97,7 @@ VOID LdrInitModuleManagement(VOID)
IoDriverObjectType->QueryName = NULL; IoDriverObjectType->QueryName = NULL;
IoDriverObjectType->OkayToClose = NULL; IoDriverObjectType->OkayToClose = NULL;
IoDriverObjectType->Create = LdrCreateModule; IoDriverObjectType->Create = LdrCreateModule;
RtlInitUnicodeString(&IoDriverObjectType->TypeName, L"Module"); RtlInitUnicodeString(&IoDriverObjectType->TypeName, L"Driver");
/* Create Modules object directory */ /* Create Modules object directory */
wcscpy(NameBuffer, MODULE_ROOT_NAME); wcscpy(NameBuffer, MODULE_ROOT_NAME);
@ -296,8 +294,6 @@ LdrLoadModule(PUNICODE_STRING Filename)
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
PMODULE_OBJECT ModuleObject; PMODULE_OBJECT ModuleObject;
FILE_STANDARD_INFORMATION FileStdInfo; FILE_STANDARD_INFORMATION FileStdInfo;
WCHAR NameBuffer[60];
UNICODE_STRING ModuleName;
/* Check for module already loaded */ /* Check for module already loaded */
if ((ModuleObject = LdrOpenModule(Filename)) != NULL) if ((ModuleObject = LdrOpenModule(Filename)) != NULL)
@ -367,19 +363,7 @@ LdrLoadModule(PUNICODE_STRING Filename)
NtClose(FileHandle); NtClose(FileHandle);
/* Build module object name */ ModuleObject = LdrProcessModule(ModuleLoadBase, Filename);
wcscpy(NameBuffer, MODULE_ROOT_NAME);
if (wcsrchr(Filename->Buffer, '\\') != 0)
{
wcscat(NameBuffer, wcsrchr(Filename->Buffer, '\\') + 1);
}
else
{
wcscat(NameBuffer, Filename->Buffer);
}
RtlInitUnicodeString (&ModuleName, NameBuffer);
ModuleObject = LdrProcessModule(ModuleLoadBase, &ModuleName);
/* Cleanup */ /* Cleanup */
ExFreePool(ModuleLoadBase); ExFreePool(ModuleLoadBase);
@ -388,12 +372,17 @@ LdrLoadModule(PUNICODE_STRING Filename)
} }
NTSTATUS NTSTATUS
LdrProcessDriver(PVOID ModuleLoadBase) LdrProcessDriver(PVOID ModuleLoadBase, PCHAR FileName)
{ {
PMODULE_OBJECT ModuleObject; PMODULE_OBJECT ModuleObject;
UNICODE_STRING ModuleName;
ModuleObject = LdrProcessModule(ModuleLoadBase, 0); RtlCreateUnicodeStringFromAsciiz(&ModuleName,
if (ModuleObject == 0) FileName);
ModuleObject = LdrProcessModule(ModuleLoadBase,
&ModuleName);
RtlFreeUnicodeString(&ModuleName);
if (ModuleObject == NULL)
{ {
return STATUS_UNSUCCESSFUL; return STATUS_UNSUCCESSFUL;
} }
@ -427,7 +416,6 @@ LdrOpenModule(PUNICODE_STRING Filename)
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
PMODULE_OBJECT ModuleObject; PMODULE_OBJECT ModuleObject;
UNICODE_STRING RemainingPath; UNICODE_STRING RemainingPath;
// PWSTR RemainingPath;
wcscpy(NameBuffer, MODULE_ROOT_NAME); wcscpy(NameBuffer, MODULE_ROOT_NAME);
if (wcsrchr(Filename->Buffer, '\\') != 0) if (wcsrchr(Filename->Buffer, '\\') != 0)
@ -478,10 +466,88 @@ LdrGetExportAddress(PMODULE_OBJECT ModuleObject,
} }
} }
NTSTATUS
LdrpQueryModuleInformation(PVOID Buffer,
ULONG Size,
PULONG ReqSize)
{
PLIST_ENTRY current_entry;
PMODULE_OBJECT current;
ULONG ModuleCount = 0;
PSYSTEM_MODULE_INFORMATION Smi;
ANSI_STRING AnsiName;
PCHAR p;
// KeAcquireSpinLock(&ModuleListLock,&oldlvl);
/* calculate required size */
current_entry = ModuleListHead.Flink;
while (current_entry != (&ModuleListHead))
{
ModuleCount++;
current_entry = current_entry->Flink;
}
*ReqSize = sizeof(SYSTEM_MODULE_INFORMATION)+
(ModuleCount - 1) * sizeof(SYSTEM_MODULE_ENTRY);
if (Size < *ReqSize)
{
// KeReleaseSpinLock(&ModuleListLock,oldlvl);
return STATUS_INFO_LENGTH_MISMATCH;
}
/* fill the buffer */
memset(Buffer, '=', Size);
Smi = (PSYSTEM_MODULE_INFORMATION)Buffer;
Smi->Count = ModuleCount;
ModuleCount = 0;
current_entry = ModuleListHead.Flink;
while (current_entry != (&ModuleListHead))
{
current = CONTAINING_RECORD(current_entry,MODULE_OBJECT,ListEntry);
Smi->Module[ModuleCount].Unknown2 = 0; /* Always 0 */
Smi->Module[ModuleCount].BaseAddress = current->Base;
Smi->Module[ModuleCount].Size = current->Length;
Smi->Module[ModuleCount].Unknown3 = 0; /* Flags ??? */
Smi->Module[ModuleCount].EntryIndex = ModuleCount;
AnsiName.Length = 0;
AnsiName.MaximumLength = 256;
AnsiName.Buffer = Smi->Module[ModuleCount].Name;
RtlUnicodeStringToAnsiString(&AnsiName,
&current->Name,
FALSE);
p = strrchr (AnsiName.Buffer, '\\');
if (p == NULL)
{
Smi->Module[ModuleCount].PathLength = 0;
Smi->Module[ModuleCount].NameLength = strlen(AnsiName.Buffer);
}
else
{
p++;
Smi->Module[ModuleCount].PathLength = p - AnsiName.Buffer;
Smi->Module[ModuleCount].NameLength = strlen(p);
}
ModuleCount++;
current_entry = current_entry->Flink;
}
// KeReleaseSpinLock(&ModuleListLock,oldlvl);
return STATUS_SUCCESS;
}
/* ---------------------------------------------- PE Module support */ /* ---------------------------------------------- PE Module support */
PMODULE_OBJECT PMODULE_OBJECT
LdrPEProcessModule(PVOID ModuleLoadBase, PUNICODE_STRING pModuleName) LdrPEProcessModule(PVOID ModuleLoadBase, PUNICODE_STRING FileName)
{ {
unsigned int DriverSize, Idx, Idx2; unsigned int DriverSize, Idx, Idx2;
ULONG RelocDelta, NumRelocs; ULONG RelocDelta, NumRelocs;
@ -492,7 +558,6 @@ LdrPEProcessModule(PVOID ModuleLoadBase, PUNICODE_STRING pModuleName)
PIMAGE_FILE_HEADER PEFileHeader; PIMAGE_FILE_HEADER PEFileHeader;
PIMAGE_OPTIONAL_HEADER PEOptionalHeader; PIMAGE_OPTIONAL_HEADER PEOptionalHeader;
PIMAGE_SECTION_HEADER PESectionHeaders; PIMAGE_SECTION_HEADER PESectionHeaders;
PIMAGE_EXPORT_DIRECTORY ExportDirectory;
PRELOCATION_DIRECTORY RelocDir; PRELOCATION_DIRECTORY RelocDir;
PRELOCATION_ENTRY RelocEntry; PRELOCATION_ENTRY RelocEntry;
PMODULE_OBJECT LibraryModuleObject; PMODULE_OBJECT LibraryModuleObject;
@ -764,32 +829,14 @@ LdrPEProcessModule(PVOID ModuleLoadBase, PUNICODE_STRING pModuleName)
} }
/* Create ModuleName string */ /* Create ModuleName string */
if (pModuleName != 0)
{
wcscpy(NameBuffer, pModuleName->Buffer);
}
else
{
wcscpy(NameBuffer, MODULE_ROOT_NAME); wcscpy(NameBuffer, MODULE_ROOT_NAME);
if (PEOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT] if (wcsrchr(FileName->Buffer, '\\') != 0)
.VirtualAddress != 0)
{ {
ExportDirectory = (PIMAGE_EXPORT_DIRECTORY) (DriverBase + wcscat(NameBuffer, wcsrchr(FileName->Buffer, '\\') + 1);
PEOptionalHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT]
.VirtualAddress);
wcscat(NameBuffer, DriverBase + ExportDirectory->Name);
} }
else else
{ {
char buf[12]; wcscat(NameBuffer, FileName->Buffer);
sprintf(buf, "%08X", (DWORD) DriverBase);
for (Idx = 0; NameBuffer[Idx] != 0; Idx++)
;
Idx2 = 0;
while ((NameBuffer[Idx + Idx2] = (WCHAR) buf[Idx2]) != 0)
Idx2++;
}
} }
RtlInitUnicodeString (&ModuleName, NameBuffer); RtlInitUnicodeString (&ModuleName, NameBuffer);
DbgPrint("Module name is: %wZ\n", &ModuleName); DbgPrint("Module name is: %wZ\n", &ModuleName);
@ -812,7 +859,8 @@ LdrPEProcessModule(PVOID ModuleLoadBase, PUNICODE_STRING pModuleName)
ModuleObject->Base = DriverBase; ModuleObject->Base = DriverBase;
ModuleObject->Flags = MODULE_FLAG_PE; ModuleObject->Flags = MODULE_FLAG_PE;
InsertTailList(&ModuleListHead, &ModuleObject->ListEntry); InsertTailList(&ModuleListHead, &ModuleObject->ListEntry);
RtlCreateUnicodeString(&ModuleObject->Name, NameBuffer); RtlCreateUnicodeString(&ModuleObject->Name, FileName->Buffer);
ModuleObject->EntryPoint = (PVOID) ((DWORD)DriverBase + ModuleObject->EntryPoint = (PVOID) ((DWORD)DriverBase +
PEOptionalHeader->AddressOfEntryPoint); PEOptionalHeader->AddressOfEntryPoint);
ModuleObject->Length = DriverSize; ModuleObject->Length = DriverSize;