29 #define WM_PH_SEARCH_UPDATE (WM_APP + 801)
30 #define WM_PH_SEARCH_FINISHED (WM_APP + 802)
39 typedef struct _PHP_OBJECT_SEARCH_RESULT
68 static RECT MinimumSize;
70 static HANDLE SearchThreadHandle = NULL;
71 static BOOLEAN SearchStop;
73 static PPH_LIST SearchResults = NULL;
74 static ULONG SearchResultsAddIndex;
77 static ULONG64 SearchPointer;
78 static BOOLEAN UseSearchPointer;
103 _In_ ULONG NumberOfResults
106 BOOLEAN allCanBeClosed =
TRUE;
109 if (NumberOfResults == 1)
114 info.
Handle = Results[0]->Handle;
115 info.
TypeName = Results[0]->TypeName;
125 for (i = 0; i < NumberOfResults; i++)
129 allCanBeClosed =
FALSE;
140 _In_opt_ PVOID Context
152 return uintptrcmp((ULONG_PTR)item1->ProcessId, (ULONG_PTR)item2->ProcessId);
158 _In_opt_ PVOID Context
170 _In_opt_ PVOID Context
182 _In_opt_ PVOID Context
188 return uintptrcmp((ULONG_PTR)item1->Handle, (ULONG_PTR)item2->Handle);
215 MinimumSize.left = 0;
217 MinimumSize.right = 150;
218 MinimumSize.bottom = 100;
219 MapDialogRect(hwndDlg, &MinimumSize);
249 SendMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwndDlg,
IDC_FILTER),
TRUE);
250 Edit_SetSel(GetDlgItem(hwndDlg,
IDC_FILTER), 0, -1);
255 ShowWindow(hwndDlg, SW_HIDE);
260 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, 0);
265 if (SearchThreadHandle)
267 SetCursor(LoadCursor(NULL, IDC_WAIT));
268 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT,
TRUE);
275 switch (LOWORD(wParam))
283 if (!SearchThreadHandle)
293 for (i = 0; i < SearchResults->
Count; i++)
300 if (searchResult->ProcessName)
313 SearchResultsAddIndex = 0;
317 if (!SearchThreadHandle)
322 SearchResults = NULL;
326 SetDlgItemText(hwndDlg, IDOK, L
"Cancel");
328 SetCursor(LoadCursor(NULL, IDC_WAIT));
333 EnableWindow(GetDlgItem(hwndDlg, IDOK),
FALSE);
339 SendMessage(hwndDlg, WM_CLOSE, 0, 0);
345 ULONG numberOfResults;
357 numberOfResults == 1 ? L
"the selected handle" : L
"the selected handles",
358 L
"Closing handles may cause system instability and data corruption.",
362 for (i = 0; i < numberOfResults; i++)
365 HANDLE processHandle;
383 DUPLICATE_CLOSE_SOURCE
390 NtClose(processHandle);
419 info.
Handle = result->Handle;
464 handleItem->
TypeName = result->TypeName;
492 LPNMHDR header = (LPNMHDR)lParam;
494 switch (header->code)
508 LPNMLVKEYDOWN keyDown = (LPNMLVKEYDOWN)header;
510 switch (keyDown->wVKey)
513 if (GetKeyState(VK_CONTROL) < 0)
517 if (GetKeyState(VK_CONTROL) < 0)
536 ULONG numberOfResults;
538 point.x = (SHORT)LOWORD(lParam);
539 point.y = (SHORT)HIWORD(lParam);
541 if (point.x == -1 && point.y == -1)
546 if (numberOfResults != 0)
591 for (i = SearchResultsAddIndex; i < SearchResults->
Count; i++)
621 searchResult->ProcessName = NULL;
629 SearchResultsAddIndex = i;
643 NtWaitForSingleObject(SearchThreadHandle,
FALSE, NULL);
644 NtClose(SearchThreadHandle);
645 SearchThreadHandle = NULL;
650 SetDlgItemText(hwndDlg, IDOK, L
"Find");
651 EnableWindow(GetDlgItem(hwndDlg, IDOK),
TRUE);
653 SetCursor(LoadCursor(NULL, IDC_ARROW));
661 typedef struct _SEARCH_HANDLE_CONTEXT
665 HANDLE ProcessHandle;
668 static NTSTATUS NTAPI SearchHandleFunction(
677 context->ProcessHandle,
678 (HANDLE)context->HandleInfo->HandleValue,
679 context->HandleInfo->ObjectTypeIndex,
692 (UseSearchPointer && context->HandleInfo->Object == (PVOID)SearchPointer))
697 searchResult->ProcessId = (HANDLE)context->HandleInfo->UniqueProcessId;
699 searchResult->Handle = (HANDLE)context->HandleInfo->HandleValue;
700 searchResult->TypeName = typeName;
701 searchResult->Name = bestObjectName;
702 PhPrintPointer(searchResult->HandleString, (PVOID)searchResult->Handle);
703 searchResult->Info = *context->HandleInfo;
710 if (SearchResults->
Count % 40 == 0)
724 if (context->NeedToFree)
727 return STATUS_SUCCESS;
730 static BOOLEAN NTAPI EnumModulesCallback(
732 _In_opt_ PVOID Context
741 (UseSearchPointer && Module->BaseAddress == (PVOID)SearchPointer))
746 switch (Module->Type)
749 typeName = L
"Mapped File";
752 typeName = L
"Mapped Image";
760 searchResult->ProcessId = (HANDLE)Context;
762 searchResult->Handle = (HANDLE)Module->BaseAddress;
773 if (SearchResults->
Count % 40 == 0)
795 if (SearchString->
Length == 0)
806 static ULONG fileObjectTypeIndex = -1;
808 BOOLEAN useWorkQueue =
FALSE;
830 PVOID *processHandlePtr;
831 HANDLE processHandle;
839 processHandleHashtable,
843 if (processHandlePtr)
845 processHandle = (HANDLE)*processHandlePtr;
856 processHandleHashtable,
867 if (useWorkQueue && handleInfo->
ObjectTypeIndex == (USHORT)fileObjectTypeIndex)
872 searchHandleContext->NeedToFree =
TRUE;
873 searchHandleContext->HandleInfo = handleInfo;
874 searchHandleContext->ProcessHandle = processHandle;
881 searchHandleContext.NeedToFree =
FALSE;
882 searchHandleContext.HandleInfo = handleInfo;
883 searchHandleContext.ProcessHandle = processHandle;
884 SearchHandleFunction(&searchHandleContext);
900 NtClose((HANDLE)entry->
Value);
928 return STATUS_SUCCESS;