forked from winsiderss/systeminformer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemprot.c
More file actions
159 lines (142 loc) · 4.83 KB
/
Copy pathmemprot.c
File metadata and controls
159 lines (142 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* Process Hacker -
* memory protection window
*
* Copyright (C) 2010 wj32
*
* This file is part of Process Hacker.
*
* Process Hacker is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Process Hacker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
*/
#include <phapp.h>
#include <memprv.h>
#include <procprv.h>
typedef struct _MEMORY_PROTECT_CONTEXT
{
PPH_PROCESS_ITEM ProcessItem;
PPH_MEMORY_ITEM MemoryItem;
} MEMORY_PROTECT_CONTEXT, *PMEMORY_PROTECT_CONTEXT;
INT_PTR CALLBACK PhpMemoryProtectDlgProc(
_In_ HWND hwndDlg,
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam
);
VOID PhShowMemoryProtectDialog(
_In_ HWND ParentWindowHandle,
_In_ PPH_PROCESS_ITEM ProcessItem,
_In_ PPH_MEMORY_ITEM MemoryItem
)
{
MEMORY_PROTECT_CONTEXT context;
context.ProcessItem = ProcessItem;
context.MemoryItem = MemoryItem;
DialogBoxParam(
PhInstanceHandle,
MAKEINTRESOURCE(IDD_MEMPROTECT),
ParentWindowHandle,
PhpMemoryProtectDlgProc,
(LPARAM)&context
);
}
static INT_PTR CALLBACK PhpMemoryProtectDlgProc(
_In_ HWND hwndDlg,
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam
)
{
switch (uMsg)
{
case WM_INITDIALOG:
{
PhSetWindowContext(hwndDlg, PH_WINDOW_CONTEXT_DEFAULT, (PVOID)lParam);
PhCenterWindow(hwndDlg, GetParent(hwndDlg));
PhSetDialogItemText(hwndDlg, IDC_INTRO,
L"Possible values:\r\n"
L"\r\n"
L"0x01 - PAGE_NOACCESS\r\n"
L"0x02 - PAGE_READONLY\r\n"
L"0x04 - PAGE_READWRITE\r\n"
L"0x08 - PAGE_WRITECOPY\r\n"
L"0x10 - PAGE_EXECUTE\r\n"
L"0x20 - PAGE_EXECUTE_READ\r\n"
L"0x40 - PAGE_EXECUTE_READWRITE\r\n"
L"0x80 - PAGE_EXECUTE_WRITECOPY\r\n"
L"Modifiers:\r\n"
L"0x100 - PAGE_GUARD\r\n"
L"0x200 - PAGE_NOCACHE\r\n"
L"0x400 - PAGE_WRITECOMBINE\r\n"
);
PhSetDialogFocus(hwndDlg, GetDlgItem(hwndDlg, IDC_VALUE));
}
break;
case WM_DESTROY:
{
PhRemoveWindowContext(hwndDlg, PH_WINDOW_CONTEXT_DEFAULT);
}
break;
case WM_COMMAND:
{
switch (GET_WM_COMMAND_ID(wParam, lParam))
{
case IDCANCEL:
EndDialog(hwndDlg, IDCANCEL);
break;
case IDOK:
{
NTSTATUS status;
PMEMORY_PROTECT_CONTEXT context = PhGetWindowContext(hwndDlg, PH_WINDOW_CONTEXT_DEFAULT);
HANDLE processHandle;
ULONG64 protect;
PhStringToInteger64(&PhaGetDlgItemText(hwndDlg, IDC_VALUE)->sr, 0, &protect);
if (NT_SUCCESS(status = PhOpenProcess(
&processHandle,
PROCESS_VM_OPERATION,
context->ProcessItem->ProcessId
)))
{
PVOID baseAddress;
SIZE_T regionSize;
ULONG oldProtect;
baseAddress = context->MemoryItem->BaseAddress;
regionSize = context->MemoryItem->RegionSize;
status = NtProtectVirtualMemory(
processHandle,
&baseAddress,
®ionSize,
(ULONG)protect,
&oldProtect
);
if (NT_SUCCESS(status))
context->MemoryItem->Protect = (ULONG)protect;
}
if (NT_SUCCESS(status))
{
EndDialog(hwndDlg, IDOK);
}
else
{
PhShowStatus(hwndDlg, L"Unable to change memory protection", status, 0);
PhSetDialogFocus(hwndDlg, GetDlgItem(hwndDlg, IDC_VALUE));
Edit_SetSel(GetDlgItem(hwndDlg, IDC_VALUE), 0, -1);
}
}
break;
}
}
break;
}
return FALSE;
}