GUI: graph improvements
This commit is contained in:
parent
d5a621b20c
commit
8cd170dd5a
|
|
@ -181,7 +181,6 @@ ulong QBeaEngine::DisassembleNext(byte_t* data, duint base, duint size, duint ip
|
|||
*
|
||||
* @return Return the disassembled instruction
|
||||
*/
|
||||
|
||||
Instruction_t QBeaEngine::DisassembleAt(byte_t* data, duint size, duint origBase, duint origInstRVA)
|
||||
{
|
||||
ENCODETYPE type = mEncodeMap->getDataType(origBase + origInstRVA);
|
||||
|
|
@ -233,7 +232,6 @@ Instruction_t QBeaEngine::DisassembleAt(byte_t* data, duint size, duint origBase
|
|||
return wInst;
|
||||
}
|
||||
|
||||
|
||||
Instruction_t QBeaEngine::DecodeDataAt(byte_t* data, duint size, duint origBase, duint origInstRVA, ENCODETYPE type)
|
||||
{
|
||||
//tokenize
|
||||
|
|
@ -287,8 +285,6 @@ void QBeaEngine::UpdateDataInstructionMap()
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void QBeaEngine::setCodeFoldingManager(CodeFoldingHelper* CodeFoldingManager)
|
||||
{
|
||||
mCodeFoldingManager = CodeFoldingManager;
|
||||
|
|
|
|||
|
|
@ -163,6 +163,7 @@ void CapstoneTokenizer::UpdateConfig()
|
|||
ConfigBool("Disassembler", "TabbedMnemonic"),
|
||||
ConfigBool("Disassembler", "ArgumentSpaces"),
|
||||
ConfigBool("Disassembler", "MemorySpaces"));
|
||||
_maxModuleLength = (int)ConfigUint("Disassembler", "MaxModuleSize");
|
||||
UpdateStringPool();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,9 @@
|
|||
|
||||
DisassemblerGraphView::DisassemblerGraphView(QWidget* parent)
|
||||
: QAbstractScrollArea(parent),
|
||||
mFontMetrics(nullptr)
|
||||
mFontMetrics(nullptr),
|
||||
currentGraph(duint(0)),
|
||||
disasm(ConfigUint("Disassembler", "MaxModuleSize"))
|
||||
{
|
||||
this->status = "Loading...";
|
||||
|
||||
|
|
@ -60,6 +62,7 @@ DisassemblerGraphView::DisassemblerGraphView(QWidget* parent)
|
|||
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));
|
||||
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdatedSlot()));
|
||||
connect(Config(), SIGNAL(shortcutsUpdated()), this, SLOT(shortcutsUpdatedSlot()));
|
||||
connect(Config(), SIGNAL(tokenizerConfigUpdated()), this, SLOT(tokenizerConfigUpdatedSlot()));
|
||||
|
||||
colorsUpdatedSlot();
|
||||
}
|
||||
|
|
@ -581,8 +584,9 @@ void DisassemblerGraphView::mouseReleaseEvent(QMouseEvent* event)
|
|||
|
||||
void DisassemblerGraphView::mouseDoubleClickEvent(QMouseEvent* event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
Token token;
|
||||
duint instr = this->getInstrForMouseEvent(event);
|
||||
navigate(DbgGetBranchDestination(instr));
|
||||
/*Token token;
|
||||
if(this->getTokenForMouseEvent(event, token))
|
||||
{
|
||||
if(!this->analysis.functions.count(token.addr))
|
||||
|
|
@ -599,7 +603,7 @@ void DisassemblerGraphView::mouseDoubleClickEvent(QMouseEvent* event)
|
|||
this->highlight_token = nullptr;
|
||||
this->viewport()->update();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
void DisassemblerGraphView::prepareGraphNode(DisassemblerBlock & block)
|
||||
|
|
@ -1261,21 +1265,24 @@ void DisassemblerGraphView::fontChanged()
|
|||
}
|
||||
}
|
||||
|
||||
void DisassemblerGraphView::loadGraphSlot(BridgeCFGraphList* graphList, duint addr)
|
||||
void DisassemblerGraphView::tokenizerConfigUpdatedSlot()
|
||||
{
|
||||
disasm.UpdateConfig();
|
||||
}
|
||||
|
||||
void DisassemblerGraphView::loadCurrentGraph()
|
||||
{
|
||||
BridgeCFGraph graph(graphList);
|
||||
Analysis anal;
|
||||
QBeaEngine disasm(int(ConfigUint("Disassembler", "MaxModuleSize")));
|
||||
anal.update_id = this->update_id + 1;
|
||||
anal.entry = graph.entryPoint;
|
||||
anal.entry = currentGraph.entryPoint;
|
||||
anal.ready = true;
|
||||
{
|
||||
Function func;
|
||||
func.entry = graph.entryPoint;
|
||||
func.entry = currentGraph.entryPoint;
|
||||
func.ready = true;
|
||||
func.update_id = anal.update_id;
|
||||
{
|
||||
for(const auto & nodeIt : graph.nodes)
|
||||
for(const auto & nodeIt : currentGraph.nodes)
|
||||
{
|
||||
const BridgeCFNode & node = nodeIt.second;
|
||||
Block block;
|
||||
|
|
@ -1284,7 +1291,7 @@ void DisassemblerGraphView::loadGraphSlot(BridgeCFGraphList* graphList, duint ad
|
|||
block.false_path = node.brfalse;
|
||||
block.true_path = node.brtrue;
|
||||
block.terminal = node.terminal;
|
||||
block.header_text = Text(ToPtrString(block.entry), Qt::red);
|
||||
block.header_text = Text(getSymbolicName(block.entry), mLabelColor, mLabelBackgroundColor);
|
||||
{
|
||||
Instr instr;
|
||||
unsigned char data[MAX_DISASM_BUFFER];
|
||||
|
|
@ -1301,7 +1308,45 @@ void DisassemblerGraphView::loadGraphSlot(BridgeCFGraphList* graphList, duint ad
|
|||
instr.opcode.resize(size);
|
||||
for(int j = 0; j < size; j++)
|
||||
instr.opcode[j] = data[j];
|
||||
|
||||
QString comment;
|
||||
bool autoComment = false;
|
||||
RichTextPainter::CustomRichText_t commentText;
|
||||
commentText.highlight = false;
|
||||
char label[MAX_LABEL_SIZE] = "";
|
||||
if(GetCommentFormat(addr, comment, &autoComment))
|
||||
{
|
||||
if(autoComment)
|
||||
{
|
||||
commentText.textColor = mAutoCommentColor;
|
||||
commentText.textBackground = mAutoCommentBackgroundColor;
|
||||
}
|
||||
else //user comment
|
||||
{
|
||||
commentText.textColor = mCommentColor;
|
||||
commentText.textBackground = mCommentBackgroundColor;
|
||||
}
|
||||
commentText.text = QString("; ") + comment;
|
||||
//add to text
|
||||
}
|
||||
else if(DbgGetLabelAt(addr, SEG_DEFAULT, label) && addr != block.entry) // label but no comment
|
||||
{
|
||||
commentText.textColor = mLabelColor;
|
||||
commentText.textBackground = mLabelBackgroundColor;
|
||||
commentText.text = QString("; ") + label;
|
||||
}
|
||||
commentText.flags = commentText.textBackground.alpha() ? RichTextPainter::FlagAll : RichTextPainter::FlagColor;
|
||||
if(commentText.text.length())
|
||||
{
|
||||
RichTextPainter::CustomRichText_t spaceText;
|
||||
spaceText.highlight = false;
|
||||
spaceText.flags = RichTextPainter::FlagNone;
|
||||
spaceText.text = " ";
|
||||
richText.push_back(spaceText);
|
||||
richText.push_back(commentText);
|
||||
}
|
||||
instr.text = Text(richText);
|
||||
|
||||
block.instrs.push_back(instr);
|
||||
i += size;
|
||||
}
|
||||
|
|
@ -1313,6 +1358,31 @@ void DisassemblerGraphView::loadGraphSlot(BridgeCFGraphList* graphList, duint ad
|
|||
}
|
||||
this->analysis = anal;
|
||||
this->function = this->analysis.entry;
|
||||
}
|
||||
|
||||
QString DisassemblerGraphView::getSymbolicName(duint addr)
|
||||
{
|
||||
char labelText[MAX_LABEL_SIZE] = "";
|
||||
char moduleText[MAX_MODULE_SIZE] = "";
|
||||
bool bHasLabel = DbgGetLabelAt(addr, SEG_DEFAULT, labelText);
|
||||
bool bHasModule = (DbgGetModuleAt(addr, moduleText) && !QString(labelText).startsWith("JMP.&"));
|
||||
QString addrText = ToPtrString(addr);
|
||||
QString finalText;
|
||||
if(bHasLabel && bHasModule) //<module.label>
|
||||
finalText = QString("%1 <%2.%3>").arg(addrText).arg(moduleText).arg(labelText);
|
||||
else if(bHasModule) //module.addr
|
||||
finalText = QString("%1.%2").arg(moduleText).arg(addrText);
|
||||
else if(bHasLabel) //<label>
|
||||
finalText = QString("<%1>").arg(labelText);
|
||||
else
|
||||
finalText = addrText;
|
||||
return finalText;
|
||||
}
|
||||
|
||||
void DisassemblerGraphView::loadGraphSlot(BridgeCFGraphList* graphList, duint addr)
|
||||
{
|
||||
currentGraph = BridgeCFGraph(graphList);
|
||||
loadCurrentGraph();
|
||||
this->cur_instr = addr ? addr : this->function;
|
||||
Bridge::getBridge()->setResult();
|
||||
}
|
||||
|
|
@ -1356,6 +1426,12 @@ void DisassemblerGraphView::colorsUpdatedSlot()
|
|||
disassemblyTracedColor = ConfigColor("DisassemblyTracedBackgroundColor");
|
||||
auto a = disassemblySelectionColor, b = disassemblyTracedColor;
|
||||
disassemblyTracedSelectionColor = QColor((a.red() + b.red()) / 2, (a.green() + b.green()) / 2, (a.blue() + b.blue()) / 2);
|
||||
mAutoCommentColor = ConfigColor("DisassemblyAutoCommentColor");
|
||||
mAutoCommentBackgroundColor = ConfigColor("DisassemblyAutoCommentBackgroundColor");
|
||||
mCommentColor = ConfigColor("DisassemblyCommentColor");
|
||||
mCommentBackgroundColor = ConfigColor("DisassemblyCommentBackgroundColor");
|
||||
mLabelColor = ConfigColor("DisassemblyLabelColor");
|
||||
mLabelBackgroundColor = ConfigColor("DisassemblyLabelBackgroundColor");
|
||||
|
||||
jmpColor = ConfigColor("GraphJmpColor");
|
||||
brtrueColor = ConfigColor("GraphBrtrueColor");
|
||||
|
|
@ -1366,6 +1442,7 @@ void DisassemblerGraphView::colorsUpdatedSlot()
|
|||
backgroundColor = disassemblySelectionColor;
|
||||
|
||||
fontChanged();
|
||||
loadCurrentGraph();
|
||||
}
|
||||
|
||||
void DisassemblerGraphView::fontsUpdatedSlot()
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
#include <QMutex>
|
||||
#include "Bridge.h"
|
||||
#include "RichTextPainter.h"
|
||||
#include "QBeaEngine.h"
|
||||
|
||||
class MenuBuilder;
|
||||
class CachedFontMetrics;
|
||||
|
|
@ -94,14 +95,15 @@ public:
|
|||
|
||||
Text() {}
|
||||
|
||||
Text(const QString & text, QColor color)
|
||||
Text(const QString & text, QColor color, QColor background)
|
||||
{
|
||||
RichTextPainter::List richText;
|
||||
RichTextPainter::CustomRichText_t rt;
|
||||
rt.highlight = false;
|
||||
rt.flags = RichTextPainter::FlagColor;
|
||||
rt.text = text;
|
||||
rt.textColor = color;
|
||||
rt.textBackground = background;
|
||||
rt.flags = rt.textBackground.alpha() ? RichTextPainter::FlagAll : RichTextPainter::FlagColor;
|
||||
richText.push_back(rt);
|
||||
lines.push_back(richText);
|
||||
}
|
||||
|
|
@ -247,6 +249,8 @@ public:
|
|||
void show_cur_instr();
|
||||
bool navigate(duint addr);
|
||||
void fontChanged();
|
||||
void loadCurrentGraph();
|
||||
QString getSymbolicName(duint addr);
|
||||
|
||||
public slots:
|
||||
void updateTimerEvent();
|
||||
|
|
@ -259,6 +263,7 @@ public slots:
|
|||
void shortcutsUpdatedSlot();
|
||||
void toggleOverviewSlot();
|
||||
void selectionGetSlot(SELECTIONDATA* selection);
|
||||
void tokenizerConfigUpdatedSlot();
|
||||
|
||||
private:
|
||||
QString status;
|
||||
|
|
@ -303,6 +308,15 @@ private:
|
|||
QColor brfalseColor;
|
||||
QColor retShadowColor;
|
||||
QColor backgroundColor;
|
||||
QColor mAutoCommentColor;
|
||||
QColor mAutoCommentBackgroundColor;
|
||||
QColor mCommentColor;
|
||||
QColor mCommentBackgroundColor;
|
||||
QColor mLabelColor;
|
||||
QColor mLabelBackgroundColor;
|
||||
|
||||
BridgeCFGraph currentGraph;
|
||||
QBeaEngine disasm;
|
||||
protected:
|
||||
#include "ActionHelpers.h"
|
||||
};
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public:
|
|||
FlagAll
|
||||
};
|
||||
|
||||
typedef struct _CustomRichText_t
|
||||
struct CustomRichText_t
|
||||
{
|
||||
QString text;
|
||||
QColor textColor;
|
||||
|
|
@ -28,7 +28,7 @@ public:
|
|||
CustomRichTextFlags flags;
|
||||
bool highlight;
|
||||
QColor highlightColor;
|
||||
} CustomRichText_t;
|
||||
};
|
||||
|
||||
typedef std::vector<CustomRichText_t> List;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue