mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-24 05:40:10 +00:00
Fix #11133 - Remove buf_hex frield from RAsmOp ##refactor
This commit is contained in:
parent
9424078b5c
commit
8058018973
@ -37,7 +37,6 @@ static int r_asm_pseudo_string(RAsmOp *op, char *input, int zero) {
|
||||
input++;
|
||||
}
|
||||
len = r_str_unescape (input) + zero;
|
||||
r_hex_bin2str ((ut8*)input, len, r_strbuf_get (&op->buf_hex));
|
||||
r_strbuf_set (&op->buf, input); // uh?
|
||||
return len;
|
||||
}
|
||||
@ -89,7 +88,6 @@ static inline int r_asm_pseudo_intN(RAsm *a, RAsmOp *op, char *input, int n) {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
r_hex_bin2str (buf, n, r_strbuf_get (&op->buf_hex));
|
||||
return n;
|
||||
}
|
||||
|
||||
@ -413,9 +411,6 @@ R_API int r_asm_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
if (mod) {
|
||||
op->size = a->pcalign - mod;
|
||||
r_strbuf_set (&op->buf_asm, "unaligned");
|
||||
r_strbuf_set (&op->buf_hex, "");
|
||||
// assume op->size after pcalign-mod will be small enough to not need checks here
|
||||
r_hex_bin2str (buf, op->size, r_strbuf_get (&op->buf_hex));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -588,11 +583,8 @@ R_API int r_asm_assemble(RAsm *a, RAsmOp *op, const char *buf) {
|
||||
if (op && ret > 0) {
|
||||
op->size = ret; // XXX shouldnt be necessary
|
||||
r_asm_op_set_asm (op, b); // XXX ase should be updating this already, isnt?
|
||||
ut8 *ophex = (ut8*)r_strbuf_get (&op->buf_hex);
|
||||
if (!*ophex) {
|
||||
ut8 *opbuf = (ut8*)r_strbuf_get (&op->buf);
|
||||
r_asm_op_set_buf (op, opbuf, ret);
|
||||
}
|
||||
ut8 *opbuf = (ut8*)r_strbuf_get (&op->buf);
|
||||
r_asm_op_set_buf (op, opbuf, ret);
|
||||
}
|
||||
free (b);
|
||||
return ret;
|
||||
@ -613,14 +605,10 @@ R_API RAsmCode* r_asm_mdisassemble(RAsm *a, const ut8 *buf, int len) {
|
||||
if (!(acode = r_asm_code_new ())) {
|
||||
return NULL;
|
||||
}
|
||||
if (!(acode->buf = malloc (1 + len))) {
|
||||
if (!(acode->bytes = malloc (1 + len))) {
|
||||
return r_asm_code_free (acode);
|
||||
}
|
||||
memcpy (acode->buf, buf, len);
|
||||
if (!(acode->buf_hex = calloc (2, len + 1))) {
|
||||
return r_asm_code_free (acode);
|
||||
}
|
||||
r_hex_bin2str (buf, len, acode->buf_hex);
|
||||
memcpy (acode->bytes, buf, len);
|
||||
if (!(buf_asm = r_strbuf_new (NULL))) {
|
||||
return r_asm_code_free (acode);
|
||||
}
|
||||
@ -637,7 +625,7 @@ 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");
|
||||
}
|
||||
acode->buf_asm = r_strbuf_drain (buf_asm);
|
||||
acode->assembly = r_strbuf_drain (buf_asm);
|
||||
acode->len = idx;
|
||||
return acode;
|
||||
}
|
||||
@ -654,7 +642,7 @@ R_API RAsmCode* r_asm_mdisassemble_hexstr(RAsm *a, RParse *p, const char *hexstr
|
||||
}
|
||||
RAsmCode *ret = r_asm_mdisassemble (a, buf, (ut64)len);
|
||||
if (ret && p) {
|
||||
r_parse_parse (p, ret->buf_asm, ret->buf_asm);
|
||||
r_parse_parse (p, ret->assembly, ret->assembly);
|
||||
}
|
||||
free (buf);
|
||||
return ret;
|
||||
@ -679,7 +667,7 @@ static void *dup_val(const void *v) {
|
||||
return (void *)strdup ((char *)v);
|
||||
}
|
||||
|
||||
R_API RAsmCode *r_asm_massemble(RAsm *a, const char *buf) {
|
||||
R_API RAsmCode *r_asm_massemble(RAsm *a, const char *assembly) {
|
||||
int num, stage, ret, idx, ctr, i, j, linenum = 0;
|
||||
char *lbuf = NULL, *ptr2, *ptr = NULL, *ptr_start = NULL;
|
||||
const char *asmcpu = NULL;
|
||||
@ -690,7 +678,7 @@ R_API RAsmCode *r_asm_massemble(RAsm *a, const char *buf) {
|
||||
char *buf_token = NULL;
|
||||
int tokens_size = 32;
|
||||
char **tokens = calloc (sizeof (char*), tokens_size);
|
||||
if (!buf) {
|
||||
if (!assembly) {
|
||||
return NULL;
|
||||
}
|
||||
ht_pp_free (a->flags);
|
||||
@ -700,18 +688,14 @@ R_API RAsmCode *r_asm_massemble(RAsm *a, const char *buf) {
|
||||
if (!(acode = r_asm_code_new ())) {
|
||||
return NULL;
|
||||
}
|
||||
if (!(acode->buf_asm = malloc (strlen (buf) + 16))) {
|
||||
if (!(acode->assembly = malloc (strlen (assembly) + 16))) {
|
||||
return r_asm_code_free (acode);
|
||||
}
|
||||
r_str_ncpy (acode->buf_asm, buf, sizeof (acode->buf_asm) - 1);
|
||||
if (!(acode->buf_hex = malloc (64))) {
|
||||
r_str_ncpy (acode->assembly, assembly, sizeof (acode->assembly) - 1);
|
||||
if (!(acode->bytes = calloc (1, 64))) {
|
||||
return r_asm_code_free (acode);
|
||||
}
|
||||
*acode->buf_hex = 0;
|
||||
if (!(acode->buf = calloc (1, 64))) {
|
||||
return r_asm_code_free (acode);
|
||||
}
|
||||
lbuf = strdup (buf);
|
||||
lbuf = strdup (assembly);
|
||||
acode->code_align = 0;
|
||||
|
||||
/* consider ,, an alias for a newline */
|
||||
@ -725,7 +709,7 @@ R_API RAsmCode *r_asm_massemble(RAsm *a, const char *buf) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// XXX: ops like mov eax, $pc+33 fail coz '+' is nov alid number!!!
|
||||
// XXX: ops like mov eax, $pc+33 fail coz '+' is not a valid number!!!
|
||||
// XXX: must be handled here to be global.. and not arch-specific
|
||||
{
|
||||
char val[32];
|
||||
@ -786,7 +770,7 @@ R_API RAsmCode *r_asm_massemble(RAsm *a, const char *buf) {
|
||||
}
|
||||
inComment = false;
|
||||
r_asm_set_pc (a, pc);
|
||||
for (idx = ret = i = j = 0, off = a->pc, acode->buf_hex[0] = '\0'; i <= ctr; i++, idx += ret) {
|
||||
for (idx = ret = i = j = 0, off = a->pc; i <= ctr; i++, idx += ret) {
|
||||
buf_token = tokens[i];
|
||||
if (!buf_token) {
|
||||
continue;
|
||||
@ -799,13 +783,9 @@ R_API RAsmCode *r_asm_massemble(RAsm *a, const char *buf) {
|
||||
}
|
||||
// XXX TODO remove arch-specific hacks
|
||||
if (!strncmp (a->cur->arch, "avr", 3)) {
|
||||
for (ptr_start = buf_token; *ptr_start && isavrseparator (*ptr_start); ptr_start++) {
|
||||
;
|
||||
}
|
||||
for (ptr_start = buf_token; *ptr_start && isavrseparator (*ptr_start); ptr_start++);
|
||||
} else {
|
||||
for (ptr_start = buf_token; *ptr_start && IS_SEPARATOR (*ptr_start); ptr_start++) {
|
||||
;
|
||||
}
|
||||
for (ptr_start = buf_token; *ptr_start && IS_SEPARATOR (*ptr_start); ptr_start++);
|
||||
}
|
||||
if (!strncmp (ptr_start, "/*", 2)) {
|
||||
if (!strstr (ptr_start + 2, "*/")) {
|
||||
@ -991,43 +971,25 @@ R_API RAsmCode *r_asm_massemble(RAsm *a, const char *buf) {
|
||||
return r_asm_code_free (acode);
|
||||
}
|
||||
acode->len = idx + ret;
|
||||
char *newbuf = realloc (acode->buf, (idx + ret) * 2);
|
||||
char *newbuf = realloc (acode->bytes, (idx + ret) * 2);
|
||||
if (!newbuf) {
|
||||
free (lbuf);
|
||||
return r_asm_code_free (acode);
|
||||
}
|
||||
acode->buf = (ut8*)newbuf;
|
||||
|
||||
const int buf_inc_size = op.buf_inc ? r_buf_size (op.buf_inc): 0;
|
||||
int newlen = strlen (acode->buf_hex) + r_strbuf_length (&op.buf_hex)
|
||||
+ buf_inc_size + 128;
|
||||
newbuf = realloc (acode->buf_hex, newlen);
|
||||
if (!newbuf) {
|
||||
free (lbuf);
|
||||
return r_asm_code_free (acode);
|
||||
}
|
||||
acode->buf_hex = newbuf;
|
||||
acode->buf = malloc (4095);
|
||||
if (acode->buf) {
|
||||
memcpy (acode->buf + idx, r_strbuf_get (&op.buf), r_strbuf_length (&op.buf)); // ret);
|
||||
}
|
||||
// XXX slow. use strbuf pls
|
||||
strcat (acode->buf_hex, r_strbuf_get (&op.buf_hex));
|
||||
acode->bytes = (ut8*)newbuf;
|
||||
memcpy (acode->bytes + idx, r_strbuf_get (&op.buf), r_strbuf_length (&op.buf));
|
||||
memset (acode->bytes + idx + ret, 0, idx + ret);
|
||||
if (op.buf_inc && r_buf_size (op.buf_inc) > 1) {
|
||||
if (*acode->buf_hex) {
|
||||
strcat (acode->buf_hex, "\n");
|
||||
}
|
||||
char *s = r_buf_free_to_string (op.buf_inc);
|
||||
if (s) {
|
||||
strcat (acode->buf_hex, s);
|
||||
free (s);
|
||||
char *inc = r_buf_free_to_string (op.buf_inc);
|
||||
if (inc) {
|
||||
ret += r_hex_str2bin (inc, acode->bytes + idx + ret);
|
||||
free (inc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
free (lbuf);
|
||||
r_hex_str2bin (acode->buf_hex, acode->buf);
|
||||
free (tokens);
|
||||
return acode;
|
||||
}
|
||||
@ -1061,8 +1023,8 @@ R_API char *r_asm_to_string(RAsm *a, ut64 addr, const ut8 *b, int l) {
|
||||
r_asm_set_pc (a, addr);
|
||||
RAsmCode *code = r_asm_mdisassemble (a, b, l);
|
||||
if (code) {
|
||||
char *buf_asm = code->buf_asm;
|
||||
code->buf_asm = NULL;
|
||||
char *buf_asm = code->assembly;
|
||||
code->assembly = NULL;
|
||||
r_asm_code_free (code);
|
||||
return buf_asm;
|
||||
}
|
||||
@ -1073,7 +1035,7 @@ R_API ut8 *r_asm_from_string(RAsm *a, ut64 addr, const char *b, int *l) {
|
||||
r_asm_set_pc (a, addr);
|
||||
RAsmCode *code = r_asm_massemble (a, b);
|
||||
if (code) {
|
||||
ut8 *buf = code->buf;
|
||||
ut8 *buf = code->bytes;
|
||||
if (l) {
|
||||
*l = code->len;
|
||||
}
|
||||
|
@ -10,9 +10,8 @@ R_API RAsmCode *r_asm_code_new(void) {
|
||||
R_API void* r_asm_code_free(RAsmCode *acode) {
|
||||
if (acode) {
|
||||
r_list_free (acode->equs);
|
||||
free (acode->buf);
|
||||
free (acode->buf_hex);
|
||||
free (acode->buf_asm);
|
||||
free (acode->bytes);
|
||||
free (acode->assembly);
|
||||
free (acode);
|
||||
}
|
||||
return NULL;
|
||||
@ -64,3 +63,12 @@ R_API char *r_asm_code_equ_replace (RAsmCode *code, char *str) {
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
R_API char* r_asm_code_get_hex(RAsmCode *acode) {
|
||||
r_return_val_if_fail (acode, NULL);
|
||||
char* str = calloc (acode->len + 1, 2);
|
||||
if (str) {
|
||||
r_hex_bin2str (acode->bytes, acode->len, str);
|
||||
}
|
||||
return str;
|
||||
}
|
@ -22,16 +22,22 @@ R_API void r_asm_op_init(RAsmOp *op) {
|
||||
R_API void r_asm_op_fini(RAsmOp *op) {
|
||||
r_strbuf_fini (&op->buf);
|
||||
r_strbuf_fini (&op->buf_asm);
|
||||
r_strbuf_fini (&op->buf_hex);
|
||||
r_buf_fini (op->buf_inc);
|
||||
}
|
||||
|
||||
// accessors
|
||||
R_API char *r_asm_op_get_hex(RAsmOp *op) {
|
||||
return r_strbuf_get (&op->buf_hex);
|
||||
r_return_val_if_fail (op, NULL);
|
||||
int size = r_strbuf_length (&op->buf);
|
||||
char* str = calloc (size + 1, 2);
|
||||
r_return_val_if_fail (str, NULL);
|
||||
|
||||
r_hex_bin2str ((const ut8*) r_strbuf_get (&op->buf), size, str);
|
||||
return str;
|
||||
}
|
||||
|
||||
R_API char *r_asm_op_get_asm(RAsmOp *op) {
|
||||
r_return_val_if_fail (op, NULL);
|
||||
return r_strbuf_get (&op->buf_asm);
|
||||
}
|
||||
|
||||
@ -52,7 +58,6 @@ R_API void r_asm_op_set_asm(RAsmOp *op, const char *str) {
|
||||
}
|
||||
|
||||
R_API int r_asm_op_set_hex(RAsmOp *op, const char *str) {
|
||||
r_strbuf_set (&op->buf_hex, str);
|
||||
ut8 *bin = (ut8*)strdup (str);
|
||||
if (bin) {
|
||||
int len = r_hex_str2bin (str, bin);
|
||||
@ -75,7 +80,6 @@ R_API int r_asm_op_set_hexbuf(RAsmOp *op, const ut8 *buf, int len) {
|
||||
return olen;
|
||||
}
|
||||
return 0;
|
||||
// TODO: update the op->buf too?
|
||||
}
|
||||
|
||||
R_API void r_asm_op_set_buf(RAsmOp *op, const ut8 *buf, int len) {
|
||||
|
@ -24,10 +24,10 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
const char *asmstr = winedbg_arm_insn_asm (arminsn);
|
||||
if (asmstr) {
|
||||
r_strbuf_set (&op->buf_asm, asmstr);
|
||||
r_strbuf_set (&op->buf_hex, winedbg_arm_insn_hex (arminsn));
|
||||
r_asm_op_set_hex(op, winedbg_arm_insn_hex (arminsn));
|
||||
} else {
|
||||
r_strbuf_set (&op->buf_asm, "invalid");
|
||||
r_strbuf_set (&op->buf_hex, "");
|
||||
r_strbuf_set (&op->buf, "");
|
||||
}
|
||||
arm_free (arminsn);
|
||||
return op->size;
|
||||
|
@ -57,7 +57,7 @@ R_API char* r_core_asm_search(RCore *core, const char *input) {
|
||||
if (!(acode = r_asm_massemble (core->assembler, input))) {
|
||||
return NULL;
|
||||
}
|
||||
ret = strdup (acode->buf_hex);
|
||||
ret = r_asm_code_get_hex (acode);
|
||||
r_asm_code_free (acode);
|
||||
return ret;
|
||||
}
|
||||
@ -490,14 +490,14 @@ R_API RList *r_core_asm_bwdisassemble(RCore *core, ut64 addr, int n, int len) {
|
||||
break;
|
||||
}
|
||||
c = r_asm_mdisassemble (core->assembler, buf+(len-idx), idx);
|
||||
if (strstr (c->buf_asm, "invalid") || strstr (c->buf_asm, ".byte")) {
|
||||
if (strstr (c->assembly, "invalid") || strstr (c->assembly, ".byte")) {
|
||||
r_asm_code_free(c);
|
||||
continue;
|
||||
}
|
||||
numinstr = 0;
|
||||
asmlen = strlen (c->buf_asm);
|
||||
asmlen = strlen (c->assembly);
|
||||
for(ii = 0; ii < asmlen; ++ii) {
|
||||
if (c->buf_asm[ii] == '\n') {
|
||||
if (c->assembly[ii] == '\n') {
|
||||
++numinstr;
|
||||
}
|
||||
}
|
||||
|
@ -4992,10 +4992,9 @@ static int cmd_debug(void *data, const char *input) {
|
||||
RAsmCode *acode;
|
||||
r_asm_set_pc (core->assembler, core->offset);
|
||||
acode = r_asm_massemble (core->assembler, input + 2);
|
||||
if (acode && *acode->buf_hex) {
|
||||
if (acode) {
|
||||
r_reg_arena_push (core->dbg->reg);
|
||||
r_debug_execute (core->dbg, acode->buf,
|
||||
acode->len, 0);
|
||||
r_debug_execute (core->dbg, acode->bytes, acode->len, 0);
|
||||
r_reg_arena_pop (core->dbg->reg);
|
||||
}
|
||||
r_asm_code_free (acode);
|
||||
|
@ -4337,12 +4337,12 @@ static int cmd_print(void *data, const char *input) {
|
||||
RAnalOp aop = {0};
|
||||
r_asm_set_pc (core->assembler, core->offset);
|
||||
RAsmCode *acode = r_asm_massemble (core->assembler, input + 2);
|
||||
if (acode && *acode->buf_hex) {
|
||||
bufsz = strlen (acode->buf_hex) >> 1;
|
||||
if (acode) {
|
||||
bufsz = acode->len;
|
||||
while (printed < bufsz) {
|
||||
aop.size = 0;
|
||||
if (r_anal_op (core->anal, &aop, core->offset,
|
||||
(const ut8 *)acode->buf + printed, bufsz - printed, R_ANAL_OP_MASK_ESIL) > 0) {
|
||||
(const ut8 *)acode->bytes + printed, bufsz - printed, R_ANAL_OP_MASK_ESIL) > 0) {
|
||||
const char *str = R_STRBUF_SAFEGET (&aop.esil);
|
||||
r_cons_println (str);
|
||||
} else {
|
||||
@ -4401,10 +4401,10 @@ static int cmd_print(void *data, const char *input) {
|
||||
{
|
||||
r_asm_set_pc (core->assembler, core->offset);
|
||||
bool is_pseudo = r_config_get_i (core->config, "asm.pseudo");
|
||||
RAsmCode *c = r_asm_mdisassemble_hexstr (core->assembler, is_pseudo ? core->parser : NULL, arg);
|
||||
if (c) {
|
||||
r_cons_print (c->buf_asm);
|
||||
r_asm_code_free (c);
|
||||
RAsmCode *acode = r_asm_mdisassemble_hexstr (core->assembler, is_pseudo ? core->parser : NULL, arg);
|
||||
if (acode) {
|
||||
r_cons_print (acode->assembly);
|
||||
r_asm_code_free (acode);
|
||||
} else {
|
||||
eprintf ("Invalid hexstr\n");
|
||||
}
|
||||
@ -4424,10 +4424,10 @@ static int cmd_print(void *data, const char *input) {
|
||||
int bytes;
|
||||
r_asm_set_pc (core->assembler, core->offset);
|
||||
RAsmCode *acode = r_asm_massemble (core->assembler, input + 1);
|
||||
if (acode && *acode->buf_hex) {
|
||||
bytes = strlen (acode->buf_hex) >> 1;
|
||||
if (acode) {
|
||||
bytes = acode->len;
|
||||
for (i = 0; i < bytes; i++) {
|
||||
ut8 b = acode->buf[i]; // core->print->big_endian? (bytes - 1 - i): i ];
|
||||
ut8 b = acode->bytes[i]; // core->print->big_endian? (bytes - 1 - i): i ];
|
||||
r_cons_printf ("%02x", b);
|
||||
}
|
||||
r_cons_newline ();
|
||||
|
@ -183,6 +183,7 @@ static void cmd_write_fail() {
|
||||
}
|
||||
|
||||
R_API int cmd_write_hexpair(RCore* core, const char* pairs) {
|
||||
r_return_val_if_fail (core && pairs, 0);
|
||||
ut8 *buf = malloc (strlen (pairs) + 1);
|
||||
int len = r_hex_str2bin (pairs, buf);
|
||||
if (len != 0) {
|
||||
@ -1437,19 +1438,21 @@ static int cmd_write(void *data, const char *input) {
|
||||
r_asm_set_pc (core->assembler, core->offset);
|
||||
acode = r_asm_massemble (core->assembler, file);
|
||||
if (acode) {
|
||||
char* hex = r_asm_code_get_hex (acode);
|
||||
if (input[1] == '*') {
|
||||
cmd_write_hexpair (core, acode->buf_hex);
|
||||
cmd_write_hexpair (core, hex);
|
||||
} else {
|
||||
if (!r_core_write_at (core, core->offset, acode->buf, acode->len)) {
|
||||
if (!r_core_write_at (core, core->offset, acode->bytes, acode->len)) {
|
||||
cmd_write_fail ();
|
||||
} else {
|
||||
if (r_config_get_i (core->config, "scr.prompt")) {
|
||||
eprintf ("Written %d byte(s) (%s) = wx %s\n", acode->len, input+2, acode->buf_hex);
|
||||
eprintf ("Written %d byte(s) (%s) = wx %s\n", acode->len, input+2, hex);
|
||||
}
|
||||
WSEEK (core, acode->len);
|
||||
}
|
||||
r_core_block_read (core);
|
||||
}
|
||||
free (hex);
|
||||
r_asm_code_free (acode);
|
||||
}
|
||||
}
|
||||
@ -1479,8 +1482,10 @@ static int cmd_write(void *data, const char *input) {
|
||||
}
|
||||
if (*b) {
|
||||
RAsmCode *ac = r_asm_massemble (core->assembler, b);
|
||||
if (ac && *ac->buf_hex) {
|
||||
r_cons_printf ("wx %s @ 0x%08"PFMT64x"\n", ac->buf_hex, addr);
|
||||
char* hex = r_asm_code_get_hex (ac);
|
||||
if (hex) {
|
||||
r_cons_printf ("wx %s @ 0x%08"PFMT64x"\n", hex, addr);
|
||||
free (hex);
|
||||
}
|
||||
r_asm_code_free (ac);
|
||||
}
|
||||
@ -1501,19 +1506,21 @@ static int cmd_write(void *data, const char *input) {
|
||||
r_asm_set_pc (core->assembler, core->offset);
|
||||
RAsmCode *acode = r_asm_assemble_file (core->assembler, file);
|
||||
if (acode) {
|
||||
char* hex = r_asm_code_get_hex (acode);
|
||||
if (input[2] == '*') {
|
||||
cmd_write_hexpair (core, acode->buf_hex);
|
||||
cmd_write_hexpair (core, hex);
|
||||
} else {
|
||||
if (r_config_get_i (core->config, "scr.prompt")) {
|
||||
eprintf ("Written %d byte(s) (%s)=wx %s\n", acode->len, input+1, acode->buf_hex);
|
||||
eprintf ("Written %d byte(s) (%s)=wx %s\n", acode->len, input+1, hex);
|
||||
}
|
||||
if (!r_core_write_at (core, core->offset, acode->buf, acode->len)) {
|
||||
if (!r_core_write_at (core, core->offset, acode->bytes, acode->len)) {
|
||||
cmd_write_fail ();
|
||||
} else {
|
||||
WSEEK (core, acode->len);
|
||||
}
|
||||
r_core_block_read (core);
|
||||
}
|
||||
free (hex);
|
||||
r_asm_code_free (acode);
|
||||
} else {
|
||||
eprintf ("Cannot assemble file\n");
|
||||
|
@ -33,16 +33,17 @@ static int readline_callback(void *_a, const char *str) {
|
||||
r_asm_code_free (a->acode);
|
||||
r_asm_set_pc (a->core->assembler, a->off);
|
||||
a->acode = r_asm_massemble (a->core->assembler, str);
|
||||
char* hex = r_asm_code_get_hex (a->acode);
|
||||
r_cons_printf ("[VA:%d]> %s\n", a->acode? a->acode->len: 0, str);
|
||||
if (a->acode && a->acode->len) {
|
||||
r_cons_printf ("* %s\n\n", a->acode->buf_hex);
|
||||
r_cons_printf ("* %s\n\n", hex);
|
||||
} else {
|
||||
r_cons_print ("\n\n");
|
||||
}
|
||||
if (a->acode) {
|
||||
xlen = R_MIN (strlen (a->acode->buf_hex), R_VISUAL_ASM_BUFSIZE - 2);
|
||||
xlen = R_MIN (strlen (hex), R_VISUAL_ASM_BUFSIZE - 2);
|
||||
strcpy (a->codebuf, a->blockbuf);
|
||||
memcpy (a->codebuf, a->acode->buf_hex, xlen);
|
||||
memcpy (a->codebuf, hex, xlen);
|
||||
if (xlen >= strlen (a->blockbuf)) {
|
||||
a->codebuf[xlen] = '\0';
|
||||
}
|
||||
@ -61,6 +62,7 @@ static int readline_callback(void *_a, const char *str) {
|
||||
free (res);
|
||||
free (cmd);
|
||||
}
|
||||
free (hex);
|
||||
}
|
||||
r_cons_flush ();
|
||||
return 1;
|
||||
@ -78,7 +80,7 @@ R_API void r_core_visual_asm(RCore *core, ut64 off) {
|
||||
|
||||
if (cva.acode && cva.acode->len > 0) {
|
||||
if (r_cons_yesno ('y', "Save changes? (Y/n)")) {
|
||||
if (!r_io_write_at (core->io, off, cva.acode->buf, cva.acode->len)) {
|
||||
if (!r_io_write_at (core->io, off, cva.acode->bytes, cva.acode->len)) {
|
||||
eprintf ("ERROR: Cannot write in here, check map permissions or reopen the file with oo+\n");
|
||||
r_cons_any_key (NULL);
|
||||
}
|
||||
|
@ -315,7 +315,7 @@ R_API bool r_egg_assemble_asm(REgg *egg, char **asm_list) {
|
||||
asmcode = r_asm_massemble (egg->rasm, code);
|
||||
if (asmcode) {
|
||||
if (asmcode->len > 0) {
|
||||
r_buf_append_bytes (egg->bin, asmcode->buf, asmcode->len);
|
||||
r_buf_append_bytes (egg->bin, asmcode->bytes, asmcode->len);
|
||||
}
|
||||
// LEAK r_asm_code_free (asmcode);
|
||||
} else {
|
||||
|
@ -68,16 +68,14 @@ typedef struct r_asm_op_t {
|
||||
// But this is pretty slow..so maybe we should add some accessors
|
||||
RStrBuf buf;
|
||||
RStrBuf buf_asm;
|
||||
RStrBuf buf_hex;
|
||||
RBuffer *buf_inc; // must die
|
||||
} RAsmOp;
|
||||
|
||||
typedef struct r_asm_code_t {
|
||||
#if 1
|
||||
int len;
|
||||
ut8 *buf;
|
||||
char *buf_hex;
|
||||
char *buf_asm;
|
||||
ut8 *bytes;
|
||||
char *assembly;
|
||||
#else
|
||||
RAsmOp op; // we have those fields already inside RAsmOp
|
||||
#endif
|
||||
@ -182,8 +180,9 @@ R_API void r_asm_list_directives(void);
|
||||
R_API RAsmCode *r_asm_code_new(void);
|
||||
R_API void* r_asm_code_free(RAsmCode *acode);
|
||||
R_API void r_asm_equ_item_free(RAsmEqu *equ);
|
||||
R_API bool r_asm_code_set_equ (RAsmCode *code, const char *key, const char *value);
|
||||
R_API char *r_asm_code_equ_replace (RAsmCode *code, char *str);
|
||||
R_API bool r_asm_code_set_equ(RAsmCode *code, const char *key, const char *value);
|
||||
R_API char *r_asm_code_equ_replace(RAsmCode *code, char *str);
|
||||
R_API char* r_asm_code_get_hex(RAsmCode *acode);
|
||||
|
||||
/* op.c */
|
||||
R_API RAsmOp *r_asm_op_new(void);
|
||||
|
@ -215,7 +215,7 @@ static int cb(RDiff *d, void *user, RDiffOp *op) {
|
||||
if (core) {
|
||||
int len = R_MAX (4, op->a_len);
|
||||
RAsmCode *ac = r_asm_mdisassemble (core->assembler, op->a_buf, len);
|
||||
char *acbufasm = strdup (ac->buf_asm);
|
||||
char *acbufasm = strdup (ac->assembly);
|
||||
if (quiet) {
|
||||
char *bufasm = r_str_prefix_all (acbufasm, "- ");
|
||||
printf ("%s\n", bufasm);
|
||||
@ -248,7 +248,7 @@ static int cb(RDiff *d, void *user, RDiffOp *op) {
|
||||
if (core) {
|
||||
int len = R_MAX (4, op->b_len);
|
||||
RAsmCode *ac = r_asm_mdisassemble (core->assembler, op->b_buf, len);
|
||||
char *acbufasm = strdup (ac->buf_asm);
|
||||
char *acbufasm = strdup (ac->assembly);
|
||||
if (quiet) {
|
||||
char *bufasm = r_str_prefix_all (acbufasm, "+ ");
|
||||
printf ("%s\n", bufasm);
|
||||
|
@ -360,7 +360,6 @@ static int rasm_disasm(RAsmState *as, char *buf, ut64 offset, int len, int bits,
|
||||
if (dr == -1 || op.size < 1) {
|
||||
op.size = 1;
|
||||
r_asm_op_set_asm (&op, "invalid");
|
||||
r_strbuf_set (&op.buf_hex, sdb_fmt ("%02x", data[ret]));
|
||||
}
|
||||
printf ("0x%08" PFMT64x " %2d %24s %s\n",
|
||||
as->a->pc, op.size, r_asm_op_get_hex (&op),
|
||||
@ -374,10 +373,10 @@ static int rasm_disasm(RAsmState *as, char *buf, ut64 offset, int len, int bits,
|
||||
goto beach;
|
||||
}
|
||||
if (as->oneliner) {
|
||||
r_str_replace_char (acode->buf_asm, '\n', ';');
|
||||
printf ("%s\"\n", acode->buf_asm);
|
||||
r_str_replace_char (acode->assembly, '\n', ';');
|
||||
printf ("%s\"\n", acode->assembly);
|
||||
} else {
|
||||
printf ("%s", acode->buf_asm);
|
||||
printf ("%s", acode->assembly);
|
||||
}
|
||||
ret = acode->len;
|
||||
r_asm_code_free (acode);
|
||||
@ -421,7 +420,7 @@ static int rasm_asm(RAsmState *as, const char *buf, ut64 offset, ut64 len, int b
|
||||
if (acode->len) {
|
||||
ret = acode->len;
|
||||
if (bin) {
|
||||
if ((ret = write (1, acode->buf, acode->len)) != acode->len) {
|
||||
if ((ret = write (1, acode->bytes, acode->len)) != acode->len) {
|
||||
eprintf ("Failed to write buffer\n");
|
||||
r_asm_code_free (acode);
|
||||
return 0;
|
||||
@ -432,7 +431,7 @@ static int rasm_asm(RAsmState *as, const char *buf, ut64 offset, ut64 len, int b
|
||||
int bytes = (b / 8) + 1;
|
||||
for (i = 0; i < bytes; i++) {
|
||||
for (j = 0; j < 8 && b--; j++) {
|
||||
printf ("%c", (acode->buf[i] & (1 << j))? '1': '0');
|
||||
printf ("%c", (acode->bytes[i] & (1 << j))? '1': '0');
|
||||
}
|
||||
}
|
||||
printf ("\n");
|
||||
@ -440,7 +439,7 @@ static int rasm_asm(RAsmState *as, const char *buf, ut64 offset, ut64 len, int b
|
||||
if (hexwords) {
|
||||
size_t i = 0;
|
||||
for (i = 0; i < acode->len; i += sizeof (ut32)) {
|
||||
ut32 dword = r_read_ble32 (acode->buf + i, R_SYS_ENDIAN);
|
||||
ut32 dword = r_read_ble32 (acode->bytes + i, R_SYS_ENDIAN);
|
||||
printf ("0x%08x ", dword);
|
||||
if ((i/4) == 7) {
|
||||
printf ("\n");
|
||||
@ -448,7 +447,11 @@ static int rasm_asm(RAsmState *as, const char *buf, ut64 offset, ut64 len, int b
|
||||
}
|
||||
printf ("\n");
|
||||
} else {
|
||||
print_buf (as, acode->buf_hex);
|
||||
char* str = r_asm_code_get_hex (acode);
|
||||
if (str) {
|
||||
print_buf (as, str);
|
||||
free (str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user