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

Commit

Permalink
undecorate exported names
Browse files Browse the repository at this point in the history
minor bug fixes
  • Loading branch information
zodiacon committed Jun 15, 2022
1 parent 612f1bb commit b4120f4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
15 changes: 13 additions & 2 deletions TotalPE/ExportsView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
#include "AssemblyView.h"
#include "ViewManager.h"
#include <ThemeHelper.h>
#include "PEStrings.h"

CString CExportsView::GetColumnText(HWND, int row, int col) const {
auto& exp = m_Exports[row];
auto const& exp = m_Exports[row];
switch (col) {
case 0: return exp.has_name() ? (CString)exp.get_func_name().c_str() : (CString)std::format(L"@{}", exp.get_ordinal()).c_str();
case 1: return std::to_wstring(exp.get_ordinal()).c_str();
case 2: return std::format(L"0x{:08X}", exp.get_rva()).c_str();
case 3: return exp.is_forward() ? exp.get_forward_name().c_str() : "";
case 4: return exp.UndecoratedName;

}

return CString();
Expand Down Expand Up @@ -44,6 +47,7 @@ void CExportsView::DoSort(SortInfo const* si) {
case 1: return SortHelper::Sort(exp1.get_ordinal(), exp2.get_ordinal(), asc);
case 2: return SortHelper::Sort(exp1.get_rva(), exp2.get_rva(), asc);
case 3: return SortHelper::Sort(exp1.get_forward_name(), exp2.get_forward_name(), asc);
case 4: return SortHelper::Sort(PEStrings::UndecorateName(exp1.get_func_name().c_str()), PEStrings::UndecorateName(exp2.get_func_name().c_str()), asc);
}
return false;
};
Expand Down Expand Up @@ -91,6 +95,7 @@ LRESULT CExportsView::OnCreate(UINT, WPARAM, LPARAM, BOOL&) {
cm->AddColumn(L"Ordinal", LVCFMT_RIGHT, 70);
cm->AddColumn(L"Address", LVCFMT_RIGHT, 110);
cm->AddColumn(L"Forwarded Name", LVCFMT_LEFT, 350);
cm->AddColumn(L"Undecorated Name", LVCFMT_LEFT, 400);

cm->UpdateColumns();

Expand Down Expand Up @@ -174,7 +179,13 @@ void CExportsView::ApplyFilter(PCWSTR text) {

void CExportsView::BuildItems() {
auto& exports = PE().get_exports();
m_Exports = exports.get_functions();
auto& funcs = exports.get_functions();
m_Exports.reserve(funcs.size());
for (auto& f : funcs) {
ExportItem item(f);
item.UndecoratedName = PEStrings::UndecorateName(f.get_func_name().c_str()).c_str();
m_Exports.push_back(std::move(item));
}
m_List.SetItemCount((int)m_Exports.size());

UpdateStatusText();
Expand Down
6 changes: 5 additions & 1 deletion TotalPE/ExportsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ class CExportsView :
LRESULT OnViewAssembly(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

private:
struct ExportItem : pe_export_entry {
CString UndecoratedName;
};

void ApplyFilter(PCWSTR text);
void BuildItems();
void UpdateStatusText();

CQuickFindEdit m_QuickFind;
CListViewCtrl m_List;
SortedFilteredVector<pe_export_entry> m_Exports;
SortedFilteredVector<ExportItem> m_Exports;
int m_Selected{ -1 };
};

2 changes: 1 addition & 1 deletion TotalPE/ImportsView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ CString CImportsView::GetColumnText(HWND h, int row, int col) const {
switch (col) {
case 0: return fun.get_func_name().c_str();
case 1: return std::to_wstring(fun.get_hint()).c_str();
case 2: return fun.get_func_name().find_first_of("@?") == std::string::npos ? L"" : PEStrings::UndecorateName(CString(fun.get_func_name().c_str())).c_str();
case 2: return PEStrings::UndecorateName(CString(fun.get_func_name().c_str())).c_str();
case 3: return std::to_wstring(fun.get_ordinal()).c_str();
}
}
Expand Down
8 changes: 6 additions & 2 deletions TotalPE/PEStrings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,12 @@ std::wstring PEStrings::PrimaryLanguageToString(WORD l) {

std::wstring PEStrings::UndecorateName(PCWSTR name) {
WCHAR result[512];
::UnDecorateSymbolNameW(name, result, _countof(result), 0);
return result;
return 0 == ::UnDecorateSymbolNameW(name, result, _countof(result), 0) ? L"" : result;
}

std::string PEStrings::UndecorateName(PCSTR name) {
char result[512];
return 0 == ::UnDecorateSymbolName(name, result, _countof(result), 0) ? "" : result;
}

std::wstring PEStrings::VersionFileOSToString(uint32_t type) {
Expand Down
1 change: 1 addition & 0 deletions TotalPE/PEStrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct PEStrings abstract final {
static std::wstring PrimaryLanguageToString(WORD l);
static std::wstring LanguageToString(uint32_t lang);
static std::wstring UndecorateName(PCWSTR name);
static std::string UndecorateName(PCSTR name);
static std::wstring VersionFileOSToString(uint32_t type);
static std::wstring FileTypeToString(uint32_t type);
static std::wstring FileSubTypeToString(uint32_t type, uint32_t subType);
Expand Down

0 comments on commit b4120f4

Please sign in to comment.