mirror of
https://github.com/reactos/reactos.git
synced 2025-07-31 19:21:38 +00:00
- 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:
parent
d4cf4b1b58
commit
ef1120e56b
4 changed files with 50 additions and 12 deletions
|
@ -19,7 +19,7 @@ NTAPI
|
|||
DbgkpSectionToFileHandle(IN PVOID Section)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
UNICODE_STRING FileName;
|
||||
POBJECT_NAME_INFORMATION FileName;
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
IO_STATUS_BLOCK IoStatusBlock;
|
||||
HANDLE Handle;
|
||||
|
@ -31,7 +31,7 @@ DbgkpSectionToFileHandle(IN PVOID Section)
|
|||
|
||||
/* Initialize object attributes */
|
||||
InitializeObjectAttributes(&ObjectAttributes,
|
||||
&FileName,
|
||||
&FileName->Name,
|
||||
OBJ_CASE_INSENSITIVE |
|
||||
OBJ_FORCE_ACCESS_CHECK |
|
||||
OBJ_KERNEL_HANDLE,
|
||||
|
@ -39,15 +39,17 @@ DbgkpSectionToFileHandle(IN PVOID Section)
|
|||
NULL);
|
||||
|
||||
/* Open the file */
|
||||
DPRINT1("Trying to open: %wZ\n", &FileName->Name);
|
||||
Status = ZwOpenFile(&Handle,
|
||||
GENERIC_READ | SYNCHRONIZE,
|
||||
&ObjectAttributes,
|
||||
&IoStatusBlock,
|
||||
FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
FILE_SYNCHRONOUS_IO_NONALERT);
|
||||
DPRINT1("Status: %lx\n", Status);
|
||||
|
||||
/* Free the name and return the handle if we succeeded */
|
||||
ExFreePool(FileName.Buffer);
|
||||
ExFreePool(FileName);
|
||||
if (!NT_SUCCESS(Status)) return NULL;
|
||||
return Handle;
|
||||
}
|
||||
|
@ -91,7 +93,8 @@ DbgkCreateThread(PVOID StartAddress)
|
|||
ULONG ProcessFlags;
|
||||
IMAGE_INFO ImageInfo;
|
||||
PIMAGE_NT_HEADERS NtHeader;
|
||||
UNICODE_STRING ModuleName;
|
||||
POBJECT_NAME_INFORMATION ModuleName;
|
||||
UNICODE_STRING NtDllName;
|
||||
NTSTATUS Status;
|
||||
PVOID DebugPort;
|
||||
DBGKM_MSG ApiMessage;
|
||||
|
@ -130,10 +133,10 @@ DbgkCreateThread(PVOID StartAddress)
|
|||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
/* Call the notify routines and free the name */
|
||||
PspRunLoadImageNotifyRoutines(&ModuleName,
|
||||
PspRunLoadImageNotifyRoutines(&ModuleName->Name,
|
||||
Process->UniqueProcessId,
|
||||
&ImageInfo);
|
||||
ExFreePool(ModuleName.Buffer);
|
||||
ExFreePool(ModuleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -160,9 +163,9 @@ DbgkCreateThread(PVOID StartAddress)
|
|||
}
|
||||
|
||||
/* Call the notify routines */
|
||||
RtlInitUnicodeString(&ModuleName,
|
||||
RtlInitUnicodeString(&NtDllName,
|
||||
L"\\SystemRoot\\System32\\ntdll.dll");
|
||||
PspRunLoadImageNotifyRoutines(&ModuleName,
|
||||
PspRunLoadImageNotifyRoutines(&NtDllName,
|
||||
Process->UniqueProcessId,
|
||||
&ImageInfo);
|
||||
}
|
||||
|
|
|
@ -653,14 +653,17 @@ DbgkpPostFakeThreadMessages(IN PEPROCESS Process,
|
|||
if (First)
|
||||
{
|
||||
/* So we'll start with the create process message */
|
||||
DPRINT1("new proces!\n");
|
||||
ApiMessage.ApiNumber = DbgKmCreateProcessApi;
|
||||
|
||||
/* Get the file handle */
|
||||
DPRINT1("section object: %p\n", Process->SectionObject);
|
||||
if (Process->SectionObject)
|
||||
{
|
||||
/* Use the section object */
|
||||
CreateProcess->FileHandle =
|
||||
DbgkpSectionToFileHandle(Process->SectionObject);
|
||||
DPRINT1("FileHandle: %p\n", CreateProcess->FileHandle);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -669,7 +672,9 @@ DbgkpPostFakeThreadMessages(IN PEPROCESS Process,
|
|||
}
|
||||
|
||||
/* Set the base address */
|
||||
DPRINT1("SectionBaseAddress: %p\n", Process->SectionBaseAddress);
|
||||
CreateProcess->BaseOfImage = Process->SectionBaseAddress;
|
||||
KEBUGCHECK(0);
|
||||
|
||||
/* Get the NT Header */
|
||||
NtHeader = RtlImageNtHeader(Process->SectionBaseAddress);
|
||||
|
|
|
@ -1326,7 +1326,7 @@ NTSTATUS
|
|||
NTAPI
|
||||
MmGetFileNameForSection(
|
||||
IN PROS_SECTION_OBJECT Section,
|
||||
OUT PUNICODE_STRING ModuleName
|
||||
OUT POBJECT_NAME_INFORMATION *ModuleName
|
||||
);
|
||||
|
||||
PVOID
|
||||
|
|
|
@ -109,10 +109,40 @@ MmGetFileObjectForSection(IN PROS_SECTION_OBJECT Section)
|
|||
NTSTATUS
|
||||
NTAPI
|
||||
MmGetFileNameForSection(IN PROS_SECTION_OBJECT Section,
|
||||
OUT PUNICODE_STRING ModuleName)
|
||||
OUT POBJECT_NAME_INFORMATION *ModuleName)
|
||||
{
|
||||
/* FIXME: TODO. ObQueryNameString on the FileObject */
|
||||
RtlCreateUnicodeString(ModuleName, L"C:\\ReactOS\\system32\\ntdll.dll");
|
||||
POBJECT_NAME_INFORMATION ObjectNameInfo;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue