* More work on r_anal_reflines
* Fixed r_bininfo build
This commit is contained in:
parent
0b7ed2a6f0
commit
6791ef0f6b
5 changed files with 134 additions and 12 deletions
122
libr/anal/anal.c
122
libr/anal/anal.c
|
|
@ -95,15 +95,14 @@ int r_anal_aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, void *data)
|
|||
return R_FALSE;
|
||||
}
|
||||
|
||||
struct r_anal_refline_t *r_anal_reflines(struct r_anal_t *anal, u8 *buf, u64 len, int nlines, int linesout)
|
||||
int r_anal_reflines_get(struct r_anal_t *anal, struct r_anal_refline_t *reflines, u8 *buf, u64 len, int nlines, int linesout)
|
||||
{
|
||||
struct r_anal_refline_t *list = MALLOC_STRUCT(struct r_anal_refline_t);
|
||||
struct r_anal_refline_t *list2;
|
||||
struct r_anal_aop_t aop;
|
||||
u8 *ptr = buf;
|
||||
u8 *end = buf + len;
|
||||
struct r_anal_aop_t aop;
|
||||
int sz, bsz = 0;
|
||||
int index = 0;
|
||||
int seek = anal->pc, sz, bsz = 0, index = 0;
|
||||
|
||||
INIT_LIST_HEAD(&(list->list));
|
||||
|
||||
|
|
@ -124,7 +123,7 @@ struct r_anal_refline_t *r_anal_reflines(struct r_anal_t *anal, u8 *buf, u64 len
|
|||
}
|
||||
}
|
||||
#endif
|
||||
anal->pc += bsz;
|
||||
seek += bsz;
|
||||
sz = r_anal_aop(anal, &aop, ptr);
|
||||
if (sz < 1) {
|
||||
sz = 1;
|
||||
|
|
@ -144,7 +143,7 @@ struct r_anal_refline_t *r_anal_reflines(struct r_anal_t *anal, u8 *buf, u64 len
|
|||
}
|
||||
|
||||
list2 = MALLOC_STRUCT(struct r_anal_refline_t);
|
||||
list2->from = anal->pc;
|
||||
list2->from = seek;
|
||||
list2->to = aop.jump;
|
||||
list2->index = index++;
|
||||
list_add_tail(&(list2->list), &(list->list));
|
||||
|
|
@ -155,6 +154,113 @@ struct r_anal_refline_t *r_anal_reflines(struct r_anal_t *anal, u8 *buf, u64 len
|
|||
ptr = ptr + sz;
|
||||
bsz += sz;
|
||||
}
|
||||
|
||||
return list;
|
||||
|
||||
reflines = list;
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
int r_anal_reflines_str(struct r_anal_t *anal, struct r_anal_refline_t *list, u64 addr, char *str, int opts)
|
||||
{
|
||||
struct list_head *pos;
|
||||
char ch = ' ';
|
||||
int dir = 0; /* dir 1=in ; 2=out */
|
||||
|
||||
int linestyle = opts & R_ANAL_REFLINE_LINESTYLE;
|
||||
int nlines = opts & R_ANAL_REFLINE_NLINES;
|
||||
int lineswide = opts & R_ANAL_REFLINE_LINESWIDE;
|
||||
int expand = opts & R_ANAL_REFLINE_EXPAND;
|
||||
|
||||
if (!list)
|
||||
return R_FALSE;
|
||||
|
||||
str[0] = '\0';
|
||||
strcat(str, " ");
|
||||
|
||||
#define _h34d_ &(list->list)
|
||||
|
||||
if (nlines) {
|
||||
int count = 0;
|
||||
|
||||
for (pos = linestyle?(_h34d_)->next:(_h34d_)->prev; pos != (_h34d_); pos = linestyle?pos->next:pos->prev)
|
||||
count++;
|
||||
for (;count<nlines;count++)
|
||||
strcat(str, " ");
|
||||
}
|
||||
|
||||
for (pos = linestyle?(_h34d_)->next:(_h34d_)->prev; pos != (_h34d_); pos = linestyle?pos->next:pos->prev) {
|
||||
struct r_anal_refline_t *ref = list_entry(pos, struct r_anal_refline_t, list);
|
||||
|
||||
if (addr == ref->to)
|
||||
dir = 1;
|
||||
if (addr == ref->from)
|
||||
dir = 2;
|
||||
|
||||
if (addr == ref->to) {
|
||||
if (!expand) {
|
||||
if (ref->from > ref->to)
|
||||
strcat(str, ".");
|
||||
else
|
||||
strcat(str, "`");
|
||||
ch = '-';
|
||||
} else
|
||||
ch = '.';
|
||||
} else
|
||||
if (addr == ref->from) {
|
||||
if (!expand) {
|
||||
if (ref->from > ref->to)
|
||||
strcat(str, "`");
|
||||
else
|
||||
strcat(str, ".");
|
||||
ch = '=';
|
||||
}
|
||||
} else {
|
||||
if (ref->from < ref->to) {
|
||||
/* down */
|
||||
if (addr > ref->from && addr < ref->to) {
|
||||
if (ch=='-'||ch=='=')
|
||||
sprintf(str, "%s%c", str, ch);
|
||||
else
|
||||
strcat(str, "|");
|
||||
} else
|
||||
if (!expand)
|
||||
sprintf(str, "%s%c", str, ch);
|
||||
} else {
|
||||
/* up */
|
||||
if (addr < ref->from && addr > ref->to) {
|
||||
if (ch=='-'||ch=='=')
|
||||
sprintf(str, "%s%c", str, ch);
|
||||
else // ^
|
||||
strcat(str, "|");
|
||||
} else {
|
||||
sprintf(str, "%s%c", str, ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lineswide) {
|
||||
switch(ch) {
|
||||
case '=':
|
||||
case '-':
|
||||
sprintf(str, "%s%c", str, ch);
|
||||
break;
|
||||
default:
|
||||
strcat(str, " ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (expand) {
|
||||
strcat(str, " ");
|
||||
} else
|
||||
if (dir==1) {
|
||||
strcat(str, "-> ");
|
||||
} else
|
||||
if (dir==2) {
|
||||
strcat(str, "=< ");
|
||||
}
|
||||
else strcat(str, " ");
|
||||
|
||||
return R_TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
// XXX addr should be off_t for 64 love
|
||||
static int aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, void *data)
|
||||
{
|
||||
|
||||
if (anal == NULL || aop == NULL || data == NULL)
|
||||
return -1;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ foo: pre libr_bininfo.so plugins
|
|||
CFLAGS+=-DCORELIB -Iformat
|
||||
#XXX
|
||||
CFLAGS+=-D__UNIX__=1 -DLIL_ENDIAN=1
|
||||
include ../config-user.mk
|
||||
include ../config.mk
|
||||
include ${STATIC_BININFO_PLUGINS}
|
||||
STATIC_OBJS=$(subst ..,p/..,$(subst bininfo_,p/bininfo_,$(STATIC_OBJ)))
|
||||
OBJ=bininfo.o ${STATIC_OBJS}
|
||||
|
|
|
|||
|
|
@ -361,16 +361,24 @@ static int cmd_print(void *data, const char *input)
|
|||
u8 *buf = core->block;
|
||||
int pseudo = (int)r_config_get_i(&core->config, "asm.pseudo");
|
||||
char str[128];
|
||||
char line[128];
|
||||
struct r_asm_aop_t aop;
|
||||
|
||||
struct r_anal_refline_t reflines;
|
||||
|
||||
r_anal_set(&core->anal, "anal_x86");
|
||||
r_anal_set_pc(&core->anal, core->seek);
|
||||
r_anal_reflines_get(&core->anal, &reflines, buf, len, 64, 0);
|
||||
|
||||
r_asm_set_pc(&core->assembler, core->seek);
|
||||
for(idx=ret=0; idx < len; idx+=ret) {
|
||||
r_asm_set_pc(&core->assembler, core->assembler.pc + ret);
|
||||
r_anal_reflines_str(&core->anal, &reflines, core->anal.pc + idx, line, 0);
|
||||
ret = r_asm_disassemble(&core->assembler, &aop, buf+idx, len-idx);
|
||||
if (ret <1) {
|
||||
ret = 1;
|
||||
fprintf(stderr, "** invalid opcode at 0x%08llx **\n", core->assembler.pc + ret);
|
||||
}
|
||||
r_cons_printf("%s", line);
|
||||
if (show_offset) r_cons_printf("0x%08llx ", core->seek + idx);
|
||||
if (show_bytes) r_cons_printf("%14s ", aop.buf_hex);
|
||||
if (pseudo) {
|
||||
|
|
|
|||
|
|
@ -68,6 +68,13 @@ enum {
|
|||
R_ANAL_STACK_ARG_SET
|
||||
};
|
||||
|
||||
enum {
|
||||
R_ANAL_REFLINE_LINESTYLE = 0x01,
|
||||
R_ANAL_REFLINE_NLINES = 0x02,
|
||||
R_ANAL_REFLINE_LINESWIDE = 0x04,
|
||||
R_ANAL_REFLINE_EXPAND = 0x08
|
||||
};
|
||||
|
||||
struct r_anal_refline_t {
|
||||
u64 from;
|
||||
u64 to;
|
||||
|
|
@ -118,6 +125,6 @@ int r_anal_set_bits(struct r_anal_t *anal, int bits);
|
|||
int r_anal_set_big_endian(struct r_anal_t *anal, int boolean);
|
||||
int r_anal_set_pc(struct r_anal_t *a, u64 pc);
|
||||
int r_anal_aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, void *data);
|
||||
struct r_anal_refline_t *r_anal_reflines(struct r_anal_t *anal, u8 *buf, u64 len, int nlines, int linesout);
|
||||
|
||||
int r_anal_reflines_get(struct r_anal_t *anal, struct r_anal_refline_t *reflines, u8 *buf, u64 len, int nlines, int linesout);
|
||||
int r_anal_reflines_str(struct r_anal_t *anal, struct r_anal_refline_t *list, u64 addr, char *str, int opts);
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in a new issue