cutter/src/common/Colors.cpp

100 lines
3.0 KiB
C++
Raw Normal View History

2017-10-15 07:14:05 +00:00
#include "Colors.h"
2018-10-17 07:55:53 +00:00
#include "common/Configuration.h"
2017-10-15 07:14:05 +00:00
2021-01-24 14:50:13 +00:00
Colors::Colors() {}
2017-10-15 11:38:28 +00:00
2018-03-21 20:32:32 +00:00
void Colors::colorizeAssembly(RichTextPainter::List &list, QString opcode, ut64 type_num)
2017-10-15 11:38:28 +00:00
{
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);
}
2017-10-15 07:14:05 +00:00
// Temporary solution
2020-12-07 07:57:11 +00:00
// Copied from RZ_API const char* r_print_color_op_type(RPrint *p, ut64 analysis_type) {
2017-10-15 07:14:05 +00:00
QString Colors::getColor(ut64 type)
{
2020-12-07 18:20:47 +00:00
switch (type & RZ_ANALYSIS_OP_TYPE_MASK) {
case RZ_ANALYSIS_OP_TYPE_NOP:
2017-10-15 07:14:05 +00:00
return "nop";
2020-12-07 18:20:47 +00:00
case RZ_ANALYSIS_OP_TYPE_ADD:
case RZ_ANALYSIS_OP_TYPE_SUB:
case RZ_ANALYSIS_OP_TYPE_MUL:
case RZ_ANALYSIS_OP_TYPE_DIV:
case RZ_ANALYSIS_OP_TYPE_MOD:
case RZ_ANALYSIS_OP_TYPE_LENGTH:
2017-10-15 07:14:05 +00:00
return "math";
2020-12-07 18:20:47 +00:00
case RZ_ANALYSIS_OP_TYPE_AND:
case RZ_ANALYSIS_OP_TYPE_OR:
case RZ_ANALYSIS_OP_TYPE_XOR:
case RZ_ANALYSIS_OP_TYPE_NOT:
case RZ_ANALYSIS_OP_TYPE_SHL:
case RZ_ANALYSIS_OP_TYPE_SAL:
case RZ_ANALYSIS_OP_TYPE_SAR:
case RZ_ANALYSIS_OP_TYPE_SHR:
case RZ_ANALYSIS_OP_TYPE_ROL:
case RZ_ANALYSIS_OP_TYPE_ROR:
case RZ_ANALYSIS_OP_TYPE_CPL:
2017-10-15 07:14:05 +00:00
return "bin";
2020-12-07 18:20:47 +00:00
case RZ_ANALYSIS_OP_TYPE_IO:
2017-10-15 07:14:05 +00:00
return "swi";
2020-12-07 18:20:47 +00:00
case RZ_ANALYSIS_OP_TYPE_JMP:
case RZ_ANALYSIS_OP_TYPE_UJMP:
case RZ_ANALYSIS_OP_TYPE_IJMP:
case RZ_ANALYSIS_OP_TYPE_RJMP:
case RZ_ANALYSIS_OP_TYPE_IRJMP:
case RZ_ANALYSIS_OP_TYPE_MJMP:
2017-10-15 07:14:05 +00:00
return "jmp";
2020-12-07 18:20:47 +00:00
case RZ_ANALYSIS_OP_TYPE_CJMP:
case RZ_ANALYSIS_OP_TYPE_UCJMP:
case RZ_ANALYSIS_OP_TYPE_SWITCH:
2017-10-15 07:14:05 +00:00
return "cjmp";
2020-12-07 18:20:47 +00:00
case RZ_ANALYSIS_OP_TYPE_CMP:
case RZ_ANALYSIS_OP_TYPE_ACMP:
2017-10-15 07:14:05 +00:00
return "cmp";
2020-12-07 18:20:47 +00:00
case RZ_ANALYSIS_OP_TYPE_UCALL:
case RZ_ANALYSIS_OP_TYPE_ICALL:
case RZ_ANALYSIS_OP_TYPE_RCALL:
case RZ_ANALYSIS_OP_TYPE_IRCALL:
case RZ_ANALYSIS_OP_TYPE_UCCALL:
case RZ_ANALYSIS_OP_TYPE_CALL:
case RZ_ANALYSIS_OP_TYPE_CCALL:
2017-10-15 07:14:05 +00:00
return "call";
2020-12-07 18:20:47 +00:00
case RZ_ANALYSIS_OP_TYPE_NEW:
case RZ_ANALYSIS_OP_TYPE_SWI:
2017-10-15 07:14:05 +00:00
return "swi";
2020-12-07 18:20:47 +00:00
case RZ_ANALYSIS_OP_TYPE_ILL:
case RZ_ANALYSIS_OP_TYPE_TRAP:
2017-10-15 07:14:05 +00:00
return "trap";
2020-12-07 18:20:47 +00:00
case RZ_ANALYSIS_OP_TYPE_CRET:
case RZ_ANALYSIS_OP_TYPE_RET:
2017-10-15 07:14:05 +00:00
return "ret";
2020-12-07 18:20:47 +00:00
case RZ_ANALYSIS_OP_TYPE_CAST:
case RZ_ANALYSIS_OP_TYPE_MOV:
case RZ_ANALYSIS_OP_TYPE_LEA:
case RZ_ANALYSIS_OP_TYPE_CMOV: // TODO: add cmov cathegory?
2017-10-15 07:14:05 +00:00
return "mov";
2020-12-07 18:20:47 +00:00
case RZ_ANALYSIS_OP_TYPE_PUSH:
case RZ_ANALYSIS_OP_TYPE_UPUSH:
case RZ_ANALYSIS_OP_TYPE_LOAD:
2017-10-15 07:14:05 +00:00
return "push";
2020-12-07 18:20:47 +00:00
case RZ_ANALYSIS_OP_TYPE_POP:
case RZ_ANALYSIS_OP_TYPE_STORE:
2017-10-15 07:14:05 +00:00
return "pop";
2020-12-07 18:20:47 +00:00
case RZ_ANALYSIS_OP_TYPE_CRYPTO:
2017-10-15 07:14:05 +00:00
return "crypto";
2020-12-07 18:20:47 +00:00
case RZ_ANALYSIS_OP_TYPE_NULL:
2017-10-15 07:14:05 +00:00
return "other";
2020-12-07 18:20:47 +00:00
case RZ_ANALYSIS_OP_TYPE_UNK:
2017-10-15 07:14:05 +00:00
default:
return "invalid";
}
}