27 #define WM_PH_MEMORY_STATUS_UPDATE (WM_APP + 301)
29 #define PH_SEARCH_UPDATE 1
30 #define PH_SEARCH_COMPLETED 2
32 typedef struct _MEMORY_STRING_CONTEXT
37 BOOLEAN DetectUnicode;
106 _In_ _Post_invalid_ PVOID Memory
147 _InterlockedIncrement(&Result->RefCount);
154 if (_InterlockedDecrement(&Result->RefCount) == 0)
156 if (Result->Display.Buffer)
165 _In_ ULONG NumberOfResults
170 for (i = 0; i < NumberOfResults; i++)
175 _In_ HANDLE ProcessHandle,
180 BOOLEAN detectUnicode;
181 ULONG memoryTypeMask;
183 MEMORY_BASIC_INFORMATION basicInfo;
187 SIZE_T displayBufferCount;
189 minimumLength = Options->MinimumLength;
190 detectUnicode = Options->DetectUnicode;
191 memoryTypeMask = Options->MemoryTypeMask;
193 if (minimumLength < 4)
196 baseAddress = (PVOID)0;
205 displayBuffer =
PhAllocatePage((displayBufferCount + 1) *
sizeof(WCHAR), NULL);
218 sizeof(MEMORY_BASIC_INFORMATION),
225 if (Options->Header.Cancel)
227 if (basicInfo.State != MEM_COMMIT)
229 if ((basicInfo.Type & memoryTypeMask) == 0)
231 if (basicInfo.Protect == PAGE_NOACCESS)
233 if (basicInfo.Protect & PAGE_GUARD)
236 readSize = basicInfo.RegionSize;
238 if (basicInfo.RegionSize > bufferSize)
241 if (basicInfo.RegionSize <= 16 * 1024 * 1024)
244 bufferSize = basicInfo.RegionSize;
252 readSize = bufferSize;
256 for (offset = 0; offset < basicInfo.RegionSize; offset += readSize)
282 for (i = 0; i < readSize; i++)
328 if (printable2 && printable1 && printable)
330 if (length < displayBufferCount)
331 displayBuffer[length] = byte;
335 else if (printable2 && printable1 && !printable)
337 if (length >= minimumLength)
344 displayBuffer[0] = byte1;
351 else if (printable2 && !printable1 && printable)
355 if (length < displayBufferCount)
356 displayBuffer[length] = byte;
361 else if (printable2 && !printable1 && !printable)
363 if (length >= minimumLength)
372 else if (!printable2 && printable1 && printable)
374 if (length >= minimumLength + 1)
382 displayBuffer[0] = byte1;
383 displayBuffer[1] = byte;
386 else if (!printable2 && printable1 && !printable)
390 else if (!printable2 && !printable1 && printable)
392 if (length < displayBufferCount)
393 displayBuffer[length] = byte;
397 else if (!printable2 && !printable1 && !printable)
402 goto AfterCreateResult;
412 lengthInBytes = length;
416 if (printable1 == printable)
432 displayLength = (ULONG)(min(length, displayBufferCount) *
sizeof(WCHAR));
436 memcpy(result->
Display.
Buffer, displayBuffer, displayLength);
441 Options->Header.Callback(
443 Options->Header.Context
453 printable2 = printable1;
454 printable1 = printable;
467 _In_ HWND ParentWindowHandle,
472 HANDLE processHandle;
479 ProcessItem->ProcessId
482 PhShowStatus(ParentWindowHandle, L
"Unable to open the process", status, 0);
487 context.ProcessId = ProcessItem->ProcessId;
488 context.ProcessHandle = processHandle;
498 NtClose(processHandle);
513 showMemoryResults->
ProcessId = ProcessItem->ProcessId;
514 showMemoryResults->
Results = context.Results;
524 NtClose(processHandle);
541 Button_SetCheck(GetDlgItem(hwndDlg,
IDC_PRIVATE), BST_CHECKED);
551 switch (LOWORD(wParam))
554 EndDialog(hwndDlg, IDCANCEL);
559 ULONG64 minimumLength = 10;
563 if (minimumLength < 4)
565 PhShowError(hwndDlg, L
"The minimum length must be at least 4.");
569 context->MinimumLength = (ULONG)minimumLength;
570 context->DetectUnicode = Button_GetCheck(GetDlgItem(hwndDlg,
IDC_DETECTUNICODE)) == BST_CHECKED;
571 context->Private = Button_GetCheck(GetDlgItem(hwndDlg,
IDC_PRIVATE)) == BST_CHECKED;
572 context->Image = Button_GetCheck(GetDlgItem(hwndDlg,
IDC_IMAGE)) == BST_CHECKED;
573 context->Mapped = Button_GetCheck(GetDlgItem(hwndDlg,
IDC_MAPPED)) == BST_CHECKED;
575 EndDialog(hwndDlg, IDOK);
586 static BOOL NTAPI PhpMemoryStringResultCallback(
588 _In_opt_ PVOID Context
604 context->Options.Header.Callback = PhpMemoryStringResultCallback;
605 context->Options.Header.Context = context;
606 context->Options.MinimumLength = context->MinimumLength;
607 context->Options.DetectUnicode = context->DetectUnicode;
609 if (context->Private)
610 context->Options.MemoryTypeMask |= MEM_PRIVATE;
612 context->Options.MemoryTypeMask |= MEM_IMAGE;
614 context->Options.MemoryTypeMask |= MEM_MAPPED;
619 context->WindowHandle,
625 return STATUS_SUCCESS;
649 context->WindowHandle = hwndDlg;
652 if (!context->ThreadHandle)
654 PhShowStatus(hwndDlg, L
"Unable to create the search thread", 0, GetLastError());
655 EndDialog(hwndDlg, IDCANCEL);
659 SetTimer(hwndDlg, 1, 500, NULL);
668 if (context->ThreadHandle)
669 NtClose(context->ThreadHandle);
676 switch (LOWORD(wParam))
683 EnableWindow(GetDlgItem(hwndDlg, IDCANCEL),
FALSE);
684 context->Options.Header.Cancel =
TRUE;
717 EndDialog(hwndDlg, IDOK);