More color theme fixes and categories (math, bin, other)

This commit is contained in:
pancake 2013-05-23 12:37:40 +02:00
parent 04bcbfd290
commit 3ba48ac9ad
7 changed files with 61 additions and 186 deletions

View File

@ -209,6 +209,16 @@ int x86_udis86_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len)
}
switch (u.mnemonic) {
case UD_Itest:
case UD_Icmp:
op->type = R_ANAL_OP_TYPE_CMP;
break;
case UD_Ixor:
op->type = R_ANAL_OP_TYPE_XOR;
break;
case UD_Ior:
op->type = R_ANAL_OP_TYPE_OR;
break;
case UD_Iand:
op->type = R_ANAL_OP_TYPE_AND;
break;

View File

@ -1,160 +0,0 @@
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
// XXX: deprecate this stuff
#include <r_cons.h>
#include <string.h>
static const char *nullstr="";
//static const char *r_cons_palette_default = "7624 6646 2378 6824 3623";
// XXX -- deprecate -- do not use global/extern stuff
static char r_cons_palette[CONS_PALETTE_SIZE][8] = {
/* PROMPT */
/* ADDRESS */
/* DEFAULT */
/* CHANGED */
/* JUMPS */
/* CALLS */
/* PUSH */
/* TRAP */
/* CMP */
/* RET */
/* NOP */
/* METADATA */
/* HEADER */
/* PRINTABLE */
/* LINES0 */
/* LINES1 */
/* LINES2 */
/* 00 */
/* 7F */
/* FF */
};
static const char *r_cons_color_names[CONS_COLORS_SIZE+1] = {
"black", "gray", "white", "red", "magenta", "blue", "green", "yellow",
"cyan", "bblack", "bgray", "bwhite", "bred", "bmagenta", "bblue",
"bgreen", "byellow", "bcyan", "reset", "bgblack", "bgred", NULL
};
static const char *r_cons_colors[CONS_COLORS_SIZE+1] = {
Color_BLACK, // 0
Color_GRAY, // 1
Color_WHITE, // 2
Color_RED, // 3
Color_MAGENTA, // 4
Color_BLUE, // 5
Color_GREEN, // 6
Color_YELLOW, // 7
Color_CYAN, // 8
/* BOLD */
Color_BBLACK, // a
Color_BGRAY, // b
Color_BWHITE, // c
Color_BRED, // d
Color_BMAGENTA, // e
Color_BBLUE, // f
Color_BGREEN, // g
Color_BYELLOW, // h
Color_BCYAN, // i
/* SPECIAL */
Color_RESET, // r
Color_BGBLACK, //
Color_BGRED,
NULL
};
const char *pal_names[CONS_PALETTE_SIZE]={
"prompt", "address", "default", "changed", "jumps", "calls",
"push", "trap", "cmp", "ret", "nop", "metadata", "header",
"printable", "lines0", "lines1", "lines2", "00", "7f", "ff",
NULL
};
static const char *r_cons_get_color(int ch) {
if (ch>='0' && ch<='8')
return r_cons_colors[ch-'0'];
if (ch>='a' && ch<='i')
return r_cons_colors['8'-'0'+ch-'a'];
return NULL;
}
static const char *r_cons_get_color_by_name(const char *str) {
int i;
for (i=0;r_cons_color_names[i];i++) {
if (!strcmp(str, r_cons_color_names[i]))
return r_cons_colors[i];
}
return nullstr;
}
R_API int r_cons_palette_init(const unsigned char *pal) {
int palstrlen;
int i,j=1,k;
if (pal==NULL || pal[0]=='\0') {
r_cons_printf ("\n=>( Targets ):");
for (j=0;pal_names[j]&&*pal_names[j];j++)
r_cons_printf("%s .%s\x1b[0m ", r_cons_palette[j], pal_names[j]);
r_cons_printf ("\n\n=>( Colors ): "
"/*normal*/, " "black, = 0, " "gray, = 1, " "white, = 2, " "red, = 3, " "magenta, = 4, "
"blue, = 5, " "green, = 6, " "yellow, = 7, " "cyan, = 8, " "/*bold*/, " "bblack, = a, "
"bgray, = b, " "bwhite, = c, " "bred, = d, " "bmagenta, = e, " "bblue, = f, " "bgreen, = g, "
"byellow, = h, " "bcyan, = i, " "/*special*/, " "reset, = r\n");
r_cons_printf("\nExample: eval scr.palette = .prompt=3.address=4\n\n");
return 0;
}
palstrlen = strlen((const char *)pal);
for (i=k=0;i<CONS_PALETTE_SIZE;i++,k++)
if (j && pal[i]) {
if (pal[i] == '.') { // che! action!!
for (j=0;pal_names[j]&&*pal_names[j];j++) {
int memcmp_len = palstrlen-i-1;
if (!pal_names[j]) break;
if (strlen(pal_names[j])<memcmp_len)
memcmp_len = strlen(pal_names[j]);
else continue;
// printf("CHK %s,%s,%d\n", pal_names[j], pal+i, memcmp_len);
if (!memcmp(pal_names[j], pal+i+1, memcmp_len -1)) {
i+=memcmp_len+1;
if (pal[i] != '=') {
eprintf ("oops (%c) invalid format string (%s)\n", pal[i], pal+i);
continue;
}
// printf("KEYWORD FOUND = %s (value = %c)\n", pal_names[j], pal[i+1]);
strcpy (r_cons_palette[j], r_cons_get_color(pal[i+1]));
}
}
} else {
const char *ptr = r_cons_get_color(pal[i]);
if (ptr) strcpy(r_cons_palette[k], ptr);
else k--;
}
} else {
strcpy (r_cons_palette[i], Color_RESET);
j = 0;
}
return 1;
}
R_API int r_cons_palette_set(const char *key, const char *value) {
const char *str;
int i;
for (i=0;pal_names[i];i++) {
if (!strcmp (key, pal_names[i])) {
str = r_cons_get_color_by_name (value);
if (str != NULL) {
strcpy (r_cons_palette[i], str);
return 0;
}
}
}
return 1;
}

View File

@ -51,7 +51,7 @@ static inline ut8 rgbnum (const char ch) {
R_API char *r_cons_pal_parse(const char *str) {
int i;
ut8 r, g, b;
char out[64];
char out[128];
char *s = strdup (str);
char *p = strchr (s+1, ' ');
out[0] = 0;
@ -61,12 +61,12 @@ R_API char *r_cons_pal_parse(const char *str) {
g = rgbnum (s[5]);
b = rgbnum (s[6]);
r_cons_rgb_str (out, r, g, b, 0);
if (p && !strncmp (p, "rgb:", 4)) {
r = rgbnum (p[4]);
g = rgbnum (p[5]);
b = rgbnum (p[6]);
r_cons_rgb_str (out+strlen (out), r, g, b, 1);
}
}
if (p && !strncmp (p, "rgb:", 4)) {
r = rgbnum (p[4]);
g = rgbnum (p[5]);
b = rgbnum (p[6]);
r_cons_rgb_str (out+strlen (out), r, g, b, 1);
}
for (i=0; colors[i].name; i++) {
if (!strcmp (s, colors[i].name))
@ -86,10 +86,13 @@ struct {
{ "prompt", r_offsetof (RConsPalette, prompt) },
{ "offset", r_offsetof (RConsPalette, offset) },
{ "input", r_offsetof (RConsPalette, input) },
{ "other", r_offsetof (RConsPalette, other) },
{ "b0x00", r_offsetof (RConsPalette, b0x00) },
{ "b0x7f", r_offsetof (RConsPalette, b0x7f) },
{ "b0xff", r_offsetof (RConsPalette, b0xff) },
{ "btext", r_offsetof (RConsPalette, btext) },
{ "math", r_offsetof (RConsPalette, math) },
{ "bin", r_offsetof (RConsPalette, bin) },
{ "push", r_offsetof (RConsPalette, push) },
{ "pop", r_offsetof (RConsPalette, pop) },
{ "jmp", r_offsetof (RConsPalette, jmp) },

View File

@ -624,7 +624,7 @@ R_API void r_core_prompt_loop(RCore *r) {
R_API int r_core_prompt(RCore *r, int sync) {
int ret;
char line[4096];
char prompt[32];
char prompt[64];
const char *cmdprompt = r_config_get (r->config, "cmd.prompt");
const char *BEGIN = r->cons->pal.prompt;

View File

@ -137,6 +137,8 @@ R_API int r_core_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int l
// TODO: only if show_color?
const char *color_comment = P(comment): Color_CYAN;
const char *color_nop = P(nop): Color_BLUE;
const char *color_bin = P(bin): Color_YELLOW;
const char *color_math = P(math): Color_YELLOW;
const char *color_jmp = P(jmp): Color_GREEN;
const char *color_call = P(call): Color_BGREEN;
const char *color_cmp = P(cmp): Color_MAGENTA;
@ -609,6 +611,18 @@ toro:
case R_ANAL_OP_TYPE_NOP:
r_cons_printf (color_nop);
break;
case R_ANAL_OP_TYPE_ADD:
case R_ANAL_OP_TYPE_SUB:
case R_ANAL_OP_TYPE_MUL:
case R_ANAL_OP_TYPE_DIV:
r_cons_strcat (color_math);
break;
case R_ANAL_OP_TYPE_AND:
case R_ANAL_OP_TYPE_OR:
case R_ANAL_OP_TYPE_XOR:
case R_ANAL_OP_TYPE_NOT:
r_cons_strcat (color_bin);
break;
case R_ANAL_OP_TYPE_JMP:
case R_ANAL_OP_TYPE_CJMP:
case R_ANAL_OP_TYPE_UJMP:
@ -757,7 +771,7 @@ toro:
case R_ANAL_OP_TYPE_CJMP:
case R_ANAL_OP_TYPE_CALL:
counter++;
if (counter<10){
if (counter<10) {
core->asmqjmps[counter] = analop.jump;
r_cons_printf (" [%d]", counter);
} else r_cons_strcat (" [?]");
@ -769,18 +783,19 @@ toro:
RFlagItem *flag = r_flag_get_at (core->flags, cc.jump);
if (show_color)
r_cons_printf ("\n%s%s %s; %s (%s+%d)"Color_RESET,
f?pre:"", refline, ccstr, flag?
flag->name: "", (f&&flag)?
cc.jump-flag->offset: 0);
f?pre:"", refline, ccstr,
(flag&&flag->name)? flag->name: "",
(flag&&flag->name)? flag->name: "",
(f&&flag)? cc.jump-flag->offset: 0);
else r_cons_printf ("\n%s%s ; %s (%s+%d)",
pre, refline, ccstr,
flag?flag->name:"", flag? cc.jump-flag->offset: 0);
(flag&&flag->name)?flag->name:"",
flag? cc.jump-flag->offset: 0);
free (ccstr);
}
}
r_anal_cc_reset (&cc);
}
switch (analop.type) {
case R_ANAL_OP_TYPE_PUSH:
if (analop.value) {

View File

@ -59,6 +59,9 @@ typedef struct r_cons_palette_t {
char *b0x7f;
char *b0xff;
char *btext;
char *other;
char *math;
char *bin;
char *push;
char *pop;
char *jmp;

View File

@ -119,7 +119,7 @@ R_API char *r_print_hexpair(RPrint *p, const char *str, int n) {
const char *s, *lastcol = Color_WHITE;
char *d, *dst = (char *)malloc ((strlen (str)+2)*32);
int colors = p->flags & R_PRINT_FLAGS_COLOR;
const char *color_0x00, *color_0x7f, *color_0xff, *color_text;
const char *color_0x00, *color_0x7f, *color_0xff, *color_text, *color_other;
/* XXX That's hacky as shit.. but partially works O:) */
/* TODO: Use r_print_set_cursor for win support */
int cur = R_MIN (p->cur, p->ocur);
@ -132,6 +132,7 @@ R_API char *r_print_hexpair(RPrint *p, const char *str, int n) {
color_0x7f = P(b0x7f): Color_YELLOW;
color_0xff = P(b0xff): Color_RED;
color_text = P(btext): Color_MAGENTA;
color_other = P(other): "";
}
if (p->cur_enabled && cur==-1)
cur = ocur;
@ -161,10 +162,11 @@ R_API char *r_print_hexpair(RPrint *p, const char *str, int n) {
else if (s[0]=='7' && s[1]=='f') lastcol = color_0x7f;
else if (s[0]=='f' && s[1]=='f') lastcol = color_0xff;
else {
ch = r_hex_pair2bin(s);
ch = r_hex_pair2bin (s);
//sscanf (s, "%02x", &ch); // XXX can be optimized
if (IS_PRINTABLE (ch))
lastcol = color_text;
else lastcol = color_other;
}
memcat (d, lastcol);
}
@ -184,10 +186,11 @@ R_API void r_print_byte(RPrint *p, const char *fmt, int idx, ut8 ch) {
//if (p->flags & R_PRINT_FLAGS_CURSOR && idx == p->cur) {
if (p->flags & R_PRINT_FLAGS_COLOR) {
#define P(x) (p->cons &&p->cons->pal.x)?p->cons->pal.x
const char *color_0x00 = P(b0x00): Color_GREEN;
const char *color_0x7f = P(b0x7f): Color_YELLOW;
const char *color_0xff = P(b0xff): Color_RED;
const char *color_text = P(btext): Color_MAGENTA;
char *color_0x00 = P(b0x00): Color_GREEN;
char *color_0x7f = P(b0x7f): Color_YELLOW;
char *color_0xff = P(b0xff): Color_RED;
char *color_text = P(btext): Color_MAGENTA;
char *color_other = P(other): Color_WHITE;
char *pre = NULL;
switch (ch) {
case 0x00: pre = color_0x00; break;
@ -196,6 +199,7 @@ R_API void r_print_byte(RPrint *p, const char *fmt, int idx, ut8 ch) {
default:
if (IS_PRINTABLE (ch))
pre = color_text;
else pre = color_other;
}
if (pre) p->printf (pre);
p->printf (fmt, rch);
@ -342,6 +346,7 @@ static int check_sparse (const ut8 *p, int len, int ch) {
// XXX: step is borken
R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int base, int step) {
int i, j, k, inc;
const char *color;
int sparse_char = 0;
int use_sparse = p->flags & R_PRINT_FLAGS_SPARSE;
const char *fmt = "%02x";
@ -367,10 +372,9 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba
inc = p->cols;
//if (base==64) inc = p->cols/1.2;
k = "";
if (p->flags & R_PRINT_FLAGS_COLOR) {
k = (p->cons && p->cons->pal.offset)? p->cons->pal.offset: "";
}
color = "";
if (p->flags & R_PRINT_FLAGS_COLOR)
color = (p->cons && p->cons->pal.offset)? p->cons->pal.offset: "";
if (base<32)
if (p->flags & R_PRINT_FLAGS_HEADER) {
ut32 opad = (ut32)(addr >> 32);
@ -383,9 +387,9 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba
ut32 s, a;
a = addr & 0xffff;
s = (addr-a)>>4;
snprintf (soff, sizeof (soff), "%s%04x:%04x", p, s, a);
snprintf (soff, sizeof (soff), "%s%04x:%04x", color, s, a);
} else {
snprintf (soff, sizeof (soff), "%s0x%08"PFMT64x, p, addr);
snprintf (soff, sizeof (soff), "%s0x%08"PFMT64x, color, addr);
}
delta = strlen (soff) - 10;
for (i=0; i<delta; i++)