mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-24 05:40:10 +00:00
Added colorization to pdn and added a dead code warning if all the bytes in a method are not consumed during analysis.
This commit is contained in:
parent
4e8ab49948
commit
6bc694f873
@ -7,7 +7,13 @@
|
||||
#include <r_io.h>
|
||||
#include "../config.h"
|
||||
|
||||
#define IFDBG if(0)
|
||||
#ifdef IFDBG
|
||||
#undef IFDBG
|
||||
#endif
|
||||
|
||||
#define DO_THE_DBG 0
|
||||
#define IFDBG if(DO_THE_DBG)
|
||||
#define IFINT if(0)
|
||||
|
||||
|
||||
static void r_anal_ex_perform_pre_anal(RAnal *anal, RAnalState *state, ut64 addr);
|
||||
|
@ -24,7 +24,12 @@
|
||||
#undef R_IPI
|
||||
#define R_IPI
|
||||
|
||||
#define IFDBG if(0)
|
||||
#ifdef IFDBG
|
||||
#undef IFDBG
|
||||
#endif
|
||||
|
||||
#define DO_THE_DBG 0
|
||||
#define IFDBG if(DO_THE_DBG)
|
||||
#define IFINT if(0)
|
||||
|
||||
struct r_anal_java_access_t;
|
||||
@ -482,7 +487,9 @@ static int java_print_ssa_fcn (RAnal *anal, char *addrs) {
|
||||
static int analyze_from_code_buffer ( RAnal *anal, RAnalFunction *fcn, ut64 addr, const ut8 *code_buf, ut64 code_length ) {
|
||||
|
||||
char gen_name[1025];
|
||||
|
||||
RListIter *bb_iter;
|
||||
RAnalBlock *bb;
|
||||
ut64 actual_size = 0;
|
||||
RAnalState *state = NULL;
|
||||
int result = R_ANAL_RET_ERROR;
|
||||
RAnalJavaLinearSweep *nodes;
|
||||
@ -505,14 +512,23 @@ static int analyze_from_code_buffer ( RAnal *anal, RAnalFunction *fcn, ut64 addr
|
||||
state->user_state = nodes;
|
||||
|
||||
result = analyze_method (anal, fcn, state);
|
||||
r_list_foreach (fcn->bbs, bb_iter, bb) {
|
||||
actual_size += bb->size;
|
||||
}
|
||||
|
||||
fcn->size = state->bytes_consumed;
|
||||
|
||||
result = state->anal_ret_val;
|
||||
|
||||
r_list_free (nodes->cfg_node_addrs);
|
||||
free (nodes);
|
||||
r_anal_state_free (state);
|
||||
IFDBG eprintf ("Completed analysing code from buffer, name: %s, desc: %s\n", fcn->name, fcn->dsc);
|
||||
|
||||
if (fcn->size != code_length) {
|
||||
r_cons_printf ("WARNING Analysis of %s Incorrect: Code Length: 0x%"PFMT64x", Function size reported 0x%"PFMT64x"\n", fcn->name, code_length, fcn->size);
|
||||
r_cons_printf ("Deadcode detected, setting code length too: 0x%"PFMT64x"\n", code_length);
|
||||
fcn->size = code_length;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -729,7 +745,7 @@ static int java_switch_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data,
|
||||
//caseop = r_anal_switch_op_add_case(op->switch_op, addr+default_loc, -1, addr+offset);
|
||||
for (cur_case = 0; cur_case <= max_val - min_val; pos+=4, cur_case++) {
|
||||
//ut32 value = (ut32)(UINT (data, pos));
|
||||
ut32 offset = (ut32)(R_BIN_JAVA_UINT (data, pos));
|
||||
int offset = (int)(ut32)(R_BIN_JAVA_UINT (data, pos));
|
||||
IFDBG eprintf ("offset value: 0x%04x, interpretted addr case: %d offset: 0x%04"PFMT64x"\n", offset, cur_case+min_val, addr+offset);
|
||||
caseop = r_anal_switch_op_add_case (op->switch_op, addr+pos, cur_case+min_val, addr+offset);
|
||||
caseop->bb_ref_to = addr+offset;
|
||||
@ -772,11 +788,11 @@ static int java_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
|
||||
}
|
||||
|
||||
if ( op->type == R_ANAL_OP_TYPE_CJMP ) {
|
||||
op->jump = addr + (int)(short)(USHORT (data, 1));
|
||||
op->jump = addr + (short)(USHORT (data, 1));
|
||||
op->fail = addr + sz;
|
||||
IFDBG eprintf ("%s jmpto 0x%04"PFMT64x" failto 0x%04"PFMT64x".\n", JAVA_OPS[op_byte].name, op->jump, op->fail);
|
||||
} else if ( op->type == R_ANAL_OP_TYPE_JMP ) {
|
||||
op->jump = addr + (int)(short)(USHORT (data, 1));
|
||||
op->jump = addr + (short)(USHORT (data, 1));
|
||||
IFDBG eprintf ("%s jmpto 0x%04"PFMT64x".\n", JAVA_OPS[op_byte].name, op->jump);
|
||||
} else if ( (op->type & R_ANAL_OP_TYPE_CALL) == R_ANAL_OP_TYPE_CALL ) {
|
||||
//op->jump = addr + (int)(short)(USHORT (data, 1));
|
||||
|
@ -6,7 +6,13 @@
|
||||
#include <r_io.h>
|
||||
#include "../config.h"
|
||||
|
||||
#define IFDBG if(0)
|
||||
#ifdef IFDBG
|
||||
#undef IFDBG
|
||||
#endif
|
||||
|
||||
#define DO_THE_DBG 0
|
||||
#define IFDBG if(DO_THE_DBG)
|
||||
#define IFINT if(0)
|
||||
|
||||
R_API RAnalState * r_anal_state_new (ut64 start, ut8* buffer, ut64 len) {
|
||||
RAnalState *state = R_NEW0 (RAnalState);
|
||||
|
@ -24,8 +24,11 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
//eprintf("Handling: %s disasm.\n", b->cur.file);
|
||||
}
|
||||
}
|
||||
return op->size = r_java_disasm (obj, a->pc, buf,
|
||||
|
||||
op->size = r_java_disasm (obj, a->pc, buf,
|
||||
op->buf_asm, sizeof (op->buf_asm));
|
||||
a->pc += op->size;
|
||||
return op->size;
|
||||
}
|
||||
|
||||
static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
|
||||
|
@ -436,6 +436,9 @@ static int pdi(RCore *core, int l, int len, int ilen) {
|
||||
}
|
||||
|
||||
static int cmd_print(void *data, const char *input) {
|
||||
RAsmOp asmop = {0};
|
||||
RAnalOp analop = {0};
|
||||
|
||||
RCore *core = (RCore *)data;
|
||||
int mode, w, p, i, l, len, total[10];
|
||||
ut64 off, from, to, at, ate, piece;
|
||||
@ -845,6 +848,10 @@ static int cmd_print(void *data, const char *input) {
|
||||
old_arch = strdup (r_config_get (core->config, "asm.arch"));
|
||||
segoff = r_config_get_i (core->config, "asm.segoff");
|
||||
old_bits = r_config_get_i (core->config, "asm.bits");
|
||||
int show_color = r_config_get_i (core->config, "scr.color");
|
||||
int colorop = r_config_get_i (core->config, "scr.colorops");
|
||||
|
||||
|
||||
// XXX - this is necessay b/c radare will automatically
|
||||
// swap flags if arch is x86 and bits == 16 see: __setsegoff in config.c
|
||||
|
||||
@ -902,23 +909,33 @@ static int cmd_print(void *data, const char *input) {
|
||||
|
||||
if (bwdhits) {
|
||||
int result = 0;
|
||||
RAsmOp asmop;
|
||||
memset(&asmop, 0, sizeof (RAnalOp));
|
||||
buf = malloc (1024);
|
||||
|
||||
r_list_foreach (bwdhits, iter, hit) {
|
||||
r_core_read_at (core, hit->addr, buf, hit->len);
|
||||
result = r_asm_disassemble (core->assembler, &asmop, buf, hit->len);
|
||||
r_anal_op (core->anal, &analop, hit->addr, buf, hit->len);
|
||||
if (result<1) {
|
||||
const char *owallawalla = "????";
|
||||
char *hex_str = r_hex_bin2strdup (buf, hit->len);
|
||||
if (hex_str == NULL) hex_str = (char *)owallawalla;
|
||||
if (show_color & colorop) r_cons_strcat (r_print_color_op_type (core->print, analop.type));
|
||||
r_cons_printf ("0x%08"PFMT64x" %16s <invalid>\n", hit->addr, hex_str);
|
||||
if (show_color & colorop) r_cons_strcat (Color_RESET);
|
||||
if (hex_str && hex_str != owallawalla) free(hex_str);
|
||||
} else if (show_color & colorop) {
|
||||
char *buf_asm = r_print_colorize_opcode (asmop.buf_asm, core->cons->pal.reg, core->cons->pal.num);
|
||||
char *buf_hex = r_print_colorize_opcode (asmop.buf_hex, core->cons->pal.reg, core->cons->pal.num);
|
||||
const char * otype = r_print_color_op_type (core->print, analop.type);
|
||||
r_cons_printf ("0x%08"PFMT64x" %s%16s %s%s\n",
|
||||
hit->addr, otype,buf_hex, buf_asm, Color_RESET);
|
||||
free (buf_asm);
|
||||
free (buf_hex);
|
||||
} else {
|
||||
r_cons_printf ("0x%08"PFMT64x" %16s %s\n",
|
||||
hit->addr, asmop.buf_hex, asmop.buf_asm);
|
||||
}
|
||||
r_anal_op_fini (&analop);
|
||||
}
|
||||
|
||||
r_list_free (bwdhits);
|
||||
@ -929,7 +946,6 @@ static int cmd_print(void *data, const char *input) {
|
||||
}
|
||||
pd_result = 0;
|
||||
} else {
|
||||
RAsmOp asmop;
|
||||
ut8 *buf = core->block;
|
||||
|
||||
// init larger block
|
||||
@ -942,31 +958,49 @@ static int cmd_print(void *data, const char *input) {
|
||||
}
|
||||
|
||||
if (buf) {
|
||||
ut64 old_pc = core->assembler->pc;
|
||||
ut8 go_by_instr = input[0] == 'd';
|
||||
ut32 pdn_offset = 0;
|
||||
ut64 instr_cnt = 0;
|
||||
|
||||
int dresult = 0;
|
||||
|
||||
core->assembler->pc = core->offset;
|
||||
if (core->anal && core->anal->cur && core->anal->cur->reset_counter ) {
|
||||
core->anal->cur->reset_counter (core->anal, core->offset);
|
||||
}
|
||||
for (pdn_offset=0; pdn_offset < use_blocksize; ) {
|
||||
dresult = r_asm_disassemble (core->assembler, &asmop, buf+pdn_offset, use_blocksize-pdn_offset);
|
||||
r_anal_op (core->anal, &analop, core->offset+pdn_offset, asmop.buf, asmop.size);
|
||||
if (dresult<1) {
|
||||
const char *owallawalla = "????";
|
||||
char *hex_str = r_hex_bin2strdup (buf+pdn_offset, 1);
|
||||
if (hex_str == NULL) hex_str = (char*)owallawalla;
|
||||
if (show_color & colorop) r_cons_strcat (r_print_color_op_type (core->print, analop.type));
|
||||
r_cons_printf ("0x%08"PFMT64x" %16s <invalid>\n", core->offset+pdn_offset, hex_str);
|
||||
if (show_color & colorop) r_cons_strcat (Color_RESET);
|
||||
pdn_offset += 1;
|
||||
instr_cnt += asmop.size;
|
||||
if (hex_str && hex_str != owallawalla) free (hex_str);
|
||||
|
||||
} else if (show_color & colorop) {
|
||||
char *buf_asm = r_print_colorize_opcode (asmop.buf_asm, core->cons->pal.reg, core->cons->pal.num);
|
||||
char *buf_hex = r_print_colorize_opcode (asmop.buf_hex, core->cons->pal.reg, core->cons->pal.num);
|
||||
const char * otype = r_print_color_op_type (core->print, analop.type);
|
||||
r_cons_printf ("0x%08"PFMT64x" %16s %s%s%s\n",
|
||||
core->offset+pdn_offset, buf_hex, otype, buf_asm, Color_RESET);
|
||||
pdn_offset += (go_by_instr? asmop.size: 1);
|
||||
free (buf_asm);
|
||||
free (buf_hex);
|
||||
} else {
|
||||
r_cons_printf ("0x%08"PFMT64x" %16s %s\n",
|
||||
core->offset+pdn_offset, asmop.buf_hex, asmop.buf_asm);
|
||||
pdn_offset += (go_by_instr? asmop.size: 1);
|
||||
}
|
||||
r_anal_op_fini (&analop);
|
||||
}
|
||||
if (buf != core->block) free (buf);
|
||||
pd_result = R_TRUE;
|
||||
core->assembler->pc = old_pc;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -1124,7 +1158,7 @@ static int cmd_print(void *data, const char *input) {
|
||||
RListIter *iter;
|
||||
RCoreAsmHit *hit;
|
||||
ut8 *block = NULL;
|
||||
|
||||
|
||||
if (bw_disassemble) {
|
||||
block = malloc (core->blocksize);
|
||||
l = -l;
|
||||
|
@ -126,17 +126,14 @@ typedef struct r_disam_options_t {
|
||||
int len;
|
||||
|
||||
int counter;
|
||||
|
||||
} RDisasmState;
|
||||
|
||||
static void handle_reflines_init (RCore *core, RDisasmState *ds);
|
||||
static void handle_add_show_color ( RCore *core, RDisasmState *ds);
|
||||
static RDisasmState * handle_init_ds (RCore * core);
|
||||
static void handle_set_pre (RDisasmState *ds, const char * str);
|
||||
static void handle_build_op_str (RCore *core, RDisasmState *ds);
|
||||
static char *filter_refline2(RCore *core, const char *str);
|
||||
static char *filter_refline(RCore *core, const char *str);
|
||||
static void colorize_opcode (char *p, const char *reg, const char *num);
|
||||
static void handle_show_xrefs (RCore *core, RDisasmState *ds);
|
||||
static void handle_atabs_option(RCore *core, RDisasmState *ds);
|
||||
static void handle_show_functions (RCore *core, RDisasmState *ds);
|
||||
@ -179,81 +176,34 @@ static int cmpaddr (void *_a, void *_b) {
|
||||
return (a->addr > b->addr);
|
||||
}
|
||||
|
||||
static void handle_add_show_color ( RCore *core, RDisasmState *ds) {
|
||||
if (ds->show_color) {
|
||||
switch (ds->analop.type) {
|
||||
case R_ANAL_OP_TYPE_NOP:
|
||||
r_cons_strcat (ds->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 (ds->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:
|
||||
case R_ANAL_OP_TYPE_SHL:
|
||||
case R_ANAL_OP_TYPE_SHR:
|
||||
case R_ANAL_OP_TYPE_ROL:
|
||||
case R_ANAL_OP_TYPE_ROR:
|
||||
r_cons_strcat (ds->color_bin);
|
||||
break;
|
||||
case R_ANAL_OP_TYPE_JMP:
|
||||
case R_ANAL_OP_TYPE_UJMP:
|
||||
r_cons_strcat (ds->color_jmp);
|
||||
break;
|
||||
case R_ANAL_OP_TYPE_CJMP:
|
||||
case R_ANAL_OP_TYPE_UCJMP:
|
||||
r_cons_strcat (ds->color_cjmp);
|
||||
break;
|
||||
case R_ANAL_OP_TYPE_CMP:
|
||||
case R_ANAL_OP_TYPE_ACMP:
|
||||
r_cons_strcat (ds->color_cmp);
|
||||
break;
|
||||
case R_ANAL_OP_TYPE_UCALL:
|
||||
case R_ANAL_OP_TYPE_UCCALL:
|
||||
case R_ANAL_OP_TYPE_CALL:
|
||||
case R_ANAL_OP_TYPE_CCALL:
|
||||
r_cons_strcat (ds->color_call);
|
||||
break;
|
||||
case R_ANAL_OP_TYPE_SWI:
|
||||
r_cons_strcat (ds->color_swi);
|
||||
break;
|
||||
case R_ANAL_OP_TYPE_ILL:
|
||||
case R_ANAL_OP_TYPE_TRAP:
|
||||
r_cons_strcat (ds->color_trap);
|
||||
break;
|
||||
case R_ANAL_OP_TYPE_CRET:
|
||||
case R_ANAL_OP_TYPE_RET:
|
||||
r_cons_strcat (ds->color_ret);
|
||||
break;
|
||||
case R_ANAL_OP_TYPE_PUSH:
|
||||
case R_ANAL_OP_TYPE_UPUSH:
|
||||
case R_ANAL_OP_TYPE_LOAD:
|
||||
r_cons_strcat (ds->color_push);
|
||||
break;
|
||||
case R_ANAL_OP_TYPE_POP:
|
||||
case R_ANAL_OP_TYPE_STORE:
|
||||
r_cons_strcat (ds->color_pop);
|
||||
break;
|
||||
case R_ANAL_OP_TYPE_NULL:
|
||||
r_cons_strcat (ds->color_other);
|
||||
break;
|
||||
case R_ANAL_OP_TYPE_UNK:
|
||||
r_cons_strcat (ds->color_invalid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static RDisasmState * handle_init_ds (RCore * core) {
|
||||
RDisasmState * ds = R_NEW0(RDisasmState);
|
||||
ds->pal_comment = core->cons->pal.comment;
|
||||
#define P(x) (core->cons && core->cons->pal.x)? core->cons->pal.x
|
||||
|
||||
ds->color_comment = P(comment): Color_CYAN;
|
||||
ds->color_fname = P(fname): Color_RED;
|
||||
ds->color_floc = P(floc): Color_MAGENTA;
|
||||
ds->color_fline = P(fline): Color_CYAN;
|
||||
ds->color_flow = P(flow): Color_CYAN;
|
||||
ds->color_flag = P(flag): Color_CYAN;
|
||||
ds->color_label = P(label): Color_CYAN;
|
||||
ds->color_other = P(other): Color_WHITE;
|
||||
ds->color_nop = P(nop): Color_BLUE;
|
||||
ds->color_bin = P(bin): Color_YELLOW;
|
||||
ds->color_math = P(math): Color_YELLOW;
|
||||
ds->color_jmp = P(jmp): Color_GREEN;
|
||||
ds->color_cjmp = P(cjmp): Color_GREEN;
|
||||
ds->color_call = P(call): Color_BGREEN;
|
||||
ds->color_cmp = P(cmp): Color_MAGENTA;
|
||||
ds->color_swi = P(swi): Color_MAGENTA;
|
||||
ds->color_trap = P(trap): Color_BRED;
|
||||
ds->color_ret = P(ret): Color_RED;
|
||||
ds->color_push = P(push): Color_YELLOW;
|
||||
ds->color_pop = P(pop): Color_BYELLOW;
|
||||
ds->color_reg = P(reg): Color_YELLOW;
|
||||
ds->color_num = P(num): Color_YELLOW;
|
||||
ds->color_invalid = P(invalid): Color_BRED;
|
||||
ds->use_esil = r_config_get_i (core->config, "asm.esil");
|
||||
ds->show_color = r_config_get_i (core->config, "scr.color");
|
||||
ds->colorop = r_config_get_i (core->config, "scr.colorops");
|
||||
@ -297,29 +247,7 @@ static RDisasmState * handle_init_ds (RCore * core) {
|
||||
ds->oldbits = 0;
|
||||
ds->ocols = 0;
|
||||
ds->lcols = 0;
|
||||
ds->color_comment = P(comment): Color_CYAN;
|
||||
ds->color_fname = P(fname): Color_RED;
|
||||
ds->color_floc = P(floc): Color_MAGENTA;
|
||||
ds->color_fline = P(fline): Color_CYAN;
|
||||
ds->color_flow = P(flow): Color_CYAN;
|
||||
ds->color_flag = P(flag): Color_CYAN;
|
||||
ds->color_label = P(label): Color_CYAN;
|
||||
ds->color_other = P(other): Color_WHITE;
|
||||
ds->color_nop = P(nop): Color_BLUE;
|
||||
ds->color_bin = P(bin): Color_YELLOW;
|
||||
ds->color_math = P(math): Color_YELLOW;
|
||||
ds->color_jmp = P(jmp): Color_GREEN;
|
||||
ds->color_cjmp = P(cjmp): Color_GREEN;
|
||||
ds->color_call = P(call): Color_BGREEN;
|
||||
ds->color_cmp = P(cmp): Color_MAGENTA;
|
||||
ds->color_swi = P(swi): Color_MAGENTA;
|
||||
ds->color_trap = P(trap): Color_BRED;
|
||||
ds->color_ret = P(ret): Color_RED;
|
||||
ds->color_push = P(push): Color_YELLOW;
|
||||
ds->color_pop = P(pop): Color_BYELLOW;
|
||||
ds->color_reg = P(reg): Color_YELLOW;
|
||||
ds->color_num = P(num): Color_YELLOW;
|
||||
ds->color_invalid = P(invalid): Color_BRED;
|
||||
|
||||
|
||||
if (r_config_get_i (core->config, "asm.linesstyle"))
|
||||
ds->linesopts |= R_ANAL_REFLINE_TYPE_STYLE;
|
||||
@ -402,11 +330,19 @@ static void handle_set_pre (RDisasmState *ds, const char * str) {
|
||||
}
|
||||
|
||||
static void handle_build_op_str (RCore *core, RDisasmState *ds) {
|
||||
char *asm_str = NULL;
|
||||
|
||||
if (ds->show_color && ds->colorop) {
|
||||
r_cons_strcat (r_print_color_op_type (core->print, ds->analop.type));
|
||||
asm_str = r_print_colorize_opcode (ds->asmop.buf_asm, ds->color_reg, ds->color_num);
|
||||
} else
|
||||
asm_str = strdup (ds->asmop.buf_asm);
|
||||
|
||||
if (ds->decode) {
|
||||
char *tmpopstr = r_anal_op_to_string (core->anal, &ds->analop);
|
||||
// TODO: Use data from code analysis..not raw ds->analop here
|
||||
// if we want to get more information
|
||||
ds->opstr = tmpopstr? tmpopstr: strdup (ds->asmop.buf_asm);
|
||||
ds->opstr = tmpopstr? tmpopstr: strdup (asm_str);
|
||||
}
|
||||
if (ds->hint && ds->hint->opcode) {
|
||||
free (ds->opstr);
|
||||
@ -428,14 +364,14 @@ static void handle_build_op_str (RCore *core, RDisasmState *ds) {
|
||||
}
|
||||
}
|
||||
r_parse_filter (core->parser, core->flags,
|
||||
ds->opstr? ds->opstr: ds->asmop.buf_asm, ds->str, sizeof (ds->str));
|
||||
ds->opstr? ds->opstr: asm_str, ds->str, sizeof (ds->str));
|
||||
core->parser->flagspace = ofs;
|
||||
free (ds->opstr);
|
||||
ds->opstr = strdup (ds->str);
|
||||
core->parser->flagspace = ofs; // ???
|
||||
} else {
|
||||
if (!ds->opstr)
|
||||
ds->opstr = strdup (ds->asmop.buf_asm);
|
||||
ds->opstr = strdup (asm_str);
|
||||
}
|
||||
if (ds->varsub) {
|
||||
RAnalFunction *f = r_anal_fcn_find (core->anal,
|
||||
@ -459,6 +395,7 @@ static void handle_build_op_str (RCore *core, RDisasmState *ds) {
|
||||
ds->opstr = p;
|
||||
}
|
||||
}
|
||||
free (asm_str);
|
||||
}
|
||||
|
||||
R_API RAnalHint *r_core_hint_begin (RCore *core, RAnalHint* hint, ut64 at) {
|
||||
@ -563,81 +500,6 @@ static char *filter_refline(RCore *core, const char *str) {
|
||||
}
|
||||
#endif
|
||||
|
||||
static void colorize_opcode (char *p, const char *reg, const char *num) {
|
||||
int i, j, k, is_mod, is_arg = 0;
|
||||
int is_jmp = (*p == 'j' || ((*p == 'c') && (p[1] == 'a')))? 1: 0;
|
||||
char *o;
|
||||
if (is_jmp)
|
||||
return;
|
||||
o = malloc (1024);
|
||||
for (i=j=0; p[i]; i++,j++) {
|
||||
/* colorize numbers */
|
||||
switch (p[i]) {
|
||||
case 0x1b:
|
||||
/* skip until 'm' */
|
||||
for (++i;p[i] && p[i]!='m'; i++)
|
||||
o[j] = p[i];
|
||||
continue;
|
||||
case '+':
|
||||
case '-':
|
||||
case '/':
|
||||
case '>':
|
||||
case '<':
|
||||
case '(':
|
||||
case ')':
|
||||
case '*':
|
||||
case '%':
|
||||
case ']':
|
||||
case '[':
|
||||
case ',':
|
||||
if (is_arg) {
|
||||
strcpy (o+j, Color_RESET);
|
||||
j += strlen (Color_RESET);
|
||||
o[j++] = p[i];
|
||||
if (p[i]=='$' || ((p[i] > '0') && (p[i] < '9'))) {
|
||||
strcpy (o+j, num);
|
||||
j += strlen (num)-1;
|
||||
} else {
|
||||
strcpy (o+j, reg);
|
||||
j += strlen (reg)-1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case ' ':
|
||||
is_arg = 1;
|
||||
// find if next ',' before ' ' is found
|
||||
is_mod = 0;
|
||||
for (k = i+1; p[k]; k++) {
|
||||
if (p[k]==' ')
|
||||
break;
|
||||
if (p[k]==',') {
|
||||
is_mod = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!p[k]) is_mod = 1;
|
||||
if (!is_jmp && is_mod) {
|
||||
// COLOR FOR REGISTER
|
||||
strcpy (o+j, reg);
|
||||
j += strlen (reg);
|
||||
}
|
||||
break;
|
||||
case '0':
|
||||
if (!is_jmp && p[i+1]== 'x') {
|
||||
strcpy (o+j, num);
|
||||
j += strlen (num);
|
||||
}
|
||||
break;
|
||||
}
|
||||
o[j] = p[i];
|
||||
}
|
||||
// decolorize at the end
|
||||
strcpy (o+j, Color_RESET);
|
||||
strcpy (p, o); // may overflow .. but shouldnt because asm.buf_asm is big enought
|
||||
free (o);
|
||||
}
|
||||
|
||||
static void handle_show_xrefs (RCore *core, RDisasmState *ds) {
|
||||
// Show xrefs
|
||||
if (ds->show_xrefs) {
|
||||
@ -1067,11 +929,6 @@ static void handle_print_trace (RCore *core, RDisasmState *ds) {
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_colorize_opcode (RCore *core, RDisasmState *ds) {
|
||||
if (ds->show_color && ds->colorop)
|
||||
colorize_opcode (ds->asmop.buf_asm, ds->color_reg, ds->color_num);
|
||||
}
|
||||
|
||||
static void handle_adistrick_comments (RCore *core, RDisasmState *ds) {
|
||||
if (ds->adistrick)
|
||||
ds->middle = r_anal_reflines_middle (core->anal,
|
||||
@ -1682,7 +1539,7 @@ toro:
|
||||
goto retry;
|
||||
}
|
||||
handle_atabs_option (core, ds);
|
||||
handle_colorize_opcode (core, ds);
|
||||
//handle_colorize_opcode (core, ds);
|
||||
// TODO: store previous oplen in core->dec
|
||||
if (core->inc == 0)
|
||||
core->inc = ds->oplen;
|
||||
@ -1721,7 +1578,6 @@ toro:
|
||||
handle_print_show_cursor (core, ds);
|
||||
handle_print_show_bytes (core, ds);
|
||||
handle_print_lines_right (core, ds);
|
||||
handle_add_show_color (core, ds);
|
||||
handle_build_op_str (core, ds);
|
||||
handle_print_opstr (core, ds);
|
||||
handle_print_fcn_name (core, ds);
|
||||
@ -2039,7 +1895,7 @@ R_API int r_core_print_fcn_disasm(RPrint *p, RCore *core, ut64 addr, int l, int
|
||||
handle_show_comments_right (core, ds);
|
||||
ret = perform_disassembly (core, ds, buf+idx, len - bb_size_consumed);
|
||||
handle_atabs_option (core, ds);
|
||||
handle_colorize_opcode (core, ds);
|
||||
//handle_colorize_opcode (core, ds);
|
||||
// TODO: store previous oplen in core->dec
|
||||
if (core->inc == 0) core->inc = ds->oplen;
|
||||
|
||||
@ -2076,7 +1932,6 @@ R_API int r_core_print_fcn_disasm(RPrint *p, RCore *core, ut64 addr, int l, int
|
||||
handle_print_show_cursor (core, ds);
|
||||
handle_print_show_bytes (core, ds);
|
||||
handle_print_lines_right (core, ds);
|
||||
handle_add_show_color (core, ds);
|
||||
handle_build_op_str (core, ds);
|
||||
handle_print_opstr (core, ds);
|
||||
handle_print_fcn_name (core, ds);
|
||||
|
@ -92,6 +92,8 @@ R_API void r_print_progressbar(RPrint *pr, int pc, int _cols);
|
||||
R_API char * r_print_randomart(const ut8 *dgst_raw, ut32 dgst_raw_len, ut64 addr);
|
||||
R_API void r_print_2bpp_row(RPrint *p, ut8 *buf);
|
||||
R_API void r_print_2bpp_tiles(RPrint *p, ut8 *buf, ut32 tiles);
|
||||
R_API char * r_print_colorize_opcode (char *p, const char *reg, const char *num);
|
||||
R_API const char * r_print_color_op_type ( RPrint *p, ut64 anal_type);
|
||||
// WIP
|
||||
R_API int r_print_unpack7bit(const char *src, char *dest);
|
||||
R_API int r_print_pack7bit(const char *src, char *dest);
|
||||
|
@ -1,5 +1,6 @@
|
||||
/* radare - LGPL - Copyright 2007-2014 - pancake */
|
||||
|
||||
#include "r_anal.h"
|
||||
#include "r_cons.h"
|
||||
#include "r_print.h"
|
||||
#include "r_util.h"
|
||||
@ -802,3 +803,169 @@ R_API void r_print_2bpp_tiles(RPrint *p, ut8 *buf, ut32 tiles)
|
||||
p->printf(Color_RESET"\n");
|
||||
}
|
||||
}
|
||||
|
||||
R_API const char * r_print_color_op_type ( RPrint *p, ut64 anal_type) {
|
||||
|
||||
switch (anal_type) {
|
||||
case R_ANAL_OP_TYPE_NOP:
|
||||
return p->cons->pal.nop;
|
||||
case R_ANAL_OP_TYPE_ADD:
|
||||
case R_ANAL_OP_TYPE_SUB:
|
||||
case R_ANAL_OP_TYPE_MUL:
|
||||
case R_ANAL_OP_TYPE_DIV:
|
||||
return p->cons->pal.math;
|
||||
case R_ANAL_OP_TYPE_AND:
|
||||
case R_ANAL_OP_TYPE_OR:
|
||||
case R_ANAL_OP_TYPE_XOR:
|
||||
case R_ANAL_OP_TYPE_NOT:
|
||||
case R_ANAL_OP_TYPE_SHL:
|
||||
case R_ANAL_OP_TYPE_SHR:
|
||||
case R_ANAL_OP_TYPE_ROL:
|
||||
case R_ANAL_OP_TYPE_ROR:
|
||||
return p->cons->pal.bin;
|
||||
case R_ANAL_OP_TYPE_JMP:
|
||||
case R_ANAL_OP_TYPE_UJMP:
|
||||
return p->cons->pal.jmp;
|
||||
case R_ANAL_OP_TYPE_CJMP:
|
||||
case R_ANAL_OP_TYPE_UCJMP:
|
||||
return p->cons->pal.cjmp;
|
||||
case R_ANAL_OP_TYPE_CMP:
|
||||
case R_ANAL_OP_TYPE_ACMP:
|
||||
return p->cons->pal.cmp;
|
||||
case R_ANAL_OP_TYPE_UCALL:
|
||||
case R_ANAL_OP_TYPE_UCCALL:
|
||||
case R_ANAL_OP_TYPE_CALL:
|
||||
case R_ANAL_OP_TYPE_CCALL:
|
||||
return p->cons->pal.call;
|
||||
case R_ANAL_OP_TYPE_SWI:
|
||||
return p->cons->pal.swi;
|
||||
case R_ANAL_OP_TYPE_ILL:
|
||||
case R_ANAL_OP_TYPE_TRAP:
|
||||
return p->cons->pal.trap;
|
||||
case R_ANAL_OP_TYPE_CRET:
|
||||
case R_ANAL_OP_TYPE_RET:
|
||||
return p->cons->pal.ret;
|
||||
case R_ANAL_OP_TYPE_PUSH:
|
||||
case R_ANAL_OP_TYPE_UPUSH:
|
||||
case R_ANAL_OP_TYPE_LOAD:
|
||||
return p->cons->pal.push;
|
||||
case R_ANAL_OP_TYPE_POP:
|
||||
case R_ANAL_OP_TYPE_STORE:
|
||||
return p->cons->pal.pop;
|
||||
case R_ANAL_OP_TYPE_NULL:
|
||||
return p->cons->pal.other;
|
||||
case R_ANAL_OP_TYPE_UNK:
|
||||
default:
|
||||
return p->cons->pal.invalid;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static char * realloc_color_buffer (char *buf, ut32 *size, ut32 add_to) {
|
||||
char *t_o = buf;
|
||||
buf = malloc (*size+add_to);
|
||||
memcpy (buf, t_o, *size);
|
||||
*size += add_to;
|
||||
free (t_o);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
R_API char * r_print_colorize_opcode (char *p, const char *reg, const char *num) {
|
||||
int i, j, k, is_mod, is_arg = 0;
|
||||
ut32 c_reset = strlen (Color_RESET);
|
||||
int is_jmp = p && (*p == 'j' || ((*p == 'c') && (p[1] == 'a')))? 1: 0;
|
||||
ut32 opcode_sz = strlen (p)*10 + 1, bytes_consumed;
|
||||
char *o;
|
||||
|
||||
if (is_jmp)
|
||||
return strdup (p);
|
||||
|
||||
o = malloc (opcode_sz);
|
||||
|
||||
for (i=j=0; p[i]; i++,j++) {
|
||||
/* colorize numbers */
|
||||
if (j+100 >= opcode_sz) {
|
||||
o = realloc_color_buffer (o, &opcode_sz, 100);
|
||||
}
|
||||
switch (p[i]) {
|
||||
case 0x1b:
|
||||
/* skip until 'm' */
|
||||
for (++i;p[i] && p[i]!='m'; i++)
|
||||
o[j] = p[i];
|
||||
continue;
|
||||
case '+':
|
||||
case '-':
|
||||
case '/':
|
||||
case '>':
|
||||
case '<':
|
||||
case '(':
|
||||
case ')':
|
||||
case '*':
|
||||
case '%':
|
||||
case ']':
|
||||
case '[':
|
||||
case ',':
|
||||
if (is_arg) {
|
||||
if (c_reset+j+10 >= opcode_sz) o = realloc_color_buffer (o, &opcode_sz, c_reset+100);
|
||||
strcpy (o+j, Color_RESET);
|
||||
j += strlen (Color_RESET);
|
||||
o[j++] = p[i];
|
||||
if (p[i]=='$' || ((p[i] > '0') && (p[i] < '9'))) {
|
||||
ut32 num_len = strlen (num);
|
||||
if (num_len+j+10 >= opcode_sz) o = realloc_color_buffer (o, &opcode_sz, num_len+100);
|
||||
strcpy (o+j, num);
|
||||
j += strlen (num)-1;
|
||||
} else {
|
||||
ut32 reg_len = strlen (reg);
|
||||
if (reg_len+j+10 >= opcode_sz) o = realloc_color_buffer (o, &opcode_sz, reg_len+100);
|
||||
strcpy (o+j, reg);
|
||||
j += strlen (reg)-1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case ' ':
|
||||
is_arg = 1;
|
||||
// find if next ',' before ' ' is found
|
||||
is_mod = 0;
|
||||
for (k = i+1; p[k]; k++) {
|
||||
if (p[k]==' ')
|
||||
break;
|
||||
if (p[k]==',') {
|
||||
is_mod = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!p[k]) is_mod = 1;
|
||||
if (!is_jmp && is_mod) {
|
||||
// COLOR FOR REGISTER
|
||||
ut32 reg_len = strlen (reg);
|
||||
if (reg_len+j+10 >= opcode_sz) o = realloc_color_buffer (o, &opcode_sz, reg_len+100);
|
||||
strcpy (o+j, reg);
|
||||
j += strlen (reg);
|
||||
}
|
||||
break;
|
||||
case '0':
|
||||
if (!is_jmp && p[i+1]== 'x') {
|
||||
ut32 num_len = strlen (num);
|
||||
if (num_len+j+10 >= opcode_sz) o = realloc_color_buffer (o, &opcode_sz, num_len+100);
|
||||
strcpy (o+j, num);
|
||||
j += strlen (num);
|
||||
}
|
||||
break;
|
||||
}
|
||||
o[j] = p[i];
|
||||
}
|
||||
// decolorize at the end
|
||||
if (j+20 >= opcode_sz) {
|
||||
char *t_o = o;
|
||||
o = malloc (opcode_sz+21);
|
||||
memcpy (o, t_o, opcode_sz);
|
||||
opcode_sz += 21;
|
||||
free (t_o);
|
||||
}
|
||||
strcpy (o+j, Color_RESET);
|
||||
//strcpy (p, o); // may overflow .. but shouldnt because asm.buf_asm is big enought
|
||||
return o;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
#undef IFDBG
|
||||
#endif
|
||||
|
||||
#define DO_THE_DBG 1
|
||||
#define DO_THE_DBG 0
|
||||
#define IFDBG if(DO_THE_DBG)
|
||||
#define IFINT if(0)
|
||||
|
||||
@ -290,7 +290,7 @@ static RList * r_bin_java_find_cp_const_by_val_utf8 (RBinJavaObj *bin_obj, const
|
||||
|
||||
|
||||
static ut8 char_needs_hexing ( ut8 b) {
|
||||
if (b <= 0x31) return 1;
|
||||
if (b < 0x20) return 1;
|
||||
switch (b) {
|
||||
case 0x7f:
|
||||
case 0x81:
|
||||
@ -2029,19 +2029,13 @@ R_API char* r_bin_java_get_utf8_from_cp_item_list(RList *cp_list, ut64 idx) {
|
||||
|
||||
item = (RBinJavaCPTypeObj *) r_list_get_n (cp_list, idx);
|
||||
if (item && (item->tag == R_BIN_JAVA_CP_UTF8) && item->metas->ord == idx) {
|
||||
ut32 len = item->info.cp_utf8.length+1;
|
||||
value = malloc (len);
|
||||
memcpy (value, item->info.cp_utf8.bytes, len-1);
|
||||
value[len-1] = 0;
|
||||
value = convert_string (item->info.cp_utf8.bytes, item->info.cp_utf8.length);
|
||||
}
|
||||
|
||||
if (value == NULL) {
|
||||
r_list_foreach (cp_list, iter, item ) {
|
||||
if (item && (item->tag == R_BIN_JAVA_CP_UTF8) && item->metas->ord == idx) {
|
||||
ut32 len = item->info.cp_utf8.length+1;
|
||||
value = malloc (len);
|
||||
memcpy (value, item->info.cp_utf8.bytes, len-1);
|
||||
value[len-1] = 0;
|
||||
value = convert_string (item->info.cp_utf8.bytes, item->info.cp_utf8.length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -2470,7 +2464,6 @@ R_API ut64 r_bin_java_parse_attrs (RBinJavaObj *bin, const ut64 offset, const ut
|
||||
bin->attrs_list = r_list_new ();
|
||||
bin->attrs_offset = offset;
|
||||
bin->attrs_count = R_BIN_JAVA_USHORT (a_buf,adv);
|
||||
|
||||
adv += 2;
|
||||
|
||||
if (bin->attrs_count > 0) {
|
||||
@ -8570,9 +8563,12 @@ R_API char * r_bin_java_resolve(RBinJavaObj *BIN_OBJ, int idx, ut8 space_bn_name
|
||||
|
||||
|
||||
} else if (strcmp (cp_name, "Utf8") == 0) {
|
||||
str = malloc (item->info.cp_utf8.length+3);
|
||||
if (str) {
|
||||
snprintf (str, item->info.cp_utf8.length+3, "\"%s\"", item->info.cp_utf8.bytes);
|
||||
char *tmp_str = convert_string (item->info.cp_utf8.bytes, item->info.cp_utf8.length);
|
||||
ut32 tmp_str_len = tmp_str ? strlen (tmp_str) + 4 : 0;
|
||||
|
||||
if (tmp_str) {
|
||||
str = malloc (tmp_str_len + 4);
|
||||
snprintf (str, tmp_str_len + 4, "\"%s\"", tmp_str);
|
||||
}
|
||||
} else if (strcmp (cp_name, "Long") == 0) {
|
||||
str = malloc (34);
|
||||
|
@ -47,9 +47,9 @@ static int enter_switch_op (ut64 addr, const ut8 * bytes, char *output, int outl
|
||||
init_switch_op ();
|
||||
IN_SWITCH_OP = 1;
|
||||
SWITCH_OP.addr = addr;
|
||||
SWITCH_OP.def_jmp = (ut32)(UINT (bytes, sz));
|
||||
SWITCH_OP.min_val = (ut32)(UINT (bytes, sz + 4));
|
||||
SWITCH_OP.max_val = (ut32)(UINT (bytes, sz + 8));
|
||||
SWITCH_OP.def_jmp = (int)(UINT (bytes, sz));
|
||||
SWITCH_OP.min_val = (int)(UINT (bytes, sz + 4));
|
||||
SWITCH_OP.max_val = (int)(UINT (bytes, sz + 8));
|
||||
sz += 12;
|
||||
snprintf (output, outlen, "%s default: 0x%04"PFMT64x, JAVA_OPS[idx].name,
|
||||
SWITCH_OP.def_jmp+SWITCH_OP.addr);
|
||||
@ -63,8 +63,8 @@ static int update_bytes_consumed (int sz) {
|
||||
|
||||
static int handle_switch_op (ut64 addr, const ut8 * bytes, char *output, int outlen ) {
|
||||
int sz = 4;
|
||||
ut32 jmp = (ut32)(UINT (bytes, 0)) + SWITCH_OP.addr;
|
||||
ut32 ccase = SWITCH_OP.cur_val + SWITCH_OP.min_val;
|
||||
ut32 jmp = (int)(UINT (bytes, 0)) + SWITCH_OP.addr;
|
||||
int ccase = SWITCH_OP.cur_val + SWITCH_OP.min_val;
|
||||
snprintf(output, outlen, "case %d: goto 0x%04x", ccase, jmp);
|
||||
SWITCH_OP.cur_val++;
|
||||
|
||||
@ -163,7 +163,7 @@ R_IPI int java_print_opcode(RBinJavaObj *obj, ut64 addr, int idx, const ut8 *byt
|
||||
case 0xa7: // goto
|
||||
case 0xa8: // jsr
|
||||
snprintf (output, outlen, "%s 0x%04"PFMT64x, JAVA_OPS[idx].name,
|
||||
addr+(int)(short)USHORT (bytes, 1));
|
||||
(addr+(short)USHORT (bytes, 1)));
|
||||
output[outlen-1] = 0;
|
||||
return update_bytes_consumed (JAVA_OPS[idx].size);
|
||||
// XXX - Figure out what constitutes the [<high>] value
|
||||
|
Loading…
Reference in New Issue
Block a user