Skip to content

Commit 6bc67f0

Browse files
committed
ExtendedTools: Fix unloaded dll event trace for system processes
1 parent 448adba commit 6bc67f0

File tree

1 file changed

+13
-82
lines changed

1 file changed

+13
-82
lines changed

plugins/ExtendedTools/unldll.c

Lines changed: 13 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -64,88 +64,32 @@ BOOLEAN EtpRefreshUnloadedDlls(
6464
)
6565
{
6666
NTSTATUS status;
67-
PULONG elementSize;
68-
PULONG elementCount;
69-
PVOID eventTrace;
70-
HANDLE processHandle = NULL;
71-
ULONG eventTraceSize;
7267
ULONG capturedElementSize;
7368
ULONG capturedElementCount;
74-
PVOID capturedEventTracePointer;
7569
PVOID capturedEventTrace = NULL;
7670
ULONG i;
7771
PVOID currentEvent;
7872
HWND lvHandle;
7973

80-
lvHandle = GetDlgItem(hwndDlg, IDC_LIST);
81-
82-
RtlGetUnloadEventTraceEx(&elementSize, &elementCount, &eventTrace);
83-
84-
if (!NT_SUCCESS(status = PhOpenProcess(&processHandle, PROCESS_VM_READ, Context->ProcessItem->ProcessId)))
85-
goto CleanupExit;
86-
87-
// We have the pointers for the unload event trace information.
88-
// Since ntdll is loaded at the same base address across all processes,
89-
// we can read the information in.
90-
91-
if (!NT_SUCCESS(status = NtReadVirtualMemory(
92-
processHandle,
93-
elementSize,
74+
status = PhGetProcessUnloadedDlls(
75+
Context->ProcessItem->ProcessId,
76+
&capturedEventTrace,
9477
&capturedElementSize,
95-
sizeof(ULONG),
96-
NULL
97-
)))
98-
goto CleanupExit;
99-
100-
if (!NT_SUCCESS(status = NtReadVirtualMemory(
101-
processHandle,
102-
elementCount,
103-
&capturedElementCount,
104-
sizeof(ULONG),
105-
NULL
106-
)))
107-
goto CleanupExit;
108-
109-
if (!NT_SUCCESS(status = NtReadVirtualMemory(
110-
processHandle,
111-
eventTrace,
112-
&capturedEventTracePointer,
113-
sizeof(PVOID),
114-
NULL
115-
)))
116-
goto CleanupExit;
117-
118-
if (!capturedEventTracePointer)
119-
goto CleanupExit; // no events
120-
121-
if (capturedElementCount > 0x4000)
122-
capturedElementCount = 0x4000;
123-
124-
eventTraceSize = capturedElementSize * capturedElementCount;
125-
126-
capturedEventTrace = PhAllocateSafe(eventTraceSize);
127-
128-
if (!capturedEventTrace)
78+
&capturedElementCount
79+
);
80+
81+
if (!NT_SUCCESS(status))
12982
{
130-
status = STATUS_NO_MEMORY;
131-
goto CleanupExit;
83+
PhShowStatus(NULL, L"Unable to retrieve unload event trace information.", status, 0);
84+
return FALSE;
13285
}
13386

134-
if (!NT_SUCCESS(status = NtReadVirtualMemory(
135-
processHandle,
136-
capturedEventTracePointer,
137-
capturedEventTrace,
138-
eventTraceSize,
139-
NULL
140-
)))
141-
goto CleanupExit;
142-
143-
currentEvent = capturedEventTrace;
144-
87+
lvHandle = GetDlgItem(hwndDlg, IDC_LIST);
14588
ExtendedListView_SetRedraw(lvHandle, FALSE);
146-
14789
ListView_DeleteAllItems(lvHandle);
14890

91+
currentEvent = capturedEventTrace;
92+
14993
for (i = 0; i < capturedElementCount; i++)
15094
{
15195
PRTL_UNLOAD_EVENT_TRACE rtlEvent = currentEvent;
@@ -199,20 +143,7 @@ BOOLEAN EtpRefreshUnloadedDlls(
199143

200144
Context->CapturedEventTrace = capturedEventTrace;
201145

202-
CleanupExit:
203-
204-
if (processHandle)
205-
NtClose(processHandle);
206-
207-
if (NT_SUCCESS(status))
208-
{
209-
return TRUE;
210-
}
211-
else
212-
{
213-
PhShowStatus(hwndDlg, L"Unable to retrieve unload event trace information", status, 0);
214-
return FALSE;
215-
}
146+
return NT_SUCCESS(status);
216147
}
217148

218149
static INT NTAPI EtpNumberCompareFunction(

0 commit comments

Comments
 (0)