From 0065f204a39bba53d0ac3615975399859bff8aaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Farag=C3=B3?= Date: Mon, 29 Oct 2018 03:33:18 +0100 Subject: [PATCH] Add DLL ordinal to symbol table and fix symbol table comparator --- src/bridge/bridgemain.h | 1 + src/dbg/module.cpp | 2 ++ src/dbg/symbolsourcebase.h | 1 + src/gui/Src/Gui/ZehSymbolTable.cpp | 35 ++++++++++++++++++++--------- src/gui/Src/Gui/ZehSymbolTable.h | 1 + src/gui/Src/Utils/Configuration.cpp | 2 +- 6 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/bridge/bridgemain.h b/src/bridge/bridgemain.h index b2ca580b..fb10dfa1 100644 --- a/src/bridge/bridgemain.h +++ b/src/bridge/bridgemain.h @@ -598,6 +598,7 @@ typedef struct SYMBOLINFO_ SYMBOLTYPE type; bool freeDecorated; bool freeUndecorated; + DWORD ordinal; } SYMBOLINFO; typedef struct diff --git a/src/dbg/module.cpp b/src/dbg/module.cpp index 03c4f8a3..3b218b93 100644 --- a/src/dbg/module.cpp +++ b/src/dbg/module.cpp @@ -1195,6 +1195,7 @@ void MODIMPORT::convertToGuiSymbol(duint base, SYMBOLINFO* info) const info->decoratedSymbol = (char*)name.c_str(); info->undecoratedSymbol = (char*)undecoratedName.c_str(); info->freeDecorated = info->freeUndecorated = false; + info->ordinal = 0; } void MODEXPORT::convertToGuiSymbol(duint base, SYMBOLINFO* info) const @@ -1204,4 +1205,5 @@ void MODEXPORT::convertToGuiSymbol(duint base, SYMBOLINFO* info) const info->decoratedSymbol = (char*)name.c_str(); info->undecoratedSymbol = (char*)undecoratedName.c_str(); info->freeDecorated = info->freeUndecorated = false; + info->ordinal = ordinal; } diff --git a/src/dbg/symbolsourcebase.h b/src/dbg/symbolsourcebase.h index 2ac01659..53255aee 100644 --- a/src/dbg/symbolsourcebase.h +++ b/src/dbg/symbolsourcebase.h @@ -28,6 +28,7 @@ struct SymbolInfo : SymbolInfoGui info->undecoratedSymbol = (char*)this->undecoratedName.c_str(); info->type = sym_symbol; info->freeDecorated = info->freeUndecorated = false; + info->ordinal = 0; } }; diff --git a/src/gui/Src/Gui/ZehSymbolTable.cpp b/src/gui/Src/Gui/ZehSymbolTable.cpp index 85a6b3f0..25a6b517 100644 --- a/src/gui/Src/Gui/ZehSymbolTable.cpp +++ b/src/gui/Src/Gui/ZehSymbolTable.cpp @@ -33,6 +33,7 @@ ZehSymbolTable::ZehSymbolTable(QWidget* parent) setAddressColumn(0); addColumnAt(charwidth * 2 * sizeof(dsint) + 8, tr("Address"), true); addColumnAt(charwidth * 6 + 8, tr("Type"), true); + addColumnAt(charwidth * 7 + 8, tr("Ordinal"), true); addColumnAt(charwidth * 80, tr("Symbol"), true); addColumnAt(2000, tr("Symbol (undecorated)"), true); loadColumnFromConfig("Symbol"); @@ -67,6 +68,11 @@ QString ZehSymbolTable::getCellContent(int r, int c) default: __debugbreak(); } + case ColOrdinal: + if(info->type == sym_export) + return QString::number(info->ordinal); + else + return QString(); case ColDecorated: return info->decoratedSymbol; case ColUndecorated: @@ -85,28 +91,35 @@ bool ZehSymbolTable::isValidIndex(int r, int c) void ZehSymbolTable::sortRows(int column, bool ascending) { QMutexLocker lock(&mMutex); - //TODO: invalid compare when !ascending std::stable_sort(mData.begin(), mData.end(), [column, ascending](const SYMBOLPTR & a, const SYMBOLPTR & b) { SymbolInfoWrapper ainfo, binfo; DbgGetSymbolInfo(&a, &ainfo); DbgGetSymbolInfo(&b, &binfo); - bool less; switch(column) { case ColAddr: - less = ainfo->addr < binfo->addr; - break; + return ascending ? ainfo->addr < binfo->addr : ainfo->addr > binfo->addr; case ColType: - less = ainfo->type < binfo->type; - break; + return ascending ? ainfo->type < binfo->type : ainfo->type > binfo->type; + case ColOrdinal: + // If we are sorting by ordinal make the exports the first entries + if(ainfo->type == sym_export && binfo->type != sym_export) + return ascending; + else if(ainfo->type != sym_export && binfo->type == sym_export) + return !ascending; + else + return ascending ? ainfo->ordinal < binfo->ordinal : ainfo->ordinal > binfo->ordinal; case ColDecorated: - less = strcmp(ainfo->decoratedSymbol, binfo->decoratedSymbol) < 0; - break; + { + int result = strcmp(ainfo->decoratedSymbol, binfo->decoratedSymbol); + return ascending ? result < 0 : result > 0; + } case ColUndecorated: - less = strcmp(ainfo->undecoratedSymbol, binfo->undecoratedSymbol) < 0; - break; + { + int result = strcmp(ainfo->undecoratedSymbol, binfo->undecoratedSymbol); + return ascending ? result < 0 : result > 0; + } } - return ascending ? less : !less; }); } diff --git a/src/gui/Src/Gui/ZehSymbolTable.h b/src/gui/Src/Gui/ZehSymbolTable.h index 1db629fd..6e067e5c 100644 --- a/src/gui/Src/Gui/ZehSymbolTable.h +++ b/src/gui/Src/Gui/ZehSymbolTable.h @@ -31,6 +31,7 @@ private: { ColAddr, ColType, + ColOrdinal, ColDecorated, ColUndecorated }; diff --git a/src/gui/Src/Utils/Configuration.cpp b/src/gui/Src/Utils/Configuration.cpp index 3acb624d..99112013 100644 --- a/src/gui/Src/Utils/Configuration.cpp +++ b/src/gui/Src/Utils/Configuration.cpp @@ -313,7 +313,7 @@ Configuration::Configuration() : QObject(), noMoreMsgbox(false) AbstractTableView::setupColumnConfigDefaultValue(guiUint, "Privilege", 2); AbstractTableView::setupColumnConfigDefaultValue(guiUint, "LocalVarsView", 3); AbstractTableView::setupColumnConfigDefaultValue(guiUint, "Module", 4); - AbstractTableView::setupColumnConfigDefaultValue(guiUint, "Symbol", 4); + AbstractTableView::setupColumnConfigDefaultValue(guiUint, "Symbol", 5); guiUint.insert("SIMDRegistersDisplayMode", 0); addWindowPosConfig(guiUint, "AssembleDialog"); addWindowPosConfig(guiUint, "AttachDialog");