Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
dmex committed Jan 23, 2025
1 parent 48a0f09 commit 09dcb24
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 74 deletions.
1 change: 1 addition & 0 deletions SystemInformer/SystemInformer.def
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ EXPORTS
PhGetSystemRoot
PhGetTaskbarDpi
PhGetTemporaryDirectoryRandomAlphaFileName
PhGetUserLocaleInfoBool
PhGetWin32Message
PhGetWindowDpi
PhInitializeHash
Expand Down
2 changes: 1 addition & 1 deletion SystemInformer/anawait.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ VOID PhUiAnalyzeWaitThread(
}
else
{
PhShowInformation2(hWnd, L"The thread does not appear to be waiting.", L"%s", L"");
PhShowInformation2(hWnd, L"Unable to analyze the thread.", L"%s", L"The thread does not appear to be waiting.");
}

PhDeleteStringBuilder(&context.StringBuilder);
Expand Down
2 changes: 1 addition & 1 deletion SystemInformer/hidnproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ INT_PTR CALLBACK PhpZombieProcessesDlgProc(
}
else
{
PhShowError2(hwndDlg, L"Unable to create a process structure for the selected process.", L"%s", L"");
PhShowStatus(hwndDlg, L"Unable to create a process structure for the selected process.", STATUS_NO_MEMORY, 0);
}
}
}
Expand Down
21 changes: 16 additions & 5 deletions SystemInformer/hndlmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,37 @@ VOID PhInsertHandleObjectPropertiesEMenuItems(
PhEqualString2(Info->TypeName, L"Mapped file", TRUE) || PhEqualString2(Info->TypeName, L"Mapped image", TRUE))
{
if (PhEqualString2(Info->TypeName, L"File", TRUE))
{
PhInsertEMenuItem(parentItem, PhCreateEMenuItem(0, ID_HANDLE_OBJECTPROPERTIES2, L"File propert&ies", NULL, NULL), indexInParent);

PhInsertEMenuItem(parentItem, PhCreateEMenuItem(0, ID_HANDLE_OBJECTPROPERTIES1, PhaAppendCtrlEnter(L"Open &file location", EnableShortcut), NULL, NULL), indexInParent);
PhInsertEMenuItem(parentItem, PhCreateEMenuItem(0, ID_HANDLE_OBJECTPROPERTIES1, PhaAppendCtrlEnter(L"Open &file location", EnableShortcut), NULL, NULL), indexInParent + 1);
PhInsertEMenuItem(parentItem, PhCreateEMenuSeparator(), indexInParent + 2);
}
else
{
PhInsertEMenuItem(parentItem, PhCreateEMenuItem(0, ID_HANDLE_OBJECTPROPERTIES1, PhaAppendCtrlEnter(L"Open &file location", EnableShortcut), NULL, NULL), indexInParent);
PhInsertEMenuItem(parentItem, PhCreateEMenuSeparator(), indexInParent + 1);
}
}
else if (PhEqualString2(Info->TypeName, L"Key", TRUE))
{
PhInsertEMenuItem(parentItem, PhCreateEMenuItem(0, ID_HANDLE_OBJECTPROPERTIES1, PhaAppendCtrlEnter(L"Open &key", EnableShortcut), NULL, NULL), indexInParent);
PhInsertEMenuItem(parentItem, PhCreateEMenuSeparator(), indexInParent + 1);
}
else if (PhEqualString2(Info->TypeName, L"Process", TRUE))
{
PhInsertEMenuItem(parentItem, PhCreateEMenuItem(0, ID_HANDLE_OBJECTPROPERTIES1, PhaAppendCtrlEnter(L"Process propert&ies", EnableShortcut), NULL, NULL), indexInParent);
PhInsertEMenuItem(parentItem, PhCreateEMenuSeparator(), indexInParent + 1);
}
else if (PhEqualString2(Info->TypeName, L"Section", TRUE))
{
PhInsertEMenuItem(parentItem, PhCreateEMenuItem(0, ID_HANDLE_OBJECTPROPERTIES1, PhaAppendCtrlEnter(L"Read/Write &memory", EnableShortcut), NULL, NULL), indexInParent);
PhInsertEMenuItem(parentItem, PhCreateEMenuSeparator(), indexInParent + 1);
}
else if (PhEqualString2(Info->TypeName, L"Thread", TRUE))
{
PhInsertEMenuItem(parentItem, PhCreateEMenuItem(0, ID_HANDLE_OBJECTPROPERTIES1, PhaAppendCtrlEnter(L"Go to t&hread", EnableShortcut), NULL, NULL), indexInParent);
PhInsertEMenuItem(parentItem, PhCreateEMenuSeparator(), indexInParent + 1);
}

PhInsertEMenuItem(parentItem, PhCreateEMenuSeparator(), indexInParent);
}

static NTSTATUS PhpDuplicateHandleFromProcessItem(
Expand Down Expand Up @@ -294,7 +303,9 @@ VOID PhShowHandleObjectProperties1(
PPH_SHOW_MEMORY_EDITOR showMemoryEditor = PhAllocate(sizeof(PH_SHOW_MEMORY_EDITOR));

if (tooBig)
PhShowWarning2(hWnd, L"The section size is greater than 32 MB. Only the first 32 MB will be available.", L"%s", L"");
{
PhShowWarning2(hWnd, L"Unable to map a view of the section.", L"%s", L"The section size is greater than 32 MB. Only the first 32 MB will be available.");
}

memset(showMemoryEditor, 0, sizeof(PH_SHOW_MEMORY_EDITOR));
showMemoryEditor->ProcessId = NtCurrentProcessId();
Expand Down
12 changes: 8 additions & 4 deletions SystemInformer/mainwnd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4499,7 +4499,9 @@ PVOID PhPluginInvokeWindowCallback(
break;
case PH_MAINWINDOW_CALLBACK_TYPE_TOGGLE_VISIBLE:
{
SendMessage(PhMainWndHandle, WM_PH_INVOKE, (WPARAM)!(BOOLEAN)wparam, (LPARAM)PhMwpInvokeActivateWindow);
BOOLEAN visibility = !(BOOLEAN)(ULONG_PTR)wparam;

SendMessage(PhMainWndHandle, WM_PH_INVOKE, (WPARAM)visibility, (LPARAM)PhMwpInvokeActivateWindow);
}
break;
case PH_MAINWINDOW_CALLBACK_TYPE_ICON_CLICK:
Expand All @@ -4513,14 +4515,14 @@ PVOID PhPluginInvokeWindowCallback(
{
PPH_SHOW_MEMORY_EDITOR showMemoryEditor = (PPH_SHOW_MEMORY_EDITOR)lparam;

SendMessage(PhMainWndHandle, WM_PH_INVOKE, (WPARAM)showMemoryEditor, (LPARAM)PhMwpInvokeShowMemoryEditorDialog);
PostMessage(PhMainWndHandle, WM_PH_INVOKE, (WPARAM)showMemoryEditor, (LPARAM)PhMwpInvokeShowMemoryEditorDialog);
}
break;
case PH_MAINWINDOW_CALLBACK_TYPE_SHOW_MEMORY_RESULTS:
{
PPH_SHOW_MEMORY_RESULTS showMemoryResults = (PPH_SHOW_MEMORY_RESULTS)lparam;

SendMessage(PhMainWndHandle, WM_PH_INVOKE, (WPARAM)showMemoryResults, (LPARAM)PhMwpInvokeShowMemoryResultsDialog);
PostMessage(PhMainWndHandle, WM_PH_INVOKE, (WPARAM)showMemoryResults, (LPARAM)PhMwpInvokeShowMemoryResultsDialog);
}
break;
case PH_MAINWINDOW_CALLBACK_TYPE_SELECT_TAB_PAGE:
Expand Down Expand Up @@ -4585,7 +4587,9 @@ PVOID PhPluginInvokeWindowCallback(
break;
case PH_MAINWINDOW_CALLBACK_TYPE_SET_UPDATE_AUTOMATICALLY:
{
if (!!((BOOLEAN)wparam) != PhMwpUpdateAutomatically)
BOOLEAN updateAutomatically = !!(BOOLEAN)(ULONG_PTR)wparam;

if (updateAutomatically != PhMwpUpdateAutomatically)
{
SendMessage(PhMainWndHandle, WM_COMMAND, ID_VIEW_UPDATEAUTOMATICALLY, 0);
}
Expand Down
120 changes: 58 additions & 62 deletions SystemInformer/memedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,57 @@ VOID PhShowMemoryEditorDialog(

if (!links)
{
NTSTATUS status;
PVOID buffer;

if (RegionSize > 1024ULL * 1024ULL * 1024ULL) // 1 GB
{
PhShowStatus(OwnerWindow, L"Unable to edit the memory region.", 0, MEM_E_INVALID_SIZE);
return;
}

status = PhAllocateVirtualMemory(NtCurrentProcess(), &buffer, RegionSize, MEM_COMMIT, PAGE_READWRITE);

if (!NT_SUCCESS(status))
{
PhShowStatus(OwnerWindow, L"Unable to edit the memory region.", status, 0);
return;
}

{
HANDLE processHandle;

status = PhOpenProcess(
&processHandle,
PROCESS_VM_READ,
ProcessId
);

if (NT_SUCCESS(status))
{
status = NtReadVirtualMemory(
processHandle,
BaseAddress,
buffer,
RegionSize,
NULL
);

NtClose(processHandle);

if (!NT_SUCCESS(status))
{
PhShowStatus(OwnerWindow, L"Unable to read memory", status, 0);
return;
}
}
else
{
PhShowStatus(OwnerWindow, L"Unable to open the process", status, 0);
return;
}
}

context = PhAllocateZero(sizeof(MEMORY_EDITOR_CONTEXT));
context->OwnerHandle = OwnerWindow;
context->ProcessId = ProcessId;
Expand All @@ -90,6 +141,7 @@ VOID PhShowMemoryEditorDialog(
context->SelectOffset = SelectOffset;
PhSwapReference(&context->Title, Title);
context->Flags = Flags;
context->Buffer = buffer;

context->WindowHandle = PhCreateDialog(
PhInstanceHandle,
Expand Down Expand Up @@ -169,9 +221,6 @@ INT_PTR CALLBACK PhpMemoryEditorDlgProc(
{
case WM_INITDIALOG:
{
NTSTATUS status;
HANDLE processHandle;

PhSetApplicationWindowIcon(hwndDlg);

if (context->Title)
Expand All @@ -192,65 +241,12 @@ INT_PTR CALLBACK PhpMemoryEditorDlgProc(
}

PhInitializeLayoutManager(&context->LayoutManager, hwndDlg);

if (context->RegionSize > 1024 * 1024 * 1024) // 1 GB
{
PhShowStatus(context->OwnerHandle, L"Unable to edit the memory region.", 0, MEM_E_INVALID_SIZE);
return TRUE;
}

context->Buffer = PhAllocatePage(context->RegionSize, NULL);

if (!context->Buffer)
{
PhShowStatus(context->OwnerHandle, L"Unable to edit the memory region.", 0, ERROR_OUTOFMEMORY);
return TRUE;
}

{
status = PhOpenProcess(
&processHandle,
PROCESS_VM_READ,
context->ProcessId
);

if (NT_SUCCESS(status))
{
status = NtReadVirtualMemory(
processHandle,
context->BaseAddress,
context->Buffer,
context->RegionSize,
NULL
);

NtClose(processHandle);

if (!NT_SUCCESS(status))
{
PhShowStatus(context->OwnerHandle, L"Unable to read memory", status, 0);
return TRUE;
}
}
else
{
PhShowStatus(context->OwnerHandle, L"Unable to open the process", status, 0);
return TRUE;
}
}

PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDOK), NULL,
PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);
PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_SAVE), NULL,
PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);
PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_BYTESPERROW), NULL,
PH_ANCHOR_BOTTOM | PH_ANCHOR_LEFT);
PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_GOTO), NULL,
PH_ANCHOR_BOTTOM | PH_ANCHOR_LEFT);
PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_WRITE), NULL,
PH_ANCHOR_BOTTOM | PH_ANCHOR_LEFT);
PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_REREAD), NULL,
PH_ANCHOR_BOTTOM | PH_ANCHOR_LEFT);
PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDOK), NULL, PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);
PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_SAVE), NULL, PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);
PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_BYTESPERROW), NULL, PH_ANCHOR_BOTTOM | PH_ANCHOR_LEFT);
PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_GOTO), NULL, PH_ANCHOR_BOTTOM | PH_ANCHOR_LEFT);
PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_WRITE), NULL, PH_ANCHOR_BOTTOM | PH_ANCHOR_LEFT);
PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_REREAD), NULL, PH_ANCHOR_BOTTOM | PH_ANCHOR_LEFT);

if (MinimumSize.left == -1)
{
Expand Down
2 changes: 1 addition & 1 deletion tools/peview/layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ NTSTATUS PvGetFileAllocatedRanges(
if (!NT_SUCCESS(status))
break;

outputCount = returnLength / sizeof(FILE_ALLOCATED_RANGE_BUFFER);
outputCount = outputLength / sizeof(FILE_ALLOCATED_RANGE_BUFFER);

if (outputCount == 0)
break;
Expand Down

0 comments on commit 09dcb24

Please sign in to comment.