From 0f1683170becea3bb4b478a9f9ce508476ce9de2 Mon Sep 17 00:00:00 2001 From: "Mr. eXoDia" Date: Fri, 8 Aug 2014 14:19:32 +0200 Subject: [PATCH 1/2] DBG: fixed a crash with very big commands --- x64_dbg_dbg/x64_dbg.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/x64_dbg_dbg/x64_dbg.cpp b/x64_dbg_dbg/x64_dbg.cpp index b68b0c3c..81bcf508 100644 --- a/x64_dbg_dbg/x64_dbg.cpp +++ b/x64_dbg_dbg/x64_dbg.cpp @@ -213,7 +213,10 @@ static bool cbCommandProvider(char* cmd, int maxlen) msgwait(gMsgStack, &msg); char* newcmd = (char*)msg.param1; if(strlen(newcmd) >= deflen) - newcmd[deflen - 1] = 0; + { + dprintf("command cut at ~%d characters\n", deflen); + newcmd[deflen - 2] = 0; + } strcpy(cmd, newcmd); efree(newcmd, "cbCommandProvider:newcmd"); //free allocated command return true; From 26d33436f5f6a4771d37ac5e7dc63c49cd3320ac Mon Sep 17 00:00:00 2001 From: "Mr. eXoDia" Date: Fri, 8 Aug 2014 15:10:55 +0200 Subject: [PATCH 2/2] GUI: double click on address in hex dump will enable the rva mode (like in the disassembler) --- x64_dbg_gui/Project/Src/BasicView/HexDump.cpp | 5 ++ x64_dbg_gui/Project/Src/BasicView/HexDump.h | 3 + x64_dbg_gui/Project/Src/Gui/CPUDump.cpp | 66 +++++++++++++++++-- x64_dbg_gui/Project/Src/Gui/CPUDump.h | 1 + x64_dbg_gui/Project/Src/Gui/CPUStack.cpp | 66 +++++++++++++++++-- x64_dbg_gui/Project/Src/Gui/CPUStack.h | 2 +- 6 files changed, 134 insertions(+), 9 deletions(-) diff --git a/x64_dbg_gui/Project/Src/BasicView/HexDump.cpp b/x64_dbg_gui/Project/Src/BasicView/HexDump.cpp index 383dc579..b9d263dc 100644 --- a/x64_dbg_gui/Project/Src/BasicView/HexDump.cpp +++ b/x64_dbg_gui/Project/Src/BasicView/HexDump.cpp @@ -21,6 +21,8 @@ HexDump::HexDump(QWidget* parent) : AbstractTableView(parent) textColor = ConfigColor("HexDumpTextColor"); selectionColor = ConfigColor("HexDumpSelectionColor"); + mRvaDisplayEnabled = false; + connect(Bridge::getBridge(), SIGNAL(updateDump()), this, SLOT(reloadData())); connect(Bridge::getBridge(), SIGNAL(dbgStateChanged(DBGSTATE)), this, SLOT(debugStateChanged(DBGSTATE))); } @@ -57,6 +59,9 @@ void HexDump::printDumpAt(int_t parVA, bool select, bool repaint) wRowCount = wSize / wBytePerRowCount; wRowCount += mByteOffset > 0 ? 1 : 0; + if(mRvaDisplayEnabled && mMemPage->getBase() != mRvaDisplayPageBase) + mRvaDisplayEnabled = false; + setRowCount(wRowCount); //set the number of rows mMemPage->setAttributes(wBase, wSize); // Set base and size (Useful when memory page changed) diff --git a/x64_dbg_gui/Project/Src/BasicView/HexDump.h b/x64_dbg_gui/Project/Src/BasicView/HexDump.h index 1b2b258a..894956e4 100644 --- a/x64_dbg_gui/Project/Src/BasicView/HexDump.h +++ b/x64_dbg_gui/Project/Src/BasicView/HexDump.h @@ -159,6 +159,9 @@ protected: int mByteOffset; QList mDescriptor; int mForceColumn; + bool mRvaDisplayEnabled; + uint_t mRvaDisplayBase; + int_t mRvaDisplayPageBase; }; #endif // _HEXDUMP_H diff --git a/x64_dbg_gui/Project/Src/Gui/CPUDump.cpp b/x64_dbg_gui/Project/Src/Gui/CPUDump.cpp index fc509d3c..bcfc02db 100644 --- a/x64_dbg_gui/Project/Src/Gui/CPUDump.cpp +++ b/x64_dbg_gui/Project/Src/Gui/CPUDump.cpp @@ -350,12 +350,40 @@ QString CPUDump::paintContent(QPainter* painter, int_t rowBase, int rowOffset, i { char label[MAX_LABEL_SIZE] = ""; QString addrText = ""; - int_t curAddr = rvaToVa((rowBase + rowOffset) * getBytePerRowCount() - mByteOffset); - addrText = QString("%1").arg(curAddr, sizeof(int_t) * 2, 16, QChar('0')).toUpper(); - if(DbgGetLabelAt(curAddr, SEG_DEFAULT, label)) //has label + int_t cur_addr = rvaToVa((rowBase + rowOffset) * getBytePerRowCount() - mByteOffset); + if(mRvaDisplayEnabled) //RVA display + { + int_t rva = cur_addr - mRvaDisplayBase; + if(rva == 0) + { +#ifdef _WIN64 + addrText = "$ ==> "; +#else + addrText = "$ ==> "; +#endif //_WIN64 + } + else if(rva > 0) + { +#ifdef _WIN64 + addrText = "$+" + QString("%1").arg(rva, -15, 16, QChar(' ')).toUpper(); +#else + addrText = "$+" + QString("%1").arg(rva, -7, 16, QChar(' ')).toUpper(); +#endif //_WIN64 + } + else if(rva < 0) + { +#ifdef _WIN64 + addrText = "$-" + QString("%1").arg(-rva, -15, 16, QChar(' ')).toUpper(); +#else + addrText = "$-" + QString("%1").arg(-rva, -7, 16, QChar(' ')).toUpper(); +#endif //_WIN64 + } + } + addrText += QString("%1").arg(cur_addr, sizeof(int_t) * 2, 16, QChar('0')).toUpper(); + if(DbgGetLabelAt(cur_addr, SEG_DEFAULT, label)) //has label { char module[MAX_MODULE_SIZE] = ""; - if(DbgGetModuleAt(curAddr, module) && !QString(label).startsWith("JMP.&")) + if(DbgGetModuleAt(cur_addr, module) && !QString(label).startsWith("JMP.&")) addrText += " <" + QString(module) + "." + QString(label) + ">"; else addrText += " <" + QString(label) + ">"; @@ -451,6 +479,36 @@ void CPUDump::contextMenuEvent(QContextMenuEvent* event) wMenu->exec(event->globalPos()); //execute context menu } +void CPUDump::mouseDoubleClickEvent(QMouseEvent* event) +{ + if(event->button() != Qt::LeftButton) + return; + switch(getColumnIndexFromX(event->x())) + { + case 0: //address + { + //very ugly way to calculate the base of the current row (no clue why it works) + int_t deltaRowBase = getInitialSelection() % getBytePerRowCount() + mByteOffset; + if(deltaRowBase >= getBytePerRowCount()) + deltaRowBase -= getBytePerRowCount(); + int_t mSelectedVa = rvaToVa(getInitialSelection() - deltaRowBase); + if(mRvaDisplayEnabled && mSelectedVa == mRvaDisplayBase) + mRvaDisplayEnabled = false; + else + { + mRvaDisplayEnabled = true; + mRvaDisplayBase = mSelectedVa; + mRvaDisplayPageBase = mMemPage->getBase(); + } + reloadData(); + } + break; + + default: + break; + } +} + void CPUDump::setLabelSlot() { if(!DbgIsDebugging()) diff --git a/x64_dbg_gui/Project/Src/Gui/CPUDump.h b/x64_dbg_gui/Project/Src/Gui/CPUDump.h index 634e09a9..fe8c6bb0 100644 --- a/x64_dbg_gui/Project/Src/Gui/CPUDump.h +++ b/x64_dbg_gui/Project/Src/Gui/CPUDump.h @@ -20,6 +20,7 @@ public: QString paintContent(QPainter* painter, int_t rowBase, int rowOffset, int col, int x, int y, int w, int h); void setupContextMenu(); void contextMenuEvent(QContextMenuEvent* event); + void mouseDoubleClickEvent(QMouseEvent* event); signals: void displayReferencesWidget(); diff --git a/x64_dbg_gui/Project/Src/Gui/CPUStack.cpp b/x64_dbg_gui/Project/Src/Gui/CPUStack.cpp index f0690946..141fb7a8 100644 --- a/x64_dbg_gui/Project/Src/Gui/CPUStack.cpp +++ b/x64_dbg_gui/Project/Src/Gui/CPUStack.cpp @@ -184,12 +184,40 @@ QString CPUStack::paintContent(QPainter* painter, int_t rowBase, int rowOffset, { char label[MAX_LABEL_SIZE] = ""; QString addrText = ""; - int_t curAddr = rvaToVa((rowBase + rowOffset) * getBytePerRowCount() - mByteOffset); - addrText = QString("%1").arg(curAddr, sizeof(int_t) * 2, 16, QChar('0')).toUpper(); - if(DbgGetLabelAt(curAddr, SEG_DEFAULT, label)) //has label + int_t cur_addr = rvaToVa((rowBase + rowOffset) * getBytePerRowCount() - mByteOffset); + if(mRvaDisplayEnabled) //RVA display + { + int_t rva = cur_addr - mRvaDisplayBase; + if(rva == 0) + { +#ifdef _WIN64 + addrText = "$ ==> "; +#else + addrText = "$ ==> "; +#endif //_WIN64 + } + else if(rva > 0) + { +#ifdef _WIN64 + addrText = "$+" + QString("%1").arg(rva, -15, 16, QChar(' ')).toUpper(); +#else + addrText = "$+" + QString("%1").arg(rva, -7, 16, QChar(' ')).toUpper(); +#endif //_WIN64 + } + else if(rva < 0) + { +#ifdef _WIN64 + addrText = "$-" + QString("%1").arg(-rva, -15, 16, QChar(' ')).toUpper(); +#else + addrText = "$-" + QString("%1").arg(-rva, -7, 16, QChar(' ')).toUpper(); +#endif //_WIN64 + } + } + addrText += QString("%1").arg(cur_addr, sizeof(int_t) * 2, 16, QChar('0')).toUpper(); + if(DbgGetLabelAt(cur_addr, SEG_DEFAULT, label)) //has label { char module[MAX_MODULE_SIZE] = ""; - if(DbgGetModuleAt(curAddr, module) && !QString(label).startsWith("JMP.&")) + if(DbgGetModuleAt(cur_addr, module) && !QString(label).startsWith("JMP.&")) addrText += " <" + QString(module) + "." + QString(label) + ">"; else addrText += " <" + QString(label) + ">"; @@ -300,6 +328,36 @@ void CPUStack::contextMenuEvent(QContextMenuEvent* event) wMenu->exec(event->globalPos()); } +void CPUStack::mouseDoubleClickEvent(QMouseEvent* event) +{ + if(event->button() != Qt::LeftButton) + return; + switch(getColumnIndexFromX(event->x())) + { + case 0: //address + { + //very ugly way to calculate the base of the current row (no clue why it works) + int_t deltaRowBase = getInitialSelection() % getBytePerRowCount() + mByteOffset; + if(deltaRowBase >= getBytePerRowCount()) + deltaRowBase -= getBytePerRowCount(); + int_t mSelectedVa = rvaToVa(getInitialSelection() - deltaRowBase); + if(mRvaDisplayEnabled && mSelectedVa == mRvaDisplayBase) + mRvaDisplayEnabled = false; + else + { + mRvaDisplayEnabled = true; + mRvaDisplayBase = mSelectedVa; + mRvaDisplayPageBase = mMemPage->getBase(); + } + reloadData(); + } + break; + + default: + break; + } +} + void CPUStack::stackDumpAt(uint_t addr, uint_t csp) { mCsp = csp; diff --git a/x64_dbg_gui/Project/Src/Gui/CPUStack.h b/x64_dbg_gui/Project/Src/Gui/CPUStack.h index 74be37c8..fca7de28 100644 --- a/x64_dbg_gui/Project/Src/Gui/CPUStack.h +++ b/x64_dbg_gui/Project/Src/Gui/CPUStack.h @@ -19,7 +19,7 @@ public: void fontsUpdated(); QString paintContent(QPainter* painter, int_t rowBase, int rowOffset, int col, int x, int y, int w, int h); void contextMenuEvent(QContextMenuEvent* event); - + void mouseDoubleClickEvent(QMouseEvent* event); void setupContextMenu(); signals: