2013-05-22 02:22:49 +00:00
|
|
|
/* radare - LGPL - Copyright 2013 - pancake */
|
|
|
|
|
|
|
|
#include <r_cons.h>
|
|
|
|
|
|
|
|
R_API void r_cons_pal_init(const char *foo) {
|
|
|
|
RCons *cons = r_cons_singleton ();
|
2013-05-23 00:26:48 +00:00
|
|
|
memset (&cons->pal, 0, sizeof (cons->pal));
|
2013-05-22 02:22:49 +00:00
|
|
|
cons->pal.prompt = Color_YELLOW;
|
|
|
|
cons->pal.offset = Color_GREEN;
|
|
|
|
cons->pal.input = Color_WHITE;
|
2013-05-23 01:03:40 +00:00
|
|
|
cons->pal.comment = Color_CYAN;
|
2013-06-17 05:42:46 +00:00
|
|
|
cons->pal.fname = Color_CYAN;
|
2013-07-16 19:16:43 +00:00
|
|
|
cons->pal.fline = Color_CYAN;
|
2013-06-25 21:44:21 +00:00
|
|
|
cons->pal.flag = Color_CYAN;
|
|
|
|
cons->pal.label = Color_CYAN;
|
2013-06-17 05:42:46 +00:00
|
|
|
cons->pal.flow = Color_CYAN;
|
2013-05-23 00:26:48 +00:00
|
|
|
cons->pal.b0x00 = Color_GREEN;
|
2013-07-04 01:34:28 +00:00
|
|
|
cons->pal.b0x7f = Color_CYAN;
|
2013-05-23 00:26:48 +00:00
|
|
|
cons->pal.b0xff = Color_RED;
|
2013-07-17 01:51:53 +00:00
|
|
|
cons->pal.other = Color_YELLOW;
|
2013-07-04 01:34:28 +00:00
|
|
|
cons->pal.btext = Color_YELLOW;
|
2013-06-17 01:26:48 +00:00
|
|
|
cons->pal.push = Color_MAGENTA;
|
|
|
|
cons->pal.pop = Color_BMAGENTA;
|
2013-05-23 01:03:40 +00:00
|
|
|
cons->pal.nop = Color_BLUE;
|
|
|
|
cons->pal.jmp = Color_GREEN;
|
2013-06-17 05:42:46 +00:00
|
|
|
cons->pal.cjmp = Color_GREEN;
|
2013-05-23 01:03:40 +00:00
|
|
|
cons->pal.call = Color_BGREEN;
|
|
|
|
cons->pal.cmp = Color_CYAN;
|
|
|
|
cons->pal.swi = Color_MAGENTA;
|
|
|
|
cons->pal.trap = Color_BRED;
|
|
|
|
cons->pal.ret = Color_RED;
|
2013-07-04 01:34:28 +00:00
|
|
|
cons->pal.num = Color_YELLOW;
|
|
|
|
cons->pal.reg = Color_CYAN;
|
2013-05-22 02:22:49 +00:00
|
|
|
cons->pal.reset = "\x1b[0m";
|
|
|
|
}
|
|
|
|
|
|
|
|
struct {
|
|
|
|
const char *name;
|
|
|
|
const char *code;
|
|
|
|
const char *bgcode;
|
|
|
|
} colors[] = {
|
|
|
|
{ "black", Color_BLACK, Color_BGBLACK },
|
|
|
|
{ "red", Color_RED, Color_BGRED },
|
|
|
|
{ "white", Color_WHITE, Color_BGWHITE },
|
|
|
|
{ "green", Color_GREEN, Color_BGGREEN },
|
|
|
|
{ "magenta", Color_MAGENTA, Color_BGMAGENTA },
|
|
|
|
{ "yellow", Color_YELLOW, Color_BGYELLOW },
|
2013-05-23 01:03:40 +00:00
|
|
|
{ "cyan", Color_CYAN, Color_BGCYAN },
|
2013-05-22 02:22:49 +00:00
|
|
|
{ "blue", Color_BLUE, Color_BGBLUE },
|
2013-05-23 00:26:48 +00:00
|
|
|
{ "gray", Color_GRAY, Color_BGGRAY },
|
|
|
|
{ NULL, NULL, NULL }
|
2013-05-22 02:22:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline ut8 rgbnum (const char ch) {
|
|
|
|
ut8 r;
|
|
|
|
r_hex_to_byte (&r, ch);
|
|
|
|
return r*16;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API char *r_cons_pal_parse(const char *str) {
|
|
|
|
int i;
|
|
|
|
ut8 r, g, b;
|
2013-05-23 10:37:40 +00:00
|
|
|
char out[128];
|
2013-05-22 02:22:49 +00:00
|
|
|
char *s = strdup (str);
|
|
|
|
char *p = strchr (s+1, ' ');
|
|
|
|
out[0] = 0;
|
|
|
|
if (p) *p++ = 0;
|
|
|
|
if (!strncmp (s, "rgb:", 4)) {
|
|
|
|
r = rgbnum (s[4]);
|
|
|
|
g = rgbnum (s[5]);
|
|
|
|
b = rgbnum (s[6]);
|
|
|
|
r_cons_rgb_str (out, r, g, b, 0);
|
2013-05-23 10:37:40 +00:00
|
|
|
}
|
|
|
|
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);
|
2013-05-22 02:22:49 +00:00
|
|
|
}
|
|
|
|
for (i=0; colors[i].name; i++) {
|
|
|
|
if (!strcmp (s, colors[i].name))
|
|
|
|
strcat (out, colors[i].code);
|
|
|
|
if (p && !strcmp (p, colors[i].name))
|
|
|
|
strcat (out, colors[i].bgcode);
|
|
|
|
}
|
|
|
|
free (s);
|
|
|
|
return *out? strdup (out): NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-17 01:51:53 +00:00
|
|
|
static struct {
|
2013-05-22 02:22:49 +00:00
|
|
|
const char *name;
|
|
|
|
int off;
|
|
|
|
} keys[] = {
|
|
|
|
{ "comment", r_offsetof (RConsPalette, comment) },
|
2013-06-17 05:42:46 +00:00
|
|
|
{ "fname", r_offsetof (RConsPalette, fname) },
|
2013-07-16 19:16:43 +00:00
|
|
|
{ "fline", r_offsetof (RConsPalette, fline) },
|
2013-06-25 21:44:21 +00:00
|
|
|
{ "flag", r_offsetof (RConsPalette, flag) },
|
|
|
|
{ "label", r_offsetof (RConsPalette, label) },
|
2013-06-17 05:42:46 +00:00
|
|
|
{ "flow", r_offsetof (RConsPalette, flow) },
|
2013-05-22 02:22:49 +00:00
|
|
|
{ "prompt", r_offsetof (RConsPalette, prompt) },
|
|
|
|
{ "offset", r_offsetof (RConsPalette, offset) },
|
|
|
|
{ "input", r_offsetof (RConsPalette, input) },
|
2013-05-23 10:37:40 +00:00
|
|
|
{ "other", r_offsetof (RConsPalette, other) },
|
2013-05-23 00:26:48 +00:00
|
|
|
{ "b0x00", r_offsetof (RConsPalette, b0x00) },
|
|
|
|
{ "b0x7f", r_offsetof (RConsPalette, b0x7f) },
|
|
|
|
{ "b0xff", r_offsetof (RConsPalette, b0xff) },
|
2013-07-17 01:51:53 +00:00
|
|
|
{ "math", r_offsetof (RConsPalette, math) },
|
|
|
|
{ "bin", r_offsetof (RConsPalette, bin) },
|
2013-05-23 00:26:48 +00:00
|
|
|
{ "btext", r_offsetof (RConsPalette, btext) },
|
2013-05-23 10:37:40 +00:00
|
|
|
{ "math", r_offsetof (RConsPalette, math) },
|
|
|
|
{ "bin", r_offsetof (RConsPalette, bin) },
|
2013-05-23 00:26:48 +00:00
|
|
|
{ "push", r_offsetof (RConsPalette, push) },
|
|
|
|
{ "pop", r_offsetof (RConsPalette, pop) },
|
|
|
|
{ "jmp", r_offsetof (RConsPalette, jmp) },
|
2013-06-17 05:42:46 +00:00
|
|
|
{ "cjmp", r_offsetof (RConsPalette, cjmp) },
|
2013-05-23 00:26:48 +00:00
|
|
|
{ "call", r_offsetof (RConsPalette, call) },
|
|
|
|
{ "nop", r_offsetof (RConsPalette, nop) },
|
|
|
|
{ "ret", r_offsetof (RConsPalette, ret) },
|
|
|
|
{ "trap", r_offsetof (RConsPalette, trap) },
|
|
|
|
{ "swi", r_offsetof (RConsPalette, swi) },
|
|
|
|
{ "cmp", r_offsetof (RConsPalette, cmp) },
|
2013-07-03 15:43:20 +00:00
|
|
|
{ "reg", r_offsetof (RConsPalette, reg) },
|
|
|
|
{ "num", r_offsetof (RConsPalette, num) },
|
2013-05-22 02:22:49 +00:00
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
R_API void r_cons_pal_walk() {
|
2013-05-22 14:15:56 +00:00
|
|
|
//RCons *c = r_cons_singleton ();
|
2013-05-22 02:22:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
R_API void r_cons_pal_load(const char *sdbfile) {
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API void r_cons_pal_save(const char *sdbfile) {
|
|
|
|
}
|
|
|
|
|
2013-05-23 00:26:48 +00:00
|
|
|
R_API void r_cons_pal_show () {
|
|
|
|
const int inc = 3;
|
|
|
|
int i, j, k, n = 0;
|
|
|
|
for (i=0; colors[i].name; i++) {
|
|
|
|
r_cons_printf ("%s%s__"Color_RESET" %s\n",
|
|
|
|
colors[i].code,
|
|
|
|
colors[i].bgcode,
|
|
|
|
colors[i].name);
|
|
|
|
}
|
|
|
|
r_cons_printf ("\nGreyscale:\n");
|
|
|
|
for (i=n=0; i<=0xf; i+=1) {
|
|
|
|
char fg[32], bg[32];
|
|
|
|
int r = i*16;
|
2013-06-27 00:19:40 +00:00
|
|
|
if (i<5) strcpy (fg, Color_WHITE);
|
2013-05-23 00:26:48 +00:00
|
|
|
else r_cons_rgb_str (fg, 0, 0, 0, 0);
|
|
|
|
r_cons_rgb_str (bg, r, r, r, 1);
|
|
|
|
r_cons_printf ("%s%s rgb:%x%x%x "Color_RESET, fg, bg, i, i, i);
|
|
|
|
if (n++==5) {
|
|
|
|
n = 0;
|
|
|
|
r_cons_newline();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r_cons_printf ("\n\nRGB:\n");
|
|
|
|
for (i=n=0; i<=0xf; i+=inc) {
|
2013-07-17 01:51:53 +00:00
|
|
|
for (k=0; k<=0xf; k+=inc) {
|
|
|
|
for (j=0; j<=0xf; j+=inc) {
|
2013-05-23 00:26:48 +00:00
|
|
|
char fg[32], bg[32];
|
|
|
|
int r = i*16;
|
|
|
|
int g = j*16;
|
|
|
|
int b = k*16;
|
2013-06-27 00:19:40 +00:00
|
|
|
if ((i<6) && (j<5) )
|
|
|
|
strcpy (fg, Color_WHITE);
|
|
|
|
//if (i<2 && j<6 && k<13)
|
2013-05-23 00:26:48 +00:00
|
|
|
else r_cons_rgb_str (fg, 0, 0, 0, 0);
|
|
|
|
r_cons_rgb_str (bg, r, g, b, 1);
|
|
|
|
r_cons_printf ("%s%s rgb:%x%x%x "Color_RESET,
|
|
|
|
fg, bg, i, j, k);
|
|
|
|
//if (n++==7) {
|
|
|
|
if (n++==5) {
|
|
|
|
n = 0;
|
|
|
|
r_cons_newline();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-17 01:51:53 +00:00
|
|
|
R_API const char *r_cons_pal_get_color(int n) {
|
|
|
|
RConsPalette *pal = &(r_cons_singleton ()->pal);
|
|
|
|
ut8 *p = (ut8*)pal;
|
|
|
|
const char **color = NULL;
|
|
|
|
int i;
|
|
|
|
for (i=0; keys[i].name; i++) {
|
|
|
|
if (i<n) continue;
|
|
|
|
color = (const char**)(p + keys[i].off);
|
|
|
|
color = (const char**)*color;
|
|
|
|
return (const char *)color;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API void r_cons_pal_list (int rad) {
|
2013-05-23 00:26:48 +00:00
|
|
|
RConsPalette *pal = &(r_cons_singleton ()->pal);
|
|
|
|
ut8 *p = (ut8*)pal;
|
2013-07-17 01:51:53 +00:00
|
|
|
ut8 r, g, b;
|
|
|
|
char **color, rgbstr[32];;
|
2013-05-23 00:26:48 +00:00
|
|
|
int i;
|
|
|
|
for (i=0; keys[i].name; i++) {
|
2013-05-23 01:03:40 +00:00
|
|
|
color = (char**)(p + keys[i].off);
|
|
|
|
color = (char**)*color;
|
2013-07-17 01:51:53 +00:00
|
|
|
if (rad) {
|
|
|
|
r = g = b = 0;
|
|
|
|
r_cons_rgb_parse (color, &r, &g, &b, NULL);
|
|
|
|
rgbstr[0] = 0;
|
|
|
|
r_cons_rgb_str (rgbstr, r, g, b, 0);
|
|
|
|
r >>=4;
|
|
|
|
g >>=4;
|
|
|
|
b >>=4;
|
|
|
|
r_cons_printf ("ec %s %srgb:%x%x%x"Color_RESET " # vs %sTEST"Color_RESET"\n",
|
|
|
|
keys[i].name, color, r, g, b, rgbstr);
|
|
|
|
} else
|
2013-05-23 01:03:40 +00:00
|
|
|
r_cons_printf (" %s##"Color_RESET" %s\n",
|
|
|
|
(color)? (char*)color: "", keys[i].name);
|
2013-05-23 00:26:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API int r_cons_pal_set (const char *key, const char *val) {
|
2013-05-22 02:22:49 +00:00
|
|
|
int i;
|
|
|
|
char **p;
|
|
|
|
for (i=0; keys[i].name; i++) {
|
|
|
|
if (!strcmp (key, keys[i].name)) {
|
|
|
|
p = (char **)((char *)&(r_cons_singleton()->pal) + keys[i].off);
|
|
|
|
// free (*p);
|
|
|
|
*p = r_cons_pal_parse (val);
|
2013-05-23 00:26:48 +00:00
|
|
|
return R_TRUE;
|
2013-05-22 02:22:49 +00:00
|
|
|
}
|
|
|
|
}
|
2013-05-23 00:26:48 +00:00
|
|
|
return R_FALSE;
|
2013-05-22 02:22:49 +00:00
|
|
|
}
|
2013-07-03 15:43:20 +00:00
|
|
|
|
2013-07-17 01:51:53 +00:00
|
|
|
R_API const char *r_cons_pal_get_i (int n) {
|
|
|
|
int i;
|
|
|
|
for (i=0; i<n && keys[i].name; i++) {}
|
|
|
|
if (i==n) return keys[n].name;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-03 15:43:20 +00:00
|
|
|
R_API const char *r_cons_pal_get (const char *key) {
|
|
|
|
int i;
|
|
|
|
char **p;
|
|
|
|
for (i=0; keys[i].name; i++) {
|
|
|
|
if (!strcmp (key, keys[i].name)) {
|
|
|
|
p = (char **)((char *)&(r_cons_singleton()->pal) + keys[i].off);
|
|
|
|
if (!p) return "";
|
|
|
|
return *p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|