mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-03 02:41:08 +00:00
Handle shift-tab to toggle px/pxa in visual
- Support non-colorized pxa output
This commit is contained in:
parent
f390898d14
commit
39750e68f9
@ -3,6 +3,7 @@
|
||||
// > pxa
|
||||
#define append(x,y) { strcat(x,y);x += strlen(y); }
|
||||
static void annotated_hexdump(RCore *core, const char *str) {
|
||||
const int usecolor = r_config_get_i (core->config, "scr.color");
|
||||
const int COLS = 16;
|
||||
const ut8 *buf = core->block;
|
||||
int len = core->blocksize;
|
||||
@ -15,17 +16,18 @@ static void annotated_hexdump(RCore *core, const char *str) {
|
||||
char *note[COLS];
|
||||
int lnote[COLS];
|
||||
char bytes[1024];
|
||||
char chars[32];
|
||||
char chars[1024];
|
||||
int i, j, low, max, marks, tmarks, setcolor, hascolor;
|
||||
ut8 ch;
|
||||
const char *colors[8] = {
|
||||
Color_WHITE, Color_GREEN, Color_YELLOW, Color_RED,
|
||||
Color_CYAN, Color_MAGENTA, Color_GRAY, Color_BLUE
|
||||
};
|
||||
int col = core->print->col;
|
||||
|
||||
r_cons_strcat (Color_GREEN);
|
||||
if (usecolor) r_cons_strcat (Color_GREEN);
|
||||
r_cons_strcat ("- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF\n");
|
||||
r_cons_strcat (Color_RESET);
|
||||
if (usecolor) r_cons_strcat (Color_RESET);
|
||||
hascolor = 0;
|
||||
tmarks = marks = 0;
|
||||
for (i=0; i<rows; i++) {
|
||||
@ -59,15 +61,18 @@ static void annotated_hexdump(RCore *core, const char *str) {
|
||||
}
|
||||
if (setcolor && !hascolor) {
|
||||
hascolor = 1;
|
||||
if (usecolor) {
|
||||
#if 1
|
||||
append (ebytes, colors[tmarks%5]);
|
||||
append (ebytes, colors[tmarks%5]);
|
||||
#else
|
||||
|
||||
// TODO: too psicodelic!
|
||||
char *color = r_cons_color_random (0);
|
||||
append (ebytes, color);
|
||||
free (color);
|
||||
// psycodelia!
|
||||
char *color = r_cons_color_random (0);
|
||||
append (ebytes, color);
|
||||
free (color);
|
||||
#endif
|
||||
} else {
|
||||
append (ebytes, Color_INVERT);
|
||||
}
|
||||
}
|
||||
ch = buf[(i*COLS)+j];
|
||||
if (core->print->ocur!=-1) {
|
||||
@ -79,28 +84,36 @@ static void annotated_hexdump(RCore *core, const char *str) {
|
||||
if (core->print->cur_enabled) {
|
||||
int here = (i*COLS)+j;
|
||||
if (low==max) {
|
||||
if (low == here)
|
||||
if (low == here) {
|
||||
append (echars, Color_INVERT);
|
||||
append (ebytes, Color_INVERT);
|
||||
}
|
||||
} else {
|
||||
if (here >= low && here <max)
|
||||
if (here >= low && here <max) {
|
||||
append (ebytes, Color_INVERT);
|
||||
append (echars, Color_INVERT);
|
||||
}
|
||||
}
|
||||
}
|
||||
sprintf (ebytes, "%02x", ch);
|
||||
ebytes += strlen (ebytes);
|
||||
sprintf (echars, "%c", IS_PRINTABLE (ch)?ch:'.');
|
||||
echars++;
|
||||
if (core->print->cur_enabled) {
|
||||
if (max == ((i*COLS)+j)) {
|
||||
append (ebytes, Color_RESET);
|
||||
append (echars, Color_RESET);
|
||||
hascolor = 0;
|
||||
}
|
||||
}
|
||||
if (j<15&&j%2) append (ebytes, " ");
|
||||
|
||||
sprintf (echars, "%c", IS_PRINTABLE (ch)?ch:'.');
|
||||
echars++;
|
||||
|
||||
if (fend!=UT64_MAX && fend == addr+j+1) {
|
||||
append (ebytes, Color_RESET);
|
||||
if (usecolor) {
|
||||
append (ebytes, Color_RESET);
|
||||
append (echars, Color_RESET);
|
||||
}
|
||||
fend = UT64_MAX;
|
||||
hascolor = 0;
|
||||
}
|
||||
@ -125,14 +138,16 @@ static void annotated_hexdump(RCore *core, const char *str) {
|
||||
r_cons_newline ();
|
||||
marks = 0;
|
||||
}
|
||||
r_cons_strcat (Color_GREEN);
|
||||
r_cons_printf ("0x%08"PFMT64x" ", addr);
|
||||
r_cons_strcat (Color_RESET);
|
||||
// show bytes
|
||||
if (usecolor) r_cons_strcat (Color_GREEN);
|
||||
r_cons_printf ("0x%08"PFMT64x, addr);
|
||||
if (usecolor) r_cons_strcat (Color_RESET);
|
||||
r_cons_strcat ((col==1)?" |":" ");
|
||||
r_cons_strcat (bytes);
|
||||
r_cons_strcat (Color_RESET" ");
|
||||
r_cons_strcat (Color_RESET);
|
||||
r_cons_strcat ((col==1)?"| ":(col==2)?" |":" ");
|
||||
r_cons_strcat (chars);
|
||||
// show chars
|
||||
r_cons_strcat (Color_RESET);
|
||||
if (col==2) r_cons_strcat ("|");
|
||||
r_cons_newline ();
|
||||
addr += 16;
|
||||
}
|
||||
|
@ -240,6 +240,11 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
|
||||
}
|
||||
} else
|
||||
switch (ch) {
|
||||
case 90: // shift+tab
|
||||
if (!strcmp (printfmt[0], "x"))
|
||||
printfmt[0] = "pxa";
|
||||
else printfmt[0] = "x";
|
||||
break;
|
||||
case 9: // tab
|
||||
{ // XXX: unify diff mode detection
|
||||
ut64 f = r_config_get_i (core->config, "diff.from");
|
||||
@ -811,31 +816,30 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
|
||||
" _ enter the hud\n"
|
||||
" . seek to program counter\n"
|
||||
" / in cursor mode search in current block\n"
|
||||
" R randomize color palette (ecr)\n"
|
||||
" :cmd run radare command\n"
|
||||
" ;[-]cmt add/remove comment\n"
|
||||
" /*+-[] change block size, [] = resize hex.cols\n"
|
||||
" >||< seek aligned to block size\n"
|
||||
" iaA (i)nsert hex, (a)ssemble code, visual (A)ssembler\n"
|
||||
" i/a/A (i)nsert hex, (a)ssemble code, visual (A)ssembler\n"
|
||||
" b/B toggle breakpoint / automatic block size\n"
|
||||
" hjkl move around (or HJKL) (left-down-up-right)\n"
|
||||
" pP rotate print modes (hex, disasm, debug, words, buf)\n"
|
||||
" cC toggle (c)ursor and (C)olors\n"
|
||||
" c/C toggle (c)ursor and (C)olors\n"
|
||||
" d[f?] define function, data, code, ..\n"
|
||||
" D enter visual diff mode (set diff.from/to)\n"
|
||||
" e edit eval configuration variables\n"
|
||||
" f/F set/unset flag\n"
|
||||
" gG go seek to begin and end of file (0-$s)\n"
|
||||
" hjkl move around (or HJKL) (left-down-up-right)\n"
|
||||
" mK/'K mark/go to Key (any key)\n"
|
||||
" M walk the mounted filesystems\n"
|
||||
" n/N seek next/prev function/flag/hit (scr.nkey)\n"
|
||||
" p/P rotate print modes (hex, disasm, debug, words, buf)\n"
|
||||
" q back to radare shell\n"
|
||||
" R randomize color palette (ecr)\n"
|
||||
" sS step / step over\n"
|
||||
" t track flags (browse symbols, functions..)\n"
|
||||
" T browse anal info and comments\n"
|
||||
" v visual code analysis menu\n"
|
||||
" V view graph using cmd.graph (agv?)\n"
|
||||
" W open web ui\n"
|
||||
" V/W (V)iew graph using cmd.graph (agv?), open (W)ebUI\n"
|
||||
" uU undo/redo seek\n"
|
||||
" x show xrefs to seek between them\n"
|
||||
" yY copy and paste selection\n"
|
||||
|
Loading…
Reference in New Issue
Block a user