mirror of
https://github.com/rizinorg/cutter.git
synced 2025-01-31 08:37:26 +00:00
Use agJ for graph
This commit is contained in:
parent
613a3e422a
commit
75bf8cf5b6
@ -7,11 +7,13 @@
|
|||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QToolTip>
|
#include <QToolTip>
|
||||||
|
#include <QTextDocument>
|
||||||
|
|
||||||
#include "cutter.h"
|
#include "cutter.h"
|
||||||
#include "utils/Colors.h"
|
#include "utils/Colors.h"
|
||||||
#include "utils/Configuration.h"
|
#include "utils/Configuration.h"
|
||||||
#include "utils/CachedFontMetrics.h"
|
#include "utils/CachedFontMetrics.h"
|
||||||
|
#include "utils/TempConfig.h"
|
||||||
|
|
||||||
DisassemblerGraphView::DisassemblerGraphView(QWidget *parent)
|
DisassemblerGraphView::DisassemblerGraphView(QWidget *parent)
|
||||||
: GraphView(parent),
|
: GraphView(parent),
|
||||||
@ -109,7 +111,9 @@ void DisassemblerGraphView::refreshView()
|
|||||||
|
|
||||||
void DisassemblerGraphView::loadCurrentGraph()
|
void DisassemblerGraphView::loadCurrentGraph()
|
||||||
{
|
{
|
||||||
QJsonDocument functionsDoc = Core()->cmdj("agj");
|
TempConfig tempConfig;
|
||||||
|
tempConfig.set("scr.html", true);
|
||||||
|
QJsonDocument functionsDoc = Core()->cmdj("agJ@e:scr.html=true");
|
||||||
QJsonArray functions = functionsDoc.array();
|
QJsonArray functions = functionsDoc.array();
|
||||||
|
|
||||||
disassembly_blocks.clear();
|
disassembly_blocks.clear();
|
||||||
@ -138,6 +142,7 @@ void DisassemblerGraphView::loadCurrentGraph()
|
|||||||
for (QJsonValueRef blockRef : func["blocks"].toArray()) {
|
for (QJsonValueRef blockRef : func["blocks"].toArray()) {
|
||||||
QJsonObject block = blockRef.toObject();
|
QJsonObject block = blockRef.toObject();
|
||||||
RVA block_entry = block["offset"].toVariant().toULongLong();
|
RVA block_entry = block["offset"].toVariant().toULongLong();
|
||||||
|
RVA block_size = block["size"].toVariant().toULongLong();
|
||||||
RVA block_fail = block["fail"].toVariant().toULongLong();
|
RVA block_fail = block["fail"].toVariant().toULongLong();
|
||||||
RVA block_jump = block["jump"].toVariant().toULongLong();
|
RVA block_jump = block["jump"].toVariant().toULongLong();
|
||||||
|
|
||||||
@ -160,50 +165,36 @@ void DisassemblerGraphView::loadCurrentGraph()
|
|||||||
}
|
}
|
||||||
gb.exits.push_back(block_jump);
|
gb.exits.push_back(block_jump);
|
||||||
}
|
}
|
||||||
for (QJsonValueRef opRef : block["ops"].toArray())
|
QJsonArray opArray = block["ops"].toArray();
|
||||||
|
for (int opIndex=0; opIndex<opArray.size(); opIndex++)
|
||||||
{
|
{
|
||||||
QJsonObject op = opRef.toObject();
|
QJsonObject op = opArray[opIndex].toObject();
|
||||||
Instr i;
|
Instr i;
|
||||||
i.addr = op["offset"].toVariant().toULongLong();
|
i.addr = op["offset"].toVariant().toULongLong();
|
||||||
|
|
||||||
|
if (opIndex < opArray.size() - 1)
|
||||||
|
{
|
||||||
|
// get instruction size from distance to next instruction ...
|
||||||
|
RVA nextOffset = opArray[opIndex+1].toObject()["offset"].toVariant().toULongLong();
|
||||||
|
i.size = nextOffset - i.addr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// or to the end of the block.
|
||||||
|
i.size = (block_entry + block_size) - i.addr;
|
||||||
|
}
|
||||||
|
|
||||||
// Skip last byte, otherwise it will overlap with next instruction
|
// Skip last byte, otherwise it will overlap with next instruction
|
||||||
i.size = op["size"].toVariant().toULongLong() - 1;
|
i.size -= 1;
|
||||||
|
|
||||||
RichTextPainter::List richText;
|
RichTextPainter::List richText;
|
||||||
QString disas;
|
QString disas;
|
||||||
if (Core()->getConfigb("asm.esil"))
|
disas = op["text"].toString();
|
||||||
disas = op["esil"].toString();
|
|
||||||
else
|
|
||||||
disas = op["disasm"].toString();
|
|
||||||
|
|
||||||
Colors::colorizeAssembly(richText, disas, op["type_num"].toVariant().toULongLong());
|
QTextDocument textDoc;
|
||||||
|
textDoc.setHtml(disas);
|
||||||
|
|
||||||
if (op["comment"].toString().length())
|
Colors::colorizeAssembly(richText, textDoc.toPlainText(), 0);
|
||||||
{
|
|
||||||
RichTextPainter::CustomRichText_t comment;
|
|
||||||
comment.text = QString(" ; %1").arg(QByteArray::fromBase64(op["comment"].toString().toLocal8Bit()).data());
|
|
||||||
comment.textColor = mCommentColor;
|
|
||||||
comment.flags = RichTextPainter::FlagColor;
|
|
||||||
richText.insert(richText.end(), comment);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Core()->getConfigb("asm.bytes"))
|
|
||||||
{
|
|
||||||
RichTextPainter::CustomRichText_t bytes;
|
|
||||||
bytes.text = op["bytes"].toVariant().toString();
|
|
||||||
|
|
||||||
if (Core()->getConfigb("asm.bytespace"))
|
|
||||||
for (int i = 2; i <= bytes.text.size(); i += 2+1)
|
|
||||||
bytes.text.insert(i, ' ');
|
|
||||||
|
|
||||||
if (Core()->getConfigb("asm.lbytes"))
|
|
||||||
bytes.text = bytes.text.leftJustified(24, ' ');
|
|
||||||
else
|
|
||||||
bytes.text = bytes.text.rightJustified(24, ' ');
|
|
||||||
|
|
||||||
bytes.textColor = Config()->getColor("bin");
|
|
||||||
bytes.flags = RichTextPainter::FlagColor;
|
|
||||||
richText.insert(richText.begin(), bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool cropped;
|
bool cropped;
|
||||||
int blockLength = Config()->getGraphBlockMaxChars() + Core()->getConfigb("asm.bytes") * 24 + Core()->getConfigb("asm.emu") * 10;
|
int blockLength = Config()->getGraphBlockMaxChars() + Core()->getConfigb("asm.bytes") * 24 + Core()->getConfigb("asm.emu") * 10;
|
||||||
|
Loading…
Reference in New Issue
Block a user