Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
exceptions view
Browse files Browse the repository at this point in the history
  • Loading branch information
zodiacon committed Apr 28, 2022
1 parent 52c5787 commit d3efb00
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 5 deletions.
48 changes: 48 additions & 0 deletions TotalPE/ExceptionsView.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "pch.h"
#include "ExceptionsView.h"
#include "SortHelper.h"

CString CExceptionsView::GetColumnText(HWND, int row, int col) const {
auto& item = m_Items[row];

switch (col) {
case 0: return std::format(L"0x{:08X}", item.get_begin_address()).c_str();
case 1: return std::format(L"0x{:08X}", item.get_end_address()).c_str();
case 2: return std::format(L"0x{:08X}", item.get_unwind_data_address()).c_str();
}
return CString();
}

void CExceptionsView::DoSort(SortInfo const* si) {
if (si == nullptr)
return;

auto compare = [&](auto& item1, auto& item2) {
switch (si->SortColumn) {
case 0: return SortHelper::Sort(item1.get_begin_address(), item2.get_begin_address(), si->SortAscending);
case 1: return SortHelper::Sort(item1.get_end_address(), item2.get_end_address(), si->SortAscending);
case 2: return SortHelper::Sort(item1.get_unwind_data_address(), item2.get_unwind_data_address(), si->SortAscending);
}
return false;
};
std::ranges::sort(m_Items, compare);
}

LRESULT CExceptionsView::OnCreate(UINT, WPARAM, LPARAM, BOOL&) {
m_hWndClient = m_List.Create(m_hWnd, rcDefault, nullptr, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
LVS_REPORT | LVS_OWNERDATA | LVS_SINGLESEL | LVS_SHOWSELALWAYS, WS_EX_CLIENTEDGE);
m_List.SetExtendedListViewStyle(LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP);

auto cm = GetColumnManager(m_List);
cm->AddColumn(L"Dummy", 0, 10);
cm->AddColumn(L"Begin Address", LVCFMT_RIGHT, 120);
cm->AddColumn(L"End Address", LVCFMT_RIGHT, 120);
cm->AddColumn(L"Unwind Address", LVCFMT_RIGHT, 120);
cm->UpdateColumns();
cm->DeleteColumn(0);

m_Items = PE().get_exceptions().get_exception_entries();
m_List.SetItemCount((int)m_Items.size());

return 0;
}
27 changes: 27 additions & 0 deletions TotalPE/ExceptionsView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include "View.h"
#include <VirtualListView.h>

class CExceptionsView :
public CView<CExceptionsView>,
public CVirtualListView<CExceptionsView> {
public:
using CView::CView;

CString GetColumnText(HWND, int row, int col) const;
void DoSort(SortInfo const* si);

BEGIN_MSG_MAP(CExceptionsView)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
CHAIN_MSG_MAP(CView<CExceptionsView>)
CHAIN_MSG_MAP(CVirtualListView<CExceptionsView>)
END_MSG_MAP()

LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);

private:
CListViewCtrl m_List;
std::vector<pe_exception_entry> m_Items;
};

6 changes: 2 additions & 4 deletions TotalPE/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void CMainFrame::InitMenu() {
int id;
UINT icon;
HICON hIcon{ nullptr };
} commands[] = {
} const commands[] = {
{ ID_EDIT_COPY, IDI_COPY },
{ ID_EDIT_PASTE, IDI_PASTE },
{ ID_FILE_OPEN, IDI_FILE_OPEN },
Expand All @@ -201,7 +201,6 @@ void CMainFrame::InitMenu() {
{ ID_VIEW_DEBUG, IDI_DEBUG},
{ ID_FILE_RUNASADMINISTRATOR, 0, IconHelper::GetShieldIcon() },
};

for (auto& cmd : commands) {
if (cmd.icon)
AddCommand(cmd.id, cmd.icon);
Expand All @@ -228,7 +227,7 @@ void CMainFrame::UpdateUI() {

void CMainFrame::ParseResources(HTREEITEM hRoot) {
auto& node = m_pe->get_resources();
for (auto& entry : node.get_entry_list()) {
for (auto const& entry : node.get_entry_list()) {
ParseResources(hRoot, entry);
}
}
Expand Down Expand Up @@ -335,7 +334,6 @@ bool CMainFrame::OpenPE(PCWSTR path) {
return false;
}


m_pe = std::move(pe);
m_Path = path;
m_ViewMgr.Clear();
Expand Down
13 changes: 13 additions & 0 deletions TotalPE/RelocationsView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ CString CRelocationsView::GetColumnText(HWND, int row, int col) const {
}

void CRelocationsView::DoSort(SortInfo const* si) {
if (si == nullptr)
return;

auto compare = [&](auto& item1, auto& item2) {
switch (si->SortColumn) {
case 0: return SortHelper::Sort(item1.type, item2.type, si->SortAscending);
case 1: return SortHelper::Sort(item1.relative_virtual_address, item2.relative_virtual_address, si->SortAscending);
case 2: return SortHelper::Sort(item1.relocation_id, item2.relocation_id, si->SortAscending);
case 3: return SortHelper::Sort(item1.data, item2.data, si->SortAscending);
}
return false;
};
std::ranges::sort(m_Items, compare);
}

LRESULT CRelocationsView::OnCreate(UINT, WPARAM, LPARAM, BOOL&) {
Expand Down
2 changes: 2 additions & 0 deletions TotalPE/TotalPE.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
<ClCompile Include="BufferManager.cpp" />
<ClCompile Include="DebugView.cpp" />
<ClCompile Include="DirectoriesView.cpp" />
<ClCompile Include="ExceptionsView.cpp" />
<ClCompile Include="ExportsView.cpp" />
<ClCompile Include="GenericWindow.cpp" />
<ClCompile Include="ImportsView.cpp" />
Expand Down Expand Up @@ -251,6 +252,7 @@
<ClInclude Include="BufferManager.h" />
<ClInclude Include="DebugView.h" />
<ClInclude Include="DirectoriesView.h" />
<ClInclude Include="ExceptionsView.h" />
<ClInclude Include="ExportsView.h" />
<ClInclude Include="GenericWindow.h" />
<ClInclude Include="ImportsView.h" />
Expand Down
6 changes: 6 additions & 0 deletions TotalPE/TotalPE.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@
<ClCompile Include="RelocationsView.cpp">
<Filter>Views</Filter>
</ClCompile>
<ClCompile Include="ExceptionsView.cpp">
<Filter>Views</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h">
Expand Down Expand Up @@ -206,6 +209,9 @@
<ClInclude Include="RelocationsView.h">
<Filter>Views</Filter>
</ClInclude>
<ClInclude Include="ExceptionsView.h">
<Filter>Views</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="TotalPE.rc">
Expand Down
8 changes: 8 additions & 0 deletions TotalPE/ViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "MessageTableView.h"
#include "SecurityView.h"
#include "RelocationsView.h"
#include "ExceptionsView.h"

ViewManager::ViewManager(IMainFrame* frame) : m_pFrame(frame) {
m_views.reserve(16);
Expand Down Expand Up @@ -96,6 +97,13 @@ HWND ViewManager::CreateOrGetView(TreeItemType type, HWND hParent, pe_image_full
break;
}

case IMAGE_DIRECTORY_ENTRY_EXCEPTION:
{
auto view = new CExceptionsView(m_pFrame, pe);
hView = view->DoCreate(hParent);
break;
}

default:
// all other directories...

Expand Down
2 changes: 1 addition & 1 deletion WTLHelper

0 comments on commit d3efb00

Please sign in to comment.