GUI: highlight relevant registers of the current instruction in the RegistersView
This commit is contained in:
parent
65ddc96542
commit
15f447cf94
|
@ -232,6 +232,38 @@ Instruction_t QBeaEngine::DisassembleAt(byte_t* data, duint size, duint origBase
|
|||
wInst.branchType = branchType;
|
||||
wInst.tokens = cap;
|
||||
|
||||
if(success)
|
||||
{
|
||||
cp.RegInfo(reginfo);
|
||||
cp.FlagInfo(flaginfo);
|
||||
|
||||
auto flaginfo2reginfo = [](uint8_t info)
|
||||
{
|
||||
auto result = 0;
|
||||
#define checkFlag(test, reg) result |= (info & test) == test ? reg : 0
|
||||
checkFlag(Capstone::Modify, Capstone::Write);
|
||||
checkFlag(Capstone::Prior, Capstone::None);
|
||||
checkFlag(Capstone::Reset, Capstone::Write);
|
||||
checkFlag(Capstone::Set, Capstone::Write);
|
||||
checkFlag(Capstone::Test, Capstone::Read);
|
||||
checkFlag(Capstone::Undefined, Capstone::None);
|
||||
#undef checkFlag
|
||||
return result;
|
||||
};
|
||||
|
||||
for(uint8_t i = Capstone::FLAG_INVALID; i < Capstone::FLAG_ENDING; i++)
|
||||
if(flaginfo[i])
|
||||
{
|
||||
reginfo[X86_REG_EFLAGS] = Capstone::None;
|
||||
wInst.regsReferenced.push_back({cp.FlagName(Capstone::Flag(i)), flaginfo2reginfo(flaginfo[i])});
|
||||
}
|
||||
|
||||
reginfo[ArchValue(X86_REG_EIP, X86_REG_RIP)] = Capstone::None;
|
||||
for(uint8_t i = X86_REG_INVALID; i < X86_REG_ENDING; i++)
|
||||
if(reginfo[i])
|
||||
wInst.regsReferenced.push_back({cp.RegName(x86_reg(i)), reginfo[i]});
|
||||
}
|
||||
|
||||
return wInst;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define QBEAENGINE_H
|
||||
|
||||
#include <QString>
|
||||
#include <vector>
|
||||
#include "capstone_gui.h"
|
||||
|
||||
class EncodeMap;
|
||||
|
@ -29,10 +30,10 @@ struct Instruction_t
|
|||
QByteArray dump;
|
||||
duint rva;
|
||||
int length;
|
||||
//DISASM disasm;
|
||||
duint branchDestination;
|
||||
BranchType branchType;
|
||||
CapstoneTokenizer::InstructionToken tokens;
|
||||
std::vector<std::pair<const char*, uint8_t>> regsReferenced;
|
||||
};
|
||||
|
||||
class QBeaEngine
|
||||
|
@ -66,6 +67,8 @@ private:
|
|||
bool _bLongDataInst;
|
||||
EncodeMap* mEncodeMap;
|
||||
CodeFoldingHelper* mCodeFoldingManager;
|
||||
uint8_t reginfo[X86_REG_ENDING];
|
||||
uint8_t flaginfo[Capstone::FLAG_ENDING];
|
||||
};
|
||||
|
||||
#endif // QBEAENGINE_H
|
||||
|
|
|
@ -467,6 +467,9 @@ void AppearanceDialog::colorInfoListInit()
|
|||
colorInfoListAppend(tr("Register Names"), "RegistersLabelColor", "");
|
||||
colorInfoListAppend(tr("Argument Register Names"), "RegistersArgumentLabelColor", "");
|
||||
colorInfoListAppend(tr("Extra Information"), "RegistersExtraInfoColor", "");
|
||||
colorInfoListAppend(tr("Highlight Read"), "RegistersHighlightReadColor", "");
|
||||
colorInfoListAppend(tr("Highlight Write"), "RegistersHighlightWriteColor", "");
|
||||
colorInfoListAppend(tr("Highlight Read+Write"), "RegistersHighlightReadWriteColor", "");
|
||||
|
||||
colorInfoListAppend(tr("Instructions:"), "", "");
|
||||
colorInfoListAppend(tr("Text"), "InstructionUncategorizedColor", "InstructionUncategorizedBackgroundColor");
|
||||
|
|
|
@ -1340,6 +1340,7 @@ RegistersView::RegistersView(CPUWidget* parent, CPUMultiDump* multiDump) : QScro
|
|||
connect(Bridge::getBridge(), SIGNAL(updateRegisters()), this, SLOT(updateRegistersSlot()));
|
||||
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(displayCustomContextMenuSlot(QPoint)));
|
||||
connect(Bridge::getBridge(), SIGNAL(dbgStateChanged(DBGSTATE)), this, SLOT(debugStateChangedSlot(DBGSTATE)));
|
||||
connect(parent->getDisasmWidget(), SIGNAL(selectionChanged(dsint)), this, SLOT(disasmSelectionChangedSlot(dsint)));
|
||||
// self communication for repainting (maybe some other widgets needs this information, too)
|
||||
connect(this, SIGNAL(refresh()), this, SLOT(reload()));
|
||||
// context menu actions
|
||||
|
@ -2296,7 +2297,44 @@ void RegistersView::drawRegister(QPainter* p, REGISTER_NAME reg, char* value)
|
|||
}
|
||||
#endif //_WIN64
|
||||
|
||||
p->drawText(x, y, width, mRowHeight, Qt::AlignVCenter, mRegisterMapping[reg]);
|
||||
//draw the register name
|
||||
auto regName = mRegisterMapping[reg];
|
||||
p->drawText(x, y, width, mRowHeight, Qt::AlignVCenter, regName);
|
||||
|
||||
//highlight the register based on access
|
||||
uint8_t highlight = 0;
|
||||
for(const auto & reg : mHighlightRegs)
|
||||
{
|
||||
if(!CapstoneTokenizer::tokenTextPoolEquals(regName, reg.first))
|
||||
continue;
|
||||
highlight = reg.second;
|
||||
break;
|
||||
}
|
||||
if(highlight)
|
||||
{
|
||||
const char* name = "";
|
||||
switch(highlight & ~(Capstone::Implicit | Capstone::Explicit))
|
||||
{
|
||||
case Capstone::Read:
|
||||
name = "RegistersHighlightReadColor";
|
||||
break;
|
||||
case Capstone::Write:
|
||||
name = "RegistersHighlightWriteColor";
|
||||
break;
|
||||
case Capstone::Read | Capstone::Write:
|
||||
name = "RegistersHighlightReadWriteColor";
|
||||
break;
|
||||
}
|
||||
auto highlightColor = ConfigColor(name);
|
||||
if(highlightColor.alpha())
|
||||
{
|
||||
QPen highlightPen(highlightColor);
|
||||
highlightPen.setWidth(2);
|
||||
p->setPen(highlightPen);
|
||||
p->drawLine(x + 1, y + mRowHeight - 1, x + mCharWidth * regName.length() - 1, y + mRowHeight - 1);
|
||||
}
|
||||
}
|
||||
|
||||
x += (mRegisterPlaces[reg].labelwidth) * mCharWidth;
|
||||
//p->drawText(offset,mRowHeight*(mRegisterPlaces[reg].line+1),mRegisterMapping[reg]);
|
||||
|
||||
|
@ -3605,3 +3643,9 @@ void RegistersView::onSIMDHQWord()
|
|||
wSIMDRegDispMode = SIMD_REG_DISP_QWORD_HEX;
|
||||
emit refresh();
|
||||
}
|
||||
|
||||
void RegistersView::disasmSelectionChangedSlot(dsint va)
|
||||
{
|
||||
mHighlightRegs = mParent->getDisasmWidget()->DisassembleAt(va - mParent->getDisasmWidget()->getBase()).regsReferenced;
|
||||
emit refresh();
|
||||
}
|
||||
|
|
|
@ -204,6 +204,7 @@ protected slots:
|
|||
//unsigned int GetStatusWordTOPValueFromString(const char* string);
|
||||
QString GetStatusWordTOPStateString(unsigned short state);
|
||||
void appendRegister(QString & text, REGISTER_NAME reg, const char* name64, const char* name32);
|
||||
void disasmSelectionChangedSlot(dsint va);
|
||||
private:
|
||||
QPushButton* mChangeViewButton;
|
||||
CPUWidget* mParent;
|
||||
|
@ -293,6 +294,7 @@ private:
|
|||
QAction* SIMDUQWord;
|
||||
QAction* SIMDHQWord;
|
||||
dsint mCip;
|
||||
std::vector<std::pair<const char*, uint8_t>> mHighlightRegs;
|
||||
};
|
||||
|
||||
#endif // REGISTERSVIEW_H
|
||||
|
|
|
@ -88,6 +88,9 @@ Configuration::Configuration() : QObject(), noMoreMsgbox(false)
|
|||
defaultColors.insert("RegistersLabelColor", QColor("#000000"));
|
||||
defaultColors.insert("RegistersArgumentLabelColor", Qt::darkGreen);
|
||||
defaultColors.insert("RegistersExtraInfoColor", QColor("#000000"));
|
||||
defaultColors.insert("RegistersHighlightReadColor", QColor("#00A000"));
|
||||
defaultColors.insert("RegistersHighlightWriteColor", QColor("#B00000"));
|
||||
defaultColors.insert("RegistersHighlightReadWriteColor", QColor("#808000"));
|
||||
|
||||
defaultColors.insert("InstructionHighlightColor", QColor("#FF0000"));
|
||||
defaultColors.insert("InstructionCommaColor", QColor("#000000"));
|
||||
|
|
Loading…
Reference in New Issue