MmCallDllInitialize(IN PLDR_DATA_TABLE_ENTRY LdrEntry,\r
IN PLIST_ENTRY ListHead)\r
{\r
+ UNICODE_STRING ServicesKeyName = RTL_CONSTANT_STRING(\r
+ L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\");\r
PMM_DLL_INITIALIZE DllInit;\r
+ UNICODE_STRING RegPath, ImportName;\r
+ NTSTATUS Status;\r
\r
/* Try to see if the image exports a DllInitialize routine */\r
DllInit = (PMM_DLL_INITIALIZE)MiLocateExportName(LdrEntry->DllBase,\r
"DllInitialize");\r
if (!DllInit) return STATUS_SUCCESS;\r
\r
- /* FIXME: TODO */\r
- DPRINT1("DllInitialize not called!\n");\r
- return STATUS_UNSUCCESSFUL;\r
+ /* Do a temporary copy of BaseDllName called ImportName\r
+ * because we'll alter the length of the string\r
+ */\r
+ ImportName.Length = LdrEntry->BaseDllName.Length;\r
+ ImportName.MaximumLength = LdrEntry->BaseDllName.MaximumLength;\r
+ ImportName.Buffer = LdrEntry->BaseDllName.Buffer;\r
+\r
+ /* Obtain the path to this dll's service in the registry */\r
+ RegPath.MaximumLength = ServicesKeyName.Length +\r
+ ImportName.Length + sizeof(UNICODE_NULL);\r
+ RegPath.Buffer = ExAllocatePoolWithTag(NonPagedPool,\r
+ RegPath.MaximumLength,\r
+ TAG_LDR_WSTR);\r
+\r
+ /* Check if this allocation was unsuccessful */\r
+ if (!RegPath.Buffer) return STATUS_INSUFFICIENT_RESOURCES;\r
+\r
+ /* Build and append the service name itself */\r
+ RegPath.Length = ServicesKeyName.Length;\r
+ RtlCopyMemory(RegPath.Buffer,\r
+ ServicesKeyName.Buffer,\r
+ ServicesKeyName.Length);\r
+\r
+ /* Check if there is a dot in the filename */\r
+ if (wcschr(ImportName.Buffer, L'.'))\r
+ {\r
+ /* Remove the extension */\r
+ ImportName.Length = (wcschr(ImportName.Buffer, L'.') -\r
+ ImportName.Buffer) * sizeof(WCHAR);\r
+ }\r
+\r
+ /* Append service name (the basename without extension) */\r
+ RtlAppendUnicodeStringToString(&RegPath, &ImportName);\r
+\r
+ /* Now call the DllInit func */\r
+ DPRINT("Calling DllInit(%wZ)\n", &RegPath);\r
+ Status = DllInit(&RegPath);\r
+\r
+ /* Clean up */\r
+ ExFreePool(RegPath.Buffer);\r
+\r
+ /* Return status value which DllInitialize returned */\r
+ return Status;\r
}\r
\r
VOID\r