Add contextmenu to memory search results window
@@ -621,6 +621,116 @@ INT_PTR CALLBACK PhpMemoryResultsDlgProc(
}
}
break;
+ case NM_RCLICK:
+ {
+ if (header->hwndFrom == lvHandle)
+ {
+ POINT point;
+ PPH_EMENU menu;
+ PPH_EMENU_ITEM selectedItem;
+ ULONG filterType = 0;
+
+ menu = PhCreateEMenu();
+ PhInsertEMenuItem(menu, PhCreateEMenuItem(0, ID_MEMORY_READWRITEMEMORY, L"Read/Write memory", NULL, NULL), -1);
+ PhInsertEMenuItem(menu, PhCreateEMenuItem(PH_EMENU_SEPARATOR, 0, L"", NULL, NULL), -1);
+ PhInsertEMenuItem(menu, PhCreateEMenuItem(0, IDC_COPY, L"Copy", NULL, NULL), -1);
+ GetCursorPos(&point);
+
+ selectedItem = PhShowEMenu(
+ menu,
+ hwndDlg,
+ PH_EMENU_SHOW_LEFTRIGHT,
+ PH_ALIGN_LEFT | PH_ALIGN_TOP,
+ point.x,
+ point.y
+ );
+
+ if (selectedItem)
+ {
+ switch (selectedItem->Id)
+ {
+ case ID_MEMORY_READWRITEMEMORY:
+ {
+ INT index;
+
+ if ((index = ListView_GetNextItem(
+ lvHandle,
+ -1,
+ LVNI_SELECTED
+ )) != -1)
+ {
+ NTSTATUS status;
+ PPH_MEMORY_RESULT result = context->Results->Items[index];
+ HANDLE processHandle;
+ MEMORY_BASIC_INFORMATION basicInfo;
+ PPH_SHOW_MEMORY_EDITOR showMemoryEditor;
+
+ if (NT_SUCCESS(status = PhOpenProcess(
+ &processHandle,
+ PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
+ context->ProcessId
+ )))
+ {
+ if (NT_SUCCESS(status = NtQueryVirtualMemory(
+ processHandle,
+ result->Address,
+ MemoryBasicInformation,
+ &basicInfo,
+ sizeof(MEMORY_BASIC_INFORMATION),
+ NULL
+ )))
+ {
+ showMemoryEditor = PhAllocate(sizeof(PH_SHOW_MEMORY_EDITOR));
+ memset(showMemoryEditor, 0, sizeof(PH_SHOW_MEMORY_EDITOR));
+ showMemoryEditor->ProcessId = context->ProcessId;
+ showMemoryEditor->BaseAddress = basicInfo.BaseAddress;
+ showMemoryEditor->RegionSize = basicInfo.RegionSize;
+ showMemoryEditor->SelectOffset = (ULONG)((ULONG_PTR)result->Address - (ULONG_PTR)basicInfo.BaseAddress);
+ showMemoryEditor->SelectLength = (ULONG)result->Length;
+ ProcessHacker_ShowMemoryEditor(PhMainWndHandle, showMemoryEditor);
+ }
+
+ NtClose(processHandle);
+ }
+
+ if (!NT_SUCCESS(status))
+ PhShowStatus(hwndDlg, L"Unable to edit memory", status, 0);
+ }
+ }
+ break;
+ case IDC_COPY:
+ {
+ HWND lvHandle;
+ PPH_STRING string;
+ ULONG selectedCount;
+
+ lvHandle = GetDlgItem(hwndDlg, IDC_LIST);
+ selectedCount = ListView_GetSelectedCount(lvHandle);
+
+ if (selectedCount == 0)
+ {
+ // User didn't select anything, so copy all items.
+ string = PhpGetStringForSelectedResults(lvHandle, context->Results, TRUE);
+ PhSetStateAllListViewItems(lvHandle, LVIS_SELECTED, LVIS_SELECTED);
+ }
+ else
+ {
+ string = PhpGetStringForSelectedResults(lvHandle, context->Results, FALSE);
+ }
+
+ PhSetClipboardString(hwndDlg, &string->sr);
+ PhDereferenceObject(string);
+
+ SendMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM)lvHandle, TRUE);
+ }
+ break;
+ }
+ }
+
+ PhDestroyEMenu(menu);
+ }
+ }
+ break;
}
}
break;
