mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-23 15:52:06 +00:00
Fix not calling r_asm_op_fini() when needed (#20506)
The RAsmOp is used on stack when disassembling and after its content is not need it needs to call its _fini to free possible heap memory previously allocated.
This commit is contained in:
parent
e540f819e0
commit
8ffa196193
@ -722,7 +722,6 @@ R_API RAsmCode* r_asm_mdisassemble(RAsm *a, const ut8 *buf, int len) {
|
||||
RStrBuf *buf_asm;
|
||||
RAsmCode *acode;
|
||||
ut64 pc = a->pc;
|
||||
RAsmOp op = {0};
|
||||
ut64 idx;
|
||||
size_t ret;
|
||||
const size_t addrbytes = a->user? ((RCore *)a->user)->io->addrbytes: 1;
|
||||
@ -738,6 +737,7 @@ R_API RAsmCode* r_asm_mdisassemble(RAsm *a, const ut8 *buf, int len) {
|
||||
return r_asm_code_free (acode);
|
||||
}
|
||||
for (idx = 0; idx + addrbytes <= len; idx += (addrbytes * ret)) {
|
||||
RAsmOp op = {0};
|
||||
r_asm_set_pc (a, pc + idx);
|
||||
ret = r_asm_disassemble (a, &op, buf + idx, len - idx);
|
||||
if (ret < 1) {
|
||||
@ -748,8 +748,8 @@ R_API RAsmCode* r_asm_mdisassemble(RAsm *a, const ut8 *buf, int len) {
|
||||
}
|
||||
r_strbuf_append (buf_asm, r_strbuf_get (&op.buf_asm));
|
||||
r_strbuf_append (buf_asm, "\n");
|
||||
r_asm_op_fini (&op);
|
||||
}
|
||||
r_asm_op_fini (&op);
|
||||
acode->assembly = r_strbuf_drain (buf_asm);
|
||||
acode->len = idx;
|
||||
return acode;
|
||||
@ -1124,9 +1124,6 @@ R_API RAsmCode *r_asm_massemble(RAsm *a, const char *assembly) {
|
||||
continue;
|
||||
}
|
||||
ret = r_asm_assemble (a, &op, ptr_start);
|
||||
// XXX This fixes a leak, unsure
|
||||
// why op_fini below doesn't catch it
|
||||
r_strbuf_fini (&op.buf_asm);
|
||||
}
|
||||
}
|
||||
if (stage == STAGES - 1) {
|
||||
|
@ -65,7 +65,6 @@ R_API char* r_core_asm_search(RCore *core, const char *input) {
|
||||
// TODO: add support for byte-per-byte opcode search
|
||||
R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut64 to, int maxhits, int regexp, int everyByte, int mode) {
|
||||
RCoreAsmHit *hit;
|
||||
RAsmOp op;
|
||||
RList *hits;
|
||||
ut64 at, toff = core->offset;
|
||||
ut8 *buf;
|
||||
@ -155,6 +154,7 @@ R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut6
|
||||
match = (val != UT64_MAX && val >= usrimm && val <= usrimm2);
|
||||
}
|
||||
if (match) {
|
||||
RAsmOp op;
|
||||
if (!(hit = r_core_asm_hit_new ())) {
|
||||
r_list_purge (hits);
|
||||
R_FREE (hits);
|
||||
@ -188,6 +188,7 @@ R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut6
|
||||
opst = strdup (r_strbuf_get (&analop.esil));
|
||||
r_anal_op_fini (&analop);
|
||||
} else {
|
||||
RAsmOp op;
|
||||
if (!(len = r_asm_disassemble (
|
||||
core->rasm, &op,
|
||||
buf + addrbytes * idx,
|
||||
@ -364,7 +365,6 @@ static int handle_forward_disassemble(RCore* core, RList *hits, ut8* buf, ut64 l
|
||||
ut64 temp_instr_len = 0;
|
||||
ut64 start = 0, end = 0;
|
||||
ut8 is_valid = false;
|
||||
RAsmOp op;
|
||||
|
||||
if (end_addr < current_instr_addr) {
|
||||
return end_addr;
|
||||
@ -372,6 +372,7 @@ static int handle_forward_disassemble(RCore* core, RList *hits, ut8* buf, ut64 l
|
||||
|
||||
r_asm_set_pc (core->rasm, current_instr_addr);
|
||||
while (tmp_current_buf_pos < len && temp_instr_addr < end_addr) {
|
||||
RAsmOp op;
|
||||
temp_instr_len = len - tmp_current_buf_pos;
|
||||
IFDBG eprintf("Current position: %"PFMT64d" instr_addr: 0x%"PFMT64x"\n", tmp_current_buf_pos, temp_instr_addr);
|
||||
temp_instr_len = r_asm_disassemble (core->rasm, &op, buf+tmp_current_buf_pos, temp_instr_len);
|
||||
@ -404,6 +405,7 @@ static int handle_forward_disassemble(RCore* core, RList *hits, ut8* buf, ut64 l
|
||||
|
||||
temp_instr_addr += temp_instr_len;
|
||||
tmp_current_buf_pos += temp_instr_len;
|
||||
r_asm_op_fini (&op);
|
||||
}
|
||||
return temp_instr_addr;
|
||||
}
|
||||
@ -483,7 +485,6 @@ static int is_hit_inrange(RCoreAsmHit *hit, ut64 start_range, ut64 end_range){
|
||||
}
|
||||
|
||||
R_API RList *r_core_asm_bwdisassemble(RCore *core, ut64 addr, int n, int len) {
|
||||
RAsmOp op;
|
||||
// if (n > core->blocksize) n = core->blocksize;
|
||||
ut64 at;
|
||||
ut32 idx = 0, hit_count;
|
||||
@ -539,10 +540,12 @@ R_API RList *r_core_asm_bwdisassemble(RCore *core, ut64 addr, int n, int len) {
|
||||
at = addr - idx / addrbytes;
|
||||
r_asm_set_pc (core->rasm, at);
|
||||
for (hit_count = 0; hit_count < n; hit_count++) {
|
||||
RAsmOp op;
|
||||
int instrlen = r_asm_disassemble (core->rasm, &op,
|
||||
buf + len - addrbytes * (addr - at), addrbytes * (addr - at));
|
||||
add_hit_to_hits (hits, at, instrlen, true);
|
||||
at += instrlen;
|
||||
r_asm_op_fini (&op);
|
||||
}
|
||||
free (buf);
|
||||
return hits;
|
||||
@ -552,7 +555,6 @@ static RList *r_core_asm_back_disassemble_all(RCore *core, ut64 addr, ut64 len,
|
||||
RList *hits = r_core_asm_hit_list_new ();
|
||||
RCoreAsmHit dummy_value;
|
||||
RCoreAsmHit *hit = NULL;
|
||||
RAsmOp op;
|
||||
ut8 *buf = (ut8 *)malloc (len + extra_padding);
|
||||
int current_instr_len = 0;
|
||||
ut64 current_instr_addr = addr,
|
||||
@ -582,6 +584,7 @@ static RList *r_core_asm_back_disassemble_all(RCore *core, ut64 addr, ut64 len,
|
||||
}
|
||||
|
||||
do {
|
||||
RAsmOp op;
|
||||
if (r_cons_is_breaked ()) {
|
||||
break;
|
||||
}
|
||||
@ -599,15 +602,15 @@ static RList *r_core_asm_back_disassemble_all(RCore *core, ut64 addr, ut64 len,
|
||||
current_buf_pos--;
|
||||
current_instr_addr--;
|
||||
hit_count++;
|
||||
r_asm_op_fini (&op);
|
||||
} while ( ((int) current_buf_pos >= 0) && (int)(len - current_buf_pos) >= 0 && hit_count <= max_hit_count);
|
||||
|
||||
free(buf);
|
||||
free (buf);
|
||||
return hits;
|
||||
}
|
||||
|
||||
static RList *r_core_asm_back_disassemble(RCore *core, ut64 addr, int len, ut64 max_hit_count, ut8 disassmble_each_addr, ut32 extra_padding) {
|
||||
RList *hits;;
|
||||
RAsmOp op;
|
||||
ut8 *buf = NULL;
|
||||
ut8 max_invalid_b4_exit = 4,
|
||||
last_num_invalid = 0;
|
||||
@ -662,6 +665,7 @@ static RList *r_core_asm_back_disassemble(RCore *core, ut64 addr, int len, ut64
|
||||
next_buf_pos = len + extra_padding - 1;
|
||||
current_instr_addr = addr - 1;
|
||||
do {
|
||||
RAsmOp op;
|
||||
if (r_cons_is_breaked ()) {
|
||||
break;
|
||||
}
|
||||
@ -742,6 +746,7 @@ static RList *r_core_asm_back_disassemble(RCore *core, ut64 addr, int len, ut64
|
||||
current_instr_addr -= 1;
|
||||
current_buf_pos -= 1;
|
||||
|
||||
r_asm_op_fini (&op);
|
||||
if (hit_count >= max_hit_count &&
|
||||
(last_num_invalid >= max_invalid_b4_exit || last_num_invalid == 0)) {
|
||||
break;
|
||||
|
@ -2132,7 +2132,6 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int
|
||||
const char *esilstr;
|
||||
const char *opexstr;
|
||||
RAnalHint *hint;
|
||||
RAsmOp asmop = {0};
|
||||
RAnalOp op = {0};
|
||||
ut64 addr;
|
||||
PJ *pj = NULL;
|
||||
@ -2162,6 +2161,7 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int
|
||||
}
|
||||
}
|
||||
for (i = idx = ret = 0; idx < len && (!nops || (nops && i < nops)); i++, idx += ret) {
|
||||
RAsmOp asmop = {0};
|
||||
addr = core->offset + idx;
|
||||
r_asm_set_pc (core->rasm, addr);
|
||||
hint = r_anal_hint_get (core->anal, addr);
|
||||
@ -2558,8 +2558,8 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int
|
||||
free (mnem);
|
||||
r_anal_hint_free (hint);
|
||||
r_anal_op_fini (&op);
|
||||
r_asm_op_fini (&asmop);
|
||||
}
|
||||
r_asm_op_fini (&asmop);
|
||||
r_anal_op_fini (&op);
|
||||
if (fmt == 's') {
|
||||
r_cons_printf ("%d\n", totalsize);
|
||||
|
@ -798,7 +798,6 @@ static bool is_repeatable_inst(RCore *core, ut64 addr) {
|
||||
}
|
||||
|
||||
static int step_until_inst(RCore *core, const char *instr, bool regex) {
|
||||
RAsmOp asmop;
|
||||
ut8 buf[32];
|
||||
ut64 pc;
|
||||
int ret;
|
||||
@ -811,6 +810,7 @@ static int step_until_inst(RCore *core, const char *instr, bool regex) {
|
||||
}
|
||||
r_cons_break_push (NULL, NULL);
|
||||
for (;;) {
|
||||
RAsmOp asmop;
|
||||
if (r_cons_is_breaked ()) {
|
||||
break;
|
||||
}
|
||||
@ -836,15 +836,18 @@ static int step_until_inst(RCore *core, const char *instr, bool regex) {
|
||||
if (regex) {
|
||||
if (r_regex_match (instr, "e", buf_asm)) {
|
||||
eprintf ("Stop.\n");
|
||||
r_asm_op_fini (&asmop);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (strstr (buf_asm, instr)) {
|
||||
eprintf ("Stop.\n");
|
||||
r_asm_op_fini (&asmop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
r_asm_op_fini (&asmop);
|
||||
}
|
||||
r_cons_break_pop ();
|
||||
return true;
|
||||
|
@ -6917,6 +6917,7 @@ static int cmd_print(void *data, const char *input) {
|
||||
}
|
||||
r_cons_printf (" // %s\n", r_strbuf_get (&asmop.buf_asm));
|
||||
i--;
|
||||
r_asm_op_fini (&asmop);
|
||||
}
|
||||
r_cons_printf (".equ shellcode_len, %d\n", len);
|
||||
} else {
|
||||
|
@ -1299,7 +1299,6 @@ static void print_rop(RCore *core, RList *hitlist, PJ *pj, int mode) {
|
||||
char *buf_asm = NULL;
|
||||
unsigned int size = 0;
|
||||
RAnalOp analop = {0};
|
||||
RAsmOp asmop;
|
||||
Sdb *db = NULL;
|
||||
const bool colorize = r_config_get_i (core->config, "scr.color");
|
||||
const bool rop_comments = r_config_get_i (core->config, "rop.comments");
|
||||
@ -1321,6 +1320,7 @@ static void print_rop(RCore *core, RList *hitlist, PJ *pj, int mode) {
|
||||
pj_o (pj);
|
||||
pj_ka (pj, "opcodes");
|
||||
r_list_foreach (hitlist, iter, hit) {
|
||||
RAsmOp asmop;
|
||||
ut8 *buf = malloc (hit->len);
|
||||
if (!buf) {
|
||||
return;
|
||||
@ -1341,6 +1341,7 @@ static void print_rop(RCore *core, RList *hitlist, PJ *pj, int mode) {
|
||||
pj_ks (pj, "type", r_anal_optype_to_string (analop.type));
|
||||
pj_end (pj);
|
||||
free (buf);
|
||||
r_asm_op_fini (&asmop);
|
||||
}
|
||||
pj_end (pj);
|
||||
if (db && hit) {
|
||||
@ -1361,6 +1362,7 @@ static void print_rop(RCore *core, RList *hitlist, PJ *pj, int mode) {
|
||||
r_cons_printf ("0x%08"PFMT64x ":",
|
||||
((RCoreAsmHit *) hitlist->head->data)->addr);
|
||||
r_list_foreach (hitlist, iter, hit) {
|
||||
RAsmOp asmop;
|
||||
ut8 *buf = malloc (hit->len);
|
||||
r_io_read_at (core->io, hit->addr, buf, hit->len);
|
||||
r_asm_set_pc (core->rasm, hit->addr);
|
||||
@ -1382,6 +1384,7 @@ static void print_rop(RCore *core, RList *hitlist, PJ *pj, int mode) {
|
||||
r_cons_printf (" %s;", r_asm_op_get_asm (&asmop));
|
||||
}
|
||||
free (buf);
|
||||
r_asm_op_fini (&asmop);
|
||||
}
|
||||
if (db && hit) {
|
||||
const ut64 addr = ((RCoreAsmHit *) hitlist->head->data)->addr;
|
||||
@ -1393,6 +1396,7 @@ static void print_rop(RCore *core, RList *hitlist, PJ *pj, int mode) {
|
||||
default:
|
||||
// Print gadgets with new instruction on a new line.
|
||||
r_list_foreach (hitlist, iter, hit) {
|
||||
RAsmOp asmop;
|
||||
const char *comment = rop_comments? r_meta_get_string (core->anal, R_META_TYPE_COMMENT, hit->addr): NULL;
|
||||
if (hit->len < 0) {
|
||||
eprintf ("Invalid hit length here\n");
|
||||
@ -1437,6 +1441,7 @@ static void print_rop(RCore *core, RList *hitlist, PJ *pj, int mode) {
|
||||
free (asm_op_hex);
|
||||
free (buf);
|
||||
r_anal_op_fini (&analop);
|
||||
r_asm_op_fini (&asmop);
|
||||
}
|
||||
if (db && hit) {
|
||||
const ut64 addr = ((RCoreAsmHit *) hitlist->head->data)->addr;
|
||||
@ -1468,7 +1473,6 @@ static int r_core_search_rop(RCore *core, RInterval search_itv, int opt, const c
|
||||
int delta = 0;
|
||||
ut8 *buf;
|
||||
RIOMap *map;
|
||||
RAsmOp asmop;
|
||||
|
||||
Sdb *gadgetSdb = NULL;
|
||||
if (r_config_get_i (core->config, "rop.sdb")) {
|
||||
@ -1614,6 +1618,7 @@ static int r_core_search_rop(RCore *core, RInterval search_itv, int opt, const c
|
||||
prev = 0;
|
||||
// Start at just before the first end gadget.
|
||||
for (i = next - ropdepth; i < (delta - max_inst_size_x86) && max_count; i += increment) {
|
||||
RAsmOp asmop;
|
||||
if (increment == 1) {
|
||||
// give in-boundary instructions a shot
|
||||
if (i < prev - max_inst_size_x86) {
|
||||
@ -1658,9 +1663,11 @@ static int r_core_search_rop(RCore *core, RInterval search_itv, int opt, const c
|
||||
from + i, buf, delta, i, grep, regexp,
|
||||
rx_list, end_gadget, badstart);
|
||||
if (!hitlist) {
|
||||
r_asm_op_fini (&asmop);
|
||||
continue;
|
||||
}
|
||||
if (align && (0 != ((from + i) % align))) {
|
||||
r_asm_op_fini (&asmop);
|
||||
continue;
|
||||
}
|
||||
if (gadgetSdb) {
|
||||
@ -1670,6 +1677,7 @@ static int r_core_search_rop(RCore *core, RInterval search_itv, int opt, const c
|
||||
char *headAddr = r_str_newf ("%"PFMT64x, hit->addr);
|
||||
if (!headAddr) {
|
||||
result = false;
|
||||
r_asm_op_fini (&asmop);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
@ -1678,6 +1686,7 @@ static int r_core_search_rop(RCore *core, RInterval search_itv, int opt, const c
|
||||
if (!addr) {
|
||||
free (headAddr);
|
||||
result = false;
|
||||
r_asm_op_fini (&asmop);
|
||||
goto bad;
|
||||
}
|
||||
sdb_concat (gadgetSdb, headAddr, addr, 0);
|
||||
@ -1701,10 +1710,12 @@ static int r_core_search_rop(RCore *core, RInterval search_itv, int opt, const c
|
||||
if (max_count > 0) {
|
||||
max_count--;
|
||||
if (max_count < 1) {
|
||||
r_asm_op_fini (&asmop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
r_asm_op_fini (&asmop);
|
||||
if (increment != 1) {
|
||||
i = next;
|
||||
}
|
||||
@ -2089,10 +2100,10 @@ static void do_ref_search(RCore *core, ut64 addr,ut64 from, ut64 to, struct sear
|
||||
RAnalRef *ref;
|
||||
RListIter *iter;
|
||||
ut8 buf[12];
|
||||
RAsmOp asmop;
|
||||
RList *list = r_anal_xrefs_get (core->anal, addr);
|
||||
if (list) {
|
||||
r_list_foreach (list, iter, ref) {
|
||||
RAsmOp asmop;
|
||||
r_io_read_at (core->io, ref->addr, buf, size);
|
||||
r_asm_set_pc (core->rasm, ref->addr);
|
||||
r_asm_disassemble (core->rasm, &asmop, buf, size);
|
||||
@ -2122,6 +2133,7 @@ static void do_ref_search(RCore *core, ut64 addr,ut64 from, ut64 to, struct sear
|
||||
}
|
||||
}
|
||||
free (buf_fcn);
|
||||
r_asm_op_fini (&asmop);
|
||||
}
|
||||
}
|
||||
r_list_free (list);
|
||||
@ -2151,6 +2163,7 @@ static void cmd_search_aF(RCore *core, const char *input) {
|
||||
size_t left = bb->size - bb->op_pos[i];
|
||||
int ret = r_asm_disassemble (core->rasm, &asmop, idata, left);
|
||||
if (ret < 1) {
|
||||
r_asm_op_fini (&asmop);
|
||||
break;
|
||||
}
|
||||
char *s = NULL;
|
||||
@ -2164,6 +2177,7 @@ static void cmd_search_aF(RCore *core, const char *input) {
|
||||
r_cons_printf ("0x%08"PFMT64x" %s: %s\n", addr, fcn->name, s);
|
||||
}
|
||||
free (s);
|
||||
r_asm_op_fini (&asmop);
|
||||
}
|
||||
free (bbdata);
|
||||
}
|
||||
@ -3230,7 +3244,6 @@ static void __core_cmd_search_backward(RCore *core, int delta) {
|
||||
}
|
||||
|
||||
static void __core_cmd_search_asm_byteswap(RCore *core, int nth) {
|
||||
RAsmOp asmop;
|
||||
ut8 buf[32];
|
||||
int i;
|
||||
r_io_read_at (core->io, 0, buf, sizeof (buf));
|
||||
@ -3238,6 +3251,7 @@ static void __core_cmd_search_asm_byteswap(RCore *core, int nth) {
|
||||
return;
|
||||
}
|
||||
for (i = 0; i <= 0xff; i++) {
|
||||
RAsmOp asmop;
|
||||
buf[nth] = i;
|
||||
if (r_asm_disassemble (core->rasm, &asmop, buf, sizeof (buf)) > 0) {
|
||||
const char *asmstr = r_strbuf_get (&asmop.buf_asm);
|
||||
@ -3245,6 +3259,7 @@ static void __core_cmd_search_asm_byteswap(RCore *core, int nth) {
|
||||
r_cons_printf ("%02x %s\n", i, asmstr);
|
||||
}
|
||||
}
|
||||
r_asm_op_fini (&asmop);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -304,6 +304,7 @@ static int cmd_seek_opcode_backward(RCore *core, int numinstr) {
|
||||
}
|
||||
val += op.size;
|
||||
addr = prev_addr;
|
||||
r_asm_op_fini (&op);
|
||||
}
|
||||
}
|
||||
r_core_seek (core, addr, true);
|
||||
|
@ -2494,6 +2494,7 @@ R_API char *r_core_anal_hasrefs_to_depth(RCore *core, ut64 value, PJ *pj, int de
|
||||
r_asm_set_pc (core->rasm, value);
|
||||
r_asm_disassemble (core->rasm, &op, buf, sizeof (buf));
|
||||
r_strbuf_appendf (s, "'%s' ", r_asm_op_get_asm (&op));
|
||||
r_asm_op_fini (&op);
|
||||
/* get library name */
|
||||
{ // NOTE: dup for mapname?
|
||||
RDebugMap *map;
|
||||
|
@ -2207,9 +2207,11 @@ static void ds_show_comments_right(RDisasmState *ds) {
|
||||
const char *vartype = r_meta_get_string (core->anal, R_META_TYPE_VARTYPE, ds->at);
|
||||
if (!comment) {
|
||||
if (vartype) {
|
||||
R_FREE (ds->comment);
|
||||
ds->comment = r_str_newf ("%s; %s", COLOR_ARG (ds, color_func_var_type), vartype);
|
||||
} else if (item && R_STR_ISNOTEMPTY (item->comment)) {
|
||||
ds->ocomment = item->comment;
|
||||
R_FREE (ds->comment);
|
||||
ds->comment = strdup (item->comment);
|
||||
}
|
||||
} else if (vartype) {
|
||||
@ -2218,6 +2220,7 @@ static void ds_show_comments_right(RDisasmState *ds) {
|
||||
ds->comment = r_str_newf ("%s; %s", COLOR_ARG (ds, color_usrcmt), comment);
|
||||
}
|
||||
if (!ds->comment || !*ds->comment) {
|
||||
R_FREE (ds->comment);
|
||||
return;
|
||||
}
|
||||
linelen = strlen (ds->comment) + 5;
|
||||
@ -5868,6 +5871,7 @@ toro:
|
||||
r_asm_set_syntax (core->rasm, R_ASM_SYNTAX_INTEL);
|
||||
r_asm_disassemble (core->rasm, &ao, ds_bufat (ds), ds_left (ds) + 5);
|
||||
r_asm_set_syntax (core->rasm, os);
|
||||
r_asm_op_fini (&ao);
|
||||
}
|
||||
if (mi_type == R_META_TYPE_FORMAT) {
|
||||
if ((ds->show_comments || ds->show_usercomments) && ds->show_comment_right) {
|
||||
@ -5907,6 +5911,7 @@ toro:
|
||||
r_asm_set_syntax (core->rasm, R_ASM_SYNTAX_INTEL);
|
||||
r_asm_disassemble (core->rasm, &ao, ds_bufat (ds), ds_left (ds) + 5);
|
||||
r_asm_set_syntax (core->rasm, os);
|
||||
r_asm_op_fini (&ao);
|
||||
}
|
||||
if (ds->show_bytes_right && ds->show_bytes) {
|
||||
ds_comment (ds, true, "");
|
||||
@ -6315,7 +6320,6 @@ R_API int r_core_print_disasm_instructions(RCore *core, int nb_bytes, int nb_opc
|
||||
}
|
||||
|
||||
R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_bytes, int nb_opcodes, PJ *pj) {
|
||||
RAsmOp asmop;
|
||||
RDisasmState *ds;
|
||||
RAnalFunction *f;
|
||||
int i, j, k, ret, line;
|
||||
@ -6399,6 +6403,7 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte
|
||||
const bool be = core->rasm->config->big_endian;
|
||||
|
||||
for (;;) {
|
||||
RAsmOp asmop;
|
||||
bool end_nbopcodes, end_nbbytes;
|
||||
int skip_bytes_flag = 0, skip_bytes_bb = 0;
|
||||
|
||||
@ -6420,7 +6425,6 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte
|
||||
} else if (i >= nb_bytes) {
|
||||
break;
|
||||
}
|
||||
memset (&asmop, 0, sizeof (RAsmOp));
|
||||
ret = r_asm_disassemble (core->rasm, &asmop, buf + i, nb_bytes - i);
|
||||
if (ret < 1) {
|
||||
char *hex = r_asm_op_get_hex (&asmop);
|
||||
@ -6635,6 +6639,7 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte
|
||||
end_nbopcodes = dis_opcodes == 1 && nb_opcodes > 0 && line>=nb_opcodes;
|
||||
end_nbbytes = dis_opcodes == 0 && nb_bytes > 0 && i>=nb_bytes;
|
||||
result = true;
|
||||
r_asm_op_fini (&asmop);
|
||||
if (end_nbopcodes || end_nbbytes) {
|
||||
break;
|
||||
}
|
||||
@ -6655,7 +6660,6 @@ R_API int r_core_print_disasm_all(RCore *core, ut64 addr, int l, int len, int mo
|
||||
int i, ret, count = 0;
|
||||
ut8 *buf = core->block;
|
||||
char str[128];
|
||||
RAsmOp asmop;
|
||||
if (l < 1) {
|
||||
l = len;
|
||||
}
|
||||
@ -6682,6 +6686,7 @@ R_API int r_core_print_disasm_all(RCore *core, ut64 addr, int l, int len, int mo
|
||||
int opalign = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_ALIGN);
|
||||
r_cons_break_push (NULL, NULL);
|
||||
for (i = 0; i < l; i += minopsz) {
|
||||
RAsmOp asmop;
|
||||
ds->at = addr + i;
|
||||
if (opalign > 1) {
|
||||
// skip unaligned addresses
|
||||
@ -6769,6 +6774,7 @@ R_API int r_core_print_disasm_all(RCore *core, ut64 addr, int l, int len, int mo
|
||||
}
|
||||
}
|
||||
}
|
||||
r_asm_op_fini (&asmop);
|
||||
}
|
||||
r_cons_break_pop ();
|
||||
if (buf != core->block) {
|
||||
@ -6796,7 +6802,6 @@ R_API int r_core_disasm_pdi_with_buf(RCore *core, ut64 address, ut8 *buf, ut32 n
|
||||
bool asm_immtrim = r_config_get_i (core->config, "asm.imm.trim");
|
||||
int i = 0, j, ret, err = 0;
|
||||
ut64 old_offset = core->offset;
|
||||
RAsmOp asmop;
|
||||
const char *color_reg = R_CONS_COLOR_DEF (reg, Color_YELLOW);
|
||||
const char *color_num = R_CONS_COLOR_DEF (num, Color_CYAN);
|
||||
const size_t addrbytes = buf ? 1 : core->io->addrbytes;
|
||||
@ -6832,6 +6837,7 @@ toro:
|
||||
// fix infinite loop
|
||||
j += opinc;
|
||||
} else for (; check_end (nb_opcodes, nb_bytes, addrbytes * i, j); j++) {
|
||||
RAsmOp asmop;
|
||||
if (r_cons_is_breaked ()) {
|
||||
err = 1;
|
||||
break;
|
||||
@ -7015,6 +7021,7 @@ toro:
|
||||
}
|
||||
}
|
||||
i += ret;
|
||||
r_asm_op_fini (&asmop);
|
||||
}
|
||||
if (buf == core->block && nb_opcodes > 0 && j < nb_opcodes) {
|
||||
r_core_seek (core, core->offset + i, true);
|
||||
|
@ -1591,6 +1591,7 @@ static void __fix_cursor_down(RCore *core) {
|
||||
if (sz < 1) {
|
||||
sz = 1;
|
||||
}
|
||||
r_asm_op_fini (&op);
|
||||
r_core_seek_delta (core, sz);
|
||||
print->cur = R_MAX (print->cur - sz, 0);
|
||||
if (print->ocur != -1) {
|
||||
@ -2778,6 +2779,7 @@ static void __direction_disassembly_cb(void *user, int direction) {
|
||||
r_core_visual_disasm_down (core, &op, &cols);
|
||||
r_core_seek (core, core->offset + cols, true);
|
||||
__set_panel_addr (core, cur, core->offset);
|
||||
r_asm_op_fini (&op);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1979,6 +1979,7 @@ static void cursor_prevrow(RCore *core, bool use_ocur) {
|
||||
r_core_seek (core, prev_addr, true);
|
||||
prev_sz = r_asm_disassemble (core->rasm, &op,
|
||||
core->block, 32);
|
||||
r_asm_op_fini (&op);
|
||||
}
|
||||
} else {
|
||||
prev_sz = roff - prev_roff;
|
||||
@ -2050,6 +2051,7 @@ static bool fix_cursor(RCore *core) {
|
||||
p->ocur = R_MAX (p->ocur - sz, 0);
|
||||
}
|
||||
res |= off_is_visible;
|
||||
r_asm_op_fini (&op);
|
||||
}
|
||||
} else if (core->print->cur >= offscreen) {
|
||||
r_core_seek (core, core->offset + p->cols, true);
|
||||
@ -2446,7 +2448,6 @@ static int process_get_click(RCore *core, int ch) {
|
||||
|
||||
R_API int r_core_visual_cmd(RCore *core, const char *arg) {
|
||||
ut8 och = arg[0];
|
||||
RAsmOp op;
|
||||
ut64 offset = core->offset;
|
||||
char buf[4096];
|
||||
const char *key_s;
|
||||
@ -3102,8 +3103,10 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) {
|
||||
times = distance;
|
||||
}
|
||||
while (times--) {
|
||||
RAsmOp op;
|
||||
if (isDisasmPrint (core->printidx)) {
|
||||
r_core_visual_disasm_down (core, &op, &cols);
|
||||
r_asm_op_fini (&op);
|
||||
} else if (!strcmp (__core_visual_print_command (core),
|
||||
"prc")) {
|
||||
cols = r_config_get_i (core->config, "hex.cols");
|
||||
@ -3130,10 +3133,12 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) {
|
||||
}
|
||||
} else {
|
||||
if (core->print->screen_bounds > 1 && core->print->screen_bounds >= core->offset) {
|
||||
RAsmOp op;
|
||||
ut64 addr = UT64_MAX;
|
||||
if (isDisasmPrint (core->printidx)) {
|
||||
if (core->print->screen_bounds == core->offset) {
|
||||
r_asm_disassemble (core->rasm, &op, core->block, 32);
|
||||
r_asm_op_fini (&op);
|
||||
}
|
||||
if (addr == core->offset || addr == UT64_MAX) {
|
||||
addr = core->offset + 48;
|
||||
|
@ -133,7 +133,6 @@ R_API bool r_core_visual_esil(RCore *core, const char *input) {
|
||||
char *word = NULL;
|
||||
int x = 0;
|
||||
char *ginput = NULL;
|
||||
RAsmOp asmop;
|
||||
RAnalOp analop;
|
||||
ut8 buf[sizeof (ut64)];
|
||||
unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size");
|
||||
@ -168,6 +167,7 @@ R_API bool r_core_visual_esil(RCore *core, const char *input) {
|
||||
if (input) {
|
||||
expr = strdup (input);
|
||||
} else {
|
||||
RAsmOp asmop;
|
||||
memcpy (buf, core->block, sizeof (ut64));
|
||||
// bool use_color = core->print->flags & R_PRINT_FLAGS_COLOR;
|
||||
(void) r_asm_disassemble (core->rasm, &asmop, buf, sizeof (ut64));
|
||||
@ -192,6 +192,7 @@ R_API bool r_core_visual_esil(RCore *core, const char *input) {
|
||||
r_cons_printf (Color_RESET"asm: %s\n"Color_RESET, op);
|
||||
free (op);
|
||||
expr = strdup (r_strbuf_get (&analop.esil));
|
||||
r_asm_op_fini (&asmop);
|
||||
}
|
||||
{
|
||||
r_cons_printf (Color_RESET"esil: %s\n"Color_RESET, expr);
|
||||
@ -362,7 +363,6 @@ R_API bool r_core_visual_bit_editor(RCore *core) {
|
||||
bool colorBits = false;
|
||||
int analopType;
|
||||
int i, j, x = 0;
|
||||
RAsmOp asmop;
|
||||
RAnalOp analop;
|
||||
ut8 buf[sizeof (ut64)];
|
||||
bool bitsInLine = false;
|
||||
@ -376,6 +376,7 @@ R_API bool r_core_visual_bit_editor(RCore *core) {
|
||||
}
|
||||
memcpy (buf, core->block + cur, sizeof (ut64));
|
||||
for (;;) {
|
||||
RAsmOp asmop;
|
||||
r_cons_clear00 ();
|
||||
bool use_color = core->print->flags & R_PRINT_FLAGS_COLOR;
|
||||
(void) r_asm_disassemble (core->rasm, &asmop, buf, sizeof (ut64));
|
||||
@ -642,6 +643,7 @@ R_API bool r_core_visual_bit_editor(RCore *core) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
r_asm_op_fini (&asmop);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -528,9 +528,9 @@ static int rasm_disasm(RAsmState *as, ut64 addr, const char *buf, int len, int b
|
||||
r_anal_op_fini (&aop);
|
||||
}
|
||||
} else if (hex) {
|
||||
RAsmOp op;
|
||||
r_asm_set_pc (as->a, addr);
|
||||
while ((len - ret) > 0) {
|
||||
RAsmOp op;
|
||||
int dr = r_asm_disassemble (as->a, &op, data + ret, len - ret);
|
||||
if (dr == -1 || op.size < 1) {
|
||||
op.size = 1;
|
||||
@ -543,6 +543,7 @@ static int rasm_disasm(RAsmState *as, ut64 addr, const char *buf, int len, int b
|
||||
free (op_hex);
|
||||
ret += op.size;
|
||||
r_asm_set_pc (as->a, addr+ ret);
|
||||
r_asm_op_fini (&op);
|
||||
}
|
||||
} else {
|
||||
r_asm_set_pc (as->a, addr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user