- Fix DbgkSectionHandleToFileHandle.

- Implement MmGetFileNameForSection.
- There is a bug in ObQueryNameString for file objects, so the full name isn't returned...

svn path=/trunk/; revision=24985
This commit is contained in:
Alex Ionescu 2006-11-30 05:22:20 +00:00
parent d4cf4b1b58
commit ef1120e56b
4 changed files with 50 additions and 12 deletions

View file

@ -19,7 +19,7 @@ NTAPI
DbgkpSectionToFileHandle(IN PVOID Section) DbgkpSectionToFileHandle(IN PVOID Section)
{ {
NTSTATUS Status; NTSTATUS Status;
UNICODE_STRING FileName; POBJECT_NAME_INFORMATION FileName;
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
IO_STATUS_BLOCK IoStatusBlock; IO_STATUS_BLOCK IoStatusBlock;
HANDLE Handle; HANDLE Handle;
@ -31,7 +31,7 @@ DbgkpSectionToFileHandle(IN PVOID Section)
/* Initialize object attributes */ /* Initialize object attributes */
InitializeObjectAttributes(&ObjectAttributes, InitializeObjectAttributes(&ObjectAttributes,
&FileName, &FileName->Name,
OBJ_CASE_INSENSITIVE | OBJ_CASE_INSENSITIVE |
OBJ_FORCE_ACCESS_CHECK | OBJ_FORCE_ACCESS_CHECK |
OBJ_KERNEL_HANDLE, OBJ_KERNEL_HANDLE,
@ -39,15 +39,17 @@ DbgkpSectionToFileHandle(IN PVOID Section)
NULL); NULL);
/* Open the file */ /* Open the file */
DPRINT1("Trying to open: %wZ\n", &FileName->Name);
Status = ZwOpenFile(&Handle, Status = ZwOpenFile(&Handle,
GENERIC_READ | SYNCHRONIZE, GENERIC_READ | SYNCHRONIZE,
&ObjectAttributes, &ObjectAttributes,
&IoStatusBlock, &IoStatusBlock,
FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_SYNCHRONOUS_IO_NONALERT); FILE_SYNCHRONOUS_IO_NONALERT);
DPRINT1("Status: %lx\n", Status);
/* Free the name and return the handle if we succeeded */ /* Free the name and return the handle if we succeeded */
ExFreePool(FileName.Buffer); ExFreePool(FileName);
if (!NT_SUCCESS(Status)) return NULL; if (!NT_SUCCESS(Status)) return NULL;
return Handle; return Handle;
} }
@ -91,7 +93,8 @@ DbgkCreateThread(PVOID StartAddress)
ULONG ProcessFlags; ULONG ProcessFlags;
IMAGE_INFO ImageInfo; IMAGE_INFO ImageInfo;
PIMAGE_NT_HEADERS NtHeader; PIMAGE_NT_HEADERS NtHeader;
UNICODE_STRING ModuleName; POBJECT_NAME_INFORMATION ModuleName;
UNICODE_STRING NtDllName;
NTSTATUS Status; NTSTATUS Status;
PVOID DebugPort; PVOID DebugPort;
DBGKM_MSG ApiMessage; DBGKM_MSG ApiMessage;
@ -130,10 +133,10 @@ DbgkCreateThread(PVOID StartAddress)
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
/* Call the notify routines and free the name */ /* Call the notify routines and free the name */
PspRunLoadImageNotifyRoutines(&ModuleName, PspRunLoadImageNotifyRoutines(&ModuleName->Name,
Process->UniqueProcessId, Process->UniqueProcessId,
&ImageInfo); &ImageInfo);
ExFreePool(ModuleName.Buffer); ExFreePool(ModuleName);
} }
else else
{ {
@ -160,9 +163,9 @@ DbgkCreateThread(PVOID StartAddress)
} }
/* Call the notify routines */ /* Call the notify routines */
RtlInitUnicodeString(&ModuleName, RtlInitUnicodeString(&NtDllName,
L"\\SystemRoot\\System32\\ntdll.dll"); L"\\SystemRoot\\System32\\ntdll.dll");
PspRunLoadImageNotifyRoutines(&ModuleName, PspRunLoadImageNotifyRoutines(&NtDllName,
Process->UniqueProcessId, Process->UniqueProcessId,
&ImageInfo); &ImageInfo);
} }

View file

@ -653,14 +653,17 @@ DbgkpPostFakeThreadMessages(IN PEPROCESS Process,
if (First) if (First)
{ {
/* So we'll start with the create process message */ /* So we'll start with the create process message */
DPRINT1("new proces!\n");
ApiMessage.ApiNumber = DbgKmCreateProcessApi; ApiMessage.ApiNumber = DbgKmCreateProcessApi;
/* Get the file handle */ /* Get the file handle */
DPRINT1("section object: %p\n", Process->SectionObject);
if (Process->SectionObject) if (Process->SectionObject)
{ {
/* Use the section object */ /* Use the section object */
CreateProcess->FileHandle = CreateProcess->FileHandle =
DbgkpSectionToFileHandle(Process->SectionObject); DbgkpSectionToFileHandle(Process->SectionObject);
DPRINT1("FileHandle: %p\n", CreateProcess->FileHandle);
} }
else else
{ {
@ -669,7 +672,9 @@ DbgkpPostFakeThreadMessages(IN PEPROCESS Process,
} }
/* Set the base address */ /* Set the base address */
DPRINT1("SectionBaseAddress: %p\n", Process->SectionBaseAddress);
CreateProcess->BaseOfImage = Process->SectionBaseAddress; CreateProcess->BaseOfImage = Process->SectionBaseAddress;
KEBUGCHECK(0);
/* Get the NT Header */ /* Get the NT Header */
NtHeader = RtlImageNtHeader(Process->SectionBaseAddress); NtHeader = RtlImageNtHeader(Process->SectionBaseAddress);

View file

@ -1326,7 +1326,7 @@ NTSTATUS
NTAPI NTAPI
MmGetFileNameForSection( MmGetFileNameForSection(
IN PROS_SECTION_OBJECT Section, IN PROS_SECTION_OBJECT Section,
OUT PUNICODE_STRING ModuleName OUT POBJECT_NAME_INFORMATION *ModuleName
); );
PVOID PVOID

View file

@ -109,10 +109,40 @@ MmGetFileObjectForSection(IN PROS_SECTION_OBJECT Section)
NTSTATUS NTSTATUS
NTAPI NTAPI
MmGetFileNameForSection(IN PROS_SECTION_OBJECT Section, MmGetFileNameForSection(IN PROS_SECTION_OBJECT Section,
OUT PUNICODE_STRING ModuleName) OUT POBJECT_NAME_INFORMATION *ModuleName)
{ {
/* FIXME: TODO. ObQueryNameString on the FileObject */ POBJECT_NAME_INFORMATION ObjectNameInfo;
RtlCreateUnicodeString(ModuleName, L"C:\\ReactOS\\system32\\ntdll.dll"); NTSTATUS Status;
ULONG ReturnLength;
/* Make sure it's an image section */
*ModuleName = NULL;
if (!(Section->AllocationAttributes & SEC_IMAGE))
{
/* It's not, fail */
return STATUS_SECTION_NOT_IMAGE;
}
/* Allocate memory for our structure */
ObjectNameInfo = ExAllocatePoolWithTag(PagedPool,
1024,
TAG('M', 'm', ' ', ' '));
if (!ObjectNameInfo) return STATUS_NO_MEMORY;
/* Query the name */
Status = ObQueryNameString(Section->FileObject,
ObjectNameInfo,
1024,
&ReturnLength);
if (!NT_SUCCESS(Status))
{
/* Failed, free memory */
ExFreePool(ObjectNameInfo);
return Status;
}
/* Success */
*ModuleName = ObjectNameInfo;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }