Skip to content

Commit 000fb0b

Browse files
Fix the right click crash issue on the UI.
1 parent bfd29ca commit 000fb0b

21 files changed

Lines changed: 158 additions & 95 deletions

WinArk/DriverTable.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ LRESULT CDriverTable::OnRBtnDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
7171
POINT pt;
7272
::GetCursorPos(&pt);
7373
int selected = m_Table.data.selected;
74-
ATLASSERT(selected >= 0);
74+
if (selected == -1)
75+
return 0;
7576
auto& p = m_Table.data.info[selected];
7677
auto& pdata = p.GetStatusProcess();
7778
if (pdata.CurrentState != ServiceState::Running) {
@@ -272,7 +273,8 @@ bool CDriverTable::CompareItems(const WinSys::DriverInfo& s1, const WinSys::Driv
272273

273274
LRESULT CDriverTable::OnKernelRoutine(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
274275
int selected = m_Table.data.selected;
275-
ATLASSERT(selected >= 0);
276+
if (selected == -1)
277+
return 0;
276278
auto& p = m_Table.data.info[selected];
277279

278280
CKernelRoutineDlg dlg;

WinArk/EtwView.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,8 @@ LRESULT CEtwView::OnClose(UINT, WPARAM, LPARAM, BOOL& handled) {
560560

561561
LRESULT CEtwView::OnCopy(WORD, WORD, HWND, BOOL&) {
562562
auto selected = m_List.GetSelectedIndex();
563-
ATLASSERT(selected >= 0);
563+
if (selected == -1)
564+
return 0;
564565
CString text, item;
565566
for (int c = 0;; c++) {
566567
if (!m_List.GetItemText(selected, c, item))

WinArk/FiltersDlg.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ LRESULT CFiltersDlg::OnLoad(WORD, WORD wID, HWND, BOOL&) {
227227

228228
LRESULT CFiltersDlg::OnEdit(WORD, WORD wID, HWND, BOOL&) {
229229
auto selected = m_List.GetSelectedIndex();
230-
ATLASSERT(selected >= 0);
230+
if (selected == -1)
231+
return 0;
231232
CString text;
232233
m_List.GetItemText(selected, 0, text);
233234
m_FilterNames.SelectString(-1, text);
@@ -257,7 +258,8 @@ LRESULT CFiltersDlg::OnMoveUp(WORD, WORD wID, HWND, BOOL&) {
257258

258259
LRESULT CFiltersDlg::OnMoveDown(WORD, WORD wID, HWND, BOOL&) {
259260
auto selected = m_List.GetSelectedIndex();
260-
ATLASSERT(selected < m_List.GetItemCount() - 1);
261+
if (selected == -1)
262+
return 0;
261263
SwapItems(m_List, selected, selected + 1);
262264
m_List.SelectItem(selected + 1);
263265

@@ -266,7 +268,8 @@ LRESULT CFiltersDlg::OnMoveDown(WORD, WORD wID, HWND, BOOL&) {
266268

267269
LRESULT CFiltersDlg::OnDelete(WORD, WORD wID, HWND, BOOL&) {
268270
auto selected = m_List.GetSelectedIndex();
269-
ATLASSERT(selected >= 0);
271+
if (selected == -1)
272+
return 0;
270273
m_List.DeleteItem(selected);
271274

272275
return 0;

WinArk/KernelInlineHookTable.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ LRESULT CKernelInlineHookTable::OnRefresh(WORD /*wNotifyCode*/, WORD /*wID*/, HW
221221

222222
LRESULT CKernelInlineHookTable::OnHookCopy(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
223223
int selected = m_Table.data.selected;
224-
ATLASSERT(selected >= 0);
224+
if (selected == -1)
225+
return 0;
225226
auto& info = m_Table.data.info[selected];
226227

227228
std::wstring text = GetSingleHookInfo(info);

WinArk/KernelModuleTable.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ LRESULT CKernelModuleTable::OnRefresh(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /
182182

183183
LRESULT CKernelModuleTable::OnKernelModuleCopy(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
184184
int selected = m_Table.data.selected;
185-
ATLASSERT(selected >= 0);
185+
if (selected == -1)
186+
return 0;
186187
auto& info = m_Table.data.info[selected];
187188

188189
CString text = GetSingleKernelModuleInfo(info).c_str();
@@ -244,7 +245,8 @@ std::wstring CKernelModuleTable::GetSingleKernelModuleInfo(std::shared_ptr<WinSy
244245

245246
LRESULT CKernelModuleTable::OnGoToFileLocation(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
246247
int selected = m_Table.data.selected;
247-
ATLASSERT(selected >= 0);
248+
if (selected == -1)
249+
return 0;
248250
auto& kernelModule = m_Table.data.info[selected];
249251
std::wstring path = Helpers::StringToWstring(kernelModule->FullPath);
250252
if ((INT_PTR)::ShellExecute(nullptr, L"open", L"explorer",
@@ -257,7 +259,8 @@ LRESULT CKernelModuleTable::OnGoToFileLocation(WORD /*wNotifyCode*/, WORD /*wID*
257259

258260
LRESULT CKernelModuleTable::OnKernelDump(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
259261
int selected = m_Table.data.selected;
260-
ATLASSERT(selected >= 0);
262+
if (selected == -1)
263+
return 0;
261264
auto& kernelModule = m_Table.data.info[selected];
262265
std::wstring path = Helpers::StringToWstring(kernelModule->NtPath);
263266
bool ok = DriverHelper::DumpSysModule(path.c_str(), kernelModule->ImageBase, kernelModule->ImageSize);
@@ -267,7 +270,8 @@ LRESULT CKernelModuleTable::OnKernelDump(WORD /*wNotifyCode*/, WORD /*wID*/, HWN
267270

268271
LRESULT CKernelModuleTable::OnKernelEATHookScan(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
269272
int selected = m_Table.data.selected;
270-
ATLASSERT(selected >= 0);
273+
if (selected == -1)
274+
return 0;
271275
auto& kernelModule = m_Table.data.info[selected];
272276

273277
CKernelEATHookDlg dlg(kernelModule);
@@ -278,7 +282,8 @@ LRESULT CKernelModuleTable::OnKernelEATHookScan(WORD /*wNotifyCode*/, WORD /*wID
278282

279283
LRESULT CKernelModuleTable::OnKernelInlineHookScan(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
280284
int selected = m_Table.data.selected;
281-
ATLASSERT(selected >= 0);
285+
if (selected == -1)
286+
return 0;
282287
auto& kernelModule = m_Table.data.info[selected];
283288

284289
CKernelInlineHookDlg dlg(kernelModule);

WinArk/KernelNotifyTable.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ LRESULT CKernelNotifyTable::OnRBtnDown(UINT uMsg, WPARAM wParam, LPARAM lParam,
7373
POINT pt;
7474
::GetCursorPos(&pt);
7575
int selected = m_Table.data.selected;
76-
ATLASSERT(selected >= 0);
76+
if (selected == -1)
77+
return 0;
7778

7879
bool show = Tablefunction(m_hWnd, uMsg, wParam, lParam);
7980
if (show) {
@@ -320,7 +321,8 @@ LRESULT CKernelNotifyTable::OnRefresh(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /
320321

321322
LRESULT CKernelNotifyTable::OnRemove(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
322323
int selected = m_Table.data.selected;
323-
ATLASSERT(selected >= 0);
324+
if (selected == -1)
325+
return 0;
324326
auto& p = m_Table.data.info[selected];
325327

326328
CString text;
@@ -367,7 +369,8 @@ LRESULT CKernelNotifyTable::OnRemove(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*
367369

368370
LRESULT CKernelNotifyTable::OnRemoveByCompanyName(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
369371
int selected = m_Table.data.selected;
370-
ATLASSERT(selected >= 0);
372+
if (selected == -1)
373+
return 0;
371374
auto& pNotify = m_Table.data.info[selected];
372375

373376
std::wstring companyName = pNotify.Company;
@@ -461,7 +464,8 @@ std::wstring CKernelNotifyTable::GetSingleNotifyInfo(CallbackInfo& info) {
461464

462465
LRESULT CKernelNotifyTable::OnNotifyCopy(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
463466
int selected = m_Table.data.selected;
464-
ATLASSERT(selected >= 0);
467+
if (selected == -1)
468+
return 0;
465469
auto& info = m_Table.data.info[selected];
466470

467471
std::wstring text = GetSingleNotifyInfo(info);

WinArk/MiniFilterTable.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ LRESULT CMiniFilterTable::OnRefresh(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*h
330330

331331
LRESULT CMiniFilterTable::OnCallback(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
332332
int selected = m_Table.data.selected;
333-
ATLASSERT(selected >= 0);
333+
if (selected == -1)
334+
return 0;
334335
auto& info = m_Table.data.info[selected];
335336

336337
CMiniFilterDlg dlg(info.FilterName);
@@ -341,7 +342,8 @@ LRESULT CMiniFilterTable::OnCallback(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*
341342

342343
LRESULT CMiniFilterTable::OnRemove(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
343344
int selected = m_Table.data.selected;
344-
ATLASSERT(selected >= 0);
345+
if (selected == -1)
346+
return 0;
345347
auto& info = m_Table.data.info[selected];
346348

347349
DWORD len = static_cast<DWORD>(info.FilterName.length());

WinArk/ObjectCallbackTable.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ LRESULT CObjectCallbackTable::OnRBtnDown(UINT uMsg, WPARAM wParam, LPARAM lParam
7878
if (selected < 0) {
7979
return FALSE;
8080
}
81-
ATLASSERT(selected >= 0);
81+
if (selected == -1)
82+
return 0;
8283

8384
bool show = Tablefunction(m_hWnd, uMsg, wParam, lParam);
8485
if (show) {
@@ -270,7 +271,8 @@ LRESULT CObjectCallbackTable::OnRefresh(WORD /*wNotifyCode*/, WORD /*wID*/, HWND
270271

271272
LRESULT CObjectCallbackTable::OnRemove(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
272273
int selected = m_Table.data.selected;
273-
ATLASSERT(selected >= 0);
274+
if (selected == -1)
275+
return 0;
274276
auto& p = m_Table.data.info[selected];
275277

276278
CString text;
@@ -293,7 +295,8 @@ LRESULT CObjectCallbackTable::OnRemove(WORD /*wNotifyCode*/, WORD /*wID*/, HWND
293295

294296
LRESULT CObjectCallbackTable::OnRemoveByCompanyName(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
295297
int selected = m_Table.data.selected;
296-
ATLASSERT(selected >= 0);
298+
if (selected == -1)
299+
return 0;
297300
auto& pCallback = m_Table.data.info[selected];
298301

299302
std::wstring companyName = pCallback.Company;
@@ -365,7 +368,8 @@ std::wstring CObjectCallbackTable::GetSingleInfo(ObjectCallbackInfo& info) {
365368

366369
LRESULT CObjectCallbackTable::OnCopy(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
367370
int selected = m_Table.data.selected;
368-
ATLASSERT(selected >= 0);
371+
if (selected == -1)
372+
return 0;
369373
auto& info = m_Table.data.info[selected];
370374

371375
std::wstring text = GetSingleInfo(info);
@@ -394,7 +398,8 @@ LRESULT CObjectCallbackTable::OnExport(WORD /*wNotifyCode*/, WORD /*wID*/, HWND
394398

395399
LRESULT CObjectCallbackTable::OnDisable(WORD, WORD, HWND, BOOL&) {
396400
int selected = m_Table.data.selected;
397-
ATLASSERT(selected >= 0);
401+
if (selected == -1)
402+
return 0;
398403
auto& p = m_Table.data.info[selected];
399404

400405
CString text;
@@ -417,7 +422,8 @@ LRESULT CObjectCallbackTable::OnDisable(WORD, WORD, HWND, BOOL&) {
417422

418423
LRESULT CObjectCallbackTable::OnEnable(WORD, WORD, HWND, BOOL&) {
419424
int selected = m_Table.data.selected;
420-
ATLASSERT(selected >= 0);
425+
if (selected == -1)
426+
return 0;
421427
auto& p = m_Table.data.info[selected];
422428

423429
CString text;

WinArk/PiDDBCacheTable.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ std::wstring CPiDDBCacheTable::GetSinglePiDDBCacheInfo(PiDDBCacheInfo& info) {
191191

192192
LRESULT CPiDDBCacheTable::OnPiDDBCacheCopy(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
193193
int selected = m_Table.data.selected;
194-
ATLASSERT(selected >= 0);
194+
if (selected == -1)
195+
return 0;
195196
auto& info = m_Table.data.info[selected];
196197

197198
CString text;

WinArk/ProcessInlineHookTable.cpp

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ LRESULT CProcessInlineHookTable::OnRBtnDown(UINT uMsg, WPARAM wParam, LPARAM lPa
200200
bool show = Tablefunction(m_hWnd, uMsg, wParam, lParam);
201201
if (show) {
202202
int selected = m_Table.data.selected;
203-
ATLASSERT(selected >= 0);
203+
if (selected == -1)
204+
return 0;
204205
auto& info = m_Table.data.info[selected];
205206
if (!info.CanRestore)
206207
EnableMenuItem(hSubMenu, ID_INLINEHOOK_RESTORE, MF_DISABLED);
@@ -778,6 +779,7 @@ void CProcessInlineHookTable::Refresh() {
778779
auto m = GetModuleByAddress(address);
779780
bool isX64Module = true;
780781
bool isCheckCode = true;
782+
isCheckCode = false;
781783
void* local_image_base = nullptr;
782784
if (m != nullptr) {
783785
moduleSize = m->ModuleSize;
@@ -786,38 +788,38 @@ void CProcessInlineHookTable::Refresh() {
786788
PEParser parser(path.c_str());
787789
isX64Module = parser.IsPe64();
788790

789-
uint32_t image_size = parser.GetImageSize();
790-
local_image_base = ::VirtualAlloc(nullptr, image_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
791-
if (!local_image_base)
792-
isCheckCode = false;
793-
794-
if (local_image_base) {
795-
BYTE* data = (BYTE*)parser.GetBaseAddress();
796-
LARGE_INTEGER fileSize = parser.GetFileSize();
797-
798-
uint64_t real_image_base = (uint64_t)m->ImageBase;
799-
800-
// Copy image headers
801-
memcpy(local_image_base, data, parser.GetHeadersSize());
802-
803-
// Copy image sections
804-
805-
for (auto i = 0; i < parser.GetSectionCount(); ++i) {
806-
auto section = parser.GetSectionHeader(i);
807-
if ((section[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA) > 0)
808-
continue;
809-
auto local_section = reinterpret_cast<void*>(reinterpret_cast<uint64_t>(local_image_base)
810-
+ section[i].VirtualAddress);
811-
if (section[i].PointerToRawData + section[i].SizeOfRawData > fileSize.QuadPart) {
812-
continue;
813-
}
814-
memcpy(local_section, reinterpret_cast<void*>(reinterpret_cast<uint64_t>(data)
815-
+ section[i].PointerToRawData), section[i].SizeOfRawData);
816-
}
817-
818-
std::vector<RelocInfo> relocs = parser.GetRelocs(local_image_base);
819-
PEParser::RelocateImageByDelta(relocs, real_image_base - parser.GetImageBase());
820-
}
791+
//uint32_t image_size = parser.GetImageSize();
792+
//local_image_base = ::VirtualAlloc(nullptr, image_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
793+
//if (!local_image_base)
794+
// isCheckCode = false;
795+
796+
//if (local_image_base) {
797+
// BYTE* data = (BYTE*)parser.GetBaseAddress();
798+
// LARGE_INTEGER fileSize = parser.GetFileSize();
799+
800+
// uint64_t real_image_base = (uint64_t)m->ImageBase;
801+
802+
// // Copy image headers
803+
// memcpy(local_image_base, data, parser.GetHeadersSize());
804+
805+
// // Copy image sections
806+
807+
// for (auto i = 0; i < parser.GetSectionCount(); ++i) {
808+
// auto section = parser.GetSectionHeader(i);
809+
// if ((section[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA) > 0)
810+
// continue;
811+
// auto local_section = reinterpret_cast<void*>(reinterpret_cast<uint64_t>(local_image_base)
812+
// + section[i].VirtualAddress);
813+
// if (section[i].PointerToRawData + section[i].SizeOfRawData > fileSize.QuadPart) {
814+
// continue;
815+
// }
816+
// memcpy(local_section, reinterpret_cast<void*>(reinterpret_cast<uint64_t>(data)
817+
// + section[i].PointerToRawData), section[i].SizeOfRawData);
818+
// }
819+
820+
// std::vector<RelocInfo> relocs = parser.GetRelocs(local_image_base);
821+
// PEParser::RelocateImageByDelta(relocs, real_image_base - parser.GetImageBase());
822+
//}
821823
}
822824
else {
823825
moduleBase = 0;
@@ -1114,7 +1116,8 @@ void CProcessInlineHookTable::CheckX64HookType4(cs_insn* insn, size_t j, size_t
11141116

11151117
LRESULT CProcessInlineHookTable::OnHookCopy(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
11161118
int selected = m_Table.data.selected;
1117-
ATLASSERT(selected >= 0);
1119+
if (selected == -1)
1120+
return 0;
11181121
auto& info = m_Table.data.info[selected];
11191122

11201123
std::wstring text = GetSingleHookInfo(info);
@@ -1213,7 +1216,8 @@ bool CProcessInlineHookTable::CheckCode(ULONG_PTR addr, SIZE_T size, ULONG_PTR i
12131216

12141217
LRESULT CProcessInlineHookTable::OnRestore(WORD, WORD, HWND, BOOL&) {
12151218
int selected = m_Table.data.selected;
1216-
ATLASSERT(selected >= 0);
1219+
if (selected == -1)
1220+
return 0;
12171221
auto& info = m_Table.data.info[selected];
12181222

12191223
SIZE_T bytes = 0;

0 commit comments

Comments
 (0)