mirror of
https://github.com/rizinorg/cutter.git
synced 2025-01-31 00:35:05 +00:00
Small refactor
This commit is contained in:
parent
1ca9b06519
commit
65835f0dc9
@ -1,10 +1,26 @@
|
|||||||
#include "Colors.h"
|
#include "Colors.h"
|
||||||
|
#include "utils/Configuration.h"
|
||||||
|
|
||||||
Colors::Colors()
|
Colors::Colors()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Colors::colorizeAssembly(RichTextPainter::List & list, QString opcode, ut64 type_num)
|
||||||
|
{
|
||||||
|
RichTextPainter::CustomRichText_t assembly;
|
||||||
|
assembly.highlight = false;
|
||||||
|
assembly.flags = RichTextPainter::FlagColor;
|
||||||
|
|
||||||
|
// TODO cut opcode and use op["ptr"] to colorate registers and immediate values
|
||||||
|
assembly.text = opcode;
|
||||||
|
|
||||||
|
QString colorName = Colors::getColor(type_num);
|
||||||
|
assembly.textColor = ConfigColor(colorName);
|
||||||
|
list.push_back(assembly);
|
||||||
|
}
|
||||||
|
|
||||||
// Temporary solution
|
// Temporary solution
|
||||||
// Copied from R_API const char* r_print_color_op_type(RPrint *p, ut64 anal_type) {
|
// Copied from R_API const char* r_print_color_op_type(RPrint *p, ut64 anal_type) {
|
||||||
QString Colors::getColor(ut64 type)
|
QString Colors::getColor(ut64 type)
|
||||||
|
@ -2,12 +2,14 @@
|
|||||||
#define COLORS_H
|
#define COLORS_H
|
||||||
|
|
||||||
#include "cutter.h"
|
#include "cutter.h"
|
||||||
#include "libr/r_anal.h"
|
#include "utils/RichTextPainter.h"
|
||||||
|
#include <r_anal.h>
|
||||||
|
|
||||||
class Colors
|
class Colors
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Colors();
|
Colors();
|
||||||
|
static void colorizeAssembly(RichTextPainter::List &list, QString opcode, ut64 type_num);
|
||||||
static QString getColor(ut64 type);
|
static QString getColor(ut64 type);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18,14 +18,15 @@ Configuration* Configuration::instance()
|
|||||||
|
|
||||||
void Configuration::loadDefaultColors()
|
void Configuration::loadDefaultColors()
|
||||||
{
|
{
|
||||||
Core()->cmd("eco solarized");
|
//Core()->cmd("eco behelit");
|
||||||
|
Core()->cmd("eco smyck");
|
||||||
QJsonObject colors = Core()->cmdj("ecj").object();
|
QJsonObject colors = Core()->cmdj("ecj").object();
|
||||||
for (auto color : colors.keys()) {
|
for (auto color : colors.keys()) {
|
||||||
QJsonArray rgb = colors[color].toArray();
|
QJsonArray rgb = colors[color].toArray();
|
||||||
QColor col = QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt());
|
QColor col = QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt());
|
||||||
s.setValue("colors." + color, col);
|
s.setValue("colors." + color, col);
|
||||||
}
|
}
|
||||||
s.setValue("colors.gui.alt_background", QColor(255, 255, 255));
|
//s.setValue("colors.gui.alt_background", QColor(255, 255, 255));
|
||||||
}
|
}
|
||||||
|
|
||||||
const QFont Configuration::getFont() const
|
const QFont Configuration::getFont() const
|
||||||
|
@ -1590,21 +1590,8 @@ void DisassemblerGraphView::loadCurrentGraph()
|
|||||||
QJsonObject op = opRef.toObject();
|
QJsonObject op = opRef.toObject();
|
||||||
Instr i;
|
Instr i;
|
||||||
i.addr = op["offset"].toInt();
|
i.addr = op["offset"].toInt();
|
||||||
// TODO
|
|
||||||
RichTextPainter::List richText;
|
RichTextPainter::List richText;
|
||||||
|
Colors::colorizeAssembly(richText, op["opcode"].toString(), op["type_num"].toVariant().toULongLong());
|
||||||
////////// TODO Put in a helper function to use it on DisassemblyWidget too.
|
|
||||||
RichTextPainter::CustomRichText_t assembly;
|
|
||||||
assembly.highlight = false;
|
|
||||||
assembly.flags = RichTextPainter::FlagColor;
|
|
||||||
// TODO cut opcode and use op["ptr"] to colorate registers and immediate values
|
|
||||||
QString opcode = op["opcode"].toString();
|
|
||||||
assembly.text = opcode;
|
|
||||||
|
|
||||||
QString colorName = Colors::getColor(op["type_num"].toVariant().toULongLong());
|
|
||||||
assembly.textColor = ConfigColor(colorName);
|
|
||||||
richText.insert(richText.begin(), assembly);
|
|
||||||
|
|
||||||
if (op["comment"].toString().length()) {
|
if (op["comment"].toString().length()) {
|
||||||
RichTextPainter::CustomRichText_t comment;
|
RichTextPainter::CustomRichText_t comment;
|
||||||
comment.text = QString(" ; %1").arg(QByteArray::fromBase64(op["comment"].toString().toLocal8Bit()).data());
|
comment.text = QString(" ; %1").arg(QByteArray::fromBase64(op["comment"].toString().toLocal8Bit()).data());
|
||||||
@ -1612,9 +1599,6 @@ void DisassemblerGraphView::loadCurrentGraph()
|
|||||||
comment.flags = RichTextPainter::FlagColor;
|
comment.flags = RichTextPainter::FlagColor;
|
||||||
richText.insert(richText.end(), comment);
|
richText.insert(richText.end(), comment);
|
||||||
}
|
}
|
||||||
//////////
|
|
||||||
|
|
||||||
|
|
||||||
i.text = Text(richText);
|
i.text = Text(richText);
|
||||||
b.instrs.push_back(i);
|
b.instrs.push_back(i);
|
||||||
}
|
}
|
||||||
@ -1626,115 +1610,6 @@ void DisassemblerGraphView::loadCurrentGraph()
|
|||||||
this->analysis = anal;
|
this->analysis = anal;
|
||||||
this->function = this->analysis.entry;
|
this->function = this->analysis.entry;
|
||||||
this->ready = true;
|
this->ready = true;
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
////////////////// REMOVE BELOW //////////////////////////////////////
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/*
|
|
||||||
bool showGraphRva = ConfigBool("Gui", "ShowGraphRva");
|
|
||||||
Analysis anal;
|
|
||||||
anal.update_id = this->update_id + 1;
|
|
||||||
anal.entry = currentGraph.entryPoint;
|
|
||||||
anal.ready = true;
|
|
||||||
{
|
|
||||||
Function func;
|
|
||||||
func.entry = currentGraph.entryPoint;
|
|
||||||
func.ready = true;
|
|
||||||
func.update_id = anal.update_id;
|
|
||||||
{
|
|
||||||
for(const auto & nodeIt : currentGraph.nodes)
|
|
||||||
{
|
|
||||||
const BridgeCFNode & node = nodeIt.second;
|
|
||||||
Block block;
|
|
||||||
block.entry = node.instrs.empty() ? node.start : node.instrs[0].addr;
|
|
||||||
block.exits = node.exits;
|
|
||||||
block.false_path = node.brfalse;
|
|
||||||
block.true_path = node.brtrue;
|
|
||||||
block.terminal = node.terminal;
|
|
||||||
block.indirectcall = node.indirectcall;
|
|
||||||
block.header_text = Text(getSymbolicName(block.entry), mLabelColor, mLabelBackgroundColor);
|
|
||||||
{
|
|
||||||
Instr instr;
|
|
||||||
for(const BridgeCFInstruction & nodeInstr : node.instrs)
|
|
||||||
{
|
|
||||||
auto addr = nodeInstr.addr;
|
|
||||||
currentBlockMap[addr] = block.entry;
|
|
||||||
Instruction_t instrTok = disasm.DisassembleAt((byte_t*)nodeInstr.data, sizeof(nodeInstr.data), 0, addr, false);
|
|
||||||
RichTextPainter::List richText;
|
|
||||||
CapstoneTokenizer::TokenToRichText(instrTok.tokens, richText, 0);
|
|
||||||
|
|
||||||
// add rva to node instruction text
|
|
||||||
if(showGraphRva)
|
|
||||||
{
|
|
||||||
RichTextPainter::CustomRichText_t rvaText;
|
|
||||||
rvaText.highlight = false;
|
|
||||||
rvaText.textColor = mAddressColor;
|
|
||||||
rvaText.textBackground = mAddressBackgroundColor;
|
|
||||||
rvaText.text = QString().number(instrTok.rva, 16).toUpper().trimmed() + " ";
|
|
||||||
rvaText.flags = rvaText.textBackground.alpha() ? RichTextPainter::FlagAll : RichTextPainter::FlagColor;
|
|
||||||
richText.insert(richText.begin(), rvaText);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto size = instrTok.length;
|
|
||||||
instr.addr = addr;
|
|
||||||
instr.opcode.resize(size);
|
|
||||||
for(int j = 0; j < size; j++)
|
|
||||||
instr.opcode[j] = nodeInstr.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);
|
|
||||||
|
|
||||||
//The summary contains calls, rets, user comments and string references
|
|
||||||
if(!onlySummary ||
|
|
||||||
instrTok.branchType == Instruction_t::Call ||
|
|
||||||
instrTok.instStr.startsWith("ret", Qt::CaseInsensitive) ||
|
|
||||||
(!commentText.text.isEmpty() && !autoComment) ||
|
|
||||||
commentText.text.contains('\"'))
|
|
||||||
block.instrs.push_back(instr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
func.blocks.push_back(block);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
anal.functions.insert({func.entry, func});
|
|
||||||
}
|
|
||||||
this->analysis = anal;
|
|
||||||
this->function = this->analysis.entry;
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user