if (!DebugObject->DebuggerInactive)
{
/* Add the event into the object's list */
- DBGKTRACE(DBGK_MESSAGE_DEBUG, "Inserting: %lx %p\n",
+ DBGKTRACE(DBGK_MESSAGE_DEBUG, "Inserting: %p %d\n",
DebugEvent, Message->ApiNumber);
InsertTailList(&DebugObject->EventList, &DebugEvent->EventList);
ObDereferenceObject(Process);
/* Free the debug event */
- ExFreePool(DebugEvent);
+ ExFreePoolWithTag(DebugEvent, 'EgbD');
}
}
BOOLEAN UseLpc = FALSE;
PAGED_CODE();
DBGKTRACE(DBGK_EXCEPTION_DEBUG,
- "ExceptionRecord: %p Port: %p\n", ExceptionRecord, DebugPort);
+ "ExceptionRecord: %p Port: %u\n", ExceptionRecord, DebugPort);
/* Setup the API Message */
ApiMessage.h.u1.Length = sizeof(DBGKM_MSG) << 16 |
/* Dereference process and thread and free the event */
ObDereferenceObject(DebugEvent->Process);
ObDereferenceObject(DebugEvent->Thread);
- ExFreePool(DebugEvent);
+ ExFreePoolWithTag(DebugEvent, 'EgbD');
}
VOID
OBJECT_ATTRIBUTES ObjectAttributes;
IO_STATUS_BLOCK IoStatusBlock;
NTSTATUS Status;
+ UNICODE_STRING FullDllName;
PAGED_CODE();
DBGKTRACE(DBGK_PROCESS_DEBUG, "Process: %p Thread: %p DebugObject: %p\n",
Process, Thread, DebugObject);
/* Quit if there's no PEB */
if (!Peb) return STATUS_SUCCESS;
- /* Get the Loader Data List */
- LdrData = Peb->Ldr;
- ListHead = &LdrData->InLoadOrderModuleList;
- NextEntry = ListHead->Flink;
-
- /* Loop the modules */
- i = 0;
- while ((NextEntry != ListHead) && (i < 500))
+ /* Accessing user memory, need SEH */
+ _SEH2_TRY
{
- /* Skip the first entry */
- if (!i)
+ /* Get the Loader Data List */
+ ProbeForRead(Peb, sizeof(*Peb), 1);
+ LdrData = Peb->Ldr;
+ ProbeForRead(LdrData, sizeof(*LdrData), 1);
+ ListHead = &LdrData->InLoadOrderModuleList;
+ ProbeForRead(ListHead, sizeof(*ListHead), 1);
+ NextEntry = ListHead->Flink;
+
+ /* Loop the modules */
+ i = 0;
+ while ((NextEntry != ListHead) && (i < 500))
{
- /* Go to the next module */
- NextEntry = NextEntry->Flink;
- i++;
- continue;
- }
+ ProbeForRead(NextEntry, sizeof(*NextEntry), 1);
+ /* Skip the first entry */
+ if (!i)
+ {
+ /* Go to the next module */
+ NextEntry = NextEntry->Flink;
+ i++;
+ continue;
+ }
- /* Get the entry */
- LdrEntry = CONTAINING_RECORD(NextEntry,
- LDR_DATA_TABLE_ENTRY,
- InLoadOrderLinks);
+ /* Get the entry */
+ LdrEntry = CONTAINING_RECORD(NextEntry,
+ LDR_DATA_TABLE_ENTRY,
+ InLoadOrderLinks);
+ ProbeForRead(LdrEntry, sizeof(*LdrEntry), 1);
- /* Setup the API Message */
- RtlZeroMemory(&ApiMessage, sizeof(DBGKM_MSG));
- ApiMessage.ApiNumber = DbgKmLoadDllApi;
+ /* Setup the API Message */
+ RtlZeroMemory(&ApiMessage, sizeof(DBGKM_MSG));
+ ApiMessage.ApiNumber = DbgKmLoadDllApi;
- /* Set base and clear the name */
- LoadDll->BaseOfDll = LdrEntry->DllBase;
- LoadDll->NamePointer = NULL;
+ /* Set base and clear the name */
+ LoadDll->BaseOfDll = LdrEntry->DllBase;
+ LoadDll->NamePointer = NULL;
- /* Get the NT Headers */
- NtHeader = RtlImageNtHeader(LoadDll->BaseOfDll);
- if (NtHeader)
- {
- /* Save debug data */
- LoadDll->DebugInfoFileOffset = NtHeader->FileHeader.
- PointerToSymbolTable;
- LoadDll->DebugInfoSize = NtHeader->FileHeader.NumberOfSymbols;
- }
+ /* Get the NT Headers */
+ NtHeader = RtlImageNtHeader(LoadDll->BaseOfDll);
+ if (NtHeader)
+ {
+ /* Save debug data */
+ LoadDll->DebugInfoFileOffset = NtHeader->FileHeader.
+ PointerToSymbolTable;
+ LoadDll->DebugInfoSize = NtHeader->FileHeader.NumberOfSymbols;
+ }
- /* Trace */
- DBGKTRACE(DBGK_PROCESS_DEBUG, "Name: %wZ. Base: %p\n",
- &LdrEntry->FullDllName, LdrEntry->DllBase);
+ /* Trace */
+ FullDllName = LdrEntry->FullDllName;
+ ProbeForRead(FullDllName.Buffer, FullDllName.MaximumLength, 1);
+ DBGKTRACE(DBGK_PROCESS_DEBUG, "Name: %wZ. Base: %p\n",
+ &FullDllName, LdrEntry->DllBase);
- /* Get the name of the DLL */
- Status = MmGetFileNameForAddress(NtHeader, &ModuleName);
- if (NT_SUCCESS(Status))
- {
- /* Setup the object attributes */
- InitializeObjectAttributes(&ObjectAttributes,
- &ModuleName,
- OBJ_FORCE_ACCESS_CHECK |
- OBJ_KERNEL_HANDLE |
- OBJ_CASE_INSENSITIVE,
- NULL,
- NULL);
+ /* Get the name of the DLL */
+ Status = MmGetFileNameForAddress(NtHeader, &ModuleName);
+ if (NT_SUCCESS(Status))
+ {
+ /* Setup the object attributes */
+ InitializeObjectAttributes(&ObjectAttributes,
+ &ModuleName,
+ OBJ_FORCE_ACCESS_CHECK |
+ OBJ_KERNEL_HANDLE |
+ OBJ_CASE_INSENSITIVE,
+ NULL,
+ NULL);
- /* Open the file to get a handle to it */
- Status = ZwOpenFile(&LoadDll->FileHandle,
- GENERIC_READ | SYNCHRONIZE,
- &ObjectAttributes,
- &IoStatusBlock,
- FILE_SHARE_READ |
- FILE_SHARE_WRITE |
- FILE_SHARE_DELETE,
- FILE_SYNCHRONOUS_IO_NONALERT);
- if (!NT_SUCCESS(Status)) LoadDll->FileHandle = NULL;
-
- /* Free the name now */
- ExFreePool(ModuleName.Buffer);
- }
+ /* Open the file to get a handle to it */
+ Status = ZwOpenFile(&LoadDll->FileHandle,
+ GENERIC_READ | SYNCHRONIZE,
+ &ObjectAttributes,
+ &IoStatusBlock,
+ FILE_SHARE_READ |
+ FILE_SHARE_WRITE |
+ FILE_SHARE_DELETE,
+ FILE_SYNCHRONOUS_IO_NONALERT);
+ if (!NT_SUCCESS(Status)) LoadDll->FileHandle = NULL;
+
+ /* Free the name now */
+ ExFreePool(ModuleName.Buffer);
+ }
- /* Send the fake module load message */
- Status = DbgkpQueueMessage(Process,
- Thread,
- &ApiMessage,
- DEBUG_EVENT_NOWAIT,
- DebugObject);
- if (!NT_SUCCESS(Status))
- {
- /* Message send failed, close the file handle if we had one */
- if (LoadDll->FileHandle) ObCloseHandle(LoadDll->FileHandle,
- KernelMode);
- }
+ /* Send the fake module load message */
+ Status = DbgkpQueueMessage(Process,
+ Thread,
+ &ApiMessage,
+ DEBUG_EVENT_NOWAIT,
+ DebugObject);
+ if (!NT_SUCCESS(Status))
+ {
+ /* Message send failed, close the file handle if we had one */
+ if (LoadDll->FileHandle) ObCloseHandle(LoadDll->FileHandle,
+ KernelMode);
+ }
- /* Go to the next module */
- NextEntry = NextEntry->Flink;
- i++;
+ /* Go to the next module */
+ NextEntry = NextEntry->Flink;
+ i++;
+ }
+ }
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+ {
+ NOTHING;
}
+ _SEH2_END;
/* Return success */
return STATUS_SUCCESS;
{
/* Dereference and fail */
if (pFirstThread) ObDereferenceObject(pFirstThread);
- if (pLastThread) ObDereferenceObject(pLastThread);
+ ObDereferenceObject(pLastThread);
return Status;
}
ObjectTypeInitializer.GenericMapping = DbgkDebugObjectMapping;
ObjectTypeInitializer.PoolType = NonPagedPool;
ObjectTypeInitializer.ValidAccessMask = DEBUG_OBJECT_ALL_ACCESS;
- ObjectTypeInitializer.UseDefaultObject = TRUE;
+ ObjectTypeInitializer.SecurityRequired = TRUE;
ObjectTypeInitializer.CloseProcedure = DbgkpCloseObject;
ObjectTypeInitializer.DeleteProcedure = DbgkpDeleteObject;
ObCreateObjectType(&Name,
&DbgkDebugObjectType);
}
+NTSTATUS
+NTAPI
+DbgkOpenProcessDebugPort(IN PEPROCESS Process,
+ IN KPROCESSOR_MODE PreviousMode,
+ OUT HANDLE *DebugHandle)
+{
+ PDEBUG_OBJECT DebugObject;
+ NTSTATUS Status;
+ PAGED_CODE();
+
+ /* If there's no debug port, just exit */
+ if (!Process->DebugPort) return STATUS_PORT_NOT_SET;
+
+ /* Otherwise, acquire the lock while we grab the port */
+ ExAcquireFastMutex(&DbgkpProcessDebugPortMutex);
+
+ /* Grab it and reference it if it exists */
+ DebugObject = Process->DebugPort;
+ if (DebugObject) ObReferenceObject(DebugObject);
+
+ /* Release the lock now */
+ ExReleaseFastMutex(&DbgkpProcessDebugPortMutex);
+
+ /* Bail out if it doesn't exist */
+ if (!DebugObject) return STATUS_PORT_NOT_SET;
+
+ /* Now get a handle to it */
+ Status = ObOpenObjectByPointer(DebugObject,
+ 0,
+ NULL,
+ MAXIMUM_ALLOWED,
+ DbgkDebugObjectType,
+ PreviousMode,
+ DebugHandle);
+ if (!NT_SUCCESS(Status)) ObDereferenceObject(DebugObject);
+
+ /* Return status */
+ return Status;
+}
+
/* PUBLIC FUNCTIONS **********************************************************/
/*
BOOLEAN NeedsWake = FALSE;
CLIENT_ID ClientId;
PAGED_CODE();
- DBGKTRACE(DBGK_OBJECT_DEBUG, "Handle: %p Status: %p\n",
+ DBGKTRACE(DBGK_OBJECT_DEBUG, "Handle: %p Status: %d\n",
DebugHandle, ContinueStatus);
/* Check if we were called from user mode*/