mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-17 04:39:36 +00:00
Make RAsmOp use RStrBuf instead of fixed-size buffers
* Seems to work, but there are many things to improve and fix * Fixed some bugs (overflow, sandbox bypass, ..) * Exposes some memleaks and bad api usages. * Refactor all the things! \o/ * Fix z80, tms320 disasm and x86.as * Care about memleaks * Support meson * And fix more tests related to pda and pdj and m68k
This commit is contained in:
parent
f7341d1949
commit
6d05365f30
@ -96,7 +96,9 @@ static int openfile(const char *f, int x) {
|
||||
}
|
||||
}
|
||||
#if __UNIX__
|
||||
if (x) fchmod (fd, 0755);
|
||||
if (x) {
|
||||
fchmod (fd, 0755);
|
||||
}
|
||||
#endif
|
||||
#if _MSC_VER
|
||||
_chsize (fd, 0);
|
||||
|
@ -290,11 +290,12 @@ static int rasm_disasm(char *buf, ut64 offset, int len, int bits, int ascii, int
|
||||
int dr = r_asm_disassemble (a, &op, data + ret, len - ret);
|
||||
if (dr == -1 || op.size < 1) {
|
||||
op.size = 1;
|
||||
strcpy (op.buf_asm, "invalid");
|
||||
sprintf (op.buf_hex, "%02x", data[ret]);
|
||||
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",
|
||||
a->pc, op.size, op.buf_hex, op.buf_asm);
|
||||
a->pc, op.size, r_asm_op_get_hex (&op),
|
||||
r_asm_op_get_asm (&op));
|
||||
ret += op.size;
|
||||
r_asm_set_pc (a, offset + ret);
|
||||
}
|
||||
|
@ -181,8 +181,7 @@ R_API int r_anal_esil_fire_interrupt(RAnalEsil *esil, int interrupt) {
|
||||
return false;
|
||||
}
|
||||
icb = (RAnalEsilInterruptCB)sdb_ptr_get (esil->interrupts, i, 0);
|
||||
if (icb) return icb (esil, interrupt);
|
||||
return false;
|
||||
return icb? icb (esil, interrupt): false;
|
||||
}
|
||||
|
||||
R_API bool r_anal_esil_set_pc(RAnalEsil *esil, ut64 addr) {
|
||||
@ -2568,17 +2567,20 @@ static int esil_num(RAnalEsil *esil) {
|
||||
|
||||
/* duplicate the last element in the stack */
|
||||
static int esil_dup(RAnalEsil *esil) {
|
||||
if (!esil || !esil->stack || esil->stackptr < 1 || esil->stackptr > (esil->stacksize - 1))
|
||||
if (!esil || !esil->stack || esil->stackptr < 1 || esil->stackptr > (esil->stacksize - 1)) {
|
||||
return false;
|
||||
}
|
||||
return r_anal_esil_push (esil, esil->stack[esil->stackptr-1]);
|
||||
}
|
||||
|
||||
static int esil_swap(RAnalEsil *esil) {
|
||||
char *tmp;
|
||||
if (!esil || !esil->stack || esil->stackptr < 2)
|
||||
if (!esil || !esil->stack || esil->stackptr < 2) {
|
||||
return false;
|
||||
if (!esil->stack[esil->stackptr-1] || !esil->stack[esil->stackptr-2])
|
||||
}
|
||||
if (!esil->stack[esil->stackptr-1] || !esil->stack[esil->stackptr-2]) {
|
||||
return false;
|
||||
}
|
||||
tmp = esil->stack[esil->stackptr-1];
|
||||
esil->stack[esil->stackptr-1] = esil->stack[esil->stackptr-2];
|
||||
esil->stack[esil->stackptr-2] = tmp;
|
||||
@ -2914,6 +2916,8 @@ loop:
|
||||
esil->skip = 0;
|
||||
esil->parse_goto = -1;
|
||||
esil->parse_stop = 0;
|
||||
// memleak or failing aetr test. wat du
|
||||
// r_anal_esil_stack_free (esil);
|
||||
esil->parse_goto_count = esil->anal? esil->anal->esil_goto_limit: R_ANAL_ESIL_GOTO_LIMIT;
|
||||
str = ostr;
|
||||
repeat:
|
||||
@ -2938,7 +2942,6 @@ repeat:
|
||||
word[wordi] = 0;
|
||||
dorunword = 2;
|
||||
}
|
||||
|
||||
if (dorunword) {
|
||||
if (*word) {
|
||||
if (!runword (esil, word)) {
|
||||
@ -2947,9 +2950,9 @@ repeat:
|
||||
word[wordi] = ',';
|
||||
wordi = 0;
|
||||
switch (evalWord (esil, ostr, &str)) {
|
||||
case 0: goto loop;
|
||||
case 1: return 0;
|
||||
case 2: continue;
|
||||
case 0: goto loop;
|
||||
case 1: return 0;
|
||||
case 2: continue;
|
||||
}
|
||||
if (dorunword == 1) {
|
||||
return 0;
|
||||
@ -2960,7 +2963,9 @@ repeat:
|
||||
word[wordi++] = *str;
|
||||
//is *str is '\0' in the next iteration the condition will be true
|
||||
//reading beyond the boundaries
|
||||
if (*str) str++;
|
||||
if (*str) {
|
||||
str++;
|
||||
}
|
||||
}
|
||||
word[wordi] = 0;
|
||||
if (*word) {
|
||||
|
@ -97,8 +97,9 @@ R_API void r_anal_esil_trace (RAnalEsil *esil, RAnalOp *op) {
|
||||
}
|
||||
ocbs = esil->cb;
|
||||
ocbs_set = true;
|
||||
if (!DB) DB = sdb_new0 ();
|
||||
|
||||
if (!DB) {
|
||||
DB = sdb_new0 ();
|
||||
}
|
||||
sdb_num_set (DB, "idx", esil->trace_idx, 0);
|
||||
sdb_num_set (DB, KEY ("addr"), op->addr, 0);
|
||||
// sdb_set (DB, KEY ("opcode"), op->mnemonic, 0);
|
||||
|
@ -329,6 +329,7 @@ R_API void r_anal_fcn_free(void *_fcn) {
|
||||
}
|
||||
free (fcn->fingerprint);
|
||||
r_anal_diff_free (fcn->diff);
|
||||
r_list_free (fcn->fcn_locs);
|
||||
free (fcn->args);
|
||||
free (fcn);
|
||||
}
|
||||
@ -557,6 +558,7 @@ static bool is_delta_pointer_table (RAnal *anal, RAnalFunction *fcn, ut64 addr,
|
||||
if (aop->type == R_ANAL_OP_TYPE_ADD) {
|
||||
add_aop = *aop;
|
||||
}
|
||||
r_anal_op_fini (aop);
|
||||
i += len - 1;
|
||||
}
|
||||
if (!isValid) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2014 Condret */
|
||||
/* radare - LGPL - Copyright 2014-2018 condret */
|
||||
|
||||
#include <string.h>
|
||||
#include <r_types.h>
|
||||
@ -9,34 +9,32 @@
|
||||
#define WS_API static
|
||||
#include "../../asm/arch/whitespace/wsdis.c"
|
||||
|
||||
|
||||
static ut64 ws_find_label(int l, RIOBind iob) {
|
||||
RIO *io = iob.io;
|
||||
ut64 cur = 0, size = iob.desc_size (io->desc);
|
||||
ut8 buf[128];
|
||||
RAsmOp aop;;
|
||||
RAsmOp aop;
|
||||
iob.read_at (iob.io, cur, buf, 128);
|
||||
while (cur <= size && wsdis(&aop, buf, 128)) {
|
||||
if( aop.buf_asm[0] == 'm' &&
|
||||
aop.buf_asm[1] == 'a' &&
|
||||
l == atoi(&aop.buf_asm[5])) {
|
||||
return cur;
|
||||
while (cur <= size && wsdis (&aop, buf, 128)) {
|
||||
const char *buf_asm = r_strbuf_get (&aop.buf_asm); // r_asm_op_get_asm (&aop);
|
||||
if (buf_asm && (strlen (buf_asm) > 4) && buf_asm[0] == 'm' && buf_asm[1] == 'a' && l == atoi (buf_asm + 5)) {
|
||||
return cur;
|
||||
}
|
||||
cur = cur + aop.size;
|
||||
iob.read_at(iob.io, cur, buf, 128);
|
||||
iob.read_at (iob.io, cur, buf, 128);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ws_anal(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len) {
|
||||
RAsmOp *aop;
|
||||
memset (op, '\0', sizeof(RAnalOp));
|
||||
memset (op, '\0', sizeof (RAnalOp));
|
||||
op->addr = addr;
|
||||
op->type = R_ANAL_OP_TYPE_UNK;
|
||||
aop = R_NEW0 (RAsmOp);
|
||||
RAsmOp *aop = R_NEW0 (RAsmOp);
|
||||
op->size = wsdis (aop, data, len);
|
||||
if (op->size) {
|
||||
switch (aop->buf_asm[0]) {
|
||||
const char *buf_asm = r_strbuf_get (&aop->buf_asm); // r_asm_op_get_asm (aop);
|
||||
switch (*buf_asm) {
|
||||
case 'n':
|
||||
op->type = R_ANAL_OP_TYPE_NOP;
|
||||
break;
|
||||
@ -44,10 +42,7 @@ static int ws_anal(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
|
||||
op->type = R_ANAL_OP_TYPE_TRAP;
|
||||
break;
|
||||
case 'd':
|
||||
if(aop->buf_asm[1] == 'u')
|
||||
op->type = R_ANAL_OP_TYPE_UPUSH;
|
||||
else
|
||||
op->type = R_ANAL_OP_TYPE_DIV;
|
||||
op->type = (buf_asm[1] == 'u')? R_ANAL_OP_TYPE_UPUSH: R_ANAL_OP_TYPE_DIV;
|
||||
break;
|
||||
case 'i':
|
||||
op->type = R_ANAL_OP_TYPE_ILL;
|
||||
@ -56,10 +51,7 @@ static int ws_anal(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
|
||||
op->type = R_ANAL_OP_TYPE_ADD;
|
||||
break;
|
||||
case 'm':
|
||||
if(aop->buf_asm[1] == 'o')
|
||||
op->type = R_ANAL_OP_TYPE_MOD;
|
||||
else
|
||||
op->type = R_ANAL_OP_TYPE_MUL;
|
||||
op->type = (buf_asm[1] == 'o') ? R_ANAL_OP_TYPE_MOD : R_ANAL_OP_TYPE_MUL;
|
||||
break;
|
||||
case 'r':
|
||||
op->type = R_ANAL_OP_TYPE_RET;
|
||||
@ -68,21 +60,21 @@ static int ws_anal(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
|
||||
op->type = R_ANAL_OP_TYPE_LOAD;
|
||||
break;
|
||||
case 'c':
|
||||
if(aop->buf_asm[1] == 'a') {
|
||||
if (buf_asm[1] == 'a') {
|
||||
op->type = R_ANAL_OP_TYPE_CALL;
|
||||
op->fail = addr + aop->size;
|
||||
op->jump = ws_find_label(atoi(&aop->buf_asm[5]), anal->iob);
|
||||
op->jump = ws_find_label (atoi (buf_asm + 5), anal->iob);
|
||||
} else {
|
||||
op->type = R_ANAL_OP_TYPE_UPUSH;
|
||||
}
|
||||
break;
|
||||
case 'j':
|
||||
if(aop->buf_asm[1] == 'm') {
|
||||
if (buf_asm[1] == 'm') {
|
||||
op->type = R_ANAL_OP_TYPE_JMP;
|
||||
op->jump = ws_find_label(atoi(&aop->buf_asm[4]), anal->iob);
|
||||
op->jump = ws_find_label(atoi (buf_asm + 4), anal->iob);
|
||||
} else {
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->jump = ws_find_label(atoi(&aop->buf_asm[3]), anal->iob);
|
||||
op->jump = ws_find_label(atoi(buf_asm + 3), anal->iob);
|
||||
}
|
||||
op->fail = addr + aop->size;
|
||||
break;
|
||||
@ -90,18 +82,17 @@ static int ws_anal(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
|
||||
op->type = R_ANAL_OP_TYPE_IO;
|
||||
break;
|
||||
case 'p':
|
||||
if(aop->buf_asm[1] == 'o') {
|
||||
if (buf_asm[1] == 'o') {
|
||||
op->type = R_ANAL_OP_TYPE_POP;
|
||||
} else {
|
||||
if(aop->buf_asm[2] == 's') {
|
||||
if (buf_asm[2] == 's') {
|
||||
op->type = R_ANAL_OP_TYPE_PUSH;
|
||||
if(127 > atoi(&aop->buf_asm[5])
|
||||
&& atoi(&aop->buf_asm[5]) >= 33) {
|
||||
if (127 > atoi (buf_asm + 5) && atoi (buf_asm + 5) >= 33) {
|
||||
char c[4];
|
||||
c[3] = '\0';
|
||||
c[0] = c[2] = '\'';
|
||||
c[1] = (char) atoi(&aop->buf_asm[5]);
|
||||
r_meta_set_string(anal, R_META_TYPE_COMMENT, addr, c);
|
||||
c[1] = (char) atoi (buf_asm + 5);
|
||||
r_meta_set_string (anal, R_META_TYPE_COMMENT, addr, c);
|
||||
}
|
||||
} else {
|
||||
op->type = R_ANAL_OP_TYPE_IO;
|
||||
@ -109,23 +100,22 @@ static int ws_anal(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
switch (aop->buf_asm[1]) {
|
||||
case 'u':
|
||||
op->type = R_ANAL_OP_TYPE_SUB;
|
||||
break;
|
||||
case 't':
|
||||
op->type = R_ANAL_OP_TYPE_STORE;
|
||||
break;
|
||||
case 'l':
|
||||
op->type = R_ANAL_OP_TYPE_LOAD; // XXX
|
||||
break;
|
||||
case 'w':
|
||||
op->type = R_ANAL_OP_TYPE_ROR;
|
||||
switch (buf_asm[1]) {
|
||||
case 'u':
|
||||
op->type = R_ANAL_OP_TYPE_SUB;
|
||||
break;
|
||||
case 't':
|
||||
op->type = R_ANAL_OP_TYPE_STORE;
|
||||
break;
|
||||
case 'l':
|
||||
op->type = R_ANAL_OP_TYPE_LOAD; // XXX
|
||||
break;
|
||||
case 'w':
|
||||
op->type = R_ANAL_OP_TYPE_ROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
r_asm_op_free(aop);
|
||||
return op->size;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ plugins: ${LIBSO} ${LIBAR}
|
||||
|
||||
include ${STATIC_ASM_PLUGINS}
|
||||
STATIC_OBJS=$(subst ..,p/..,$(subst asm_,p/asm_,$(STATIC_OBJ)))
|
||||
OBJS=${STATIC_OBJS} asm.o code.o
|
||||
OBJS=${STATIC_OBJS} asm.o code.o op.o
|
||||
# hack to b
|
||||
OBJS+=${SHARED2_OBJ}
|
||||
|
||||
|
@ -138,39 +138,41 @@ static int _6502Disass (ut64 pc, RAsmOp *op, const ut8 *buf, ut64 len) {
|
||||
int i;
|
||||
for (i=0; ops[i].name != NULL; i++) {
|
||||
if (ops[i].op == buf[0]) {
|
||||
const char *buf_asm = "invalid";
|
||||
int len = ops[i].len;
|
||||
switch (ops[i].len) {
|
||||
case 1:
|
||||
sprintf (op->buf_asm, "%s", ops[i].name);
|
||||
buf_asm = sdb_fmt ("%s", ops[i].name);
|
||||
break;
|
||||
case 2:
|
||||
if (len>1) {
|
||||
sprintf (op->buf_asm, ops[i].name, buf[1]);
|
||||
if (len > 1) {
|
||||
buf_asm = sdb_fmt (ops[i].name, buf[1]);
|
||||
} else {
|
||||
strcpy (op->buf_asm, "truncated");
|
||||
return -1;
|
||||
buf_asm = "truncated";
|
||||
len = -1;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (len>2) {
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), ops[i].name, buf[1]+0x100*buf[2]);
|
||||
if (len > 2) {
|
||||
buf_asm = sdb_fmt (ops[i].name, buf[1] + 0x100 * buf[2]);
|
||||
} else {
|
||||
strcpy (op->buf_asm, "truncated");
|
||||
return -1;
|
||||
buf_asm = "truncated";
|
||||
len = -1;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (len>3) {
|
||||
sprintf (op->buf_asm, ops[i].name,
|
||||
buf[1]+0x100*buf[2]+0x10000*buf[3]);
|
||||
if (len > 3) {
|
||||
buf_asm = sdb_fmt (ops[i].name, buf[1]+0x100*buf[2]+0x10000*buf[3]);
|
||||
} else {
|
||||
strcpy (op->buf_asm, "truncated");
|
||||
return -1;
|
||||
buf_asm = "truncated";
|
||||
len = -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
goto beach;
|
||||
}
|
||||
return ops[i].len;
|
||||
r_strbuf_set (&op->buf_asm, buf_asm);
|
||||
return len;
|
||||
}
|
||||
}
|
||||
beach:
|
||||
|
@ -116,7 +116,7 @@ int _8051_disas (ut64 pc, RAsmOp *op, const ut8 *buf, ut64 len) {
|
||||
val1 = buf[1];
|
||||
}
|
||||
} else {
|
||||
strcpy (op->buf_asm, "truncated");
|
||||
r_strbuf_set (&op->buf_asm, "truncated");
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
@ -154,7 +154,7 @@ int _8051_disas (ut64 pc, RAsmOp *op, const ut8 *buf, ut64 len) {
|
||||
val1 = buf[1];
|
||||
}
|
||||
} else {
|
||||
strcpy (op->buf_asm, "truncated");
|
||||
r_strbuf_set (&op->buf_asm, "truncated");
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
@ -167,7 +167,7 @@ int _8051_disas (ut64 pc, RAsmOp *op, const ut8 *buf, ut64 len) {
|
||||
if (disasm) {
|
||||
disasm = _replace_register (disasm, arg1, val1);
|
||||
disasm = _replace_register (disasm, arg2, val2);
|
||||
r_str_ncpy (op->buf_asm, disasm, sizeof (op->buf_asm));
|
||||
r_strbuf_set (&op->buf_asm, disasm);
|
||||
free (disasm);
|
||||
}
|
||||
return oplen;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2013-2014 - condret@runas-racer.com */
|
||||
/* radare - LGPL - Copyright 2013-2018 - condret, pancake */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
@ -9,14 +9,14 @@
|
||||
#include "gb_op_table.h"
|
||||
|
||||
static int gbOpLength(int gboptype){
|
||||
switch(gboptype) {
|
||||
switch (gboptype) {
|
||||
case GB_8BIT:
|
||||
return 1;
|
||||
case GB_8BIT+ARG_8+GB_IO:
|
||||
case GB_8BIT+ARG_8:
|
||||
case GB_8BIT + ARG_8 + GB_IO:
|
||||
case GB_8BIT + ARG_8:
|
||||
case GB_16BIT:
|
||||
return 2;
|
||||
case GB_8BIT+ARG_16:
|
||||
case GB_8BIT + ARG_16:
|
||||
return 3;
|
||||
}
|
||||
return 0;
|
||||
@ -25,25 +25,30 @@ static int gbOpLength(int gboptype){
|
||||
#ifndef GB_DIS_LEN_ONLY
|
||||
static int gbDisass(RAsmOp *op, const ut8 *buf, int len){
|
||||
int foo = gbOpLength (gb_op[buf[0]].type);
|
||||
if (len<foo)
|
||||
if (len < foo) {
|
||||
return 0;
|
||||
}
|
||||
const char *buf_asm = NULL;
|
||||
switch (gb_op[buf[0]].type) {
|
||||
case GB_8BIT:
|
||||
sprintf (op->buf_asm, "%s", gb_op[buf[0]].name);
|
||||
buf_asm = sdb_fmt ("%s", gb_op[buf[0]].name);
|
||||
break;
|
||||
case GB_16BIT:
|
||||
sprintf (op->buf_asm, "%s %s", cb_ops[buf[1]>>3], cb_regs[buf[1]&7]);
|
||||
buf_asm = sdb_fmt ("%s %s", cb_ops[buf[1]>>3], cb_regs[buf[1]&7]);
|
||||
break;
|
||||
case GB_8BIT+ARG_8:
|
||||
sprintf (op->buf_asm, gb_op[buf[0]].name, buf[1]);
|
||||
buf_asm = sdb_fmt (gb_op[buf[0]].name, buf[1]);
|
||||
break;
|
||||
case GB_8BIT+ARG_16:
|
||||
sprintf (op->buf_asm, gb_op[buf[0]].name, buf[1]+0x100*buf[2]);
|
||||
buf_asm = sdb_fmt (gb_op[buf[0]].name, buf[1]+0x100*buf[2]);
|
||||
break;
|
||||
case GB_8BIT+ARG_8+GB_IO:
|
||||
sprintf (op->buf_asm, gb_op[buf[0]].name, 0xff00+buf[1]);
|
||||
buf_asm = sdb_fmt (gb_op[buf[0]].name, 0xff00+buf[1]);
|
||||
break;
|
||||
}
|
||||
if (buf_asm) {
|
||||
r_strbuf_set (&op->buf_asm, buf_asm);
|
||||
}
|
||||
return foo;
|
||||
}
|
||||
#endif
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2014-2016 - condret@runas-racer.com */
|
||||
/* radare - LGPL - Copyright 2014-2018 - condret, pancake */
|
||||
|
||||
#include <r_asm.h>
|
||||
#include <r_types.h>
|
||||
@ -57,40 +57,37 @@ static int i4004_get_ins_len (ut8 hex) {
|
||||
}
|
||||
|
||||
static int i4004dis (RAsmOp *op, const ut8 *buf, int len) {
|
||||
const size_t basz = sizeof (op->buf_asm)-1;
|
||||
char *basm = op->buf_asm;
|
||||
int rlen = i4004_get_ins_len (*buf);
|
||||
ut8 high = (*buf & 0xf0)>>4;
|
||||
ut8 high = (*buf & 0xf0) >> 4;
|
||||
ut8 low = (*buf & 0xf);
|
||||
|
||||
if (rlen > len) return op->size = 0;
|
||||
switch (high) {
|
||||
case 0: strcpy (basm, low? "invalid": "nop"); break;
|
||||
case 1: snprintf (basm, basz, "jcn %d 0x%02x", low, buf[1]); break;
|
||||
case 2:
|
||||
if (rlen == 1)
|
||||
snprintf (basm, basz, "src r%d", (low & 0xe));
|
||||
else snprintf (basm, basz, "fim r%d, 0x%02x", (low & 0xe), buf[1]);
|
||||
break;
|
||||
case 3: snprintf (basm, basz, "fin r%d", (low & 0xe)); break;
|
||||
case 4: snprintf (basm, basz, "jun 0x%03x", ((ut16)(low<<8) | buf[1])); break;
|
||||
case 5: snprintf (basm, basz, "jms 0x%03x", ((ut16)(low<<8) | buf[1])); break;
|
||||
case 6: snprintf (basm, basz, "inc r%d", low); break;
|
||||
case 7: snprintf (basm, basz, "isz r%d, 0x%02x", low, buf[1]); break;
|
||||
case 8: snprintf (basm, basz, "add r%d", low); break;
|
||||
case 9: snprintf (basm, basz, "sub r%d", low); break;
|
||||
case 10: snprintf (basm, basz, "ld r%d", low); break;
|
||||
case 11: snprintf (basm, basz, "xch r%d", low); break;
|
||||
case 12: snprintf (basm, basz, "bbl %d", low); break;
|
||||
case 13: snprintf (basm, basz, "ldm %d", low); break;
|
||||
case 14:
|
||||
strncpy (basm, i4004_e[low], basz);
|
||||
basm[basz] = '\0';
|
||||
break;
|
||||
case 15:
|
||||
strncpy (basm, i4004_f[low], basz);
|
||||
basm[basz] = '\0';
|
||||
break;
|
||||
const char *buf_asm = "invalid";
|
||||
if (rlen > len) {
|
||||
return op->size = 0;
|
||||
}
|
||||
switch (high) {
|
||||
case 0: buf_asm = low? "invalid": "nop"; break;
|
||||
case 1: buf_asm = sdb_fmt ("jcn %d 0x%02x", low, buf[1]); break;
|
||||
case 2:
|
||||
if (rlen == 1) {
|
||||
buf_asm = sdb_fmt ("src r%d", (low & 0xe));
|
||||
} else {
|
||||
buf_asm = sdb_fmt ("fim r%d, 0x%02x", (low & 0xe), buf[1]);
|
||||
}
|
||||
break;
|
||||
case 3: buf_asm = sdb_fmt ("fin r%d", (low & 0xe)); break;
|
||||
case 4: buf_asm = sdb_fmt ("jun 0x%03x", ((ut16)(low<<8) | buf[1])); break;
|
||||
case 5: buf_asm = sdb_fmt ("jms 0x%03x", ((ut16)(low<<8) | buf[1])); break;
|
||||
case 6: buf_asm = sdb_fmt ("inc r%d", low); break;
|
||||
case 7: buf_asm = sdb_fmt ("isz r%d, 0x%02x", low, buf[1]); break;
|
||||
case 8: buf_asm = sdb_fmt ("add r%d", low); break;
|
||||
case 9: buf_asm = sdb_fmt ("sub r%d", low); break;
|
||||
case 10: buf_asm = sdb_fmt ("ld r%d", low); break;
|
||||
case 11: buf_asm = sdb_fmt ("xch r%d", low); break;
|
||||
case 12: buf_asm = sdb_fmt ("bbl %d", low); break;
|
||||
case 13: buf_asm = sdb_fmt ("ldm %d", low); break;
|
||||
case 14: buf_asm = i4004_e[low]; break;
|
||||
case 15: buf_asm = i4004_f[low]; break;
|
||||
}
|
||||
r_strbuf_set (&op->buf_asm, buf_asm);
|
||||
return op->size = rlen;
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include "pic_baseline.h"
|
||||
|
||||
|
||||
static const PicBaselineOpInfo pic_baseline_op_info[PIC_BASELINE_OPCODE_INVALID] = {
|
||||
{ "nop", PIC_BASELINE_OP_ARGS_NONE },
|
||||
{ "option", PIC_BASELINE_OP_ARGS_NONE },
|
||||
@ -42,7 +41,6 @@ static const PicBaselineOpInfo pic_baseline_op_info[PIC_BASELINE_OPCODE_INVALID]
|
||||
{ "xorlw", PIC_BASELINE_OP_ARGS_8K }
|
||||
};
|
||||
|
||||
|
||||
PicBaselineOpcode pic_baseline_get_opcode(ut16 instr) {
|
||||
if (instr & 0xf000) {
|
||||
return PIC_BASELINE_OPCODE_INVALID;
|
||||
@ -193,10 +191,10 @@ const PicBaselineOpInfo *pic_baseline_get_op_info(PicBaselineOpcode opcode) {
|
||||
}
|
||||
|
||||
|
||||
int pic_baseline_disassemble(RAsm *a, RAsmOp *op, const ut8 *b, int l) {
|
||||
int pic_baseline_disassemble(RAsmOp *op, char *opbuf, const ut8 *b, int l) {
|
||||
#define EMIT_INVALID { \
|
||||
op->size = 1; \
|
||||
strncpy (op->buf_asm, "invalid", sizeof(op->buf_asm) - 1); \
|
||||
strcpy (opbuf, "invalid"); \
|
||||
return 1; \
|
||||
}
|
||||
if (!b || l < 2) {
|
||||
@ -218,53 +216,39 @@ int pic_baseline_disassemble(RAsm *a, RAsmOp *op, const ut8 *b, int l) {
|
||||
|
||||
op->size = 2;
|
||||
|
||||
const char *buf_asm = "invalid";
|
||||
switch (op_info->args) {
|
||||
case PIC_BASELINE_OP_ARGS_NONE:
|
||||
strncpy (op->buf_asm, op_info->mnemonic, sizeof(op->buf_asm) - 1);
|
||||
buf_asm = op_info->mnemonic;
|
||||
break;
|
||||
case PIC_BASELINE_OP_ARGS_2F:
|
||||
snprintf (op->buf_asm, sizeof(op->buf_asm), "%s 0x%x",
|
||||
op_info->mnemonic,
|
||||
instr & PIC_BASELINE_OP_ARGS_2F_MASK_F);
|
||||
buf_asm = sdb_fmt ("%s 0x%x", op_info->mnemonic, instr & PIC_BASELINE_OP_ARGS_2F_MASK_F);
|
||||
break;
|
||||
case PIC_BASELINE_OP_ARGS_3F:
|
||||
snprintf (op->buf_asm, sizeof(op->buf_asm), "%s 0x%x",
|
||||
op_info->mnemonic,
|
||||
instr & PIC_BASELINE_OP_ARGS_3F_MASK_F);
|
||||
buf_asm = sdb_fmt ("%s 0x%x", op_info->mnemonic, instr & PIC_BASELINE_OP_ARGS_3F_MASK_F);
|
||||
break;
|
||||
case PIC_BASELINE_OP_ARGS_3K:
|
||||
snprintf (op->buf_asm, sizeof(op->buf_asm), "%s 0x%x",
|
||||
op_info->mnemonic,
|
||||
instr & PIC_BASELINE_OP_ARGS_3K_MASK_K);
|
||||
buf_asm = sdb_fmt ("%s 0x%x", op_info->mnemonic, instr & PIC_BASELINE_OP_ARGS_3K_MASK_K);
|
||||
break;
|
||||
case PIC_BASELINE_OP_ARGS_1D_5F:
|
||||
snprintf (op->buf_asm, sizeof(op->buf_asm), "%s 0x%x, %c",
|
||||
op_info->mnemonic,
|
||||
instr & PIC_BASELINE_OP_ARGS_1D_5F_MASK_F,
|
||||
buf_asm = sdb_fmt ("%s 0x%x, %c", op_info->mnemonic, instr & PIC_BASELINE_OP_ARGS_1D_5F_MASK_F,
|
||||
(instr & PIC_BASELINE_OP_ARGS_1D_5F_MASK_D) >> 5 ? 'f' : 'w');
|
||||
break;
|
||||
case PIC_BASELINE_OP_ARGS_5F:
|
||||
snprintf (op->buf_asm, sizeof(op->buf_asm), "%s 0x%x",
|
||||
op_info->mnemonic,
|
||||
instr & PIC_BASELINE_OP_ARGS_5F_MASK_F);
|
||||
buf_asm = sdb_fmt ("%s 0x%x", op_info->mnemonic, instr & PIC_BASELINE_OP_ARGS_5F_MASK_F);
|
||||
break;
|
||||
case PIC_BASELINE_OP_ARGS_3B_5F:
|
||||
snprintf (op->buf_asm, sizeof(op->buf_asm), "%s 0x%x, 0x%x",
|
||||
op_info->mnemonic,
|
||||
instr & PIC_BASELINE_OP_ARGS_3B_5F_MASK_F,
|
||||
buf_asm = sdb_fmt ("%s 0x%x, 0x%x", op_info->mnemonic, instr & PIC_BASELINE_OP_ARGS_3B_5F_MASK_F,
|
||||
(instr & PIC_BASELINE_OP_ARGS_3B_5F_MASK_B) >> 5);
|
||||
break;
|
||||
case PIC_BASELINE_OP_ARGS_8K:
|
||||
snprintf (op->buf_asm, sizeof(op->buf_asm), "%s 0x%x",
|
||||
op_info->mnemonic,
|
||||
instr & PIC_BASELINE_OP_ARGS_8K_MASK_K);
|
||||
buf_asm = sdb_fmt ("%s 0x%x", op_info->mnemonic, instr & PIC_BASELINE_OP_ARGS_8K_MASK_K);
|
||||
break;
|
||||
case PIC_BASELINE_OP_ARGS_9K:
|
||||
snprintf (op->buf_asm, sizeof(op->buf_asm), "%s 0x%x",
|
||||
op_info->mnemonic,
|
||||
instr & PIC_BASELINE_OP_ARGS_9K_MASK_K);
|
||||
buf_asm = sdb_fmt ("%s 0x%x", op_info->mnemonic, instr & PIC_BASELINE_OP_ARGS_9K_MASK_K);
|
||||
break;
|
||||
}
|
||||
strcpy (opbuf, buf_asm);
|
||||
|
||||
return op->size;
|
||||
}
|
||||
}
|
||||
|
@ -76,6 +76,6 @@ typedef enum {
|
||||
|
||||
PicBaselineOpcode pic_baseline_get_opcode(ut16 instr);
|
||||
const PicBaselineOpInfo *pic_baseline_get_op_info(PicBaselineOpcode opcode);
|
||||
int pic_baseline_disassemble(RAsm *a, RAsmOp *op, const ut8 *b, int l);
|
||||
int pic_baseline_disassemble(RAsmOp *op, char *opbuf, const ut8 *b, int l);
|
||||
|
||||
#endif //PIC_BASELINE_H
|
||||
|
@ -154,14 +154,14 @@ const PicMidrangeOpInfo *pic_midrange_get_op_info (PicMidrangeOpcode opcode) {
|
||||
return &pic_midrange_op_info[opcode];
|
||||
}
|
||||
|
||||
int pic_midrange_disassemble (RAsm *a, RAsmOp *op, const ut8 *b, int l) {
|
||||
int pic_midrange_disassemble (RAsmOp *op, char *opbuf, const ut8 *b, int l) {
|
||||
char fsr_op[6];
|
||||
st16 branch;
|
||||
|
||||
#define EMIT_INVALID \
|
||||
{ \
|
||||
op->size = 2; \
|
||||
strncpy (op->buf_asm, "invalid", sizeof (op->buf_asm) - 1); \
|
||||
strcpy (opbuf, "invalid"); \
|
||||
return 1; \
|
||||
}
|
||||
if (!b || l < 2) {
|
||||
@ -183,73 +183,52 @@ int pic_midrange_disassemble (RAsm *a, RAsmOp *op, const ut8 *b, int l) {
|
||||
|
||||
op->size = 2;
|
||||
|
||||
const char *buf_asm = NULL;
|
||||
switch (op_info->args) {
|
||||
case PIC_MIDRANGE_OP_ARGS_NONE:
|
||||
strncpy (op->buf_asm, op_info->mnemonic,
|
||||
sizeof (op->buf_asm) - 1);
|
||||
buf_asm = op_info->mnemonic;
|
||||
break;
|
||||
case PIC_MIDRANGE_OP_ARGS_2F:
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), "%s 0x%x",
|
||||
op_info->mnemonic,
|
||||
instr & PIC_MIDRANGE_OP_ARGS_2F_MASK_F);
|
||||
buf_asm = sdb_fmt ("%s 0x%x", op_info->mnemonic, instr & PIC_MIDRANGE_OP_ARGS_2F_MASK_F);
|
||||
break;
|
||||
case PIC_MIDRANGE_OP_ARGS_7F:
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), "%s 0x%x",
|
||||
op_info->mnemonic,
|
||||
instr & PIC_MIDRANGE_OP_ARGS_7F_MASK_F);
|
||||
buf_asm = sdb_fmt ("%s 0x%x", op_info->mnemonic, instr & PIC_MIDRANGE_OP_ARGS_7F_MASK_F);
|
||||
break;
|
||||
case PIC_MIDRANGE_OP_ARGS_1D_7F:
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), "%s 0x%x, %c",
|
||||
op_info->mnemonic,
|
||||
buf_asm = sdb_fmt ("%s 0x%x, %c", op_info->mnemonic,
|
||||
instr & PIC_MIDRANGE_OP_ARGS_1D_7F_MASK_F,
|
||||
(instr & PIC_MIDRANGE_OP_ARGS_1D_7F_MASK_D) >> 7 ?
|
||||
'f' :
|
||||
'w');
|
||||
(instr & PIC_MIDRANGE_OP_ARGS_1D_7F_MASK_D) >> 7 ? 'f' : 'w');
|
||||
break;
|
||||
case PIC_MIDRANGE_OP_ARGS_1N_6K:
|
||||
if (opcode == PIC_MIDRANGE_OPCODE_ADDFSR) {
|
||||
snprintf (
|
||||
op->buf_asm, sizeof (op->buf_asm),
|
||||
"%s FSR%d, 0x%x", op_info->mnemonic,
|
||||
(instr & PIC_MIDRANGE_OP_ARGS_1N_6K_MASK_N) >>
|
||||
6,
|
||||
instr & PIC_MIDRANGE_OP_ARGS_1N_6K_MASK_K);
|
||||
buf_asm = sdb_fmt ( "%s FSR%d, 0x%x", op_info->mnemonic,
|
||||
(instr & PIC_MIDRANGE_OP_ARGS_1N_6K_MASK_N) >>
|
||||
6, instr & PIC_MIDRANGE_OP_ARGS_1N_6K_MASK_K);
|
||||
} else {
|
||||
snprintf (
|
||||
op->buf_asm, sizeof (op->buf_asm),
|
||||
"%s 0x%x[FSR%d]", op_info->mnemonic,
|
||||
buf_asm = sdb_fmt ("%s 0x%x[FSR%d]", op_info->mnemonic,
|
||||
instr & PIC_MIDRANGE_OP_ARGS_1N_6K_MASK_K,
|
||||
(instr & PIC_MIDRANGE_OP_ARGS_1N_6K_MASK_N) >>
|
||||
6);
|
||||
(instr & PIC_MIDRANGE_OP_ARGS_1N_6K_MASK_N) >> 6);
|
||||
}
|
||||
break;
|
||||
case PIC_MIDRANGE_OP_ARGS_3B_7F:
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), "%s 0x%x, %d",
|
||||
op_info->mnemonic,
|
||||
instr & PIC_MIDRANGE_OP_ARGS_3B_7F_MASK_F,
|
||||
buf_asm = sdb_fmt ("%s 0x%x, %d", op_info->mnemonic, instr & PIC_MIDRANGE_OP_ARGS_3B_7F_MASK_F,
|
||||
(instr & PIC_MIDRANGE_OP_ARGS_3B_7F_MASK_B) >> 7);
|
||||
break;
|
||||
case PIC_MIDRANGE_OP_ARGS_4K:
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), "%s 0x%x",
|
||||
op_info->mnemonic,
|
||||
instr & PIC_MIDRANGE_OP_ARGS_4K_MASK_K);
|
||||
buf_asm = sdb_fmt ("%s 0x%x", op_info->mnemonic, instr & PIC_MIDRANGE_OP_ARGS_4K_MASK_K);
|
||||
break;
|
||||
case PIC_MIDRANGE_OP_ARGS_8K:
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), "%s 0x%x",
|
||||
op_info->mnemonic,
|
||||
instr & PIC_MIDRANGE_OP_ARGS_8K_MASK_K);
|
||||
buf_asm = sdb_fmt ("%s 0x%x", op_info->mnemonic, instr & PIC_MIDRANGE_OP_ARGS_8K_MASK_K);
|
||||
break;
|
||||
case PIC_MIDRANGE_OP_ARGS_9K:
|
||||
branch = (instr & PIC_MIDRANGE_OP_ARGS_9K_MASK_K);
|
||||
branch |= ((branch & 0x100) ? 0xfe00 : 0);
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), "%s %s0x%x",
|
||||
buf_asm = sdb_fmt ("%s %s0x%x",
|
||||
op_info->mnemonic, branch < 0 ? "-" : "",
|
||||
branch < 0 ? -branch : branch);
|
||||
break;
|
||||
case PIC_MIDRANGE_OP_ARGS_11K:
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), "%s 0x%x",
|
||||
op_info->mnemonic,
|
||||
instr & PIC_MIDRANGE_OP_ARGS_11K_MASK_K);
|
||||
buf_asm = sdb_fmt ("%s 0x%x", op_info->mnemonic, instr & PIC_MIDRANGE_OP_ARGS_11K_MASK_K);
|
||||
break;
|
||||
case PIC_MIDRANGE_OP_ARGS_1N_2M:
|
||||
snprintf (
|
||||
@ -257,10 +236,11 @@ int pic_midrange_disassemble (RAsm *a, RAsmOp *op, const ut8 *b, int l) {
|
||||
PicMidrangeFsrOps[instr &
|
||||
PIC_MIDRANGE_OP_ARGS_1N_2M_MASK_M],
|
||||
(instr & PIC_MIDRANGE_OP_ARGS_1N_2M_MASK_N) >> 2);
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), "%s %s",
|
||||
op_info->mnemonic, fsr_op);
|
||||
buf_asm = sdb_fmt ("%s %s", op_info->mnemonic, fsr_op);
|
||||
break;
|
||||
}
|
||||
|
||||
if (buf_asm) {
|
||||
strcpy (opbuf, buf_asm);
|
||||
}
|
||||
return op->size;
|
||||
}
|
||||
|
@ -98,6 +98,6 @@ typedef enum {
|
||||
|
||||
PicMidrangeOpcode pic_midrange_get_opcode (ut16 instr);
|
||||
const PicMidrangeOpInfo *pic_midrange_get_op_info (PicMidrangeOpcode opcode);
|
||||
int pic_midrange_disassemble (RAsm *a, RAsmOp *op, const ut8 *b, int l);
|
||||
int pic_midrange_disassemble (RAsmOp *op, char *opbuf, const ut8 *b, int l);
|
||||
|
||||
#endif // PIC_MIDRANGE_H
|
||||
|
@ -30,201 +30,188 @@ static struct {
|
||||
ut8 optype;
|
||||
//and some magical hocus pocus ;)
|
||||
} ops[] = {
|
||||
{0xf000, 0xffff, "nop", NO_ARG},
|
||||
{0xef00, 0xefff, "goto", GOTO_T},
|
||||
{0xee00, 0xee3f, "lfsr", LFSR_T},
|
||||
{0xec00, 0xedff, "call", CALL_T},
|
||||
{0xe700, 0xe7ff, "bnn", N_T},
|
||||
{0xe600, 0xe6ff, "bn", N_T},
|
||||
{0xe500, 0xe5ff, "bnov", N_T},
|
||||
{0xe400, 0xe4ff, "bov", N_T},
|
||||
{0xe300, 0xe3ff, "bnc", N_T},
|
||||
{0xe200, 0xe2ff, "bc", N_T},
|
||||
{0xe100, 0xe1ff, "bnz", N_T},
|
||||
{0xe000, 0xe0ff, "bz", N_T},
|
||||
{0xd800, 0xdfff, "rcall", NEX_T},
|
||||
{0xd000, 0xd7ff, "bra", NEX_T},
|
||||
{0xc000, 0xcfff, "movff", F32_T},
|
||||
{0xb000, 0xbfff, "btfsc", BAF_T},
|
||||
{0xa000, 0xafff, "btfss", BAF_T},
|
||||
{0x9000, 0x9fff, "bcf", BAF_T},
|
||||
{0x8000, 0x8fff, "bsf", BAF_T},
|
||||
{0x7000, 0x7fff, "btg", BAF_T},
|
||||
{0x6e00, 0x6fff, "movwf", AF_T},
|
||||
{0x6c00, 0x6dff, "negf", AF_T},
|
||||
{0x6a00, 0x6bff, "clrf", AF_T},
|
||||
{0x6800, 0x69ff, "setf", AF_T},
|
||||
{0x6600, 0x67ff, "tstfsz", AF_T},
|
||||
{0x6400, 0x65ff, "cpfsgt", AF_T},
|
||||
{0x6200, 0x63ff, "cpfseq", AF_T},
|
||||
{0x6000, 0x61ff, "cpfslt", AF_T},
|
||||
{0x5c00, 0x5fff, "subwf", DAF_T},
|
||||
{0x5800, 0x5bff, "subwfb", DAF_T},
|
||||
{0x5400, 0x57ff, "subfwb", DAF_T},
|
||||
{0x5000, 0x53ff, "movf", DAF_T},
|
||||
{0x4c00, 0x4fff, "dcfsnz", DAF_T},
|
||||
{0x4800, 0x4bff, "infsnz", DAF_T},
|
||||
{0x4400, 0x47ff, "rlncf", DAF_T},
|
||||
{0x4000, 0x43ff, "rrncf", DAF_T},
|
||||
{0x3c00, 0x3fff, "incfsz", DAF_T},
|
||||
{0x3800, 0x3bff, "swapf", DAF_T},
|
||||
{0x3400, 0x37ff, "rlcf", DAF_T},
|
||||
{0x3000, 0x33ff, "rrcf", DAF_T},
|
||||
{0x2c00, 0x2fff, "decfsz", DAF_T},
|
||||
{0x2800, 0x2bff, "incf", DAF_T},
|
||||
{0x2400, 0x27ff, "addwf", DAF_T},
|
||||
{0x2000, 0x23ff, "addwfc", DAF_T},
|
||||
{0x1c00, 0x1fff, "comf", DAF_T},
|
||||
{0x1800, 0x1bff, "xorwf", DAF_T},
|
||||
{0x1400, 0x17ff, "andwf", DAF_T},
|
||||
{0x1000, 0x13ff, "iorwf", DAF_T},
|
||||
{0xf00, 0xfff, "addlw", K_T},
|
||||
{0xe00, 0xeff, "movlw", K_T},
|
||||
{0xd00, 0xdff, "mullw", K_T},
|
||||
{0xc00, 0xcff, "retlw", K_T},
|
||||
{0xb00, 0xbff, "andlw", K_T},
|
||||
{0xa00, 0xaff, "xorlw", K_T},
|
||||
{0x900, 0x9ff, "iorlw", K_T},
|
||||
{0x800, 0x8ff, "sublw", K_T},
|
||||
{0x400, 0x7ff, "decf", DAF_T},
|
||||
{0x200, 0x3ff, "mulwf", AF_T},
|
||||
{0x100, 0x10f, "movlb", SHK_T},
|
||||
{0xff, 0xff, "reset", NO_ARG},
|
||||
{0x12, 0x13, "return", S_T},
|
||||
{0x10, 0x11, "retfie", S_T},
|
||||
{0xf, 0xf, "tblwt+*", NO_ARG},
|
||||
{0xe, 0xe, "tblwt*-", NO_ARG},
|
||||
{0xd, 0xd, "tblwt*+", NO_ARG},
|
||||
{0xc, 0xc, "tblwt*", NO_ARG},
|
||||
{0xb, 0xb, "tblrd+*", NO_ARG},
|
||||
{0xa, 0xa, "tblrd*-", NO_ARG},
|
||||
{0x9, 0x9, "tblrd*+", NO_ARG},
|
||||
{0x8, 0x8, "tblrd*", NO_ARG},
|
||||
{0x7, 0x7, "daw", NO_ARG},
|
||||
{0x6, 0x6, "pop", NO_ARG},
|
||||
{0x5, 0x5, "push", NO_ARG},
|
||||
{0x4, 0x4, "clrwdt", NO_ARG},
|
||||
{0x3, 0x3, "sleep", NO_ARG},
|
||||
{0x0, 0x0, "nop", NO_ARG},
|
||||
{0x0, 0xffff, "invalid", NO_ARG},
|
||||
{0xf000, 0xffff, "nop", NO_ARG},
|
||||
{0xef00, 0xefff, "goto", GOTO_T},
|
||||
{0xee00, 0xee3f, "lfsr", LFSR_T},
|
||||
{0xec00, 0xedff, "call", CALL_T},
|
||||
{0xe700, 0xe7ff, "bnn", N_T},
|
||||
{0xe600, 0xe6ff, "bn", N_T},
|
||||
{0xe500, 0xe5ff, "bnov", N_T},
|
||||
{0xe400, 0xe4ff, "bov", N_T},
|
||||
{0xe300, 0xe3ff, "bnc", N_T},
|
||||
{0xe200, 0xe2ff, "bc", N_T},
|
||||
{0xe100, 0xe1ff, "bnz", N_T},
|
||||
{0xe000, 0xe0ff, "bz", N_T},
|
||||
{0xd800, 0xdfff, "rcall", NEX_T},
|
||||
{0xd000, 0xd7ff, "bra", NEX_T},
|
||||
{0xc000, 0xcfff, "movff", F32_T},
|
||||
{0xb000, 0xbfff, "btfsc", BAF_T},
|
||||
{0xa000, 0xafff, "btfss", BAF_T},
|
||||
{0x9000, 0x9fff, "bcf", BAF_T},
|
||||
{0x8000, 0x8fff, "bsf", BAF_T},
|
||||
{0x7000, 0x7fff, "btg", BAF_T},
|
||||
{0x6e00, 0x6fff, "movwf", AF_T},
|
||||
{0x6c00, 0x6dff, "negf", AF_T},
|
||||
{0x6a00, 0x6bff, "clrf", AF_T},
|
||||
{0x6800, 0x69ff, "setf", AF_T},
|
||||
{0x6600, 0x67ff, "tstfsz", AF_T},
|
||||
{0x6400, 0x65ff, "cpfsgt", AF_T},
|
||||
{0x6200, 0x63ff, "cpfseq", AF_T},
|
||||
{0x6000, 0x61ff, "cpfslt", AF_T},
|
||||
{0x5c00, 0x5fff, "subwf", DAF_T},
|
||||
{0x5800, 0x5bff, "subwfb", DAF_T},
|
||||
{0x5400, 0x57ff, "subfwb", DAF_T},
|
||||
{0x5000, 0x53ff, "movf", DAF_T},
|
||||
{0x4c00, 0x4fff, "dcfsnz", DAF_T},
|
||||
{0x4800, 0x4bff, "infsnz", DAF_T},
|
||||
{0x4400, 0x47ff, "rlncf", DAF_T},
|
||||
{0x4000, 0x43ff, "rrncf", DAF_T},
|
||||
{0x3c00, 0x3fff, "incfsz", DAF_T},
|
||||
{0x3800, 0x3bff, "swapf", DAF_T},
|
||||
{0x3400, 0x37ff, "rlcf", DAF_T},
|
||||
{0x3000, 0x33ff, "rrcf", DAF_T},
|
||||
{0x2c00, 0x2fff, "decfsz", DAF_T},
|
||||
{0x2800, 0x2bff, "incf", DAF_T},
|
||||
{0x2400, 0x27ff, "addwf", DAF_T},
|
||||
{0x2000, 0x23ff, "addwfc", DAF_T},
|
||||
{0x1c00, 0x1fff, "comf", DAF_T},
|
||||
{0x1800, 0x1bff, "xorwf", DAF_T},
|
||||
{0x1400, 0x17ff, "andwf", DAF_T},
|
||||
{0x1000, 0x13ff, "iorwf", DAF_T},
|
||||
{0xf00, 0xfff, "addlw", K_T},
|
||||
{0xe00, 0xeff, "movlw", K_T},
|
||||
{0xd00, 0xdff, "mullw", K_T},
|
||||
{0xc00, 0xcff, "retlw", K_T},
|
||||
{0xb00, 0xbff, "andlw", K_T},
|
||||
{0xa00, 0xaff, "xorlw", K_T},
|
||||
{0x900, 0x9ff, "iorlw", K_T},
|
||||
{0x800, 0x8ff, "sublw", K_T},
|
||||
{0x400, 0x7ff, "decf", DAF_T},
|
||||
{0x200, 0x3ff, "mulwf", AF_T},
|
||||
{0x100, 0x10f, "movlb", SHK_T},
|
||||
{0xff, 0xff, "reset", NO_ARG},
|
||||
{0x12, 0x13, "return", S_T},
|
||||
{0x10, 0x11, "retfie", S_T},
|
||||
{0xf, 0xf, "tblwt+*", NO_ARG},
|
||||
{0xe, 0xe, "tblwt*-", NO_ARG},
|
||||
{0xd, 0xd, "tblwt*+", NO_ARG},
|
||||
{0xc, 0xc, "tblwt*", NO_ARG},
|
||||
{0xb, 0xb, "tblrd+*", NO_ARG},
|
||||
{0xa, 0xa, "tblrd*-", NO_ARG},
|
||||
{0x9, 0x9, "tblrd*+", NO_ARG},
|
||||
{0x8, 0x8, "tblrd*", NO_ARG},
|
||||
{0x7, 0x7, "daw", NO_ARG},
|
||||
{0x6, 0x6, "pop", NO_ARG},
|
||||
{0x5, 0x5, "push", NO_ARG},
|
||||
{0x4, 0x4, "clrwdt", NO_ARG},
|
||||
{0x3, 0x3, "sleep", NO_ARG},
|
||||
{0x0, 0x0, "nop", NO_ARG},
|
||||
{0x0, 0xffff, "invalid", NO_ARG},
|
||||
};
|
||||
|
||||
int pic_pic18_disassemble(RAsm *a, RAsmOp *op, const ut8 *b, int l) {
|
||||
int pic_pic18_disassemble(RAsmOp *op, char *opbuf, const ut8 *b, int l) {
|
||||
int i;
|
||||
if(l<2){//well noone loves reading bitstream of size zero or 1 !!
|
||||
strncpy (op->buf_asm,"invalid", R_ASM_BUFSIZE);
|
||||
if (l < 2) { //well noone loves reading bitstream of size zero or 1 !!
|
||||
strcpy (opbuf, "invalid");
|
||||
op->size = l;
|
||||
return -1;
|
||||
|
||||
}
|
||||
ut16 instr = *(ut16 *)b; //instruction
|
||||
// if still redundan code is reported think of this of instr=0x2
|
||||
const char *buf_asm = "invalid";
|
||||
strcpy (opbuf, buf_asm);
|
||||
|
||||
for (i = 0;ops[i].opmin != (ops[i].opmin & instr) || ops[i].opmax != (ops[i].opmax | instr); i++);
|
||||
if (ops[i].opmin == 0 && ops[i].opmax==0xffff) {
|
||||
strncpy (op->buf_asm, ops[i].name, R_ASM_BUFSIZE);
|
||||
if (ops[i].opmin == 0 && ops[i].opmax == 0xffff) {
|
||||
strcpy (opbuf, ops[i].name);
|
||||
op->size = 2;
|
||||
return -1;
|
||||
}
|
||||
op->size = 2;
|
||||
switch (ops[i].optype) {
|
||||
case NO_ARG:
|
||||
strncpy (op->buf_asm, ops[i].name, R_ASM_BUFSIZE);
|
||||
return 2;
|
||||
buf_asm = ops[i].name;
|
||||
break;
|
||||
case N_T:
|
||||
case K_T:
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s 0x%x",
|
||||
ops[i].name, instr & 0xff);
|
||||
buf_asm = sdb_fmt ("%s 0x%x", ops[i].name, instr & 0xff);
|
||||
break;
|
||||
case DAF_T:
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s 0x%x, %d, %d",
|
||||
ops[i].name, instr & 0xff, (instr >> 9) & 1, (instr >> 8) & 1);
|
||||
buf_asm = sdb_fmt ("%s 0x%x, %d, %d", ops[i].name, instr & 0xff, (instr >> 9) & 1, (instr >> 8) & 1);
|
||||
break;
|
||||
case AF_T:
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s 0x%x, %d", ops[i].name,
|
||||
instr & 0xff, (instr >> 8) & 1);
|
||||
buf_asm = sdb_fmt ("%s 0x%x, %d", ops[i].name, instr & 0xff, (instr >> 8) & 1);
|
||||
break;
|
||||
|
||||
case BAF_T:
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s 0x%x, %d, %d", ops[i].name,
|
||||
instr & 0xff, (instr >> 9) & 0x7, (instr >> 8) & 0x1);
|
||||
buf_asm = sdb_fmt ("%s 0x%x, %d, %d", ops[i].name, instr & 0xff, (instr >> 9) & 0x7, (instr >> 8) & 0x1);
|
||||
break;
|
||||
case NEX_T:
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s 0x%x",
|
||||
ops[i].name, instr & 0x7ff);
|
||||
buf_asm = sdb_fmt ("%s 0x%x", ops[i].name, instr & 0x7ff);
|
||||
break;
|
||||
case CALL_T: {
|
||||
case CALL_T:
|
||||
if (l < 4) {
|
||||
strcpy (op->buf_asm, "invalid");
|
||||
return -1;
|
||||
}
|
||||
op->size = 4;
|
||||
{
|
||||
ut32 dword_instr = *(ut32 *)b;
|
||||
//I dont even know how the bits are arranged but it works !!!
|
||||
//`the wierdness of little endianess`
|
||||
if (dword_instr >> 28 != 0xf) {
|
||||
strcpy (op->buf_asm, "invalid");
|
||||
return -1;
|
||||
}
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s 0x%x, %d", ops[i].name,
|
||||
(dword_instr & 0xff) |
|
||||
(dword_instr >> 8 & 0xfff00),
|
||||
(dword_instr >> 8) & 0x1);
|
||||
buf_asm = sdb_fmt ("%s 0x%x, %d", ops[i].name,
|
||||
(dword_instr & 0xff) | (dword_instr >> 8 & 0xfff00), (dword_instr >> 8) & 0x1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GOTO_T: {
|
||||
case GOTO_T:
|
||||
if (l < 4) {
|
||||
strcpy (op->buf_asm, "invalid");
|
||||
return -1;
|
||||
}
|
||||
{
|
||||
op->size = 4;
|
||||
ut32 dword_instr = *(ut32 *)b;
|
||||
if (dword_instr >> 28 != 0xf) {
|
||||
strcpy (op->buf_asm, "invalid");
|
||||
return -1;
|
||||
}
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s 0x%x", ops[i].name,
|
||||
((dword_instr & 0xff) | ((dword_instr & 0xfff0000) >>8) )*2);
|
||||
buf_asm = sdb_fmt ("%s 0x%x", ops[i].name,
|
||||
((dword_instr & 0xff) | ((dword_instr & 0xfff0000) >>8) )*2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case F32_T: {
|
||||
case F32_T:
|
||||
if (l < 4) {
|
||||
strcpy (op->buf_asm, "invalid");
|
||||
return -1;
|
||||
}
|
||||
op->size = 4;
|
||||
{
|
||||
ut32 dword_instr = *(ut32 *)b;
|
||||
if (dword_instr >> 28 != 0xf) {
|
||||
strcpy (op->buf_asm, "invalid");
|
||||
return -1;
|
||||
}
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s 0x%x, 0x%x", ops[i].name,
|
||||
dword_instr & 0xfff,
|
||||
(dword_instr >> 16) & 0xfff);
|
||||
buf_asm = sdb_fmt ("%s 0x%x, 0x%x", ops[i].name,
|
||||
dword_instr & 0xfff, (dword_instr >> 16) & 0xfff);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SHK_T:
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s 0x%x",
|
||||
ops[i].name, instr & 0xf);
|
||||
buf_asm = sdb_fmt ("%s 0x%x", ops[i].name, instr & 0xf);
|
||||
break;
|
||||
case S_T:
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s %d",
|
||||
ops[i].name, instr & 0x1);
|
||||
buf_asm = sdb_fmt ("%s %d", ops[i].name, instr & 0x1);
|
||||
break;
|
||||
case LFSR_T: {
|
||||
op->size = 4;
|
||||
ut32 dword_instr = *(ut32 *)b;
|
||||
if (dword_instr >> 28 != 0xf) {
|
||||
strcpy (op->buf_asm, "invalid");
|
||||
return -1;
|
||||
}
|
||||
ut8 reg_n = (dword_instr >> 4) & 0x3;
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s %s, %d", ops[i].name,
|
||||
fsr[reg_n], (dword_instr & 0xf) << 8 |
|
||||
((dword_instr >> 16) & 0xff));
|
||||
buf_asm = sdb_fmt ("%s %s, %d", ops[i].name, fsr[reg_n],
|
||||
(dword_instr & 0xf) << 8 | ((dword_instr >> 16) & 0xff));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
sprintf (op->buf_asm, "unknown args");
|
||||
buf_asm = "unknown args";
|
||||
};
|
||||
strcpy (opbuf, buf_asm);
|
||||
return op->size;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,6 @@
|
||||
|
||||
#include <r_asm.h>
|
||||
|
||||
int pic_pic18_disassemble(RAsm *a, RAsmOp *op, const ut8 *b, int l);
|
||||
int pic_pic18_disassemble(RAsmOp *op, char *opbuf, const ut8 *b, int l);
|
||||
|
||||
#endif //PIC_PIC18_H
|
||||
|
@ -285,37 +285,30 @@ static struct riscv_opcode *get_opcode (insn_t word) {
|
||||
return (struct riscv_opcode *)riscv_hash[OP_HASH_IDX (word)];
|
||||
}
|
||||
|
||||
static int
|
||||
riscv_disassemble(RAsm *a, RAsmOp *rop, insn_t word, int xlen, int len) {
|
||||
static int riscv_disassemble(RAsm *a, RAsmOp *rop, insn_t word, int xlen, int len) {
|
||||
const bool no_alias = false;
|
||||
const struct riscv_opcode *op = get_opcode (word);
|
||||
if (!op) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(; op < &riscv_opcodes[NUMOPCODES]; op++) {
|
||||
for (; op < &riscv_opcodes[NUMOPCODES]; op++) {
|
||||
if ( !(op->match_func)(op, word) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (no_alias && (op->pinfo & INSN_ALIAS)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isdigit ((ut8)op->subset[0]) && atoi (op->subset) != xlen ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (op->name && op->args) {
|
||||
snprintf (rop->buf_asm, sizeof (rop->buf_asm), "%s", op->name);
|
||||
get_insn_args (rop->buf_asm, op->args, word, a->pc);
|
||||
r_asm_op_set_asm (rop, op->name);
|
||||
get_insn_args (op->name, op->args, word, a->pc);
|
||||
return 0;
|
||||
} else {
|
||||
sprintf (rop->buf_asm, "invalid word(%"PFMT64x")", (ut64)word);
|
||||
return -1;
|
||||
}
|
||||
r_asm_op_set_asm (rop, sdb_fmt ("invalid word(%"PFMT64x")", (ut64)word));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2015-2016 - condret@runas-racer.com */
|
||||
/* radare - LGPL - Copyright 2015-2018 - condret, pancake */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
@ -9,50 +9,49 @@
|
||||
|
||||
static int snesDisass(int M_flag, int X_flag, ut64 pc, RAsmOp *op, const ut8 *buf, int len){
|
||||
snes_op_t *s_op = &snes_op[buf[0]];
|
||||
int op_len = snes_op_get_size(M_flag, X_flag, s_op);
|
||||
if (len < op_len)
|
||||
int op_len = snes_op_get_size (M_flag, X_flag, s_op);
|
||||
if (len < op_len) {
|
||||
return 0;
|
||||
}
|
||||
const char *buf_asm = "invalid";
|
||||
switch (s_op->len) {
|
||||
case SNES_OP_8BIT:
|
||||
strncpy (op->buf_asm, s_op->name, sizeof (op->buf_asm) - 1);
|
||||
buf_asm = s_op->name;
|
||||
break;
|
||||
case SNES_OP_16BIT:
|
||||
if (*buf % 0x20 == 0x10 || *buf == 0x80) { // relative branch
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), s_op->name, pc + 2 + (st8)buf[1]);
|
||||
buf_asm = sdb_fmt (s_op->name, pc + 2 + (st8)buf[1]);
|
||||
} else {
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), s_op->name, buf[1]);
|
||||
buf_asm = sdb_fmt (s_op->name, buf[1]);
|
||||
}
|
||||
break;
|
||||
case SNES_OP_24BIT:
|
||||
if (*buf == 0x44 || *buf == 0x54) { // mvp and mvn
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), s_op->name, buf[1], buf[2]);
|
||||
buf_asm = sdb_fmt (s_op->name, buf[1], buf[2]);
|
||||
} else if (*buf == 0x82) { // brl
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), s_op->name, pc + 3 + (st16)ut8p_bw(buf+1));
|
||||
buf_asm = sdb_fmt (s_op->name, pc + 3 + (st16)ut8p_bw(buf + 1));
|
||||
} else {
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), s_op->name, ut8p_bw(buf+1));
|
||||
buf_asm = sdb_fmt (s_op->name, ut8p_bw (buf + 1));
|
||||
}
|
||||
break;
|
||||
case SNES_OP_32BIT:
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), s_op->name, buf[1]|buf[2]<<8|buf[3]<<16);
|
||||
buf_asm = sdb_fmt (s_op->name, buf[1]|buf[2]<<8|buf[3]<<16);
|
||||
break;
|
||||
case SNES_OP_IMM_M:
|
||||
if (M_flag) {
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), "%s #0x%02x",
|
||||
s_op->name, buf[1]);
|
||||
buf_asm = sdb_fmt ("%s #0x%02x", s_op->name, buf[1]);
|
||||
} else {
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), "%s #0x%04x",
|
||||
s_op->name, ut8p_bw (buf+1));
|
||||
buf_asm = sdb_fmt ("%s #0x%04x", s_op->name, ut8p_bw (buf + 1));
|
||||
}
|
||||
break;
|
||||
case SNES_OP_IMM_X:
|
||||
if (X_flag) {
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), "%s #0x%02x",
|
||||
s_op->name, buf[1]);
|
||||
buf_asm = sdb_fmt ("%s #0x%02x", s_op->name, buf[1]);
|
||||
} else {
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), "%s #0x%04x",
|
||||
s_op->name, ut8p_bw (buf+1));
|
||||
buf_asm = sdb_fmt ("%s #0x%04x", s_op->name, ut8p_bw (buf + 1));
|
||||
}
|
||||
break;
|
||||
}
|
||||
r_strbuf_set (&op->buf_asm, buf_asm);
|
||||
return op_len;
|
||||
}
|
||||
|
@ -21,21 +21,24 @@ static int spc700OpLength(int spcoptype){
|
||||
|
||||
static int spc700Disass(RAsmOp *op, const ut8 *buf, int len) {
|
||||
int foo = spc700OpLength (spc_op_table[buf[0]].type);
|
||||
if (len < foo)
|
||||
if (len < foo) {
|
||||
return 0;
|
||||
}
|
||||
const char *buf_asm = "invalid";
|
||||
switch (spc_op_table[buf[0]].type) {
|
||||
case SPC_OP:
|
||||
sprintf (op->buf_asm, "%s", spc_op_table[buf[0]].name);
|
||||
buf_asm = spc_op_table[buf[0]].name;
|
||||
break;
|
||||
case SPC_ARG8_1:
|
||||
sprintf (op->buf_asm, spc_op_table[buf[0]].name, buf[1]);
|
||||
buf_asm = sdb_fmt (spc_op_table[buf[0]].name, buf[1]);
|
||||
break;
|
||||
case SPC_ARG8_2:
|
||||
sprintf (op->buf_asm, spc_op_table[buf[0]].name, buf[1], buf[2]);
|
||||
buf_asm = sdb_fmt (spc_op_table[buf[0]].name, buf[1], buf[2]);
|
||||
break;
|
||||
case SPC_ARG16:
|
||||
sprintf (op->buf_asm, spc_op_table[buf[0]].name, buf[1]+0x100*buf[2]);
|
||||
buf_asm = sdb_fmt (spc_op_table[buf[0]].name, buf[1]+0x100*buf[2]);
|
||||
break;
|
||||
}
|
||||
r_asm_op_set_asm (op, buf_asm);
|
||||
return foo;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
// dso, condret, pancake 2014-2017
|
||||
/* radare - LGPL - Copyright 2014-2018 - dso, condret, pancake */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_asm.h>
|
||||
#include <string.h>
|
||||
@ -18,45 +19,37 @@ enum {
|
||||
WS_OP_IO
|
||||
};
|
||||
|
||||
static int get_ws_pref_optype(const ut8 *buf, int len)
|
||||
{
|
||||
if (len) {
|
||||
switch (buf[0]) {
|
||||
case ' ':
|
||||
return WS_OP_STACK;
|
||||
case '\t':
|
||||
return WS_OP_PREF;
|
||||
case 10:
|
||||
return WS_OP_FLOW;
|
||||
default:
|
||||
return WS_OP_NOP;
|
||||
}
|
||||
static int get_ws_pref_optype(const ut8 *buf, int len) {
|
||||
if (len < 1) {
|
||||
return WS_OP_UNK;
|
||||
}
|
||||
switch (buf[0]) {
|
||||
case ' ': return WS_OP_STACK;
|
||||
case '\t': return WS_OP_PREF;
|
||||
case 10: return WS_OP_FLOW;
|
||||
default: return WS_OP_NOP;
|
||||
}
|
||||
return WS_OP_UNK;
|
||||
}
|
||||
|
||||
static int get_ws_suf_optype(const ut8 *buf, int len) {
|
||||
if (len > 0) {
|
||||
switch (buf[0]) {
|
||||
case ' ':
|
||||
return WS_OP_ARITH;
|
||||
case '\t':
|
||||
return WS_OP_HEAP;
|
||||
case 10:
|
||||
return WS_OP_IO;
|
||||
default:
|
||||
return WS_OP_NOP;
|
||||
}
|
||||
if (len < 1) {
|
||||
return WS_OP_UNK;
|
||||
}
|
||||
switch (buf[0]) {
|
||||
case ' ': return WS_OP_ARITH;
|
||||
case '\t': return WS_OP_HEAP;
|
||||
case 10: return WS_OP_IO;
|
||||
default: return WS_OP_NOP;
|
||||
}
|
||||
return WS_OP_UNK;
|
||||
}
|
||||
|
||||
WS_API int get_ws_optype(const ut8 *buf, int len) {
|
||||
const ut8 *ptr;
|
||||
if (get_ws_pref_optype (buf, len) == WS_OP_PREF) {
|
||||
ptr = buf + 1;
|
||||
while (get_ws_suf_optype (ptr, len - (ptr - buf)) == WS_OP_NOP)
|
||||
while (get_ws_suf_optype (ptr, len - (ptr - buf)) == WS_OP_NOP) {
|
||||
ptr++;
|
||||
}
|
||||
return get_ws_suf_optype (ptr, len - (ptr - buf));
|
||||
}
|
||||
return get_ws_pref_optype (buf, len);
|
||||
@ -79,12 +72,10 @@ WS_API const ut8 *get_ws_next_token(const ut8 *buf, int len) {
|
||||
|
||||
static st32 get_ws_val(const ut8 *buf, int len) {
|
||||
ut8 sig;
|
||||
const ut8 *tok;
|
||||
int i, ret;
|
||||
ret = 0;
|
||||
tok = get_ws_next_token (buf, len);
|
||||
int i, ret = 0;
|
||||
const ut8 *tok = get_ws_next_token (buf, len);
|
||||
sig = (*tok == '\t');
|
||||
len = len - (tok - buf) - 1;
|
||||
len -= (tok - buf) - 1;
|
||||
for (i = 0; i < 30; i++) { // XXX : conceptually wrong
|
||||
tok++;
|
||||
tok = get_ws_next_token (tok, len);
|
||||
@ -118,7 +109,7 @@ WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) {
|
||||
case WS_OP_UNK:
|
||||
return op->size = 0;
|
||||
case WS_OP_NOP:
|
||||
sprintf (op->buf_asm, "nop");
|
||||
r_strbuf_set (&op->buf_asm, "nop");
|
||||
return op->size = 1;
|
||||
case WS_OP_STACK:
|
||||
ptr++;
|
||||
@ -127,15 +118,12 @@ WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) {
|
||||
}
|
||||
switch (*get_ws_next_token (ptr, len - 1)) {
|
||||
case ' ':
|
||||
if (-1 == test_ws_token_exist (get_ws_next_token (ptr, len - 1), 10, len - 1)) {
|
||||
if (test_ws_token_exist (get_ws_next_token (ptr, len - 1), 10, len - 1) == -1) {
|
||||
return op->size = 0;
|
||||
}
|
||||
sprintf (op->buf_asm, "push");
|
||||
{
|
||||
int n = test_ws_token_exist (ptr - 1, 10, len);
|
||||
sprintf (op->buf_asm + 4, " %d", n);
|
||||
return op->size = n;
|
||||
}
|
||||
int n = test_ws_token_exist (ptr - 1, 10, len);
|
||||
r_strbuf_set (&op->buf_asm, sdb_fmt ("push %d", n));
|
||||
return op->size = n;
|
||||
case 10:
|
||||
ptr = get_ws_next_token (ptr, len - 1) + 1;
|
||||
ptr = get_ws_next_token (ptr, len - (ptr - buf));
|
||||
@ -144,13 +132,13 @@ WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) {
|
||||
}
|
||||
switch (*ptr) {
|
||||
case ' ':
|
||||
sprintf (op->buf_asm, "dup");
|
||||
r_strbuf_set (&op->buf_asm, "dup");
|
||||
break;
|
||||
case '\t':
|
||||
sprintf (op->buf_asm, "swap");
|
||||
r_strbuf_set (&op->buf_asm, "swap");
|
||||
break;
|
||||
case 10:
|
||||
sprintf (op->buf_asm, "pop");
|
||||
r_strbuf_set (&op->buf_asm, "pop");
|
||||
break;
|
||||
}
|
||||
return op->size = ptr - buf + 1;
|
||||
@ -162,24 +150,24 @@ WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) {
|
||||
}
|
||||
switch (*ptr) {
|
||||
case ' ':
|
||||
sprintf (op->buf_asm, "copy");
|
||||
r_strbuf_set (&op->buf_asm, "copy");
|
||||
break;
|
||||
case 10:
|
||||
sprintf (op->buf_asm, "slide");
|
||||
r_strbuf_set (&op->buf_asm, "slide");
|
||||
break;
|
||||
case '\t':
|
||||
sprintf (op->buf_asm, "illegal_stack_t");
|
||||
r_strbuf_set (&op->buf_asm, "illegal_stack_t");
|
||||
return op->size = ptr - buf + 1;
|
||||
}
|
||||
ptr++;
|
||||
if (-1 == test_ws_token_exist (ptr, 10, len - (ptr - buf) - 1)) {
|
||||
op->buf_asm[0] = '\0'; // XXX
|
||||
r_strbuf_set (&op->buf_asm, "");
|
||||
return op->size = 0;
|
||||
}
|
||||
if (strlen (op->buf_asm) < 6) {
|
||||
sprintf (&op->buf_asm[strlen (op->buf_asm)], " %d", get_ws_val (ptr, len - (ptr - buf) - 1));
|
||||
if (r_strbuf_length (&op->buf_asm) < 6) {
|
||||
r_strbuf_append (&op->buf_asm, sdb_fmt (" %d", get_ws_val (ptr, len - (ptr - buf) - 1)));
|
||||
}
|
||||
return op->size = test_ws_token_exist (ptr, 10, len - (ptr - buf) - 1) + ptr - buf + 1; // +1?
|
||||
return op->size = test_ws_token_exist (ptr, 10, len - (ptr - buf) - 1) + ptr - buf + 1; // +1?
|
||||
}
|
||||
case WS_OP_HEAP:
|
||||
ptr = get_ws_next_token (ptr + 1, len - 1) + 1;
|
||||
@ -189,13 +177,13 @@ WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) {
|
||||
}
|
||||
switch (*ptr) {
|
||||
case ' ':
|
||||
sprintf (op->buf_asm, "store");
|
||||
r_strbuf_set (&op->buf_asm, "store");
|
||||
break;
|
||||
case '\t':
|
||||
sprintf (op->buf_asm, "load");
|
||||
r_strbuf_set (&op->buf_asm, "load");
|
||||
break;
|
||||
case 10:
|
||||
sprintf (op->buf_asm, "illegal_heap");
|
||||
r_strbuf_set (&op->buf_asm, "illegal_heap");
|
||||
break;
|
||||
}
|
||||
return op->size = ptr - buf + 1;
|
||||
@ -214,10 +202,10 @@ WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) {
|
||||
}
|
||||
switch (*ptr) {
|
||||
case ' ':
|
||||
sprintf (op->buf_asm, "putc");
|
||||
r_strbuf_set (&op->buf_asm, "putc");
|
||||
return op->size = ptr - buf + 1;
|
||||
case '\t':
|
||||
sprintf (op->buf_asm, "puti");
|
||||
r_strbuf_set (&op->buf_asm, "puti");
|
||||
return op->size = ptr - buf + 1;
|
||||
}
|
||||
break;
|
||||
@ -229,21 +217,23 @@ WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) {
|
||||
}
|
||||
switch (*ptr) {
|
||||
case ' ':
|
||||
sprintf (op->buf_asm, "getc");
|
||||
r_strbuf_set (&op->buf_asm, "getc");
|
||||
return op->size = ptr - buf + 1;
|
||||
case '\t':
|
||||
sprintf (op->buf_asm, "geti");
|
||||
r_strbuf_set (&op->buf_asm, "geti");
|
||||
return op->size = ptr - buf + 1;
|
||||
}
|
||||
}
|
||||
sprintf (op->buf_asm, "illegal_io");
|
||||
r_strbuf_set (&op->buf_asm, "illegal_io");
|
||||
return op->size = ptr - buf + 1;
|
||||
break;
|
||||
case WS_OP_ARITH:
|
||||
ptr = get_ws_next_token (ptr + 1, len - 1) + 1;
|
||||
ptr = get_ws_next_token (ptr, len - (ptr - buf));
|
||||
if (!ptr) {
|
||||
return op->size = 0;
|
||||
}
|
||||
const char *buf_asm = NULL;
|
||||
switch (*ptr) {
|
||||
case ' ':
|
||||
ptr++;
|
||||
@ -252,17 +242,11 @@ WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) {
|
||||
return op->size = 0;
|
||||
}
|
||||
switch (*ptr) {
|
||||
case ' ':
|
||||
sprintf (op->buf_asm, "add");
|
||||
break;
|
||||
case '\t':
|
||||
sprintf (op->buf_asm, "sub");
|
||||
break;
|
||||
case 10:
|
||||
sprintf (op->buf_asm, "mul");
|
||||
break;
|
||||
case ' ': buf_asm = "add"; break;
|
||||
case '\t': buf_asm = "sub"; break;
|
||||
case 10: buf_asm = "mul"; break;
|
||||
}
|
||||
return op->size = ptr - buf + 1;
|
||||
break;
|
||||
case '\t':
|
||||
ptr++;
|
||||
ptr = get_ws_next_token (ptr, len - (ptr - buf));
|
||||
@ -270,18 +254,17 @@ WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) {
|
||||
return op->size = 0;
|
||||
}
|
||||
switch (*ptr) {
|
||||
case ' ':
|
||||
sprintf (op->buf_asm, "div");
|
||||
break;
|
||||
case '\t':
|
||||
sprintf (op->buf_asm, "mod");
|
||||
break;
|
||||
case 10:
|
||||
sprintf (op->buf_asm, "illegal_ar_t");
|
||||
case ' ': buf_asm = "div"; break;
|
||||
case '\t': buf_asm = "mod"; break;
|
||||
case 10: buf_asm = "illegal_ar_t"; break;
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
sprintf (op->buf_asm, "illegal_ar");
|
||||
buf_asm = "illegal_ar";
|
||||
break;
|
||||
}
|
||||
if (buf_asm) {
|
||||
r_strbuf_set (&op->buf_asm, buf_asm);
|
||||
}
|
||||
return op->size = ptr - buf + 1;
|
||||
case WS_OP_FLOW:
|
||||
@ -297,9 +280,9 @@ WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) {
|
||||
return op->size = 0;
|
||||
}
|
||||
if (*ptr == 10) {
|
||||
sprintf (op->buf_asm, "exit");
|
||||
r_strbuf_set (&op->buf_asm, "exit");
|
||||
} else {
|
||||
sprintf (op->buf_asm, "illegal_fl_lf");
|
||||
r_strbuf_set (&op->buf_asm, "illegal_fl_lf");
|
||||
}
|
||||
return op->size = ptr - buf + 1;
|
||||
case '\t':
|
||||
@ -310,22 +293,22 @@ WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) {
|
||||
}
|
||||
switch (*ptr) {
|
||||
case 10:
|
||||
sprintf (op->buf_asm, "ret");
|
||||
r_strbuf_set (&op->buf_asm, "ret");
|
||||
return op->size = ptr - buf + 1;
|
||||
case '\t':
|
||||
sprintf (op->buf_asm, "jn");
|
||||
r_strbuf_set (&op->buf_asm, "jn");
|
||||
break;
|
||||
case ' ':
|
||||
sprintf (op->buf_asm, "jz");
|
||||
r_strbuf_set (&op->buf_asm, "jz");
|
||||
break;
|
||||
}
|
||||
ptr++;
|
||||
if (-1 == test_ws_token_exist (ptr, 10, len - (ptr - buf))) {
|
||||
op->buf_asm[0] = '\0';
|
||||
r_strbuf_set (&op->buf_asm, "");
|
||||
return op->size = 0;
|
||||
}
|
||||
if (strlen (op->buf_asm) == 2) {
|
||||
sprintf (&op->buf_asm[2], " %d", get_ws_val (ptr, len - (ptr - buf) - 1));
|
||||
if (r_strbuf_length (&op->buf_asm) == 2) {
|
||||
r_strbuf_append (&op->buf_asm, sdb_fmt (" %d", get_ws_val (ptr, len - (ptr - buf) - 1)));
|
||||
}
|
||||
return op->size = ptr - buf + test_ws_token_exist (ptr, 10, len - (ptr - buf)) + 1;
|
||||
case ' ':
|
||||
@ -335,25 +318,22 @@ WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) {
|
||||
return op->size = 0;
|
||||
}
|
||||
switch (*ptr) {
|
||||
case 10:
|
||||
sprintf (op->buf_asm, "jmp");
|
||||
break;
|
||||
case '\t':
|
||||
sprintf (op->buf_asm, "call");
|
||||
break;
|
||||
case ' ':
|
||||
sprintf (op->buf_asm, "mark");
|
||||
break;
|
||||
case 10: buf_asm = "jmp"; break;
|
||||
case '\t': buf_asm = "call"; break;
|
||||
case ' ': buf_asm = "mark"; break;
|
||||
}
|
||||
ptr++;
|
||||
if (-1 == test_ws_token_exist (ptr, 10, len - (ptr - buf))) {
|
||||
op->buf_asm[0] = '\0';
|
||||
buf_asm = NULL;
|
||||
return op->size = 0;
|
||||
}
|
||||
sprintf (&op->buf_asm[strlen (op->buf_asm)], " %d", get_ws_val (ptr, len - (ptr - buf) - 1));
|
||||
if (buf_asm) {
|
||||
r_strbuf_set (&op->buf_asm, buf_asm);
|
||||
}
|
||||
r_strbuf_append (&op->buf_asm, sdb_fmt (" %d", get_ws_val (ptr, len - (ptr - buf) - 1)));
|
||||
return op->size = ptr - buf + test_ws_token_exist (ptr, 10, len - (ptr - buf)) + 1;
|
||||
}
|
||||
}
|
||||
sprintf (op->buf_asm, "wtf");
|
||||
r_strbuf_set (&op->buf_asm, "wtf");
|
||||
return op->size = 0;
|
||||
}
|
||||
|
@ -9,29 +9,20 @@
|
||||
#include "z80_tab.h"
|
||||
|
||||
static ut8 z80_op_24_branch_index_res (ut8 hex) {
|
||||
if (hex < 0x40)
|
||||
if (hex < 0x40) {
|
||||
return hex;
|
||||
switch (hex) {
|
||||
case 0x46:
|
||||
return 0x40;
|
||||
case 0x4e:
|
||||
return 0x41;
|
||||
case 0x56:
|
||||
return 0x42;
|
||||
case 0x5e:
|
||||
return 0x43;
|
||||
case 0x66:
|
||||
return 0x44;
|
||||
case 0x6e:
|
||||
return 0x45;
|
||||
case 0x76:
|
||||
return 0x46;
|
||||
case 0x7e:
|
||||
return 0x47;
|
||||
}
|
||||
if (hex > 0x7f)
|
||||
return hex-0x38;
|
||||
return 0xc8;
|
||||
switch (hex) {
|
||||
case 0x46: return 0x40;
|
||||
case 0x4e: return 0x41;
|
||||
case 0x56: return 0x42;
|
||||
case 0x5e: return 0x43;
|
||||
case 0x66: return 0x44;
|
||||
case 0x6e: return 0x45;
|
||||
case 0x76: return 0x46;
|
||||
case 0x7e: return 0x47;
|
||||
}
|
||||
return (hex > 0x7f)? hex - 0x38: 0xc8;
|
||||
}
|
||||
|
||||
static int z80OpLength (const ut8 *buf, int len) {
|
||||
@ -41,8 +32,9 @@ static int z80OpLength (const ut8 *buf, int len) {
|
||||
return 0;
|
||||
op = z80_op;
|
||||
if (op[buf[0]].type & Z80_OP_UNK) {
|
||||
if (len < 2)
|
||||
if (len < 2) {
|
||||
return 0;
|
||||
}
|
||||
if (op[buf[0]].type & Z80_ENC0) {
|
||||
op = (z80_opcode *)op[buf[0]].op_moar;
|
||||
type = op[z80_fddd_branch_index_res(buf[1])].type;
|
||||
@ -53,19 +45,24 @@ static int z80OpLength (const ut8 *buf, int len) {
|
||||
} else {
|
||||
type = op[buf[0]].type;
|
||||
}
|
||||
if (type & Z80_OP8)
|
||||
if (type & Z80_OP8) {
|
||||
ret++;
|
||||
if ((type & Z80_ARG8) && !(type & Z80_ARG16)) //XXX
|
||||
}
|
||||
if ((type & Z80_ARG8) && !(type & Z80_ARG16)) { //XXX
|
||||
ret++;
|
||||
if (type & Z80_OP16)
|
||||
}
|
||||
if (type & Z80_OP16) {
|
||||
ret += 2;
|
||||
if (type & Z80_ARG16)
|
||||
}
|
||||
if (type & Z80_ARG16) {
|
||||
ret += 2;
|
||||
if (type & Z80_OP24)
|
||||
}
|
||||
if (type & Z80_OP24) {
|
||||
ret += 3;
|
||||
if (ret > len)
|
||||
}
|
||||
if (ret > len) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -75,49 +72,59 @@ FUNC_ATTR_USED static int z80Disass (RAsmOp *op, const ut8 *buf, int len) {
|
||||
z80_opcode *z_op;
|
||||
char **cb_tab;
|
||||
ut8 res;
|
||||
if (!ret)
|
||||
if (!ret) {
|
||||
return ret;
|
||||
z_op = z80_op;
|
||||
|
||||
switch (z_op[buf[0]].type) {
|
||||
case Z80_OP8:
|
||||
sprintf (op->buf_asm, "%s", z_op[buf[0]].name);
|
||||
return ret;
|
||||
case Z80_OP8^Z80_ARG8:
|
||||
sprintf (op->buf_asm, z_op[buf[0]].name, buf[1]);
|
||||
return ret;
|
||||
case Z80_OP8^Z80_ARG16:
|
||||
sprintf (op->buf_asm, z_op[buf[0]].name, buf[1]+(buf[2]<<8));
|
||||
return ret;
|
||||
case Z80_OP16:
|
||||
cb_tab = (char **) z_op[buf[0]].op_moar;
|
||||
sprintf (op->buf_asm, "%s", cb_tab[buf[1]]);
|
||||
return ret;
|
||||
case Z80_OP_UNK^Z80_ENC1:
|
||||
z_op = (z80_opcode *)z_op[buf[0]].op_moar;
|
||||
res = z80_ed_branch_index_res (buf[1]);
|
||||
if (z_op[res].type == Z80_OP16)
|
||||
sprintf (op->buf_asm, "%s", z_op[res].name);
|
||||
if (z_op[res].type == (Z80_OP16^Z80_ARG16))
|
||||
sprintf (op->buf_asm, z_op[res].name, buf[2]+(buf[3]<<8));
|
||||
return ret;
|
||||
case Z80_OP_UNK^Z80_ENC0:
|
||||
z_op = (z80_opcode *)z_op[buf[0]].op_moar;
|
||||
res = z80_fddd_branch_index_res (buf[1]);
|
||||
if (z_op[res].type == Z80_OP16)
|
||||
sprintf (op->buf_asm, "%s", z_op[res].name);
|
||||
if (z_op[res].type == (Z80_OP16^Z80_ARG16))
|
||||
sprintf (op->buf_asm, z_op[res].name, buf[2]+(buf[3]<<8));
|
||||
if (z_op[res].type == (Z80_OP16^Z80_ARG8))
|
||||
sprintf (op->buf_asm, z_op[res].name, buf[2], buf[3]);
|
||||
if (z_op[res].type == (Z80_OP24^Z80_ARG8)) {
|
||||
cb_tab = (char **) z_op[res].op_moar;
|
||||
sprintf (op->buf_asm, cb_tab[z80_op_24_branch_index_res (buf[3])], buf[2]);
|
||||
}
|
||||
if (z_op[res].type == (Z80_OP16^Z80_ARG8^Z80_ARG16))
|
||||
sprintf (op->buf_asm, z_op[res].name, buf[2], buf[3]);
|
||||
}
|
||||
if (!strcmp (op->buf_asm, "invalid"))
|
||||
z_op = z80_op;
|
||||
const char *buf_asm = "invalid";
|
||||
switch (z_op[buf[0]].type) {
|
||||
case Z80_OP8:
|
||||
buf_asm = sdb_fmt ("%s", z_op[buf[0]].name);
|
||||
break;
|
||||
case Z80_OP8^Z80_ARG8:
|
||||
buf_asm = sdb_fmt (z_op[buf[0]].name, buf[1]);
|
||||
break;
|
||||
case Z80_OP8^Z80_ARG16:
|
||||
buf_asm = sdb_fmt (z_op[buf[0]].name, buf[1]+(buf[2]<<8));
|
||||
break;
|
||||
case Z80_OP16:
|
||||
cb_tab = (char **) z_op[buf[0]].op_moar;
|
||||
buf_asm = sdb_fmt ("%s", cb_tab[buf[1]]);
|
||||
break;
|
||||
case Z80_OP_UNK^Z80_ENC1:
|
||||
z_op = (z80_opcode *)z_op[buf[0]].op_moar;
|
||||
res = z80_ed_branch_index_res (buf[1]);
|
||||
if (z_op[res].type == Z80_OP16) {
|
||||
buf_asm = sdb_fmt ("%s", z_op[res].name);
|
||||
}
|
||||
if (z_op[res].type == (Z80_OP16^Z80_ARG16)) {
|
||||
buf_asm = sdb_fmt (z_op[res].name, buf[2]+(buf[3]<<8));
|
||||
}
|
||||
break;
|
||||
case Z80_OP_UNK^Z80_ENC0:
|
||||
z_op = (z80_opcode *)z_op[buf[0]].op_moar;
|
||||
res = z80_fddd_branch_index_res (buf[1]);
|
||||
if (z_op[res].type == Z80_OP16) {
|
||||
buf_asm = sdb_fmt ("%s", z_op[res].name);
|
||||
}
|
||||
if (z_op[res].type == (Z80_OP16^Z80_ARG16)) {
|
||||
buf_asm = sdb_fmt (z_op[res].name, buf[2]+(buf[3]<<8));
|
||||
}
|
||||
if (z_op[res].type == (Z80_OP16^Z80_ARG8)) {
|
||||
buf_asm = sdb_fmt (z_op[res].name, buf[2], buf[3]);
|
||||
}
|
||||
if (z_op[res].type == (Z80_OP24^Z80_ARG8)) {
|
||||
cb_tab = (char **) z_op[res].op_moar;
|
||||
buf_asm = sdb_fmt (cb_tab[z80_op_24_branch_index_res (buf[3])], buf[2]);
|
||||
}
|
||||
if (z_op[res].type == (Z80_OP16^Z80_ARG8^Z80_ARG16)) {
|
||||
buf_asm = sdb_fmt (z_op[res].name, buf[2], buf[3]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!strcmp (buf_asm, "invalid")) {
|
||||
ret = 0;
|
||||
}
|
||||
r_asm_op_set_asm (op, buf_asm);
|
||||
return ret;
|
||||
}
|
||||
|
190
libr/asm/asm.c
190
libr/asm/asm.c
@ -18,6 +18,7 @@ char *directives[] = {
|
||||
|
||||
static RAsmPlugin *asm_static_plugins[] = { R_ASM_STATIC_PLUGINS };
|
||||
|
||||
/* pseudo.c - private api */
|
||||
static int r_asm_pseudo_align(RAsmCode *acode, RAsmOp *op, char *input) {
|
||||
acode->code_align = r_num_math (NULL, input);
|
||||
return 0;
|
||||
@ -36,8 +37,8 @@ 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, op->buf_hex);
|
||||
strncpy ((char*)op->buf, input, R_ASM_BUFSIZE - 1);
|
||||
r_hex_bin2str ((ut8*)input, len, r_strbuf_get (&op->buf_hex));
|
||||
r_strbuf_set (&op->buf, input); // uh?
|
||||
return len;
|
||||
}
|
||||
|
||||
@ -62,10 +63,11 @@ static inline int r_asm_pseudo_org(RAsm *a, char *input) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// wtf isnt this the same as r_asm_op_set_hex() ??
|
||||
static inline int r_asm_pseudo_hex(RAsmOp *op, char *input) {
|
||||
int len = r_hex_str2bin (input, op->buf);
|
||||
// non null terminated string
|
||||
r_str_ncpy (op->buf_hex, r_str_trim_head_tail (input), sizeof op->buf_hex);
|
||||
// assume input fits inside op->buf
|
||||
int len = r_hex_str2bin (input, (ut8*)r_strbuf_get (&op->buf));
|
||||
r_asm_op_set_hex (op, r_str_trim_head_tail (input));
|
||||
if (len < 0) {
|
||||
len = -len;
|
||||
len--;
|
||||
@ -84,19 +86,20 @@ static inline int r_asm_pseudo_intN(RAsm *a, RAsmOp *op, char *input, int n) {
|
||||
return 0;
|
||||
}
|
||||
// XXX honor endian here
|
||||
ut8 *buf = (ut8*)r_strbuf_get (&op->buf);
|
||||
if (n == 2) {
|
||||
s = (short)s64;
|
||||
r_write_ble16 (op->buf, s, a->big_endian);
|
||||
r_write_ble16 (buf, s, a->big_endian);
|
||||
} else if (n == 4) {
|
||||
i = (int)s64;
|
||||
r_write_ble32 (op->buf, i, a->big_endian);
|
||||
r_write_ble32 (buf, i, a->big_endian);
|
||||
} else if (n == 8) {
|
||||
l = (long int)s64;
|
||||
r_write_ble64 (op->buf, l, a->big_endian);
|
||||
r_write_ble64 (buf, l, a->big_endian);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
r_hex_bin2str (op->buf, n, op->buf_hex);
|
||||
r_hex_bin2str (buf, n, r_strbuf_get (&op->buf_hex));
|
||||
return n;
|
||||
}
|
||||
|
||||
@ -117,24 +120,31 @@ static inline int r_asm_pseudo_byte(RAsmOp *op, char *input) {
|
||||
r_str_replace_char (input, ',', ' ');
|
||||
len = r_str_word_count (input);
|
||||
r_str_word_set0 (input);
|
||||
ut8 *buf = malloc (len);
|
||||
if (!buf) {
|
||||
return 0;
|
||||
}
|
||||
for (i = 0; i < len; i++) {
|
||||
const char *word = r_str_word_get0 (input, i);
|
||||
int num = (int)r_num_math (NULL, word);
|
||||
op->buf[i] = num;
|
||||
buf[i] = num;
|
||||
}
|
||||
r_hex_bin2str (op->buf, len, op->buf_hex);
|
||||
r_asm_op_set_buf (op, buf, len);
|
||||
free (buf);
|
||||
return len;
|
||||
}
|
||||
|
||||
static inline int r_asm_pseudo_fill(RAsmOp *op, char *input) {
|
||||
int i, repeat=0, size=0, value=0;
|
||||
int i, repeat = 0, size=0, value=0;
|
||||
sscanf (input, "%d,%d,%d", &repeat, &size, &value); // use r_num?
|
||||
size *= repeat;
|
||||
if (size > 0) {
|
||||
ut8 *buf = malloc (size);
|
||||
for (i = 0; i < size; i++) {
|
||||
op->buf[i] = value;
|
||||
buf[i] = value;
|
||||
}
|
||||
r_hex_bin2str (op->buf, size, op->buf_hex);
|
||||
r_asm_op_set_buf (op, buf, size);
|
||||
free (buf);
|
||||
} else {
|
||||
size = 0;
|
||||
}
|
||||
@ -142,15 +152,13 @@ static inline int r_asm_pseudo_fill(RAsmOp *op, char *input) {
|
||||
}
|
||||
|
||||
static inline int r_asm_pseudo_incbin(RAsmOp *op, char *input) {
|
||||
int skip = 0;
|
||||
int count = 0;
|
||||
int bytes_read = 0;
|
||||
r_str_replace_char (input, ',', ' ');
|
||||
// int len = r_str_word_count (input);
|
||||
r_str_word_set0 (input);
|
||||
//const char *filename = r_str_word_get0 (input, 0);
|
||||
skip = (int)r_num_math (NULL, r_str_word_get0 (input, 1));
|
||||
count = (int)r_num_math (NULL,r_str_word_get0 (input, 2));
|
||||
int skip = (int)r_num_math (NULL, r_str_word_get0 (input, 1));
|
||||
int count = (int)r_num_math (NULL,r_str_word_get0 (input, 2));
|
||||
char *content = r_file_slurp (input, &bytes_read);
|
||||
if (skip > 0) {
|
||||
skip = skip > bytes_read ? bytes_read : skip;
|
||||
@ -164,7 +172,6 @@ static inline int r_asm_pseudo_incbin(RAsmOp *op, char *input) {
|
||||
r_buf_free (op->buf_inc);
|
||||
op->buf_inc = r_buf_new_with_string (content + skip);
|
||||
// Terminate the original buffer
|
||||
op->buf_hex[0] = '\0';
|
||||
free (content);
|
||||
return count;
|
||||
}
|
||||
@ -401,8 +408,13 @@ R_API int r_asm_set_pc(RAsm *a, ut64 pc) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool isInvalid (RAsmOp *op) {
|
||||
const char *buf_asm = r_strbuf_get (&op->buf_asm);
|
||||
return (buf_asm && *buf_asm && !strcmp (buf_asm, "invalid"));
|
||||
}
|
||||
|
||||
R_API int r_asm_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
int oplen, ret;
|
||||
int ret;
|
||||
if (!a || !buf || !op) {
|
||||
return -1;
|
||||
}
|
||||
@ -412,17 +424,15 @@ R_API int r_asm_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
if (len < 1) {
|
||||
return 0;
|
||||
}
|
||||
op->buf_asm[0] = '\0';
|
||||
r_asm_op_set_asm (op, "");
|
||||
if (a->pcalign) {
|
||||
const int mod = a->pc % a->pcalign;
|
||||
if (mod) {
|
||||
op->size = a->pcalign - mod;
|
||||
strcpy (op->buf_asm, "unaligned");
|
||||
*op->buf_hex = 0;
|
||||
if ((op->size * 4) >= sizeof (op->buf_hex)) {
|
||||
oplen = (sizeof (op->buf_hex) / 4) - 1;
|
||||
}
|
||||
r_hex_bin2str (buf, op->size, op->buf_hex);
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -442,7 +452,7 @@ R_API int r_asm_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
if (ret < 0) {
|
||||
ret = 0;
|
||||
}
|
||||
oplen = r_asm_op_get_size (op);
|
||||
int oplen = r_asm_op_get_size (op);
|
||||
if (op->bitsize > 0) {
|
||||
oplen = op->size = op->bitsize / 8;
|
||||
a->bitshift += op->bitsize % 8;
|
||||
@ -457,38 +467,40 @@ R_API int r_asm_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
if (oplen < 1) {
|
||||
oplen = 1;
|
||||
}
|
||||
if (!op->buf_asm[0] || op->size < 1 || !strcmp (op->buf_asm, "invalid")) {
|
||||
|
||||
if (op->size < 1 || isInvalid (op)) {
|
||||
if (a->invhex) {
|
||||
if (a->bits == 16) {
|
||||
ut16 b = r_read_le16 (buf);
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), ".word 0x%04x", b);
|
||||
r_strbuf_set (&op->buf_asm, sdb_fmt (".word 0x%04x", b));
|
||||
} else {
|
||||
ut32 b = r_read_le32 (buf);
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), ".dword 0x%08x", b);
|
||||
r_strbuf_set (&op->buf_asm, sdb_fmt (".dword 0x%08x", b));
|
||||
}
|
||||
// TODO: something for 64bits too?
|
||||
} else {
|
||||
strcpy (op->buf_asm, "invalid");
|
||||
r_strbuf_set (&op->buf_asm, "invalid");
|
||||
}
|
||||
}
|
||||
if (a->ofilter) {
|
||||
r_parse_parse (a->ofilter, op->buf_asm, op->buf_asm);
|
||||
char *buf_asm = r_strbuf_get (&op->buf_asm);
|
||||
r_parse_parse (a->ofilter, buf_asm, buf_asm);
|
||||
}
|
||||
// XXX this is crap and needs proper fix
|
||||
int dstlen = R_MIN ((R_ASM_BUFSIZE -1), oplen);
|
||||
int cpylen = R_MIN (dstlen, len);
|
||||
if (cpylen > 0) {
|
||||
memcpy (op->buf, buf, cpylen);
|
||||
const int addrbytes = a->user ? ((RCore *)a->user)->io->addrbytes : 1;
|
||||
int len = R_MIN (addrbytes * oplen, (sizeof (op->buf_hex) - 1) / 2);
|
||||
// len is the length in input buffer, not len of output, so we must / 2
|
||||
r_hex_bin2str (op->buf, len, op->buf_hex);
|
||||
if (op->size > 0) {
|
||||
r_asm_op_set_buf (op, buf, R_MAX (0, op->size));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
typedef int (*Ase)(RAsm *a, RAsmOp *op, const char *buf);
|
||||
|
||||
static bool assemblerMatches(RAsm *a, RAsmPlugin *h) {
|
||||
if (!a || !h->arch || !h->assemble || !has_bits (h, a->bits)) {
|
||||
return false;
|
||||
}
|
||||
return (!strncmp (a->cur->arch, h->arch, strlen (a->cur->arch)));
|
||||
}
|
||||
|
||||
static Ase findAssembler(RAsm *a, const char *kw) {
|
||||
Ase ase = NULL;
|
||||
RAsmPlugin *h;
|
||||
@ -497,11 +509,7 @@ static Ase findAssembler(RAsm *a, const char *kw) {
|
||||
return a->acur->assemble;
|
||||
}
|
||||
r_list_foreach (a->plugins, iter, h) {
|
||||
if (h->arch && h->assemble
|
||||
&& has_bits (h, a->bits)
|
||||
&& !strncmp (a->cur->arch,
|
||||
h->arch,
|
||||
strlen (a->cur->arch))) {
|
||||
if (assemblerMatches (a, h)) {
|
||||
if (kw) {
|
||||
if (strstr (h->name, kw)) {
|
||||
return h->assemble;
|
||||
@ -569,7 +577,6 @@ R_API void r_asm_list_directives() {
|
||||
R_API int r_asm_assemble(RAsm *a, RAsmOp *op, const char *buf) {
|
||||
int ret = 0;
|
||||
char *b = strdup (buf);
|
||||
|
||||
if (!b) {
|
||||
return 0;
|
||||
}
|
||||
@ -596,16 +603,21 @@ R_API int r_asm_assemble(RAsm *a, RAsmOp *op, const char *buf) {
|
||||
ret = ase (a, op, b);
|
||||
}
|
||||
}
|
||||
// XXX delete this block, the ase thing should be setting asm, buf and hex
|
||||
if (op && ret > 0) {
|
||||
r_hex_bin2str (op->buf, ret, op->buf_hex);
|
||||
op->size = ret;
|
||||
op->buf_hex[ret*2] = 0;
|
||||
strncpy (op->buf_asm, b, R_ASM_BUFSIZE - 1);
|
||||
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);
|
||||
}
|
||||
}
|
||||
free (b);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// TODO: Use RStrBuf api here pls
|
||||
R_API RAsmCode* r_asm_mdisassemble(RAsm *a, const ut8 *buf, int len) {
|
||||
RStrBuf *buf_asm;
|
||||
RAsmCode *acode;
|
||||
@ -636,9 +648,10 @@ R_API RAsmCode* r_asm_mdisassemble(RAsm *a, const ut8 *buf, int len) {
|
||||
ret = 1;
|
||||
}
|
||||
if (a->ofilter) {
|
||||
r_parse_parse (a->ofilter, op.buf_asm, op.buf_asm);
|
||||
char *op_buf_asm = r_strbuf_get (&op.buf_asm);
|
||||
r_parse_parse (a->ofilter, op_buf_asm, op_buf_asm);
|
||||
}
|
||||
r_strbuf_append (buf_asm, op.buf_asm);
|
||||
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);
|
||||
@ -718,7 +731,6 @@ R_API RAsmCode* r_asm_massemble(RAsm *a, const char *buf) {
|
||||
}
|
||||
lbuf = strdup (buf);
|
||||
acode->code_align = 0;
|
||||
memset (&op, 0, sizeof (op));
|
||||
|
||||
/* consider ,, an alias for a newline */
|
||||
lbuf = r_str_replace (lbuf, ",,", "\n", true);
|
||||
@ -787,7 +799,6 @@ R_API RAsmCode* r_asm_massemble(RAsm *a, const char *buf) {
|
||||
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) {
|
||||
memset (buf_token, 0, R_ASM_BUFSIZE);
|
||||
strncpy (buf_token, tokens[i], R_ASM_BUFSIZE - 1);
|
||||
if (inComment) {
|
||||
if (!strncmp (ptr_start, "*/", 2)) {
|
||||
@ -834,13 +845,12 @@ R_API RAsmCode* r_asm_massemble(RAsm *a, const char *buf) {
|
||||
if (is_a_label) {
|
||||
//if (stage != 2) {
|
||||
if (ptr_start[1] != 0 && ptr_start[1] != ' ') {
|
||||
char food[64];
|
||||
*ptr = 0;
|
||||
if (acode->code_align) {
|
||||
off += (acode->code_align - (off % acode->code_align));
|
||||
}
|
||||
char food[64];
|
||||
snprintf (food, sizeof (food), "0x%"PFMT64x"", off);
|
||||
|
||||
ht_insert (a->flags, ptr_start, food);
|
||||
// TODO: warning when redefined
|
||||
r_asm_code_set_equ (acode, ptr_start, food);
|
||||
@ -976,26 +986,31 @@ R_API RAsmCode* r_asm_massemble(RAsm *a, const char *buf) {
|
||||
if (stage == STAGES - 1) {
|
||||
if (ret < 1) {
|
||||
eprintf ("Cannot assemble '%s' at line %d\n", ptr_start, linenum);
|
||||
free(lbuf);
|
||||
free (lbuf);
|
||||
return r_asm_code_free (acode);
|
||||
}
|
||||
acode->len = idx + ret;
|
||||
char *newbuf = realloc (acode->buf, (idx + ret) * 2);
|
||||
if (!newbuf) {
|
||||
free(lbuf);
|
||||
free (lbuf);
|
||||
return r_asm_code_free (acode);
|
||||
}
|
||||
acode->buf = (ut8*)newbuf;
|
||||
newbuf = realloc (acode->buf_hex, strlen (acode->buf_hex) + strlen (op.buf_hex) + r_buf_size (op.buf_inc) + 1);
|
||||
|
||||
int newlen = strlen (acode->buf_hex) + r_strbuf_length (&op.buf_hex)
|
||||
+ r_buf_size (op.buf_inc) + 128;
|
||||
newbuf = realloc (acode->buf_hex, newlen);
|
||||
if (!newbuf) {
|
||||
free(lbuf);
|
||||
free (lbuf);
|
||||
return r_asm_code_free (acode);
|
||||
}
|
||||
acode->buf_hex = newbuf;
|
||||
memcpy (acode->buf + idx, op.buf, ret);
|
||||
strcat (acode->buf_hex, op.buf_hex);
|
||||
acode->buf = malloc (4095);
|
||||
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));
|
||||
if (r_buf_size (op.buf_inc) > 1) {
|
||||
if (strlen (acode->buf_hex) > 0) {
|
||||
if (*acode->buf_hex) {
|
||||
strcat (acode->buf_hex, "\n");
|
||||
}
|
||||
char *s = r_buf_free_to_string (op.buf_inc);
|
||||
@ -1013,31 +1028,8 @@ R_API RAsmCode* r_asm_massemble(RAsm *a, const char *buf) {
|
||||
return acode;
|
||||
}
|
||||
|
||||
R_API int r_asm_modify(RAsm *a, ut8 *buf, int field, ut64 val) {
|
||||
if (a->cur && a->cur->modify) {
|
||||
return a->cur->modify (a, buf, field, val);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API char *r_asm_op_get_hex(RAsmOp *op) {
|
||||
return strdup (op->buf_hex);
|
||||
}
|
||||
|
||||
R_API char *r_asm_op_get_asm(RAsmOp *op) {
|
||||
return strdup (op->buf_asm);
|
||||
}
|
||||
|
||||
R_API int r_asm_op_get_size(RAsmOp *op) {
|
||||
int len;
|
||||
if (!op) {
|
||||
return 1;
|
||||
}
|
||||
len = op->size - op->payload;
|
||||
if (len < 1) {
|
||||
len = 1;
|
||||
}
|
||||
return len;
|
||||
R_API bool r_asm_modify(RAsm *a, ut8 *buf, int field, ut64 val) {
|
||||
return (a->cur && a->cur->modify) ? a->cur->modify (a, buf, field, val): false;
|
||||
}
|
||||
|
||||
R_API int r_asm_get_offset(RAsm *a, int type, int idx) { // link to rbin
|
||||
@ -1048,30 +1040,21 @@ R_API int r_asm_get_offset(RAsm *a, int type, int idx) { // link to rbin
|
||||
}
|
||||
|
||||
R_API char *r_asm_describe(RAsm *a, const char* str) {
|
||||
if (!a->pair) {
|
||||
return NULL;
|
||||
}
|
||||
return sdb_get (a->pair, str, 0);
|
||||
return (a && a->pair)? sdb_get (a->pair, str, 0): NULL;
|
||||
}
|
||||
|
||||
R_API RList* r_asm_get_plugins(RAsm *a) {
|
||||
return a->plugins;
|
||||
}
|
||||
|
||||
/* new simplified API */
|
||||
|
||||
R_API bool r_asm_set_arch(RAsm *a, const char *name, int bits) {
|
||||
if (!r_asm_use (a, name)) {
|
||||
return false;
|
||||
}
|
||||
return r_asm_set_bits (a, bits);
|
||||
return r_asm_use (a, name)? r_asm_set_bits (a, bits): false;
|
||||
}
|
||||
|
||||
/* to ease the use of the native bindings (not used in r2) */
|
||||
R_API char *r_asm_to_string(RAsm *a, ut64 addr, const ut8 *b, int l) {
|
||||
RAsmCode *code;
|
||||
r_asm_set_pc (a, addr);
|
||||
code = r_asm_mdisassemble (a, b, l);
|
||||
RAsmCode *code = r_asm_mdisassemble (a, b, l);
|
||||
if (code) {
|
||||
char *buf_asm = code->buf_asm;
|
||||
code->buf_asm = NULL;
|
||||
@ -1137,6 +1120,9 @@ R_API int r_asm_mnemonics_byname(RAsm *a, const char *name) {
|
||||
|
||||
R_API RAsmCode* r_asm_rasm_assemble(RAsm *a, const char *buf, bool use_spp) {
|
||||
char *lbuf = strdup (buf);
|
||||
if (!lbuf) {
|
||||
return NULL;
|
||||
}
|
||||
RAsmCode *acode;
|
||||
if (use_spp) {
|
||||
Output out;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2017 - pancake */
|
||||
/* radare - LGPL - Copyright 2009-2018 - pancake */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <r_asm.h>
|
||||
|
@ -1,5 +1,6 @@
|
||||
files = [
|
||||
'asm.c',
|
||||
'op.c',
|
||||
'code.c',
|
||||
'p/asm_6502.c',
|
||||
'p/asm_8051.c',
|
||||
|
73
libr/asm/op.c
Normal file
73
libr/asm/op.c
Normal file
@ -0,0 +1,73 @@
|
||||
/* radare - LGPL - Copyright 2018 - pancake */
|
||||
|
||||
#include <r_asm.h>
|
||||
|
||||
R_API RAsmOp *r_asm_op_new() {
|
||||
return R_NEW0 (RAsmOp);
|
||||
}
|
||||
|
||||
R_API void r_asm_op_free(RAsmOp *op) {
|
||||
r_asm_op_fini (op);
|
||||
free (op);
|
||||
}
|
||||
|
||||
R_API void r_asm_op_init(RAsmOp *op) {
|
||||
memset (op, 0, sizeof (*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_API char *r_asm_op_get_asm(RAsmOp *op) {
|
||||
return r_strbuf_get (&op->buf_asm);
|
||||
}
|
||||
|
||||
R_API int r_asm_op_get_size(RAsmOp *op) {
|
||||
if (!op) {
|
||||
return 1;
|
||||
}
|
||||
const int len = op->size - op->payload;
|
||||
return R_MAX (1, len);
|
||||
}
|
||||
|
||||
R_API void r_asm_op_set_asm(RAsmOp *op, const char *str) {
|
||||
r_strbuf_set (&op->buf_asm, str);
|
||||
}
|
||||
|
||||
R_API void 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);
|
||||
if (len > 0) {
|
||||
r_strbuf_setbin (&op->buf, bin, len);
|
||||
}
|
||||
free (bin);
|
||||
}
|
||||
}
|
||||
|
||||
R_API void r_asm_op_set_hexbuf(RAsmOp *op, const ut8 *buf, int len) {
|
||||
char *hex = malloc (len * 4);
|
||||
if (hex) {
|
||||
r_hex_bin2str (buf, len, hex);
|
||||
r_asm_op_set_hex (op, hex);
|
||||
free (hex);
|
||||
}
|
||||
// TODO: update the op->buf too?
|
||||
}
|
||||
|
||||
R_API void r_asm_op_set_buf(RAsmOp *op, const ut8 *buf, int len) {
|
||||
if (op && buf && len >= 0) {
|
||||
r_strbuf_setbin (&op->buf, buf, len);
|
||||
r_asm_op_set_hexbuf (op, buf, len);
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
/* radare - LGPL - Copyright 2012-2015 - pancake, condret */
|
||||
/* radare - LGPL - Copyright 2012-2018 - pancake, condret */
|
||||
|
||||
// copypasta from asm_gb.c
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
#include <r_asm.h>
|
||||
@ -10,9 +9,7 @@
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
int dlen = _6502Disass (a->pc, op, buf, len);
|
||||
if(dlen<0) dlen=0;
|
||||
op->size = dlen;
|
||||
return dlen;
|
||||
return op->size = R_MAX (dlen, 0);
|
||||
}
|
||||
|
||||
RAsmPlugin r_asm_plugin_6502 = {
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2012-2016 - pancake */
|
||||
/* radare - LGPL - Copyright 2012-2018 - pancake */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
@ -67,7 +67,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
if (len < 2) {
|
||||
return -1;
|
||||
}
|
||||
buf_global = op->buf_asm;
|
||||
buf_global = r_strbuf_get (&op->buf_asm);
|
||||
Offset = a->pc;
|
||||
if (len > sizeof (bytes)) {
|
||||
len = sizeof (bytes);
|
||||
@ -86,14 +86,14 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
disasm_obj.fprintf_func = &buf_fprintf;
|
||||
disasm_obj.stream = stdout;
|
||||
disasm_obj.mach = 0;
|
||||
op->buf_asm[0] = '\0';
|
||||
r_strbuf_set (&op->buf_asm, "");
|
||||
if (a->bits == 16) {
|
||||
op->size = ARCompact_decodeInstr ((bfd_vma)Offset, &disasm_obj);
|
||||
} else {
|
||||
op->size = ARCTangent_decodeInstr ((bfd_vma)Offset, &disasm_obj);
|
||||
}
|
||||
if (op->size == -1) {
|
||||
strncpy (op->buf_asm, " (data)", R_ASM_BUFSIZE);
|
||||
r_strbuf_set (&op->buf_asm, "(data)");
|
||||
}
|
||||
return op->size;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2015 pancake */
|
||||
/* radare - LGPL - Copyright 2015-2018 pancake */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
@ -18,16 +18,16 @@
|
||||
static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
|
||||
const char *bitconfig = "";
|
||||
char *ipath, *opath;
|
||||
int ifd, ofd;
|
||||
char *as = NULL;
|
||||
char asm_buf[R_ASM_BUFSIZE];
|
||||
int len = 0;
|
||||
|
||||
ifd = r_file_mkstemp ("r_as", &ipath);
|
||||
if (ifd == -1)
|
||||
int ifd = r_file_mkstemp ("r_as", &ipath);
|
||||
if (ifd == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ofd = r_file_mkstemp ("r_as", &opath);
|
||||
int ofd = r_file_mkstemp ("r_as", &opath);
|
||||
if (ofd == -1) {
|
||||
free (ipath);
|
||||
return -1;
|
||||
@ -52,29 +52,30 @@ static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
|
||||
"%s\n"
|
||||
".ascii \"ENDMARK\"\n",
|
||||
bitconfig, buf); // a->pc ??
|
||||
write (ifd, asm_buf, len);
|
||||
close (ifd);
|
||||
(void)write (ifd, asm_buf, len);
|
||||
(void)close (ifd);
|
||||
|
||||
if (!r_sys_cmdf ("%s %s -o %s", as, ipath, opath)) {
|
||||
const ut8 *begin, *end;
|
||||
close (ofd);
|
||||
ofd = open (opath, O_BINARY|O_RDONLY);
|
||||
ofd = r_sandbox_open (opath, O_BINARY|O_RDONLY, 0644);
|
||||
if (ofd < 0) {
|
||||
free (as);
|
||||
free (ipath);
|
||||
free (opath);
|
||||
return -1;
|
||||
}
|
||||
len = read (ofd, op->buf, R_ASM_BUFSIZE);
|
||||
begin = r_mem_mem (op->buf, len, (const ut8*)"BEGINMARK", 9);
|
||||
end = r_mem_mem (op->buf, len, (const ut8*)"ENDMARK", 7);
|
||||
ut8 buf[4096];
|
||||
len = read (ofd, buf, sizeof (buf));
|
||||
begin = r_mem_mem (buf, len, (const ut8*)"BEGINMARK", 9);
|
||||
end = r_mem_mem (buf, len, (const ut8*)"ENDMARK", 7);
|
||||
if (!begin || !end) {
|
||||
eprintf ("Cannot find water marks\n");
|
||||
len = 0;
|
||||
} else {
|
||||
len = (int)(size_t)(end - begin - 9);
|
||||
if (len > 0) {
|
||||
memcpy (op->buf, begin + 9, len);
|
||||
r_strbuf_setbin (&op->buf, begin + 9, len);
|
||||
} else {
|
||||
len = 0;
|
||||
}
|
||||
@ -101,6 +102,7 @@ RAsmPlugin r_asm_plugin_arm_as = {
|
||||
.name = "arm.as",
|
||||
.desc = "as ARM Assembler (use ARM_AS environment)",
|
||||
.arch = "arm",
|
||||
.author = "pancake",
|
||||
.license = "LGPL3",
|
||||
.bits = 16|32|64,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG,
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare2 - LGPL - Copyright 2013-2017 - pancake */
|
||||
/* radare2 - LGPL - Copyright 2013-2018 - pancake */
|
||||
|
||||
#include <r_asm.h>
|
||||
#include <r_lib.h>
|
||||
@ -6,11 +6,39 @@
|
||||
#include "../arch/arm/asm-arm.h"
|
||||
|
||||
bool arm64ass(const char *str, ut64 addr, ut32 *op);
|
||||
static int check_features(RAsm *a, cs_insn *insn);
|
||||
static csh cd = 0;
|
||||
|
||||
#include "cs_mnemonics.c"
|
||||
|
||||
static bool check_features(RAsm *a, cs_insn *insn) {
|
||||
int i;
|
||||
if (!insn || !insn->detail) {
|
||||
return true;
|
||||
}
|
||||
for (i = 0; i < insn->detail->groups_count; i++) {
|
||||
int id = insn->detail->groups[i];
|
||||
switch (id) {
|
||||
case ARM_GRP_ARM:
|
||||
case ARM_GRP_THUMB:
|
||||
case ARM_GRP_THUMB1ONLY:
|
||||
case ARM_GRP_THUMB2:
|
||||
continue;
|
||||
default:
|
||||
if (id < 128) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const char *name = cs_group_name (cd, id);
|
||||
if (!name) {
|
||||
return true;
|
||||
}
|
||||
if (!strstr (a->features, name)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
static int omode = -1;
|
||||
static int obits = 32;
|
||||
@ -44,7 +72,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
}
|
||||
if (op) {
|
||||
op->size = 4;
|
||||
op->buf_asm[0] = 0;
|
||||
r_strbuf_set (&op->buf_asm, "");
|
||||
}
|
||||
if (!cd || mode != omode) {
|
||||
ret = (a->bits == 64)?
|
||||
@ -55,53 +83,45 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
goto beach;
|
||||
}
|
||||
}
|
||||
if (a->syntax == R_ASM_SYNTAX_REGNUM) {
|
||||
cs_option (cd, CS_OPT_SYNTAX, CS_OPT_SYNTAX_NOREGNAME);
|
||||
} else {
|
||||
cs_option (cd, CS_OPT_SYNTAX, CS_OPT_SYNTAX_DEFAULT);
|
||||
}
|
||||
if (a->features && *a->features) {
|
||||
cs_option (cd, CS_OPT_DETAIL, CS_OPT_ON);
|
||||
} else {
|
||||
cs_option (cd, CS_OPT_DETAIL, CS_OPT_OFF);
|
||||
}
|
||||
cs_option (cd, CS_OPT_SYNTAX, (a->syntax == R_ASM_SYNTAX_REGNUM)
|
||||
? CS_OPT_SYNTAX_NOREGNAME
|
||||
: CS_OPT_SYNTAX_DEFAULT);
|
||||
cs_option (cd, CS_OPT_DETAIL, (a->features && *a->features)
|
||||
? CS_OPT_ON: CS_OPT_OFF);
|
||||
if (!buf) {
|
||||
goto beach;
|
||||
}
|
||||
n = cs_disasm (cd, buf, R_MIN (4, len), a->pc, 1, &insn);
|
||||
if (n < 1) {
|
||||
if (n < 1 || insn->size < 1) {
|
||||
ret = -1;
|
||||
goto beach;
|
||||
}
|
||||
if (op) {
|
||||
op->size = 0;
|
||||
}
|
||||
if (insn->size < 1) {
|
||||
ret = -1;
|
||||
goto beach;
|
||||
}
|
||||
if (a->features && *a->features) {
|
||||
if (!check_features (a, insn) && op) {
|
||||
op->size = insn->size;
|
||||
strcpy (op->buf_asm, "illegal");
|
||||
r_strbuf_set (&op->buf_asm, "illegal");
|
||||
}
|
||||
}
|
||||
if (op && !op->size) {
|
||||
op->size = insn->size;
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s%s%s",
|
||||
char *buf_asm = sdb_fmt ("%s%s%s",
|
||||
insn->mnemonic,
|
||||
insn->op_str[0]?" ":"",
|
||||
insn->op_str);
|
||||
if (!disp_hash) {
|
||||
r_str_rmch (op->buf_asm, '#');
|
||||
r_str_rmch (buf_asm, '#');
|
||||
}
|
||||
r_strbuf_set (&op->buf_asm, buf_asm);
|
||||
}
|
||||
cs_free (insn, n);
|
||||
beach:
|
||||
cs_close (&cd);
|
||||
if (op) {
|
||||
if (!op->buf_asm[0]) {
|
||||
strcpy (op->buf_asm, "invalid");
|
||||
if (!*r_strbuf_get (&op->buf_asm)) {
|
||||
r_strbuf_set (&op->buf_asm, "invalid");
|
||||
}
|
||||
return op->size;
|
||||
}
|
||||
@ -126,27 +146,29 @@ static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
|
||||
if (opcode == UT32_MAX) {
|
||||
return -1;
|
||||
}
|
||||
ut8 opbuf[4];
|
||||
if (is_thumb) {
|
||||
const int o = opcode >> 16;
|
||||
opsize = o > 0? 4: 2; //(o&0x80 && ((o&0xe0)==0xe0))? 4: 2;
|
||||
opsize = o > 0? 4: 2;
|
||||
if (opsize == 4) {
|
||||
if (a->big_endian) {
|
||||
r_write_le16 (op->buf, opcode >> 16);
|
||||
r_write_le16 (op->buf + 2, opcode & UT16_MAX);
|
||||
r_write_le16 (opbuf, opcode >> 16);
|
||||
r_write_le16 (opbuf + 2, opcode & UT16_MAX);
|
||||
} else {
|
||||
r_write_be32 (op->buf, opcode);
|
||||
r_write_be32 (opbuf, opcode);
|
||||
}
|
||||
} else if (opsize == 2) {
|
||||
r_write_be16 (op->buf, opcode & UT16_MAX);
|
||||
r_write_be16 (opbuf, opcode & UT16_MAX);
|
||||
}
|
||||
} else {
|
||||
opsize = 4;
|
||||
if (a->big_endian) {
|
||||
r_write_le32 (op->buf, opcode);
|
||||
r_write_le32 (opbuf, opcode);
|
||||
} else {
|
||||
r_write_be32 (op->buf, opcode);
|
||||
r_write_be32 (opbuf, opcode);
|
||||
}
|
||||
}
|
||||
r_strbuf_setbin (&op->buf, opbuf, opsize);
|
||||
// XXX. thumb endian assembler needs no swap
|
||||
return opsize;
|
||||
}
|
||||
@ -172,36 +194,6 @@ RAsmPlugin r_asm_plugin_arm_cs = {
|
||||
#endif
|
||||
};
|
||||
|
||||
static int check_features(RAsm *a, cs_insn *insn) {
|
||||
const char *name;
|
||||
int i;
|
||||
if (!insn || !insn->detail) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 0; i < insn->detail->groups_count; i++) {
|
||||
int id = insn->detail->groups[i];
|
||||
if (id == ARM_GRP_ARM)
|
||||
continue;
|
||||
if (id == ARM_GRP_THUMB)
|
||||
continue;
|
||||
if (id == ARM_GRP_THUMB1ONLY)
|
||||
continue;
|
||||
if (id == ARM_GRP_THUMB2)
|
||||
continue;
|
||||
if (id < 128) {
|
||||
continue;
|
||||
}
|
||||
name = cs_group_name (cd, id);
|
||||
if (!name) {
|
||||
return 1;
|
||||
}
|
||||
if (!strstr (a->features, name)) {
|
||||
//eprintf ("CANNOT FIND %s\n", name);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifndef CORELIB
|
||||
RLibStruct radare_plugin = {
|
||||
|
@ -134,7 +134,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
if (a->bits < 64 && len < (a->bits / 8)) {
|
||||
return -1;
|
||||
}
|
||||
buf_global = op->buf_asm;
|
||||
buf_global = r_strbuf_get (&op->buf_asm);
|
||||
Offset = a->pc;
|
||||
|
||||
/* prepare disassembler */
|
||||
@ -180,7 +180,7 @@ cpucode = 66471;
|
||||
obj.bytes_per_chunk =
|
||||
obj.bytes_per_line = (a->bits / 8);
|
||||
|
||||
op->buf_asm[0] = '\0';
|
||||
r_strbuf_set (&op->buf_asm, "");
|
||||
if (a->bits == 64) {
|
||||
obj.disassembler_options = NULL;
|
||||
memcpy (bytes, buf, 4);
|
||||
@ -193,11 +193,10 @@ cpucode = 66471;
|
||||
}
|
||||
opsize = op->size;
|
||||
if (op->size == -1) {
|
||||
strncpy (op->buf_asm, " (data)", R_ASM_BUFSIZE);
|
||||
r_strbuf_set (&op->buf_asm, "(data)");
|
||||
op->size = 4;
|
||||
}
|
||||
if (strstr (op->buf_asm, "UNDEF")) {
|
||||
strcpy (op->buf_asm, "undefined");
|
||||
} else if (strstr (buf_global, "UNDEF")) {
|
||||
r_strbuf_set (&op->buf_asm, "undefined");
|
||||
op->size = 2;
|
||||
opsize = 2;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2017 - nibble, pancake */
|
||||
/* radare - LGPL - Copyright 2009-2018 - nibble, pancake */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
@ -23,11 +23,11 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
op->size = arm_disasm_one_insn (arminsn);
|
||||
const char *asmstr = winedbg_arm_insn_asm (arminsn);
|
||||
if (asmstr) {
|
||||
r_str_ncpy (op->buf_asm, asmstr, sizeof (op->buf_asm));
|
||||
r_str_ncpy (op->buf_hex, winedbg_arm_insn_hex (arminsn), sizeof (op->buf_hex));
|
||||
r_strbuf_set (&op->buf_asm, asmstr);
|
||||
r_strbuf_set (&op->buf_hex, winedbg_arm_insn_hex (arminsn));
|
||||
} else {
|
||||
strcpy (op->buf_asm, "invalid");
|
||||
op->buf_hex[0] = 0;
|
||||
r_strbuf_set (&op->buf_asm, "invalid");
|
||||
r_strbuf_set (&op->buf_hex, "");
|
||||
}
|
||||
arm_free (arminsn);
|
||||
return op->size;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2010-2015 - pancake, dark_k3y */
|
||||
/* radare - LGPL - Copyright 2010-2018 - pancake, dark_k3y */
|
||||
/* AVR assembler realization by Alexander Bolshev aka @dark_k3y, LGPL -- 2015,
|
||||
heavily based (and using!) on disassemble module */
|
||||
|
||||
@ -14,11 +14,13 @@
|
||||
#include "../arch/avr/disasm.c"
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
int ret = op->size = avrdis (op->buf_asm, a->pc, buf, len);
|
||||
if (op->buf_asm[0] == '.') {
|
||||
op->buf_asm[0] = 0;
|
||||
char buf_asm[32] = {0};
|
||||
op->size = avrdis (buf_asm, a->pc, buf, len);
|
||||
if (*buf_asm == '.') {
|
||||
*buf_asm = 0;
|
||||
}
|
||||
return ret;
|
||||
r_strbuf_set (&op->buf_asm, buf_asm);
|
||||
return op->size;
|
||||
}
|
||||
|
||||
extern instructionInfo instructionSet[AVR_TOTAL_INSTRUCTIONS];
|
||||
@ -76,8 +78,12 @@ static int parse_specialreg(const char *reg) {
|
||||
/* gets the number from string
|
||||
duplicate from asm_x86_nz.c -- may be create a generic function? */
|
||||
static int getnum(RAsm *a, const char *s) {
|
||||
if (!s) return 0;
|
||||
if (*s=='$') s++;
|
||||
if (!s) {
|
||||
return 0;
|
||||
}
|
||||
if (*s == '$') {
|
||||
s++;
|
||||
}
|
||||
return r_num_math (a->num, s);
|
||||
}
|
||||
|
||||
@ -115,9 +121,10 @@ static int search_instruction(RAsm *a, char instr[3][MAX_TOKEN_SIZE], int args)
|
||||
&& instructionSet[i].operandTypes[1] == OPERAND_LONG_ABSOLUTE_ADDRESS) {
|
||||
// ineffective, but needed for lds/sts and other cases
|
||||
if (strlen(instr[2]) > 0) {
|
||||
op2 = getnum(a, instr[2]);
|
||||
if (op2 > 127)
|
||||
op2 = getnum (a, instr[2]);
|
||||
if (op2 > 127) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
// handling st & std instruction with 2 args
|
||||
} else if (instructionSet[i].mnemonic[0] == 's'
|
||||
@ -133,9 +140,10 @@ static int search_instruction(RAsm *a, char instr[3][MAX_TOKEN_SIZE], int args)
|
||||
&& instructionSet[i].operandTypes[0] == OPERAND_LONG_ABSOLUTE_ADDRESS) {
|
||||
// same for 1st operand of sts
|
||||
if (strlen(instr[1]) > 0) {
|
||||
op1 = getnum(a, instr[1]);
|
||||
if (op1 > 127)
|
||||
op1 = getnum (a, instr[1]);
|
||||
if (op1 > 127) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return i; // it's not st/ld/lpm-like instruction with 2 args
|
||||
@ -404,7 +412,7 @@ static int assemble(RAsm *a, RAsmOp *ao, const char *str) {
|
||||
|
||||
// copying result to radare struct
|
||||
if (len > 0) {
|
||||
memcpy (ao->buf, &coded, len);
|
||||
r_strbuf_setbin (&ao->buf, (const ut8*)&coded, len);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2017 - pancake, nibble */
|
||||
/* radare - LGPL - Copyright 2009-2018 - pancake, nibble */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -16,143 +16,126 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
rep++;
|
||||
}
|
||||
}
|
||||
|
||||
const char *buf_asm = "invalid";
|
||||
switch (*buf) {
|
||||
case '[':
|
||||
strcpy (op->buf_asm, "while [ptr]");
|
||||
buf_asm = "while [ptr]";
|
||||
break;
|
||||
case ']':
|
||||
strcpy (op->buf_asm, "loop"); // TODO: detect clause and put label name
|
||||
buf_asm = "loop";
|
||||
break;
|
||||
case '>':
|
||||
if (rep > 1) {
|
||||
strcpy (op->buf_asm, "add ptr");
|
||||
} else {
|
||||
strcpy (op->buf_asm, "inc ptr");
|
||||
}
|
||||
buf_asm = (rep > 1)? "add ptr": "inc ptr";
|
||||
break;
|
||||
case '<':
|
||||
if (rep > 1) {
|
||||
strcpy (op->buf_asm, "sub ptr");
|
||||
} else {
|
||||
strcpy (op->buf_asm, "dec ptr");
|
||||
}
|
||||
buf_asm = (rep > 1)? "sub ptr": "dec ptr";
|
||||
break;
|
||||
case '+':
|
||||
if (rep > 1) {
|
||||
strcpy (op->buf_asm, "add [ptr]");
|
||||
} else {
|
||||
strcpy (op->buf_asm, "inc [ptr]");
|
||||
}
|
||||
buf_asm = (rep > 1)? "add [ptr]": "inc [ptr]";
|
||||
break;
|
||||
case '-':
|
||||
if (rep > 1) {
|
||||
strcpy (op->buf_asm, "sub [ptr]");
|
||||
} else {
|
||||
strcpy (op->buf_asm, "dec [ptr]");
|
||||
}
|
||||
buf_asm = (rep > 1)? "sub [ptr]": "dec [ptr]";
|
||||
break;
|
||||
case ',':
|
||||
strcpy (op->buf_asm, "in [ptr]");
|
||||
buf_asm = "in [ptr]";
|
||||
break;
|
||||
case '.':
|
||||
strcpy (op->buf_asm, "out [ptr]");
|
||||
buf_asm = "out [ptr]";
|
||||
break;
|
||||
case 0xff:
|
||||
case 0x00:
|
||||
strcpy (op->buf_asm, "trap");
|
||||
buf_asm = "trap";
|
||||
break;
|
||||
default:
|
||||
strcpy (op->buf_asm, "nop");
|
||||
buf_asm = "nop";
|
||||
break;
|
||||
}
|
||||
|
||||
if (rep > 1) {
|
||||
/* Note: snprintf's source and destination buffers may not
|
||||
* overlap. */
|
||||
const char *fmt = strchr (op->buf_asm, ' ')? "%s, %d": "%s %d";
|
||||
char buf[sizeof (op->buf_asm)];
|
||||
snprintf (buf, sizeof (buf), fmt, op->buf_asm, rep);
|
||||
strcpy (op->buf_asm, buf);
|
||||
const char *fmt = strchr (buf_asm, ' ')? "%s, %d": "%s %d";
|
||||
buf_asm = sdb_fmt (fmt, buf_asm, rep);
|
||||
}
|
||||
|
||||
r_strbuf_set (&op->buf_asm, buf_asm);
|
||||
op->size = rep;
|
||||
return rep;
|
||||
}
|
||||
|
||||
static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
|
||||
const char *ref, *arg;
|
||||
int n = 0;
|
||||
if (buf[0] && buf[1] == ' ') {
|
||||
buf += 2;
|
||||
}
|
||||
arg = strchr (buf, ',');
|
||||
ref = strchr (buf, '[');
|
||||
const char *arg = strchr (buf, ',');
|
||||
const char *ref = strchr (buf, '[');
|
||||
ut8 opbuf[32];
|
||||
if (!strncmp (buf, "trap", 4)) {
|
||||
if (arg) {
|
||||
n = atoi (arg + 1);
|
||||
memset (op->buf, 0xcc, n);
|
||||
memset (opbuf, 0xcc, n);
|
||||
} else {
|
||||
op->buf[0] = 0x90;
|
||||
opbuf[0] = 0x90;
|
||||
n = 1;
|
||||
}
|
||||
} else if (!strncmp (buf, "nop", 3)) {
|
||||
if (arg) {
|
||||
n = atoi (arg + 1);
|
||||
memset (op->buf, 0x90, n);
|
||||
memset (opbuf, 0x90, n);
|
||||
} else {
|
||||
op->buf[0] = 0x90;
|
||||
opbuf[0] = 0x90;
|
||||
n = 1;
|
||||
}
|
||||
} else if (!strncmp (buf, "inc", 3)) {
|
||||
char ch = ref? '+': '>';
|
||||
op->buf[0] = ch;
|
||||
opbuf[0] = ch;
|
||||
n = 1;
|
||||
} else if (!strncmp (buf, "dec", 3)) {
|
||||
char ch = ref? '-': '<';
|
||||
op->buf[0] = ch;
|
||||
opbuf[0] = ch;
|
||||
n = 1;
|
||||
} else if (!strncmp (buf, "sub", 3)) {
|
||||
char ch = ref? '-': '<';
|
||||
if (arg) {
|
||||
n = atoi (arg + 1);
|
||||
memset (op->buf, ch, n);
|
||||
memset (opbuf, ch, n);
|
||||
} else {
|
||||
op->buf[0] = '<';
|
||||
opbuf[0] = '<';
|
||||
n = 1;
|
||||
}
|
||||
} else if (!strncmp (buf, "add", 3)) {
|
||||
char ch = ref? '+': '>';
|
||||
if (arg) {
|
||||
n = atoi (arg + 1);
|
||||
memset (op->buf, ch, n);
|
||||
memset (opbuf, ch, n);
|
||||
} else {
|
||||
op->buf[0] = '<';
|
||||
opbuf[0] = '<';
|
||||
n = 1;
|
||||
}
|
||||
} else if (!strncmp (buf, "while", 5)) {
|
||||
op->buf[0] = '[';
|
||||
opbuf[0] = '[';
|
||||
n = 1;
|
||||
} else if (!strncmp (buf, "loop", 4)) {
|
||||
op->buf[0] = ']';
|
||||
opbuf[0] = ']';
|
||||
n = 1;
|
||||
} else if (!strncmp (buf, "in", 4)) {
|
||||
if (arg) {
|
||||
n = atoi (arg + 1);
|
||||
memset (op->buf, ',', n);
|
||||
memset (opbuf, ',', n);
|
||||
} else {
|
||||
op->buf[0] = ',';
|
||||
opbuf[0] = ',';
|
||||
n = 1;
|
||||
}
|
||||
} else if (!strncmp (buf, "out", 4)) {
|
||||
if (arg) {
|
||||
n = atoi (arg + 1);
|
||||
memset (op->buf, '.', n);
|
||||
memset (opbuf, '.', n);
|
||||
} else {
|
||||
op->buf[0] = '.';
|
||||
opbuf[0] = '.';
|
||||
n = 1;
|
||||
}
|
||||
}
|
||||
r_strbuf_setbin (&op->buf, opbuf, n);
|
||||
return n;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL3 - Copyright 2017 - maijin */
|
||||
/* radare - LGPL3 - Copyright 2017-2018 - maijin */
|
||||
|
||||
#include <r_asm.h>
|
||||
#include <r_lib.h>
|
||||
@ -10,75 +10,77 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *b, int l) {
|
||||
uint8_t nibble = opcode & 0x0F;
|
||||
uint16_t nnn = opcode & 0x0FFF;
|
||||
uint8_t kk = opcode & 0xFF;
|
||||
const char *buf_asm = "invalid";
|
||||
switch (opcode & 0xF000) {
|
||||
case 0x0000:
|
||||
if (opcode == 0x00E0) {
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "cls");
|
||||
buf_asm = "cls";
|
||||
} else if (opcode == 0x00EE) {
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "ret");
|
||||
buf_asm = "ret";
|
||||
} else if ((opcode & 0xFFF0) == 0x00C0) {
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "scd 0x%01x", nibble);
|
||||
buf_asm = sdb_fmt ("scd 0x%01x", nibble);
|
||||
} else if (opcode == 0x00FB) {
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "scr");
|
||||
buf_asm = "scr";
|
||||
} else if (opcode == 0x00FC) {
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "scl");
|
||||
buf_asm = "scl";
|
||||
} else if (opcode == 0x00FD) {
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "exit");
|
||||
buf_asm = "exit";
|
||||
} else if (opcode == 0x00FE) {
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "low");
|
||||
buf_asm = "low";
|
||||
} else if (opcode == 0x00FF) {
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "high");
|
||||
buf_asm = "high";
|
||||
}
|
||||
break;
|
||||
case 0x1000: snprintf (op->buf_asm, R_ASM_BUFSIZE, "jp 0x%03x", nnn); break;
|
||||
case 0x2000: snprintf (op->buf_asm, R_ASM_BUFSIZE, "call 0x%03x", nnn); break;
|
||||
case 0x3000: snprintf (op->buf_asm, R_ASM_BUFSIZE, "se v%1x, 0x%02x", x, kk); break;
|
||||
case 0x4000: snprintf (op->buf_asm, R_ASM_BUFSIZE, "sne v%1x, 0x%02x", x, kk); break;
|
||||
case 0x5000: snprintf (op->buf_asm, R_ASM_BUFSIZE, "se v%1x, v%1x", x, y); break;
|
||||
case 0x6000: snprintf (op->buf_asm, R_ASM_BUFSIZE, "ld v%1x, 0x%02x", x, kk); break;
|
||||
case 0x7000: snprintf (op->buf_asm, R_ASM_BUFSIZE, "add v%1x, 0x%02x", x, kk); break;
|
||||
case 0x1000: buf_asm = sdb_fmt ("jp 0x%03x", nnn); break;
|
||||
case 0x2000: buf_asm = sdb_fmt ("call 0x%03x", nnn); break;
|
||||
case 0x3000: buf_asm = sdb_fmt ("se v%1x, 0x%02x", x, kk); break;
|
||||
case 0x4000: buf_asm = sdb_fmt ("sne v%1x, 0x%02x", x, kk); break;
|
||||
case 0x5000: buf_asm = sdb_fmt ("se v%1x, v%1x", x, y); break;
|
||||
case 0x6000: buf_asm = sdb_fmt ("ld v%1x, 0x%02x", x, kk); break;
|
||||
case 0x7000: buf_asm = sdb_fmt ("add v%1x, 0x%02x", x, kk); break;
|
||||
case 0x8000: {
|
||||
switch (nibble) {
|
||||
case 0x0: snprintf (op->buf_asm, R_ASM_BUFSIZE, "ld v%1x, v%1x", x, y); break;
|
||||
case 0x1: snprintf (op->buf_asm, R_ASM_BUFSIZE, "or v%1x, v%1x", x, y); break;
|
||||
case 0x2: snprintf (op->buf_asm, R_ASM_BUFSIZE, "and v%1x, v%1x", x, y); break;
|
||||
case 0x3: snprintf (op->buf_asm, R_ASM_BUFSIZE, "xor v%1x, v%1x", x, y); break;
|
||||
case 0x4: snprintf (op->buf_asm, R_ASM_BUFSIZE, "add v%1x, v%1x", x, y); break;
|
||||
case 0x5: snprintf (op->buf_asm, R_ASM_BUFSIZE, "sub v%1x, v%1x", x, y); break;
|
||||
case 0x6: snprintf (op->buf_asm, R_ASM_BUFSIZE, "shr v%1x, v%1x", x, y); break;
|
||||
case 0x7: snprintf (op->buf_asm, R_ASM_BUFSIZE, "subn v%1x, v%1x", x, y); break;
|
||||
case 0xE: snprintf (op->buf_asm, R_ASM_BUFSIZE, "shl v%1x, v%1x", x, y); break;
|
||||
case 0x0: buf_asm = sdb_fmt ("ld v%1x, v%1x", x, y); break;
|
||||
case 0x1: buf_asm = sdb_fmt ("or v%1x, v%1x", x, y); break;
|
||||
case 0x2: buf_asm = sdb_fmt ("and v%1x, v%1x", x, y); break;
|
||||
case 0x3: buf_asm = sdb_fmt ("xor v%1x, v%1x", x, y); break;
|
||||
case 0x4: buf_asm = sdb_fmt ("add v%1x, v%1x", x, y); break;
|
||||
case 0x5: buf_asm = sdb_fmt ("sub v%1x, v%1x", x, y); break;
|
||||
case 0x6: buf_asm = sdb_fmt ("shr v%1x, v%1x", x, y); break;
|
||||
case 0x7: buf_asm = sdb_fmt ("subn v%1x, v%1x", x, y); break;
|
||||
case 0xE: buf_asm = sdb_fmt ("shl v%1x, v%1x", x, y); break;
|
||||
}
|
||||
} break;
|
||||
case 0x9000: snprintf (op->buf_asm, R_ASM_BUFSIZE, "sne v%1x, v%1x", x, y); break;
|
||||
case 0xA000: snprintf (op->buf_asm, R_ASM_BUFSIZE, "ld i, 0x%03x", nnn); break;
|
||||
case 0xB000: snprintf (op->buf_asm, R_ASM_BUFSIZE, "jp v0, 0x%03x", nnn); break;
|
||||
case 0xC000: snprintf (op->buf_asm, R_ASM_BUFSIZE, "rnd v%1x, 0x%02x", x, kk); break;
|
||||
case 0xD000: snprintf (op->buf_asm, R_ASM_BUFSIZE, "drw v%1x, v%1x, 0x%01x", x, y, nibble); break;
|
||||
case 0x9000: buf_asm = sdb_fmt ("sne v%1x, v%1x", x, y); break;
|
||||
case 0xA000: buf_asm = sdb_fmt ("ld i, 0x%03x", nnn); break;
|
||||
case 0xB000: buf_asm = sdb_fmt ("jp v0, 0x%03x", nnn); break;
|
||||
case 0xC000: buf_asm = sdb_fmt ("rnd v%1x, 0x%02x", x, kk); break;
|
||||
case 0xD000: buf_asm = sdb_fmt ("drw v%1x, v%1x, 0x%01x", x, y, nibble); break;
|
||||
case 0xE000: {
|
||||
if (kk == 0x9E) {
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "skp v%1x", x);
|
||||
buf_asm = sdb_fmt ("skp v%1x", x);
|
||||
} else if (kk == 0xA1) {
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "sknp v%1x", x);
|
||||
buf_asm = sdb_fmt ("sknp v%1x", x);
|
||||
}
|
||||
} break;
|
||||
case 0xF000: {
|
||||
switch (kk) {
|
||||
case 0x07: snprintf (op->buf_asm, R_ASM_BUFSIZE, "ld v%1x, dt", x); break;
|
||||
case 0x0A: snprintf (op->buf_asm, R_ASM_BUFSIZE, "ld v%1x, k", x); break;
|
||||
case 0x15: snprintf (op->buf_asm, R_ASM_BUFSIZE, "ld dt, v%1x", x); break;
|
||||
case 0x18: snprintf (op->buf_asm, R_ASM_BUFSIZE, "ld st, v%1x", x); break;
|
||||
case 0x1E: snprintf (op->buf_asm, R_ASM_BUFSIZE, "add i, v%1x", x); break;
|
||||
case 0x29: snprintf (op->buf_asm, R_ASM_BUFSIZE, "ld f, v%1x", x); break;
|
||||
case 0x33: snprintf (op->buf_asm, R_ASM_BUFSIZE, "ld b, v%1x", x); break;
|
||||
case 0x55: snprintf (op->buf_asm, R_ASM_BUFSIZE, "ld [i], v%1x", x); break;
|
||||
case 0x65: snprintf (op->buf_asm, R_ASM_BUFSIZE, "ld v%1x, [i]", x); break;
|
||||
case 0x30: snprintf (op->buf_asm, R_ASM_BUFSIZE, "ld hf, v%1x", x); break;
|
||||
case 0x75: snprintf (op->buf_asm, R_ASM_BUFSIZE, "ld r, v%1x", x); break;
|
||||
case 0x85: snprintf (op->buf_asm, R_ASM_BUFSIZE, "ld v%1x, r", x); break;
|
||||
case 0x07: buf_asm = sdb_fmt ("ld v%1x, dt", x); break;
|
||||
case 0x0A: buf_asm = sdb_fmt ("ld v%1x, k", x); break;
|
||||
case 0x15: buf_asm = sdb_fmt ("ld dt, v%1x", x); break;
|
||||
case 0x18: buf_asm = sdb_fmt ("ld st, v%1x", x); break;
|
||||
case 0x1E: buf_asm = sdb_fmt ("add i, v%1x", x); break;
|
||||
case 0x29: buf_asm = sdb_fmt ("ld f, v%1x", x); break;
|
||||
case 0x33: buf_asm = sdb_fmt ("ld b, v%1x", x); break;
|
||||
case 0x55: buf_asm = sdb_fmt ("ld [i], v%1x", x); break;
|
||||
case 0x65: buf_asm = sdb_fmt ("ld v%1x, [i]", x); break;
|
||||
case 0x30: buf_asm = sdb_fmt ("ld hf, v%1x", x); break;
|
||||
case 0x75: buf_asm = sdb_fmt ("ld r, v%1x", x); break;
|
||||
case 0x85: buf_asm = sdb_fmt ("ld v%1x, r", x); break;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
r_strbuf_set (&op->buf_asm, buf_asm);
|
||||
op->size = 2;
|
||||
return op->size;
|
||||
}
|
||||
@ -93,9 +95,9 @@ RAsmPlugin r_asm_plugin_chip8 = {
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
struct RLibStruct radare_plugin = {
|
||||
RLibStruct radare_plugin = {
|
||||
.type = R_LIB_TYPE_ASM,
|
||||
.data = &r_asm_plugin_chip8
|
||||
.version = R2_VERSION
|
||||
.version = R2_VERSION
|
||||
};
|
||||
#endif
|
||||
|
@ -1,22 +1,17 @@
|
||||
/* radare - LGPL - Copyright 2014-2018 - fedor.sakharov */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <r_types.h>
|
||||
#include <r_lib.h>
|
||||
#include <r_asm.h>
|
||||
|
||||
#include <cr16_disas.h>
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len)
|
||||
{
|
||||
int ret = 1;
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
struct cr16_cmd cmd;
|
||||
|
||||
ret = cr16_decode_command (buf, &cmd);
|
||||
|
||||
snprintf(op->buf_asm, R_ASM_BUFSIZE, "%s %s", cmd.instr, cmd.operands);
|
||||
op->size = ret;
|
||||
|
||||
return ret;
|
||||
int ret = cr16_decode_command (buf, &cmd);
|
||||
r_strbuf_set (&op->buf_asm, sdb_fmt ("%s %s", cmd.instr, cmd.operands));
|
||||
return op->size = ret;
|
||||
}
|
||||
|
||||
RAsmPlugin r_asm_plugin_cr16 = {
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2014 - pancake */
|
||||
/* radare - LGPL - Copyright 2014-2018 - pancake */
|
||||
|
||||
#if 0
|
||||
|
||||
@ -75,11 +75,10 @@ int print_insn_crisv10_v32_with_register_prefix (bfd_vma vma, disassemble_info *
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
struct disassemble_info disasm_obj;
|
||||
int mode = 2;
|
||||
|
||||
op->buf_asm[0]='\0';
|
||||
if (len<4)
|
||||
if (len < 4) {
|
||||
return -1;
|
||||
buf_global = op->buf_asm;
|
||||
}
|
||||
buf_global = r_strbuf_get (&op->buf_asm);
|
||||
Offset = a->pc;
|
||||
memcpy (bytes, buf, R_MIN (len, 8)); // TODO handle thumb
|
||||
|
||||
@ -114,10 +113,9 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
op->size = print_insn_crisv10_v32_without_register_prefix (
|
||||
(bfd_vma)Offset, &disasm_obj);
|
||||
}
|
||||
|
||||
if (op->size == -1)
|
||||
strncpy (op->buf_asm, " (data)", R_ASM_BUFSIZE);
|
||||
|
||||
if (op->size == -1) {
|
||||
r_strbuf_set (&op->buf_asm, "(data)");
|
||||
}
|
||||
return op->size;
|
||||
}
|
||||
|
||||
@ -126,6 +124,7 @@ RAsmPlugin r_asm_plugin_cris_gnu = {
|
||||
.arch = "cris",
|
||||
.cpus = "v10,v32,v10+v32",
|
||||
.license = "GPL3",
|
||||
.author = "pancake",
|
||||
.bits = 32,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.desc = "Axis Communications 32-bit embedded processor",
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2017 - earada, pancake */
|
||||
/* radare - LGPL - Copyright 2009-2018 - earada, pancake, h4ng3r */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -20,17 +20,20 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
const char *flag_str;
|
||||
a->dataalign = 2;
|
||||
|
||||
op->buf_asm[0] = 0;
|
||||
const char *buf_asm = NULL;
|
||||
if (buf[0] == 0x00) { /* nop */
|
||||
if (len < 2) {
|
||||
return -1;
|
||||
}
|
||||
switch (buf[1]) {
|
||||
case 0x01: /* packed-switch-payload */
|
||||
// ushort size
|
||||
// int first_key
|
||||
// int[size] = relative offsets
|
||||
{
|
||||
unsigned short array_size = buf[2] | (buf[3] << 8);
|
||||
ut16 array_size = buf[2] | (buf[3] << 8);
|
||||
int first_key = buf[4] | (buf[5] << 8) | (buf[6] << 16) | (buf[7] << 24);
|
||||
snprintf (op->buf_asm, sizeof(op->buf_asm), "packed-switch-payload %d, %d", array_size, first_key);
|
||||
buf_asm = sdb_fmt ("packed-switch-payload %d, %d", array_size, first_key);
|
||||
size = 8;
|
||||
payload = 2 * (array_size * 2);
|
||||
len = 0;
|
||||
@ -41,10 +44,10 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
// int[size] keys
|
||||
// int[size] relative offsets
|
||||
{
|
||||
unsigned short array_size = buf[2] | (buf[3] << 8);
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm), "sparse-switch-payload %d", array_size);
|
||||
ut16 array_size = buf[2] | (buf[3] << 8);
|
||||
buf_asm = sdb_fmt ("sparse-switch-payload %d", array_size);
|
||||
size = 4;
|
||||
payload = 2 * (array_size*4);
|
||||
payload = 2 * (array_size * 4);
|
||||
len = 0;
|
||||
}
|
||||
break;
|
||||
@ -53,11 +56,9 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
// size = 4 bytes uint
|
||||
// ([size*element_width+1)/2)+4
|
||||
if (len > 7) {
|
||||
unsigned short elem_width = buf[2] | (buf[3] << 8);
|
||||
unsigned int array_size = buf[4] | (buf[5] << 8) | (buf[6] << 16) | (buf[7] << 24);
|
||||
snprintf (op->buf_asm, sizeof (op->buf_asm),
|
||||
"fill-array-data-payload %d, %d",
|
||||
elem_width, array_size);
|
||||
ut16 elem_width = buf[2] | (buf[3] << 8);
|
||||
ut32 array_size = buf[4] | (buf[5] << 8) | (buf[6] << 16) | (buf[7] << 24);
|
||||
buf_asm = sdb_fmt ("fill-array-data-payload %d, %d", elem_width, array_size);
|
||||
payload = array_size * elem_width;
|
||||
}
|
||||
size = 8;
|
||||
@ -68,10 +69,12 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (buf_asm) {
|
||||
r_strbuf_set (&op->buf_asm, buf_asm);
|
||||
}
|
||||
strasm = NULL;
|
||||
if (size <= len) {
|
||||
strncpy (op->buf_asm, dalvik_opcodes[i].name, sizeof (op->buf_asm) - 1);
|
||||
strasm = strdup (op->buf_asm);
|
||||
strasm = strdup (dalvik_opcodes[i].name);
|
||||
size = dalvik_opcodes[i].len;
|
||||
switch (dalvik_opcodes[i].fmt) {
|
||||
case fmtop: break;
|
||||
@ -482,8 +485,7 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
flag_str = R_ASM_GET_NAME (a, 'm', vB);
|
||||
if (flag_str) {
|
||||
snprintf (str, sizeof (str), " {v%i..v%i}, %s", vC, vC + vA - 1, flag_str);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
snprintf (str, sizeof (str), " {v%i..v%i}, method+%i", vC, vC + vA - 1, vB);
|
||||
}
|
||||
strasm = r_str_append (strasm, str);
|
||||
@ -491,8 +493,7 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
flag_str = R_ASM_GET_NAME (a, 'p', vH);
|
||||
if (flag_str) {
|
||||
snprintf (str, sizeof (str), ", %s", flag_str);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
snprintf (str, sizeof (str), ", proto+%i", vH);
|
||||
}
|
||||
strasm = r_str_append (strasm, str);
|
||||
@ -501,20 +502,13 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
case fmtoptinvokeIR:
|
||||
case fmt00:
|
||||
default:
|
||||
strcpy (op->buf_asm, "invalid ");
|
||||
free (strasm);
|
||||
strasm = NULL;
|
||||
size = 2;
|
||||
}
|
||||
if (strasm) {
|
||||
strncpy (op->buf_asm, strasm, sizeof (op->buf_asm) - 1);
|
||||
op->buf_asm[sizeof (op->buf_asm) - 1] = 0;
|
||||
} else {
|
||||
//op->buf_asm[0] = 0;
|
||||
strcpy (op->buf_asm , "invalid");
|
||||
}
|
||||
r_strbuf_set (&op->buf_asm, strasm? strasm: "invalid");
|
||||
} else if (len > 0) {
|
||||
strcpy (op->buf_asm, "invalid ");
|
||||
r_strbuf_set (&op->buf_asm, "invalid");
|
||||
op->size = len;
|
||||
size = len;
|
||||
}
|
||||
@ -536,7 +530,9 @@ static int dalvik_assemble(RAsm *a, RAsmOp *op, const char *buf) {
|
||||
// TODO: use a hashtable here
|
||||
for (i = 0; i < 256; i++) {
|
||||
if (!strcmp (dalvik_opcodes[i].name, buf)) {
|
||||
r_write_ble32 (op->buf, i, a->big_endian);
|
||||
ut8 buf[4];
|
||||
r_write_ble32 (buf, i, a->big_endian);
|
||||
r_strbuf_setbin (&op->buf, buf, sizeof (buf));
|
||||
op->size = dalvik_opcodes[i].len;
|
||||
return op->size;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare2 - LGPL - Copyright 2012-2015 pancake */
|
||||
/* radare2 - LGPL - Copyright 2012-2018 pancake */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
@ -12,15 +12,17 @@
|
||||
#include "../arch/dcpu16/asm.c"
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
if (len<2) return -1; // at least 2 bytes!
|
||||
op->size = dcpu16_disasm (op->buf_asm, (const ut16*)buf, len, NULL);
|
||||
if (op->size == -1)
|
||||
strcpy (op->buf_asm, " (data)");
|
||||
char buf_asm[32];
|
||||
if (len < 2) {
|
||||
return -1; // at least 2 bytes!
|
||||
}
|
||||
op->size = dcpu16_disasm (buf_asm, (const ut16*)buf, len, NULL);
|
||||
r_strbuf_set (&op->buf_asm, (op->size > 0) ? buf_asm: "(data)");
|
||||
return op->size;
|
||||
}
|
||||
|
||||
static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
|
||||
return dcpu16_assemble (op->buf, buf);
|
||||
return dcpu16_assemble ((ut8*)r_strbuf_get (&op->buf), buf);
|
||||
}
|
||||
|
||||
RAsmPlugin r_asm_plugin_dcpu16 = {
|
||||
|
@ -1,35 +1,26 @@
|
||||
/* radare - LGPL - Copyright 2012-2013 - pancake
|
||||
2013 - Fedor Sakharov <fedor.sakharov@gmail.com> */
|
||||
/* radare - LGPL - Copyright 2012-2018 - pancake, fedor sakharov */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <r_types.h>
|
||||
#include <r_lib.h>
|
||||
#include <r_asm.h>
|
||||
|
||||
#include <ebc_disas.h>
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
int ret = 1;
|
||||
ebc_command_t cmd = { {0}, {0} };
|
||||
|
||||
ret = ebc_decode_command(buf, &cmd);
|
||||
|
||||
if (cmd.operands[0]) {
|
||||
snprintf(op->buf_asm, R_ASM_BUFSIZE,
|
||||
"%s %s", cmd.instr, cmd.operands);
|
||||
} else {
|
||||
snprintf(op->buf_asm, R_ASM_BUFSIZE, "%s", cmd.instr);
|
||||
}
|
||||
|
||||
op->size = ret;
|
||||
return ret;
|
||||
int ret = ebc_decode_command (buf, &cmd);
|
||||
const char *buf_asm = (cmd.operands[0])
|
||||
? sdb_fmt ("%s %s", cmd.instr, cmd.operands): cmd.instr;
|
||||
r_asm_op_set_asm (op, buf_asm);
|
||||
return op->size = ret;
|
||||
}
|
||||
|
||||
RAsmPlugin r_asm_plugin_ebc = {
|
||||
.name = "ebc",
|
||||
.license = "LGPL3",
|
||||
.desc = "EFI Bytecode",
|
||||
.author = "Fedor Sakharov",
|
||||
.arch = "ebc",
|
||||
.bits = 32|64,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2012-2015 - pancake, condret */
|
||||
/* radare - LGPL - Copyright 2012-2018 - pancake, condret */
|
||||
|
||||
// fork of asm_z80.c
|
||||
|
||||
@ -11,9 +11,7 @@
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *r_op, const ut8 *buf, int len) {
|
||||
int dlen = gbDisass(r_op,buf,len);
|
||||
if(dlen<0) dlen=0;
|
||||
r_op->size = dlen;
|
||||
return dlen;
|
||||
return r_op->size = R_MAX (0, dlen);
|
||||
}
|
||||
|
||||
static int assemble(RAsm *a, RAsmOp *r_op, const char *buf) {
|
||||
@ -24,6 +22,7 @@ RAsmPlugin r_asm_plugin_gb = {
|
||||
.name = "gb",
|
||||
.desc = "GameBoy(TM) (z80-like)",
|
||||
.arch = "z80",
|
||||
.author = "condret",
|
||||
.license = "LGPL3",
|
||||
.bits = 16,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
|
@ -1,22 +1,17 @@
|
||||
/* radare - LGPL - Copyright 2014-2018 - fedor.sakharov */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <r_types.h>
|
||||
#include <r_lib.h>
|
||||
#include <r_asm.h>
|
||||
|
||||
#include <h8300_disas.h>
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len)
|
||||
{
|
||||
int ret = 1;
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
struct h8300_cmd cmd;
|
||||
|
||||
ret = h8300_decode_command(buf, &cmd);
|
||||
|
||||
snprintf(op->buf_asm, R_ASM_BUFSIZE, "%s %s", cmd.instr, cmd.operands);
|
||||
op->size = ret;
|
||||
|
||||
return ret;
|
||||
int ret = h8300_decode_command(buf, &cmd);
|
||||
r_strbuf_set (&op->buf_asm, sdb_fmt ("%s %s", cmd.instr, cmd.operands));
|
||||
return op->size = ret;
|
||||
}
|
||||
|
||||
RAsmPlugin r_asm_plugin_h8300 = {
|
||||
|
@ -7,21 +7,18 @@
|
||||
#include "hexagon.h"
|
||||
#include "hexagon_insn.h"
|
||||
|
||||
static int disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int l)
|
||||
{
|
||||
HexInsn hi;
|
||||
ut32 data = 0;
|
||||
memset(&hi, 0, sizeof(hi));
|
||||
data = r_read_le32(buf);
|
||||
int size = hexagon_disasm_instruction(data, &hi);
|
||||
op->size = size;
|
||||
strcpy(op->buf_asm, hi.mnem);
|
||||
return size;
|
||||
static int disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int l) {
|
||||
HexInsn hi = {0};
|
||||
ut32 data = r_read_le32 (buf);
|
||||
op->size = hexagon_disasm_instruction (data, &hi);
|
||||
r_strbuf_set (&op->buf_asm, hi.mnem);
|
||||
return op->size;
|
||||
}
|
||||
|
||||
RAsmPlugin r_asm_plugin_hexagon = {
|
||||
.name = "hexagon",
|
||||
.arch = "hexagon",
|
||||
.author = "xvilka",
|
||||
.license = "LGPL3",
|
||||
.bits = 32,
|
||||
.desc = "Qualcomm Hexagon (QDSP6) V6",
|
||||
@ -29,7 +26,7 @@ RAsmPlugin r_asm_plugin_hexagon = {
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
struct r_lib_struct_t radare_plugin = {
|
||||
RLibStruct radare_plugin = {
|
||||
.type = R_LIB_TYPE_ASM,
|
||||
.data = &r_asm_plugin_hexagon
|
||||
};
|
||||
|
@ -73,16 +73,16 @@ static int buf_fprintf(void *stream, const char *format, ...) {
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
struct disassemble_info disasm_obj;
|
||||
op->buf_asm[0]='\0';
|
||||
if (len<4)
|
||||
if (len < 4) {
|
||||
return -1;
|
||||
buf_global = op->buf_asm;
|
||||
}
|
||||
buf_global = r_strbuf_get (&op->buf_asm);
|
||||
Offset = a->pc;
|
||||
memcpy (bytes, buf, 4); // TODO handle thumb
|
||||
|
||||
/* prepare disassembler */
|
||||
memset (&disasm_obj, '\0', sizeof (struct disassemble_info));
|
||||
disasm_obj.disassembler_options=(a->bits==64)?"64":"";
|
||||
disasm_obj.disassembler_options = (a->bits == 64)?"64":"";
|
||||
disasm_obj.buffer = bytes;
|
||||
disasm_obj.read_memory_func = &hppa_buffer_read_memory;
|
||||
disasm_obj.symbol_at_address_func = &symbol_at_address;
|
||||
@ -93,9 +93,9 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
disasm_obj.stream = stdout;
|
||||
|
||||
op->size = print_insn_hppa ((bfd_vma)Offset, &disasm_obj);
|
||||
if (op->size == -1)
|
||||
strncpy (op->buf_asm, " (data)", R_ASM_BUFSIZE);
|
||||
|
||||
if (op->size == -1) {
|
||||
r_strbuf_set (&op->buf_asm, "(data)");
|
||||
}
|
||||
return op->size;
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,14 @@
|
||||
/* radare - LGPL - Copyright 2012-2013 - Alexander */
|
||||
/* radare - LGPL - Copyright 2012-2018 - Alexander */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
#include <r_lib.h>
|
||||
#include <r_asm.h>
|
||||
|
||||
#include "../arch/i8080/i8080dis.c"
|
||||
|
||||
static int do_disassemble(RAsm *a, struct r_asm_op_t *op, const ut8 *buf, int len) {
|
||||
int dlen = i8080_disasm (buf, op->buf_asm, len);
|
||||
if (dlen<0) dlen = 0;
|
||||
op->size = dlen;
|
||||
return op->size;
|
||||
static int do_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
int dlen = i8080_disasm (buf, r_strbuf_get (&op->buf_asm), len);
|
||||
return op->size = R_MAX (0, dlen);
|
||||
}
|
||||
|
||||
RAsmPlugin r_asm_plugin_i8080 = {
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2017 - nibble, pancake */
|
||||
/* radare - LGPL - Copyright 2009-2018 - nibble, pancake */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
@ -10,7 +10,6 @@
|
||||
#include "../../shlr/java/class.h"
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
//void *cp;
|
||||
RBinJavaObj *obj = NULL;
|
||||
RBin *bin = a->binb.bin;
|
||||
RBinPlugin *plugin = bin && bin->cur && bin->cur->o ?
|
||||
@ -21,15 +20,16 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
//eprintf("Handling: %s disasm.\n", b->cur.file);
|
||||
}
|
||||
}
|
||||
|
||||
op->size = r_java_disasm (obj, a->pc, buf, len,
|
||||
op->buf_asm, sizeof (op->buf_asm));
|
||||
char buf_asm[256];
|
||||
op->size = r_java_disasm (obj, a->pc, buf, len, buf_asm, sizeof (buf_asm));
|
||||
r_strbuf_set (&op->buf_asm, buf_asm);
|
||||
return op->size;
|
||||
}
|
||||
|
||||
static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
|
||||
static int assemble(RAsm *a, RAsmOp *op, const char *input) {
|
||||
// TODO: get class info from bin if possible
|
||||
return op->size = r_java_assemble (a->pc, op->buf, buf);
|
||||
// XXX wrong usage of strbuf_get here
|
||||
return op->size = r_java_assemble (a->pc, (ut8*)r_strbuf_get (&op->buf), input);
|
||||
}
|
||||
|
||||
RAsmPlugin r_asm_plugin_java = {
|
||||
|
@ -1,20 +1,17 @@
|
||||
/* radare - LGPL - Copyright 2016 - pancake */
|
||||
/* radare - LGPL - Copyright 2016-2018 - pancake */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_lib.h>
|
||||
#include <r_util.h>
|
||||
#include <r_asm.h>
|
||||
|
||||
#include "disas-asm.h"
|
||||
|
||||
|
||||
static unsigned long Offset = 0;
|
||||
static char *buf_global = NULL;
|
||||
static int buf_global_size = 0;
|
||||
static int buf_global_size = 64; // hardcoded sizeof (RStrBuf.buf);
|
||||
static unsigned char bytes[4];
|
||||
|
||||
static int lanai_buffer_read_memory (bfd_vma memaddr, bfd_byte *myaddr, ut32 length, struct disassemble_info *info) {
|
||||
@ -56,9 +53,8 @@ static int buf_fprintf(void *stream, const char *format, ...) {
|
||||
}
|
||||
memcpy (tmp, buf_global, glen);
|
||||
memcpy (tmp+glen, format, flen);
|
||||
tmp[flen+glen] = 0;
|
||||
// XXX: overflow here?
|
||||
|
||||
tmp[flen + glen] = 0;
|
||||
// XXX: overflow here?
|
||||
vsnprintf (buf_global, buf_global_size, tmp, ap);
|
||||
free (tmp);
|
||||
va_end (ap);
|
||||
@ -67,12 +63,10 @@ static int buf_fprintf(void *stream, const char *format, ...) {
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
struct disassemble_info disasm_obj;
|
||||
op->buf_asm[0]='\0';
|
||||
if (len < 4) {
|
||||
return -1;
|
||||
}
|
||||
buf_global = op->buf_asm;
|
||||
buf_global_size = sizeof (op->buf_asm);
|
||||
buf_global = r_strbuf_get (&op->buf_asm);
|
||||
Offset = a->pc;
|
||||
memcpy (bytes, buf, 4); // TODO handle thumb
|
||||
|
||||
@ -89,9 +83,8 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
disasm_obj.stream = stdout;
|
||||
|
||||
op->size = print_insn_lanai ((bfd_vma)Offset, &disasm_obj);
|
||||
|
||||
if (op->size == -1) {
|
||||
strncpy (op->buf_asm, " (data)", R_ASM_BUFSIZE);
|
||||
r_strbuf_set (&op->buf_asm, "(data)");
|
||||
}
|
||||
return op->size;
|
||||
}
|
||||
|
@ -8,23 +8,22 @@
|
||||
|
||||
static int disassemble(RAsm *as, RAsmOp *op, const ut8 *buf, int len) {
|
||||
struct lh5801_insn insn;
|
||||
|
||||
if (!op) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int consumed = lh5801_decode (&insn, buf, len);
|
||||
if (consumed == -1 || consumed == 0) {
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "invalid");
|
||||
r_strbuf_set (&op->buf_asm, "invalid");
|
||||
op->size = 1;
|
||||
return 0;
|
||||
} else {
|
||||
lh5801_print_insn (op->buf_asm, R_ASM_BUFSIZE, &insn);
|
||||
op->size = consumed;
|
||||
//op->payload = lh5801_insn_descs[insn.type].format & 3;
|
||||
// ^ MAYBE?
|
||||
return op->size;
|
||||
}
|
||||
char buf_asm[128] = {0};
|
||||
lh5801_print_insn (buf_asm, sizeof (buf_asm), &insn);
|
||||
r_strbuf_set (&op->buf_asm, buf_asm);
|
||||
op->size = consumed;
|
||||
//op->payload = lh5801_insn_descs[insn.type].format & 3;
|
||||
// ^ MAYBE?
|
||||
return op->size;
|
||||
}
|
||||
|
||||
RAsmPlugin r_asm_plugin_lh5801 = {
|
||||
|
@ -384,7 +384,6 @@ static int assemble(RAsm *a, RAsmOp *ao, const char *str) {
|
||||
//TODO
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
@ -392,13 +391,13 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
instr.value = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];
|
||||
instr.addr = a->pc;
|
||||
if (r_asm_lm32_decode (&instr)) {
|
||||
strcpy (op->buf_asm, "invalid");
|
||||
r_strbuf_set (&op->buf_asm, "invalid");
|
||||
a->invhex = 1;
|
||||
return -1;
|
||||
}
|
||||
//op->buf_asm is 256 chars long, which is more than sufficient
|
||||
if (r_asm_lm32_stringify (&instr, op->buf_asm)) {
|
||||
strcpy (op->buf_asm, "invalid");
|
||||
if (r_asm_lm32_stringify (&instr, r_strbuf_get (&op->buf_asm))) {
|
||||
r_strbuf_set (&op->buf_asm, "invalid");
|
||||
a->invhex = 1;
|
||||
return -1;
|
||||
}
|
||||
@ -409,6 +408,7 @@ RAsmPlugin r_asm_plugin_lm32 = {
|
||||
.name = "lm32",
|
||||
.arch = "lm32",
|
||||
.desc = "disassembly plugin for Lattice Micro 32 ISA",
|
||||
.author = "Felix Held",
|
||||
.license = "BSD",
|
||||
.bits = 32,
|
||||
.endian = R_SYS_ENDIAN_BIG,
|
||||
|
@ -49,7 +49,6 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
mode |= CS_MODE_M68K_060;
|
||||
if (op) {
|
||||
op->size = 4;
|
||||
op->buf_asm[0] = 0;
|
||||
}
|
||||
if (cd == 0) {
|
||||
ret = cs_open (CS_ARCH_M68K, mode, &cd);
|
||||
@ -81,26 +80,24 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
ret = -1;
|
||||
goto beach;
|
||||
}
|
||||
const char *buf_asm = NULL;
|
||||
if (a->features && *a->features) {
|
||||
if (!check_features (a, insn)) {
|
||||
if (op) {
|
||||
op->size = insn->size;
|
||||
strcpy (op->buf_asm, "illegal");
|
||||
op->size = insn->size;
|
||||
buf_asm = "illegal";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (op && !op->size) {
|
||||
op->size = insn->size;
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s%s%s",
|
||||
insn->mnemonic,
|
||||
insn->op_str[0]?" ":"",
|
||||
insn->op_str);
|
||||
buf_asm = sdb_fmt ("%s%s%s", insn->mnemonic, insn->op_str[0]?" ":"", insn->op_str);
|
||||
}
|
||||
if (op) {
|
||||
char *p = r_str_replace (strdup (op->buf_asm),
|
||||
"$", "0x", true);
|
||||
if (op && buf_asm) {
|
||||
char *p = r_str_replace (strdup (buf_asm), "$", "0x", true);
|
||||
if (p) {
|
||||
strncpy (op->buf_asm, p, R_ASM_BUFSIZE-1);
|
||||
r_str_rmch (p, '#');
|
||||
r_asm_op_set_asm (op, p);
|
||||
free (p);
|
||||
}
|
||||
}
|
||||
@ -108,10 +105,12 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
beach:
|
||||
//cs_close (&cd);
|
||||
if (op) {
|
||||
if (!strncmp (op->buf_asm, "dc.w", 4)) {
|
||||
strcpy (op->buf_asm, "invalid");
|
||||
const char *bufasm = r_asm_op_get_asm (op);
|
||||
if (!strncmp (buf_asm, "dc.w", 4)) {
|
||||
r_asm_op_set_asm (op, "invalid");
|
||||
bufasm = r_asm_op_get_asm (op);
|
||||
}
|
||||
r_str_rmch (op->buf_asm, '#');
|
||||
r_str_rmch (buf_asm, '#');
|
||||
return op->size;
|
||||
}
|
||||
return ret;
|
||||
@ -147,6 +146,7 @@ RAsmPlugin r_asm_plugin_m68k_cs = {
|
||||
.name = "m68k.cs (unsupported)",
|
||||
.desc = "Capstone M68K disassembler (unsupported)",
|
||||
.license = "BSD",
|
||||
.author = "pancake",
|
||||
.arch = "m68k",
|
||||
.bits = 16 | 32,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG,
|
||||
|
@ -1,48 +1,36 @@
|
||||
/* radare - LGPL - Copyright 2014-2018 condret, pancake */
|
||||
|
||||
#include <r_asm.h>
|
||||
#include <r_types.h>
|
||||
#include <r_lib.h>
|
||||
#include <string.h>
|
||||
|
||||
static int mal_dis(RAsmOp *op, ut64 c, const ut8 *buf, ut64 len) {
|
||||
if(len) {
|
||||
switch ((buf[0]+c)%94) {
|
||||
case 4:
|
||||
sprintf(op->buf_asm, "jmp [d]");
|
||||
break;
|
||||
case 5:
|
||||
sprintf(op->buf_asm, "out a");
|
||||
break;
|
||||
case 23:
|
||||
sprintf(op->buf_asm, "in a");
|
||||
break;
|
||||
case 39:
|
||||
sprintf(op->buf_asm, "rotr [d], mov a, [d]");
|
||||
break;
|
||||
case 40:
|
||||
sprintf(op->buf_asm, "mov d, [d]");
|
||||
break;
|
||||
case 62:
|
||||
sprintf(op->buf_asm, "crz [d], a, mov a, [d]");
|
||||
break;
|
||||
case 81:
|
||||
sprintf(op->buf_asm, "end");
|
||||
break;
|
||||
default:
|
||||
sprintf(op->buf_asm, "nop");
|
||||
static const char *mal_dis(ut64 c, const ut8 *buf, ut64 len) {
|
||||
if (len) {
|
||||
switch ((buf[0] + c) % 94) {
|
||||
case 4: return "jmp [d]";
|
||||
case 5: return "out a";
|
||||
case 23: return "in a";
|
||||
case 39: return "rotr [d], mov a, [d]";
|
||||
case 40: return "mov d, [d]";
|
||||
case 62: return "crz [d], a, mov a, [d]";
|
||||
case 81: return "end";
|
||||
default: return "nop";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int __disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
return op->size = mal_dis(op, a->pc, buf, len);
|
||||
const char *opstr = mal_dis (a->pc, buf, len);
|
||||
return op->size = opstr? 1: 0;
|
||||
}
|
||||
|
||||
RAsmPlugin r_asm_plugin_malbolge = {
|
||||
.name = "malbolge",
|
||||
.desc = "Malbolge Ternary VM",
|
||||
.arch = "malbolge",
|
||||
.author = "condret",
|
||||
.license = "LGPL3",
|
||||
.bits = 32,
|
||||
.endian = R_SYS_ENDIAN_NONE,
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyrigth - 2015 - condret */
|
||||
/* radare - LGPL - Copyrigth - 2015-2018 - condret */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <string.h>
|
||||
@ -7,23 +7,19 @@
|
||||
#include "../arch/mcs96/mcs96.h"
|
||||
|
||||
static int mcs96_len (const ut8 buf) {
|
||||
if (mcs96_op[buf].type & MCS96_6B)
|
||||
return 6;
|
||||
if (mcs96_op[buf].type & MCS96_5B)
|
||||
return 5;
|
||||
if (mcs96_op[buf].type & MCS96_4B)
|
||||
return 4;
|
||||
if (mcs96_op[buf].type & MCS96_3B)
|
||||
return 3;
|
||||
if (mcs96_op[buf].type & MCS96_2B)
|
||||
return 2;
|
||||
if (mcs96_op[buf].type & MCS96_6B) return 6;
|
||||
if (mcs96_op[buf].type & MCS96_5B) return 5;
|
||||
if (mcs96_op[buf].type & MCS96_4B) return 4;
|
||||
if (mcs96_op[buf].type & MCS96_3B) return 3;
|
||||
if (mcs96_op[buf].type & MCS96_2B) return 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
if (len>1 && !memcmp (buf, "\xff\xff", 2))
|
||||
if (len > 1 && !memcmp (buf, "\xff\xff", 2)) {
|
||||
return -1;
|
||||
strncpy (op->buf_asm, mcs96_op[buf[0]].ins, sizeof (op->buf_asm)-1);
|
||||
}
|
||||
r_strbuf_set (&op->buf_asm, mcs96_op[buf[0]].ins);
|
||||
op->size = mcs96_len (buf[0]);
|
||||
return op->size;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare2 - LGPL - Copyright 2013-2017 - pancake */
|
||||
/* radare2 - LGPL - Copyright 2013-2018 - pancake */
|
||||
|
||||
#include <r_asm.h>
|
||||
#include <r_lib.h>
|
||||
@ -47,7 +47,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
cs_option (cd, CS_OPT_DETAIL, CS_OPT_OFF);
|
||||
n = cs_disasm (cd, (ut8*)buf, len, a->pc, 1, &insn);
|
||||
if (n < 1) {
|
||||
strcpy (op->buf_asm, "invalid");
|
||||
r_asm_op_set_asm (op, "invalid");
|
||||
op->size = 4;
|
||||
goto beach;
|
||||
} else {
|
||||
@ -57,11 +57,13 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
goto beach;
|
||||
}
|
||||
op->size = insn->size;
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s%s%s",
|
||||
insn->mnemonic, insn->op_str[0]? " ": "",
|
||||
insn->op_str);
|
||||
// remove the '$'<registername> in the string
|
||||
r_str_replace_char (op->buf_asm, '$', 0);
|
||||
char *str = r_str_newf ("%s%s%s", insn->mnemonic, insn->op_str[0]? " ": "", insn->op_str);
|
||||
if (str) {
|
||||
r_str_replace_char (str, '$', 0);
|
||||
// remove the '$'<registername> in the string
|
||||
r_asm_op_set_asm (op, str);
|
||||
free (str);
|
||||
}
|
||||
cs_free (insn, n);
|
||||
beach:
|
||||
// cs_close (&cd);
|
||||
@ -70,14 +72,16 @@ fin:
|
||||
}
|
||||
|
||||
static int assemble(RAsm *a, RAsmOp *op, const char *str) {
|
||||
int ret = mips_assemble (str, a->pc, op->buf);
|
||||
ut8 *opbuf = (ut8*)r_strbuf_get (&op->buf);
|
||||
int ret = mips_assemble (str, a->pc, opbuf);
|
||||
if (a->big_endian) {
|
||||
ut8 tmp = op->buf[0];
|
||||
op->buf[0] = op->buf[3];
|
||||
op->buf[3] = tmp;
|
||||
tmp = op->buf[1];
|
||||
op->buf[1] = op->buf[2];
|
||||
op->buf[2] = tmp;
|
||||
ut8 *buf = opbuf;
|
||||
ut8 tmp = buf[0];
|
||||
buf[0] = buf[3];
|
||||
buf[3] = tmp;
|
||||
tmp = buf[1];
|
||||
buf[1] = buf[2];
|
||||
buf[2] = tmp;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2014 - pancake, nibble */
|
||||
/* radare - LGPL - Copyright 2009-2018 - pancake, nibble */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
@ -33,8 +33,9 @@ static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_in
|
||||
|
||||
static void print_address(bfd_vma address, struct disassemble_info *info) {
|
||||
char tmp[32];
|
||||
if (!buf_global)
|
||||
if (!buf_global) {
|
||||
return;
|
||||
}
|
||||
sprintf (tmp, "0x%08"PFMT64x, (ut64)address);
|
||||
strcat (buf_global, tmp);
|
||||
}
|
||||
@ -59,8 +60,10 @@ static int buf_fprintf(void *stream, const char *format, ...) {
|
||||
|
||||
static int disassemble(struct r_asm_t *a, struct r_asm_op_t *op, const ut8 *buf, int len) {
|
||||
static struct disassemble_info disasm_obj;
|
||||
if (len<4) return -1;
|
||||
buf_global = op->buf_asm;
|
||||
if (len < 4) {
|
||||
return -1;
|
||||
}
|
||||
buf_global = r_strbuf_get (&op->buf_asm);
|
||||
Offset = a->pc;
|
||||
memcpy (bytes, buf, 4); // TODO handle thumb
|
||||
|
||||
@ -79,26 +82,25 @@ static int disassemble(struct r_asm_t *a, struct r_asm_op_t *op, const ut8 *buf,
|
||||
disasm_obj.fprintf_func = &buf_fprintf;
|
||||
disasm_obj.stream = stdout;
|
||||
|
||||
op->buf_asm[0] = '\0';
|
||||
if (disasm_obj.endian == BFD_ENDIAN_LITTLE) {
|
||||
op->size = print_insn_little_mips ((bfd_vma)Offset, &disasm_obj);
|
||||
} else {
|
||||
op->size = print_insn_big_mips ((bfd_vma)Offset, &disasm_obj);
|
||||
op->size = (disasm_obj.endian == BFD_ENDIAN_LITTLE)
|
||||
? print_insn_little_mips ((bfd_vma)Offset, &disasm_obj)
|
||||
: print_insn_big_mips ((bfd_vma)Offset, &disasm_obj);
|
||||
if (op->size == -1) {
|
||||
r_strbuf_set (&op->buf_asm, "(data)");
|
||||
}
|
||||
if (op->size == -1)
|
||||
strncpy (op->buf_asm, " (data)", R_ASM_BUFSIZE);
|
||||
return op->size;
|
||||
}
|
||||
|
||||
static int assemble(RAsm *a, RAsmOp *op, const char *str) {
|
||||
int ret = mips_assemble (str, a->pc, op->buf);
|
||||
ut8 *opbuf = (ut8*)r_strbuf_get (&op->buf);
|
||||
int ret = mips_assemble (str, a->pc, opbuf);
|
||||
if (a->big_endian) {
|
||||
ut8 tmp = op->buf[0];
|
||||
op->buf[0] = op->buf[3];
|
||||
op->buf[3] = tmp;
|
||||
tmp = op->buf[1];
|
||||
op->buf[1] = op->buf[2];
|
||||
op->buf[2] = tmp;
|
||||
ut8 tmp = opbuf[0];
|
||||
opbuf[0] = opbuf[3];
|
||||
opbuf[3] = tmp;
|
||||
tmp = opbuf[1];
|
||||
opbuf[1] = opbuf[2];
|
||||
opbuf[2] = tmp;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -107,7 +109,7 @@ RAsmPlugin r_asm_plugin_mips_gnu = {
|
||||
.name = "mips.gnu",
|
||||
.arch = "mips",
|
||||
.license = "GPL3",
|
||||
.bits = 32|64,
|
||||
.bits = 32 | 64,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG,
|
||||
.desc = "MIPS CPU",
|
||||
.disassemble = &disassemble,
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* radare - LGPL - Copyright 2014-2015 - fedor.sakharov */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <r_types.h>
|
||||
@ -11,9 +13,9 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
int ret = msp430_decode_command (buf, len, &cmd);
|
||||
if (ret > 0) {
|
||||
if (cmd.operands[0]) {
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s %s", cmd.instr, cmd.operands);
|
||||
r_strbuf_set (&op->buf_asm, sdb_fmt ("%s %s", cmd.instr, cmd.operands));
|
||||
} else {
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s", cmd.instr);
|
||||
r_strbuf_set (&op->buf_asm, sdb_fmt ("%s", cmd.instr));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare2 - LGPL - Copyright 2014 - pancake */
|
||||
/* radare2 - LGPL - Copyright 2014-2018 - pancake */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
@ -32,27 +32,30 @@ static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_in
|
||||
}
|
||||
|
||||
static void print_address(bfd_vma address, struct disassemble_info *info) {
|
||||
char tmp[32];
|
||||
if (!buf_global)
|
||||
return;
|
||||
sprintf(tmp, "0x%08"PFMT64x"", (ut64)address);
|
||||
strcat(buf_global, tmp);
|
||||
if (buf_global) {
|
||||
char tmp[32];
|
||||
snprintf (tmp, sizeof (tmp), "0x%08"PFMT64x"", (ut64)address);
|
||||
strcat (buf_global, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
static int buf_fprintf(void *stream, const char *format, ...) {
|
||||
int flen, glen;
|
||||
va_list ap;
|
||||
char *tmp;
|
||||
if (!buf_global)
|
||||
if (!buf_global) {
|
||||
return 0;
|
||||
}
|
||||
va_start (ap, format);
|
||||
flen = strlen (format);
|
||||
glen = strlen (buf_global);
|
||||
tmp = malloc (flen + glen + 2);
|
||||
if (!tmp) return 0;
|
||||
if (!tmp) {
|
||||
return 0;
|
||||
}
|
||||
memcpy (tmp, buf_global, glen);
|
||||
memcpy (tmp+glen, format, flen);
|
||||
tmp[flen+glen] = 0;
|
||||
tmp[flen + glen] = 0;
|
||||
// XXX: overflow here?
|
||||
vsprintf (buf_global, tmp, ap);
|
||||
va_end (ap);
|
||||
@ -62,9 +65,10 @@ static int buf_fprintf(void *stream, const char *format, ...) {
|
||||
|
||||
static int disassemble(RAsm *a, struct r_asm_op_t *op, const ut8 *buf, int len) {
|
||||
struct disassemble_info disasm_obj;
|
||||
if (len<4)
|
||||
if (len < 4) {
|
||||
return -1;
|
||||
buf_global = op->buf_asm;
|
||||
}
|
||||
buf_global = r_strbuf_get (&op->buf_asm);
|
||||
Offset = a->pc;
|
||||
memcpy (bytes, buf, 4); // TODO handle thumb
|
||||
|
||||
@ -80,14 +84,14 @@ static int disassemble(RAsm *a, struct r_asm_op_t *op, const ut8 *buf, int len)
|
||||
disasm_obj.fprintf_func = &buf_fprintf;
|
||||
disasm_obj.stream = stdout;
|
||||
|
||||
op->buf_asm[0]='\0';
|
||||
if (disasm_obj.endian == BFD_ENDIAN_BIG)
|
||||
if (disasm_obj.endian == BFD_ENDIAN_BIG) {
|
||||
op->size = print_insn_big_nios2 ((bfd_vma)Offset, &disasm_obj);
|
||||
else op->size = print_insn_little_nios2 ((bfd_vma)Offset, &disasm_obj);
|
||||
|
||||
if (op->size == -1)
|
||||
strncpy (op->buf_asm, " (data)", R_ASM_BUFSIZE);
|
||||
|
||||
} else {
|
||||
op->size = print_insn_little_nios2 ((bfd_vma)Offset, &disasm_obj);
|
||||
}
|
||||
if (op->size == -1) {
|
||||
r_asm_op_set_asm (op, "(data)");
|
||||
}
|
||||
return op->size;
|
||||
}
|
||||
|
||||
|
@ -8,18 +8,19 @@
|
||||
#include "../arch/pic/pic_midrange.h"
|
||||
|
||||
static int asm_pic_disassemble(RAsm *a, RAsmOp *op, const ut8 *b, int l) {
|
||||
int res = -1;
|
||||
char opbuf[128];
|
||||
const char *opstr = opbuf;
|
||||
strcpy (opbuf, "invalid");
|
||||
if (a->cpu && strcasecmp (a->cpu, "baseline") == 0) {
|
||||
return pic_baseline_disassemble (a, op, b, l);
|
||||
res = pic_baseline_disassemble (op, opbuf, b, l);
|
||||
} else if (a->cpu && strcasecmp (a->cpu, "midrange") == 0) {
|
||||
res = pic_midrange_disassemble (op, opbuf, b, l);
|
||||
} else if (a->cpu && strcasecmp (a->cpu, "pic18") == 0) {
|
||||
res = pic_pic18_disassemble (op, opbuf, b, l);
|
||||
}
|
||||
if (a->cpu && strcasecmp (a->cpu, "midrange") == 0) {
|
||||
return pic_midrange_disassemble (a, op, b, l);
|
||||
}
|
||||
if (a->cpu && strcasecmp (a->cpu, "pic18") == 0) {
|
||||
return pic_pic18_disassemble (a, op, b, l);
|
||||
}
|
||||
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE - 1, "Unknown asm.cpu");
|
||||
return op->size = -1;
|
||||
r_asm_op_set_asm (op, opstr);
|
||||
return op->size = res;
|
||||
}
|
||||
|
||||
RAsmPlugin r_asm_plugin_pic = {
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare2 - LGPL - Copyright 2014-2015 - pancake */
|
||||
/* radare2 - LGPL - Copyright 2014-2018 - pancake */
|
||||
|
||||
#include <r_asm.h>
|
||||
#include <r_lib.h>
|
||||
@ -24,10 +24,12 @@ static int decompile_vle(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
}
|
||||
if (!vle_init (&handle, buf, len) && (instr = vle_next (&handle))) {
|
||||
op->size = instr->size;
|
||||
vle_snprint (op->buf_asm, R_ASM_BUFSIZE, a->pc, instr);
|
||||
char buf_asm[64];
|
||||
vle_snprint (buf_asm, sizeof (buf_asm), a->pc, instr);
|
||||
r_asm_op_set_asm (op, buf_asm);
|
||||
vle_free (instr);
|
||||
} else {
|
||||
strcpy (op->buf_asm, "invalid");
|
||||
r_asm_op_set_asm (op, "invalid");
|
||||
op->size = 2;
|
||||
return -1;
|
||||
}
|
||||
@ -41,12 +43,13 @@ static int decompile_ps(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
}
|
||||
op->size = 4;
|
||||
const ut32 data = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
|
||||
if (libps_decode (data, &instr)) {
|
||||
libps_snprint (op->buf_asm, R_ASM_BUFSIZE, a->pc, &instr);
|
||||
} else {
|
||||
strcpy (op->buf_asm, "invalid");
|
||||
if (libps_decode (data, &instr) < 1) {
|
||||
r_asm_op_set_asm (op, "invalid");
|
||||
return -1;
|
||||
}
|
||||
char buf_asm[64];
|
||||
libps_snprint (buf_asm, sizeof (buf_asm), a->pc, &instr);
|
||||
r_asm_op_set_asm (op, buf_asm);
|
||||
return op->size;
|
||||
}
|
||||
|
||||
@ -90,15 +93,12 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
}
|
||||
}
|
||||
op->size = 4;
|
||||
op->buf_asm[0] = 0;
|
||||
cs_option (handle, CS_OPT_DETAIL, CS_OPT_OFF);
|
||||
|
||||
n = cs_disasm (handle, (const ut8*) buf, len, off, 1, &insn);
|
||||
op->size = 4;
|
||||
if (n > 0 && insn->size > 0) {
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s%s%s",
|
||||
insn->mnemonic, insn->op_str[0] ? " " : "",
|
||||
insn->op_str);
|
||||
const char *opstr = sdb_fmt ("%s%s%s", insn->mnemonic, insn->op_str[0] ? " " : "", insn->op_str);
|
||||
r_asm_op_set_asm (op, opstr);
|
||||
cs_free (insn, n);
|
||||
return op->size;
|
||||
}
|
||||
@ -111,6 +111,7 @@ RAsmPlugin r_asm_plugin_ppc_cs = {
|
||||
.name = "ppc",
|
||||
.desc = "Capstone PowerPC disassembler",
|
||||
.license = "BSD",
|
||||
.author = "pancake",
|
||||
.arch = "ppc",
|
||||
.cpus = "ppc,vle,ps",
|
||||
.bits = 32 | 64,
|
||||
|
@ -31,10 +31,10 @@ static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_in
|
||||
|
||||
static void print_address(bfd_vma address, struct disassemble_info *info) {
|
||||
char tmp[32];
|
||||
if (!buf_global)
|
||||
return;
|
||||
sprintf(tmp, "0x%08"PFMT64x"", (ut64)address);
|
||||
strcat(buf_global, tmp);
|
||||
if (buf_global) {
|
||||
sprintf (tmp, "0x%08"PFMT64x"", (ut64)address);
|
||||
strcat (buf_global, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
static int buf_fprintf(void *stream, const char *format, ...) {
|
||||
@ -60,16 +60,16 @@ static int buf_fprintf(void *stream, const char *format, ...) {
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
struct disassemble_info disasm_obj;
|
||||
op->buf_asm[0]='\0';
|
||||
if (len<4)
|
||||
if (len<4) {
|
||||
return -1;
|
||||
buf_global = op->buf_asm;
|
||||
}
|
||||
buf_global = r_strbuf_get (&op->buf_asm);
|
||||
Offset = a->pc;
|
||||
memcpy (bytes, buf, 4); // TODO handle thumb
|
||||
|
||||
/* prepare disassembler */
|
||||
memset (&disasm_obj, '\0', sizeof (struct disassemble_info));
|
||||
disasm_obj.disassembler_options=(a->bits==64)?"64":"";
|
||||
disasm_obj.disassembler_options = (a->bits==64)?"64":"";
|
||||
disasm_obj.buffer = bytes;
|
||||
disasm_obj.read_memory_func = &ppc_buffer_read_memory;
|
||||
disasm_obj.symbol_at_address_func = &symbol_at_address;
|
||||
@ -78,14 +78,14 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
disasm_obj.endian = !a->big_endian;
|
||||
disasm_obj.fprintf_func = &buf_fprintf;
|
||||
disasm_obj.stream = stdout;
|
||||
|
||||
if (a->big_endian)
|
||||
if (a->big_endian) {
|
||||
op->size = print_insn_big_powerpc ((bfd_vma)Offset, &disasm_obj);
|
||||
else op->size = print_insn_little_powerpc ((bfd_vma)Offset, &disasm_obj);
|
||||
|
||||
if (op->size == -1)
|
||||
strncpy (op->buf_asm, " (data)", R_ASM_BUFSIZE);
|
||||
|
||||
} else {
|
||||
op->size = print_insn_little_powerpc ((bfd_vma)Offset, &disasm_obj);
|
||||
}
|
||||
if (op->size == -1) {
|
||||
r_asm_op_set_asm (op, "(data)");
|
||||
}
|
||||
return op->size;
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* radare - LGPL - Copyright 2014 - fedor.sakharov */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <r_types.h>
|
||||
@ -6,23 +8,19 @@
|
||||
|
||||
#include <propeller_disas.h>
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len)
|
||||
{
|
||||
int ret;
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
const char *buf_asm;
|
||||
struct propeller_cmd cmd;
|
||||
|
||||
ret = propeller_decode_command (buf, &cmd);
|
||||
|
||||
int ret = propeller_decode_command (buf, &cmd);
|
||||
if (cmd.prefix[0] && cmd.operands[0]) {
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s %s %s", cmd.prefix, cmd.instr, cmd.operands);
|
||||
buf_asm = sdb_fmt ("%s %s %s", cmd.prefix, cmd.instr, cmd.operands);
|
||||
} else if (cmd.operands[0]) {
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s %s", cmd.instr, cmd.operands);
|
||||
buf_asm = sdb_fmt ("%s %s", cmd.instr, cmd.operands);
|
||||
} else {
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s", cmd.instr);
|
||||
buf_asm = sdb_fmt ("%s", cmd.instr);
|
||||
}
|
||||
|
||||
r_asm_op_set_asm (op, buf_asm);
|
||||
op->size = 4;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,6 @@ static void snappendf(char** dst, size_t* size, const char* format, ...) {
|
||||
}
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
ut32 iw;
|
||||
rsp_instruction r_instr;
|
||||
int i;
|
||||
char* buffer;
|
||||
@ -39,10 +38,10 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
}
|
||||
op->size = 4;
|
||||
|
||||
iw = r_read_ble32 (buf, a->big_endian);
|
||||
ut32 iw = r_read_ble32 (buf, a->big_endian);
|
||||
r_instr = rsp_instruction_decode (a->pc, iw);
|
||||
|
||||
buffer = op->buf_asm;
|
||||
buffer = r_strbuf_get (&op->buf_asm);
|
||||
size = sizeof (op->buf_asm);
|
||||
|
||||
snappendf (&buffer, &size, r_instr.mnemonic);
|
||||
|
@ -57,8 +57,10 @@ static int buf_fprintf(void *stream, const char *format, ...) {
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
static struct disassemble_info disasm_obj;
|
||||
if (len<2) return -1;
|
||||
buf_global = op->buf_asm;
|
||||
if (len < 2) {
|
||||
return -1;
|
||||
}
|
||||
buf_global = r_strbuf_get (&op->buf_asm);
|
||||
Offset = a->pc;
|
||||
memcpy (bytes, buf, 2);
|
||||
|
||||
@ -73,14 +75,14 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
disasm_obj.fprintf_func = &buf_fprintf;
|
||||
disasm_obj.stream = stdout;
|
||||
|
||||
op->buf_asm[0] = '\0';
|
||||
if (disasm_obj.endian == BFD_ENDIAN_BIG)
|
||||
if (disasm_obj.endian == BFD_ENDIAN_BIG) {
|
||||
op->size = print_insn_shb ((bfd_vma)Offset, &disasm_obj);
|
||||
else
|
||||
} else {
|
||||
op->size = print_insn_shl ((bfd_vma)Offset, &disasm_obj);
|
||||
|
||||
if (op->size == -1)
|
||||
strncpy (op->buf_asm, " (data)", R_ASM_BUFSIZE);
|
||||
}
|
||||
if (op->size == -1) {
|
||||
r_asm_op_set_asm (op, "(data)");
|
||||
}
|
||||
return op->size;
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
n = cs_disasm (cd, buf, len, a->pc, 1, &insn);
|
||||
}
|
||||
if (n < 1) {
|
||||
strcpy (op->buf_asm, "invalid");
|
||||
r_asm_op_set_asm (op, "invalid");
|
||||
op->size = 4;
|
||||
ret = -1;
|
||||
goto beach;
|
||||
@ -45,10 +45,11 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
goto beach;
|
||||
}
|
||||
op->size = insn->size;
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s%s%s",
|
||||
char *buf_asm = sdb_fmt ("%s%s%s",
|
||||
insn->mnemonic, insn->op_str[0]? " ": "",
|
||||
insn->op_str);
|
||||
r_str_replace_char (op->buf_asm, '%', 0);
|
||||
r_str_replace_char (buf_asm, '%', 0);
|
||||
r_asm_op_set_asm (op, buf_asm);
|
||||
// TODO: remove the '$'<registername> in the string
|
||||
cs_free (insn, n);
|
||||
beach:
|
||||
|
@ -38,11 +38,11 @@ static void print_address(bfd_vma address, struct disassemble_info *info) {
|
||||
static int buf_fprintf(void *stream, const char *format, ...) {
|
||||
va_list ap;
|
||||
char tmp[1024];
|
||||
if (!buf_global)
|
||||
return 0;
|
||||
va_start (ap, format);
|
||||
vsnprintf (tmp, sizeof (tmp), format, ap);
|
||||
strcat (buf_global, tmp);
|
||||
if (buf_global) {
|
||||
vsnprintf (tmp, sizeof (tmp), format, ap);
|
||||
strcat (buf_global, tmp);
|
||||
}
|
||||
va_end (ap);
|
||||
return 0;
|
||||
}
|
||||
@ -52,7 +52,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
if (len < 4) {
|
||||
return -1;
|
||||
}
|
||||
buf_global = op->buf_asm;
|
||||
buf_global = r_strbuf_get (&op->buf_asm);
|
||||
Offset = a->pc;
|
||||
// disasm inverted
|
||||
r_mem_swapendian (bytes, buf, 4); // TODO handle thumb
|
||||
@ -71,15 +71,13 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
? bfd_mach_sparc_v9b
|
||||
: 0);
|
||||
|
||||
op->buf_asm[0] = '\0';
|
||||
op->size = print_insn_sparc ((bfd_vma)Offset, &disasm_obj);
|
||||
|
||||
if (!strncmp (op->buf_asm, "unknown", 7)) {
|
||||
strncpy (op->buf_asm, "invalid", R_ASM_BUFSIZE);
|
||||
if (!strncmp (r_strbuf_get (&op->buf_asm), "unknown", 7)) {
|
||||
r_asm_op_set_asm (op, "invalid");
|
||||
}
|
||||
|
||||
if (op->size == -1) {
|
||||
strncpy (op->buf_asm, " (data)", R_ASM_BUFSIZE);
|
||||
r_asm_op_set_asm (op, "(data)");
|
||||
}
|
||||
return op->size;
|
||||
}
|
||||
|
@ -30,21 +30,23 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
omode = mode;
|
||||
if (cd == 0) {
|
||||
ret = cs_open (CS_ARCH_SYSZ, mode, &cd);
|
||||
if (ret) return 0;
|
||||
if (ret) {
|
||||
return 0;
|
||||
}
|
||||
cs_option (cd, CS_OPT_DETAIL, CS_OPT_OFF);
|
||||
}
|
||||
n = cs_disasm (cd, (const ut8*)buf, len, off, 1, &insn);
|
||||
if (n>0) {
|
||||
if (insn->size>0) {
|
||||
op->size = insn->size;
|
||||
char *ptrstr;
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s%s%s",
|
||||
insn->mnemonic, insn->op_str[0]?" ":"",
|
||||
char *buf_asm = sdb_fmt ("%s%s%s",
|
||||
insn->mnemonic, insn->op_str[0]?" ": "",
|
||||
insn->op_str);
|
||||
ptrstr = strstr (op->buf_asm, "ptr ");
|
||||
char *ptrstr = strstr (buf_asm, "ptr ");
|
||||
if (ptrstr) {
|
||||
memmove (ptrstr, ptrstr+4, strlen (ptrstr+4)+1);
|
||||
memmove (ptrstr, ptrstr + 4, strlen (ptrstr + 4) + 1);
|
||||
}
|
||||
r_asm_op_set_asm (op, buf_asm);
|
||||
}
|
||||
cs_free (insn, n);
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ static int tms320c64x_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len)
|
||||
}
|
||||
n = cs_disasm (cd, buf, len, a->pc, 1, &insn);
|
||||
if (n < 1) {
|
||||
strcpy (op->buf_asm, "invalid");
|
||||
r_asm_op_set_asm (op, "invalid");
|
||||
op->size = 4;
|
||||
ret = -1;
|
||||
goto beach;
|
||||
@ -56,11 +56,10 @@ static int tms320c64x_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len)
|
||||
goto beach;
|
||||
}
|
||||
op->size = insn->size;
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s%s%s",
|
||||
insn->mnemonic, insn->op_str[0]? " ": "",
|
||||
insn->op_str);
|
||||
r_str_replace_char (op->buf_asm, '%', 0);
|
||||
r_str_case (op->buf_asm, false);
|
||||
char *buf_asm = sdb_fmt ("%s%s%s", insn->mnemonic, insn->op_str[0]? " ": "", insn->op_str);
|
||||
r_str_replace_char (buf_asm, '%', 0);
|
||||
r_str_case (buf_asm, false);
|
||||
r_asm_op_set_asm (op, buf_asm);
|
||||
cs_free (insn, n);
|
||||
beach:
|
||||
// cs_close (&cd);
|
||||
@ -86,12 +85,11 @@ static int tms320_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
return tms320c64x_disassemble (a, op, buf, len);
|
||||
}
|
||||
#endif
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE - 1, "Unknown asm.cpu");
|
||||
r_asm_op_set_asm (op, "unknown asm.cpu");
|
||||
return op->size = -1;
|
||||
}
|
||||
op->size = tms320_dasm (&engine, buf, len);
|
||||
strncpy (op->buf_asm, engine.syntax, R_ASM_BUFSIZE - 1);
|
||||
op->buf_asm[R_ASM_BUFSIZE - 1] = 0;
|
||||
r_asm_op_set_asm (op, engine.syntax);
|
||||
return op->size;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare2 - LGPL - Copyright 2017 - pancake */
|
||||
/* radare2 - LGPL - Copyright 2017-2018 - pancake */
|
||||
|
||||
#include <r_asm.h>
|
||||
#include <r_lib.h>
|
||||
@ -36,7 +36,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
}
|
||||
n = cs_disasm (cd, buf, len, a->pc, 1, &insn);
|
||||
if (n < 1) {
|
||||
strcpy (op->buf_asm, "invalid");
|
||||
r_asm_op_set_asm (op, "invalid");
|
||||
op->size = 4;
|
||||
ret = -1;
|
||||
goto beach;
|
||||
@ -47,11 +47,11 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
goto beach;
|
||||
}
|
||||
op->size = insn->size;
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s%s%s",
|
||||
r_asm_op_set_asm (op, sdb_fmt ("%s%s%s",
|
||||
insn->mnemonic, insn->op_str[0]? " ": "",
|
||||
insn->op_str);
|
||||
r_str_replace_char (op->buf_asm, '%', 0);
|
||||
r_str_case (op->buf_asm, false);
|
||||
insn->op_str));
|
||||
r_str_replace_char (r_strbuf_get (&op->buf_asm), '%', 0);
|
||||
r_str_case (r_strbuf_get (&op->buf_asm), false);
|
||||
cs_free (insn, n);
|
||||
beach:
|
||||
// cs_close (&cd);
|
||||
|
@ -94,7 +94,7 @@ static int buf_fprintf(void *stream, const char *format, ...) {
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
struct disassemble_info disasm_obj;
|
||||
buf_global = op->buf_asm;
|
||||
buf_global = r_strbuf_get (&op->buf_asm);
|
||||
Offset = a->pc;
|
||||
memcpy (bytes, buf, R_MIN (len, 8)); // TODO handle thumb
|
||||
|
||||
@ -113,9 +113,9 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
disasm_obj.mach = 2; // select CPU TYPE
|
||||
|
||||
op->size = print_insn_tricore ((bfd_vma)Offset, &disasm_obj);
|
||||
if (op->size == -1)
|
||||
strncpy (op->buf_asm, " (data)", R_ASM_BUFSIZE);
|
||||
|
||||
if (op->size == -1) {
|
||||
r_asm_op_set_asm (op, " (data)");
|
||||
}
|
||||
return op->size;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2012-2015 - pancake */
|
||||
/* radare - LGPL - Copyright 2012-2018 - pancake */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -13,11 +13,12 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
.instr = "",
|
||||
.operands = ""
|
||||
};
|
||||
if (len < 2) return -1;
|
||||
if (len < 2) {
|
||||
return -1;
|
||||
}
|
||||
int ret = v810_decode_command (buf, len, &cmd);
|
||||
if (ret > 0) {
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s %s",
|
||||
cmd.instr, cmd.operands);
|
||||
r_asm_op_set_asm (op, sdb_fmt ("%s %s", cmd.instr, cmd.operands));
|
||||
}
|
||||
return op->size = ret;
|
||||
}
|
||||
@ -26,6 +27,7 @@ RAsmPlugin r_asm_plugin_v810 = {
|
||||
.name = "v810",
|
||||
.license = "LGPL3",
|
||||
.desc = "v810 disassembly plugin",
|
||||
.author = "pancake",
|
||||
.arch = "v810",
|
||||
.bits = 32,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
|
@ -19,8 +19,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
}
|
||||
int ret = v850_decode_command (buf, len, &cmd);
|
||||
if (ret > 0) {
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s %s",
|
||||
cmd.instr, cmd.operands);
|
||||
r_asm_op_set_asm (op, sdb_fmt ("%s %s", cmd.instr, cmd.operands));
|
||||
}
|
||||
return op->size = ret;
|
||||
}
|
||||
|
@ -50,8 +50,9 @@ static int buf_fprintf(void *stream, const char *format, ...) {
|
||||
int flen, glen;
|
||||
va_list ap;
|
||||
char *tmp;
|
||||
if (!buf_global)
|
||||
if (!buf_global) {
|
||||
return 0;
|
||||
}
|
||||
va_start (ap, format);
|
||||
flen = strlen (format);
|
||||
glen = strlen (buf_global);
|
||||
@ -69,10 +70,10 @@ static int buf_fprintf(void *stream, const char *format, ...) {
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
struct disassemble_info disasm_obj;
|
||||
op->buf_asm[0]='\0';
|
||||
if (len<4)
|
||||
if (len < 4) {
|
||||
return -1;
|
||||
buf_global = op->buf_asm;
|
||||
}
|
||||
buf_global = r_strbuf_get (&op->buf_asm);
|
||||
bytes = buf;
|
||||
bytes_size = len;
|
||||
Offset = a->pc;
|
||||
@ -87,11 +88,11 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
disasm_obj.endian = BFD_ENDIAN_LITTLE;
|
||||
disasm_obj.fprintf_func = &buf_fprintf;
|
||||
disasm_obj.stream = stdout;
|
||||
|
||||
op->size = print_insn_vax ((bfd_vma)Offset, &disasm_obj);
|
||||
|
||||
if (op->size == -1)
|
||||
strncpy (op->buf_asm, " (data)", R_ASM_BUFSIZE);
|
||||
if (op->size == -1) {
|
||||
r_asm_op_set_asm (op, "(data)");
|
||||
}
|
||||
return op->size;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2017 - pancake, cgvwzq */
|
||||
/* radare - LGPL - Copyright 2017-2018 - pancake, cgvwzq */
|
||||
|
||||
// http://webassembly.org/docs/binary-encoding/#module-structure
|
||||
|
||||
@ -13,14 +13,14 @@
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
WasmOp wop = {0};
|
||||
int ret = wasm_dis (&wop, buf, len);
|
||||
strncpy (op->buf_asm, wop.txt, sizeof (op->buf_asm));
|
||||
op->buf_asm[sizeof (op->buf_asm) - 1] = 0;
|
||||
r_asm_op_set_asm (op, wop.txt);
|
||||
op->size = ret;
|
||||
return op->size;
|
||||
}
|
||||
|
||||
static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
|
||||
op->size = wasm_asm (buf, op->buf, sizeof (op->buf));
|
||||
ut8 *opbuf = (ut8*)r_strbuf_get (&op->buf);
|
||||
op->size = wasm_asm (buf, opbuf, 32); // XXX hardcoded opsize
|
||||
return op->size;
|
||||
}
|
||||
|
||||
|
@ -11,18 +11,19 @@
|
||||
|
||||
static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
|
||||
char *ipath, *opath;
|
||||
int ifd, ofd;
|
||||
const char *syntaxstr = "";
|
||||
char asm_buf[R_ASM_BUFSIZE];
|
||||
int len = 0;
|
||||
|
||||
ifd = r_file_mkstemp ("r_as", &ipath);
|
||||
if (ifd == -1)
|
||||
int ifd = r_file_mkstemp ("r_as", &ipath);
|
||||
if (ifd == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ofd = r_file_mkstemp ("r_as", &opath);
|
||||
int ofd = r_file_mkstemp ("r_as", &opath);
|
||||
if (ofd == -1) {
|
||||
free (ipath);
|
||||
close (ifd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -45,22 +46,27 @@ static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
|
||||
if (!r_sys_cmdf ("as %s -o %s", ipath, opath)) {
|
||||
const ut8 *begin, *end;
|
||||
close (ofd);
|
||||
ofd = open (opath, O_BINARY|O_RDONLY);
|
||||
// r_sys_cmdf ("cat %s", opath);
|
||||
ofd = r_sandbox_open (opath, O_BINARY|O_RDONLY, 0644);
|
||||
if (ofd < 0) {
|
||||
free (ipath);
|
||||
free (opath);
|
||||
return -1;
|
||||
}
|
||||
len = read (ofd, op->buf, R_ASM_BUFSIZE);
|
||||
begin = r_mem_mem (op->buf, len, (const ut8*)"BEGINMARK", 9);
|
||||
end = r_mem_mem (op->buf, len, (const ut8*)"ENDMARK", 7);
|
||||
ut8 opbuf[512] = {0};
|
||||
len = read (ofd, opbuf, sizeof (opbuf));
|
||||
begin = r_mem_mem (opbuf, len, (const ut8*)"BEGINMARK", 9);
|
||||
end = r_mem_mem (opbuf, len, (const ut8*)"ENDMARK", 7);
|
||||
if (!begin || !end) {
|
||||
eprintf ("Cannot find water marks\n");
|
||||
len = 0;
|
||||
} else {
|
||||
len = (int)(size_t)(end-begin-9);
|
||||
if (len>0) memcpy (op->buf, begin+9, len);
|
||||
else len = 0;
|
||||
len = (int)(size_t)(end - begin - 9);
|
||||
if (len > 0) {
|
||||
r_asm_op_set_buf (op, begin + 9, len);
|
||||
} else {
|
||||
len = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
eprintf ("Error running: as %s -o %s", ipath, opath);
|
||||
|
@ -100,27 +100,29 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
if (a->features && *a->features) {
|
||||
if (!check_features (a, insn)) {
|
||||
op->size = insn->size;
|
||||
strcpy (op->buf_asm, "illegal");
|
||||
r_asm_op_set_asm (op, "illegal");
|
||||
}
|
||||
}
|
||||
if (op->size == 0 && n > 0 && insn->size > 0) {
|
||||
char *ptrstr;
|
||||
op->size = insn->size;
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s%s%s",
|
||||
char *buf_asm = sdb_fmt ("%s%s%s",
|
||||
insn->mnemonic, insn->op_str[0]?" ":"",
|
||||
insn->op_str);
|
||||
ptrstr = strstr (op->buf_asm, "ptr ");
|
||||
ptrstr = strstr (buf_asm, "ptr ");
|
||||
if (ptrstr) {
|
||||
memmove (ptrstr, ptrstr + 4, strlen (ptrstr + 4) + 1);
|
||||
}
|
||||
r_asm_op_set_asm (op, buf_asm);
|
||||
} else {
|
||||
decompile_vm (a, op, buf, len);
|
||||
}
|
||||
if (a->syntax == R_ASM_SYNTAX_JZ) {
|
||||
if (!strncmp (op->buf_asm, "je ", 3)) {
|
||||
memcpy (op->buf_asm, "jz", 2);
|
||||
} else if (!strncmp (op->buf_asm, "jne ", 4)) {
|
||||
memcpy (op->buf_asm, "jnz", 3);
|
||||
char *buf_asm = r_strbuf_get (&op->buf_asm);
|
||||
if (!strncmp (buf_asm, "je ", 3)) {
|
||||
memcpy (buf_asm, "jz", 2);
|
||||
} else if (!strncmp (buf_asm, "jne ", 4)) {
|
||||
memcpy (buf_asm, "jnz", 3);
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
|
@ -31,8 +31,10 @@ static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
|
||||
|
||||
close (ifd);
|
||||
|
||||
if ( !r_sys_cmdf ("nasm %s -o %s", ipath, opath)) {
|
||||
len = read (ofd, op->buf, R_ASM_BUFSIZE);
|
||||
if (!r_sys_cmdf ("nasm %s -o %s", ipath, opath)) {
|
||||
char buf[512]; // TODO: remove limits
|
||||
len = read (ofd, buf, sizeof (buf));
|
||||
r_asm_op_set_buf (op, buf, len);
|
||||
} else {
|
||||
eprintf ("Error running 'nasm'\n");
|
||||
len = 0;
|
||||
|
@ -4541,7 +4541,8 @@ static int oprep(RAsm *a, ut8 *data, const Opcode *op) {
|
||||
}
|
||||
|
||||
static int assemble(RAsm *a, RAsmOp *ao, const char *str) {
|
||||
ut8 *data = ao->buf;
|
||||
ut8 __data[32] = {0};
|
||||
ut8 *data = __data;
|
||||
char op[128];
|
||||
LookupTable *lt_ptr;
|
||||
int retval = -1;
|
||||
@ -4578,6 +4579,7 @@ static int assemble(RAsm *a, RAsmOp *ao, const char *str) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
r_asm_op_set_buf (ao, __data, retval);
|
||||
free (instr.mnemonic);
|
||||
return retval;
|
||||
}
|
||||
|
@ -28,86 +28,90 @@
|
||||
#define VPCEXT2(y,x) ((y)[2]==(x))
|
||||
|
||||
void decompile_vm(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
const char *buf_asm = "invalid";
|
||||
if (len > 3 && buf[0] == 0x0F && buf[1] == 0x3F && (VPCEXT2 (buf, 0x01) || VPCEXT2 (buf, 0x05) || VPCEXT2 (buf, 0x07) || VPCEXT2 (buf, 0x0D) || VPCEXT2 (buf, 0x10))) {
|
||||
if(a->syntax == R_ASM_SYNTAX_ATT) {
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "vpcext $0x%x, $0x%x", buf[3], buf[2]);
|
||||
if (a->syntax == R_ASM_SYNTAX_ATT) {
|
||||
buf_asm = sdb_fmt ("vpcext $0x%x, $0x%x", buf[3], buf[2]);
|
||||
} else {
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "vpcext %xh, %xh", buf[2], buf[3]);
|
||||
buf_asm = sdb_fmt ("vpcext %xh, %xh", buf[2], buf[3]);
|
||||
}
|
||||
op->size = 4;
|
||||
} else if (len > 4 && buf[0] == 0x0F && buf[1] == 0xC6 && buf[2] == 0x28 && buf[3] == 1 && buf[4] == 0) {
|
||||
/* 0F C6 28 01 00 vmcpuid */
|
||||
strcpy (op->buf_asm, "vmcpuid");
|
||||
buf_asm ="vmcpuid";
|
||||
op->size = 5;
|
||||
} else if (len > 4 && buf[0] == 0x0F && buf[1] == 0xC6 && buf[2] == 0x28 && buf[3] == 0x00 && buf[4] == 0x00) {
|
||||
/* 0F C6 28 00 00 vmgetinfo */
|
||||
strcpy (op->buf_asm, "vmgetinfo");
|
||||
buf_asm ="vmgetinfo";
|
||||
op->size = 5;
|
||||
} else if (len > 4 && buf[0] == 0x0F && buf[1] == 0xC6 && buf[2] == 0x28 && buf[3] == 0x00 && buf[4] == 0x01) {
|
||||
/* 0F C6 28 00 01 vmsetinfo */
|
||||
strcpy (op->buf_asm, "vmsetinfo");
|
||||
buf_asm ="vmsetinfo";
|
||||
op->size = 5;
|
||||
} else if (len > 4 && buf[0] == 0x0F && buf[1] == 0xC6 && buf[2] == 0x28 && buf[3] == 0x00 && buf[4] == 0x02) {
|
||||
/* 0F C6 28 00 02 vmdxdsbl */
|
||||
strcpy (op->buf_asm, "vmdxdsbl");
|
||||
buf_asm ="vmdxdsbl";
|
||||
op->size = 5;
|
||||
} else if (len > 4 && buf[0] == 0x0F && buf[1] == 0xC6 && buf[2] == 0x28 && buf[3] == 0x00 && buf[4] == 0x03) {
|
||||
/* 0F C6 28 00 03 vmdxenbl */
|
||||
strcpy (op->buf_asm, "vmdxenbl");
|
||||
buf_asm ="vmdxenbl";
|
||||
op->size = 5;
|
||||
} else if (len > 4 && buf[0] == 0x0F && buf[1] == 0xC6 && buf[2] == 0x28 && buf[3] == 0x01 && buf[4] == 0x00) {
|
||||
/* 0F C6 28 01 00 vmcpuid */
|
||||
strcpy (op->buf_asm, "vmcpuid");
|
||||
buf_asm ="vmcpuid";
|
||||
op->size = 5;
|
||||
} else if (len > 4 && buf[0] == 0x0F && buf[1] == 0xC6 && buf[2] == 0x28 && buf[3] == 0x01 && buf[4] == 0x01) {
|
||||
/* 0F C6 28 01 01 vmhlt */
|
||||
strcpy (op->buf_asm, "vmhlt");
|
||||
buf_asm ="vmhlt";
|
||||
op->size = 5;
|
||||
} else if (len > 4 && buf[0] == 0x0F && buf[1] == 0xC6 && buf[2] == 0x28 && buf[3] == 0x01 && buf[4] == 0x02) {
|
||||
/* 0F C6 28 01 02 vmsplaf */
|
||||
strcpy (op->buf_asm, "vmsplaf");
|
||||
buf_asm ="vmsplaf";
|
||||
op->size = 5;
|
||||
} else if (len > 4 && buf[0] == 0x0F && buf[1] == 0xC6 && buf[2] == 0x28 && buf[3] == 0x02 && buf[4] == 0x00) {
|
||||
/* 0F C6 28 02 00 vmpushfd */
|
||||
strcpy (op->buf_asm, "vmpushfd");
|
||||
buf_asm ="vmpushfd";
|
||||
op->size = 5;
|
||||
} else if (len > 4 && buf[0] == 0x0F && buf[1] == 0xC6 && buf[2] == 0x28 && buf[3] == 0x02 && buf[4] == 0x01) {
|
||||
/* 0F C6 28 02 01 vmpopfd */
|
||||
strcpy (op->buf_asm, "vmpopfd");
|
||||
buf_asm ="vmpopfd";
|
||||
op->size = 5;
|
||||
} else if (len > 4 && buf[0] == 0x0F && buf[1] == 0xC6 && buf[2] == 0x28 && buf[3] == 0x02 && buf[4] == 0x02) {
|
||||
/* 0F C6 28 02 02 vmcli */
|
||||
strcpy (op->buf_asm, "vmcli");
|
||||
buf_asm ="vmcli";
|
||||
op->size = 5;
|
||||
} else if (len > 4 && buf[0] == 0x0F && buf[1] == 0xC6 && buf[2] == 0x28 && buf[3] == 0x02 && buf[4] == 0x03) {
|
||||
/* 0F C6 28 02 03 vmsti */
|
||||
strcpy (op->buf_asm, "vmsti");
|
||||
buf_asm ="vmsti";
|
||||
op->size = 5;
|
||||
} else if (len > 4 && buf[0] == 0x0F && buf[1] == 0xC6 && buf[2] == 0x28 && buf[3] == 0x02 && buf[4] == 0x04) {
|
||||
/* 0F C6 28 02 04 vmiretd */
|
||||
strcpy (op->buf_asm, "vmiretd");
|
||||
buf_asm ="vmiretd";
|
||||
op->size = 5;
|
||||
} else if (len > 4 && buf[0] == 0x0F && buf[1] == 0xC6 && buf[2] == 0x28 && buf[3] == 0x03 && buf[4] == 0x00) {
|
||||
/* 0F C6 28 03 00 vmsgdt */
|
||||
strcpy (op->buf_asm, "vmsgdt");
|
||||
buf_asm ="vmsgdt";
|
||||
op->size = 5;
|
||||
} else if (len > 4 && buf[0] == 0x0F && buf[1] == 0xC6 && buf[2] == 0x28 && buf[3] == 0x03 && buf[4] == 0x01) {
|
||||
/* 0F C6 28 03 01 vmsidt */
|
||||
strcpy (op->buf_asm, "vmsidt");
|
||||
buf_asm ="vmsidt";
|
||||
op->size = 5;
|
||||
} else if (len > 4 && buf[0] == 0x0F && buf[1] == 0xC6 && buf[2] == 0x28 && buf[3] == 0x03 && buf[4] == 0x02) {
|
||||
/* 0F C6 28 03 02 vmsldt */
|
||||
strcpy (op->buf_asm, "vmsldt");
|
||||
buf_asm ="vmsldt";
|
||||
op->size = 5;
|
||||
} else if (len > 4 && buf[0] == 0x0F && buf[1] == 0xC6 && buf[2] == 0x28 && buf[3] == 0x03 && buf[4] == 0x03) {
|
||||
/* 0F C6 28 03 03 vmstr */
|
||||
strcpy (op->buf_asm, "vmstr");
|
||||
buf_asm ="vmstr";
|
||||
op->size = 5;
|
||||
} else if (len > 4 && buf[0] == 0x0F && buf[1] == 0xC6 && buf[2] == 0x28 && buf[3] == 0x04 && buf[4] == 0x00) {
|
||||
/* 0F C6 28 04 00 vmsdte */
|
||||
strcpy (op->buf_asm, "vmsdte");
|
||||
buf_asm ="vmsdte";
|
||||
op->size = 5;
|
||||
}
|
||||
if (buf_asm) {
|
||||
r_asm_op_set_asm (op, buf_asm);
|
||||
}
|
||||
}
|
||||
|
||||
#undef VPCEXT2
|
||||
|
@ -16,10 +16,12 @@ static int arch_xap_disasm(char *str, const unsigned char *buf, ut64 seek) {
|
||||
s->s_out = NULL;
|
||||
d = next_inst(s);
|
||||
if (d != NULL) {
|
||||
xap_decode(s, d);
|
||||
strcpy(str, d->d_asm);
|
||||
free(d);
|
||||
} else *str = '\0';
|
||||
xap_decode (s, d);
|
||||
strcpy (str, d->d_asm);
|
||||
free (d);
|
||||
} else {
|
||||
*str = '\0';
|
||||
}
|
||||
#if 0
|
||||
if (s->s_ff_quirk) {
|
||||
sprintf(d->d_asm, "DC\t0x%x", i2u16(&d->d_inst));
|
||||
@ -29,8 +31,9 @@ static int arch_xap_disasm(char *str, const unsigned char *buf, ut64 seek) {
|
||||
return 0;
|
||||
}
|
||||
static int disassemble(RAsm *a, struct r_asm_op_t *op, const ut8 *buf, int len) {
|
||||
arch_xap_disasm (op->buf_asm, buf, a->pc);
|
||||
return (op->size=2);
|
||||
char *buf_asm = r_strbuf_get (&op->buf_asm);
|
||||
arch_xap_disasm (buf_asm, buf, a->pc);
|
||||
return (op->size = 2);
|
||||
}
|
||||
|
||||
RAsmPlugin r_asm_plugin_xap = {
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare2 - LGPL - Copyright 2014-2015 - pancake */
|
||||
/* radare2 - LGPL - Copyright 2014-2018 - pancake */
|
||||
|
||||
#include <r_asm.h>
|
||||
#include <r_lib.h>
|
||||
@ -12,21 +12,25 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
memset (op, 0, sizeof (RAsmOp));
|
||||
op->size = 4;
|
||||
ret = cs_open (CS_ARCH_XCORE, mode, &handle);
|
||||
if (ret) goto fin;
|
||||
if (ret) {
|
||||
goto fin;
|
||||
}
|
||||
cs_option (handle, CS_OPT_DETAIL, CS_OPT_OFF);
|
||||
n = cs_disasm (handle, (ut8*)buf, len, a->pc, 1, &insn);
|
||||
if (n<1) {
|
||||
strcpy (op->buf_asm, "invalid");
|
||||
if (n < 1) {
|
||||
r_asm_op_set_asm (op, "invalid");
|
||||
op->size = 4;
|
||||
ret = -1;
|
||||
goto beach;
|
||||
} else ret = 4;
|
||||
if (insn->size<1)
|
||||
}
|
||||
ret = 4;
|
||||
if (insn->size < 1) {
|
||||
goto beach;
|
||||
}
|
||||
op->size = insn->size;
|
||||
snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s%s%s",
|
||||
r_asm_op_set_asm (op, sdb_fmt ("%s%s%s",
|
||||
insn->mnemonic, insn->op_str[0]? " ": "",
|
||||
insn->op_str);
|
||||
insn->op_str));
|
||||
// TODO: remove the '$'<registername> in the string
|
||||
beach:
|
||||
cs_free (insn, n);
|
||||
@ -39,6 +43,7 @@ RAsmPlugin r_asm_plugin_xcore_cs = {
|
||||
.name = "xcore",
|
||||
.desc = "Capstone XCore disassembler",
|
||||
.license = "BSD",
|
||||
.author = "pancake",
|
||||
.arch = "xcore",
|
||||
.bits = 32,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG,
|
||||
|
@ -66,8 +66,7 @@ static int buf_fprintf(void *stream, const char *format, ...) {
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
struct disassemble_info disasm_obj;
|
||||
op->buf_asm[0] = '\0';
|
||||
buf_global = op->buf_asm;
|
||||
buf_global = r_strbuf_get (&op->buf_asm);
|
||||
offset = a->pc;
|
||||
if (len > INSN_BUFFER_SIZE) {
|
||||
len = INSN_BUFFER_SIZE;
|
||||
@ -89,7 +88,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
|
||||
op->size = print_insn_xtensa ((bfd_vma)offset, &disasm_obj);
|
||||
if (op->size == -1) {
|
||||
strncpy (op->buf_asm, " (data)", R_ASM_BUFSIZE);
|
||||
r_asm_op_set_asm (op, "(data)");
|
||||
}
|
||||
return op->size;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2012-2017 - pancake */
|
||||
/* radare - LGPL - Copyright 2012-2018 - pancake */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
@ -13,13 +13,14 @@ static int do_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
}
|
||||
|
||||
static int do_assemble(RAsm *a, RAsmOp *op, const char *buf) {
|
||||
return op->size = z80asm (op->buf, buf);
|
||||
return op->size = z80asm ((ut8*)r_strbuf_get (&op->buf), buf);
|
||||
}
|
||||
|
||||
RAsmPlugin r_asm_plugin_z80 = {
|
||||
.name = "z80",
|
||||
.desc = "Zilog Z80",
|
||||
.license = "GPL",
|
||||
.author = "condret",
|
||||
.arch = "z80",
|
||||
.bits = 8,
|
||||
.endian = R_SYS_ENDIAN_NONE,
|
||||
|
@ -20,7 +20,8 @@ include $(SHLR)/ar/deps.mk
|
||||
include $(LIBR)/magic/deps.mk
|
||||
|
||||
STATIC_OBJS=$(addprefix $(LTOP)/bin/p/, $(STATIC_OBJ))
|
||||
OBJS=bin.o dbginfo.o bin_ldr.o bin_write.o demangle.o dwarf.o filter.o file.o obj.o open.o
|
||||
OBJS=bin.o dbginfo.o bin_ldr.o bin_write.o demangle.o
|
||||
OBJS+=dwarf.o filter.o bfile.o obj.o open.o
|
||||
OBJS+=mangling/cxx/cp-demangle.o ${STATIC_OBJS}
|
||||
OBJS+=mangling/demangler.o
|
||||
OBJS+=mangling/microsoft_demangle.o
|
||||
|
@ -794,7 +794,6 @@ R_API void r_bin_file_free(void /*RBinFile*/ *bf_) {
|
||||
if (a->curxtr && a->curxtr->destroy && a->xtr_obj) {
|
||||
a->curxtr->free_xtr ((void *)(a->xtr_obj));
|
||||
}
|
||||
r_buf_free (a->buf);
|
||||
// TODO: unset related sdb namespaces
|
||||
if (a && a->sdb_addrinfo) {
|
||||
sdb_free (a->sdb_addrinfo);
|
@ -176,12 +176,11 @@ R_API void r_bin_info_free(RBinInfo *rb) {
|
||||
|
||||
R_API RBinImport *r_bin_import_clone(RBinImport *o) {
|
||||
RBinImport *res = r_mem_dup (o, sizeof (*o));
|
||||
if (!res) {
|
||||
return NULL;
|
||||
if (res) {
|
||||
res->name = R_STR_DUP (o->name);
|
||||
res->classname = R_STR_DUP (o->classname);
|
||||
res->descriptor = R_STR_DUP (o->descriptor);
|
||||
}
|
||||
res->name = R_STR_DUP (o->name);
|
||||
res->classname = R_STR_DUP (o->classname);
|
||||
res->descriptor = R_STR_DUP (o->descriptor);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ files = [
|
||||
'demangle.c',
|
||||
'dwarf.c',
|
||||
'filter.c',
|
||||
'file.c',
|
||||
'bfile.c',
|
||||
'obj.c',
|
||||
'open.c',
|
||||
'p/bin_any.c',
|
||||
|
@ -483,7 +483,7 @@ static RBinSymbol *convert_symbol(struct Elf_(r_bin_elf_obj_t) *bin,
|
||||
if (!(ptr = R_NEW0 (RBinSymbol))) {
|
||||
return NULL;
|
||||
}
|
||||
ptr->name = symbol->name[0] ? r_str_newf (namefmt, &symbol->name[0]) : strdup("");
|
||||
ptr->name = symbol->name[0] ? r_str_newf (namefmt, &symbol->name[0]) : strdup ("");
|
||||
ptr->forwarder = r_str_const ("NONE");
|
||||
ptr->bind = r_str_const (symbol->bind);
|
||||
ptr->type = r_str_const (symbol->type);
|
||||
@ -550,18 +550,15 @@ static RList* symbols(RBinFile *bf) {
|
||||
if (!symbol[i].size) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ptr = convert_symbol (bin, &symbol[i], "imp.%s");
|
||||
if (!ptr) {
|
||||
break;
|
||||
}
|
||||
|
||||
// special case where there is not entry in the plt for the import
|
||||
if (ptr->vaddr == UT32_MAX) {
|
||||
ptr->paddr = 0;
|
||||
ptr->vaddr = 0;
|
||||
}
|
||||
|
||||
insert_symbol (bin, ptr, symbol[i].is_sht_null, ret);
|
||||
}
|
||||
return ret;
|
||||
|
@ -137,7 +137,7 @@ R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut6
|
||||
continue;
|
||||
}
|
||||
//opsz = op.size;
|
||||
opst = strdup (op.buf_asm);
|
||||
opst = strdup (r_strbuf_get (&op.buf_asm));
|
||||
}
|
||||
matches = strcmp (opst, "invalid") && strcmp (opst, "unaligned");
|
||||
if (matches && tokens[matchcount]) {
|
||||
@ -355,17 +355,18 @@ static int handle_disassembly_overlap(RCore* core, RList *hits, ut8* buf, int le
|
||||
|
||||
static int is_addr_in_range(ut64 start, ut64 end, ut64 start_range, ut64 end_range){
|
||||
int result = false;
|
||||
|
||||
if (start == start_range) {
|
||||
return true;
|
||||
} else if (start < end && start_range < end_range) {
|
||||
}
|
||||
if (start < end && start_range < end_range) {
|
||||
// ez cases
|
||||
if ( start_range <= start && start < end_range )
|
||||
if (start_range <= start && start < end_range) {
|
||||
result = true;
|
||||
else if (start_range < end && end < end_range )
|
||||
} else if (start_range < end && end < end_range) {
|
||||
result = true;
|
||||
else if ( start <= start_range && end_range < end )
|
||||
} else if ( start <= start_range && end_range < end) {
|
||||
result = true;
|
||||
}
|
||||
// XXX - these cases need to be tested
|
||||
// (long long) start_range < 0 < end_range
|
||||
} else if (start_range > end_range) {
|
||||
@ -374,9 +375,9 @@ static int is_addr_in_range(ut64 start, ut64 end, ut64 start_range, ut64 end_ran
|
||||
result = true;
|
||||
else if (end <= end_range)
|
||||
result = true;
|
||||
else if ( start_range <= start )
|
||||
else if (start_range <= start)
|
||||
result = true;
|
||||
else if ( start_range < end )
|
||||
else if (start_range < end)
|
||||
result = true;
|
||||
// (long long) start < 0 < end
|
||||
} else {
|
||||
@ -384,7 +385,7 @@ static int is_addr_in_range(ut64 start, ut64 end, ut64 start_range, ut64 end_ran
|
||||
result = true;
|
||||
else if (end <= end_range)
|
||||
result = true;
|
||||
else if ( start_range <= start )
|
||||
else if (start_range <= start)
|
||||
result = true;
|
||||
}
|
||||
// XXX - these cases need to be tested
|
||||
@ -414,7 +415,6 @@ R_API RList *r_core_asm_bwdisassemble(RCore *core, ut64 addr, int n, int len) {
|
||||
RAsmOp op;
|
||||
// len = n * 32;
|
||||
// if (n > core->blocksize) n = core->blocksize;
|
||||
ut8 *buf;
|
||||
ut64 at;
|
||||
ut32 idx = 0, hit_count;
|
||||
int numinstr, asmlen, ii;
|
||||
@ -429,7 +429,7 @@ R_API RList *r_core_asm_bwdisassemble(RCore *core, ut64 addr, int n, int len) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buf = (ut8 *)malloc (len);
|
||||
ut8 *buf = (ut8 *)malloc (len);
|
||||
if (!buf) {
|
||||
r_list_free (hits);
|
||||
return NULL;
|
||||
@ -466,7 +466,7 @@ R_API RList *r_core_asm_bwdisassemble(RCore *core, ut64 addr, int n, int len) {
|
||||
r_asm_set_pc (core->assembler, at);
|
||||
for (hit_count = 0; hit_count < n; hit_count++) {
|
||||
int instrlen = r_asm_disassemble (core->assembler, &op,
|
||||
buf + len - addrbytes*(addr-at), addrbytes * (addr-at));
|
||||
buf + len - addrbytes * (addr - at), addrbytes * (addr - at));
|
||||
add_hit_to_hits (hits, at, instrlen, true);
|
||||
at += instrlen;
|
||||
}
|
||||
@ -545,14 +545,13 @@ static RList *r_core_asm_back_disassemble (RCore *core, ut64 addr, int len, ut64
|
||||
RCoreAsmHit dummy_value;
|
||||
ut32 hit_count = 0;
|
||||
|
||||
if (disassmble_each_addr){
|
||||
if (disassmble_each_addr) {
|
||||
return r_core_asm_back_disassemble_all(core, addr, len, max_hit_count, extra_padding+1);
|
||||
}
|
||||
|
||||
hits = r_core_asm_hit_list_new ();
|
||||
buf = malloc (len + extra_padding);
|
||||
|
||||
if (!hits || !buf ){
|
||||
if (!hits || !buf) {
|
||||
if (hits) {
|
||||
r_list_purge (hits);
|
||||
free (hits);
|
||||
@ -587,7 +586,7 @@ static RList *r_core_asm_back_disassemble (RCore *core, ut64 addr, int len, ut64
|
||||
// so we need to account for that with current_buf_pos
|
||||
current_buf_pos = len - extra_padding - 1;
|
||||
next_buf_pos = len + extra_padding - 1;
|
||||
current_instr_addr = addr-1;
|
||||
current_instr_addr = addr - 1;
|
||||
do {
|
||||
if (r_cons_is_breaked ()) {
|
||||
break;
|
||||
@ -601,19 +600,20 @@ static RList *r_core_asm_back_disassemble (RCore *core, ut64 addr, int len, ut64
|
||||
eprintf("current_instr_addr: 0x%"PFMT64x", current_buf_pos: 0x%"PFMT64x", current_instr_len: %d \n", current_instr_addr, current_buf_pos, current_instr_len);
|
||||
|
||||
ut8 *hex_str = (ut8*)r_hex_bin2strdup(buf+current_buf_pos, byte_cnt);
|
||||
eprintf("==== current_instr_bytes: %s ",hex_str);
|
||||
eprintf ("==== current_instr_bytes: %s ",hex_str);
|
||||
|
||||
if (current_instr_len > 0) {
|
||||
eprintf("op.buf_asm: %s\n", op.buf_asm);
|
||||
eprintf("op.buf_asm: %s\n", r_strbuf_get (&op.buf_asm));
|
||||
} else {
|
||||
eprintf("op.buf_asm: <invalid>\n");
|
||||
}
|
||||
free (hex_str);
|
||||
}
|
||||
|
||||
// disassembly invalid
|
||||
if (current_instr_len == 0 || strstr (op.buf_asm, "invalid")) {
|
||||
if (current_instr_len == 0) current_instr_len = 1;
|
||||
if (current_instr_len == 0 || strstr (r_strbuf_get (&op.buf_asm), "invalid")) {
|
||||
if (current_instr_len == 0) {
|
||||
current_instr_len = 1;
|
||||
}
|
||||
add_hit_to_sorted_hits(hits, current_instr_addr, current_instr_len, /* is_valid */ false);
|
||||
hit_count ++;
|
||||
last_num_invalid ++;
|
||||
|
@ -850,11 +850,12 @@ R_API RAnalOp* r_core_anal_op(RCore *core, ut64 addr, int mask) {
|
||||
|
||||
// decode instruction here
|
||||
r_asm_set_pc (core->assembler, addr);
|
||||
r_asm_op_init (&asmop);
|
||||
if (r_asm_disassemble (core->assembler, &asmop, ptr, len) > 0) {
|
||||
op->mnemonic = strdup (asmop.buf_asm);
|
||||
op->mnemonic = strdup (r_strbuf_get (&asmop.buf_asm));
|
||||
}
|
||||
r_asm_op_fini (&asmop);
|
||||
return op;
|
||||
|
||||
err_op:
|
||||
free (op);
|
||||
return NULL;
|
||||
|
@ -1336,7 +1336,7 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int
|
||||
ret = r_anal_op (core->anal, &op, core->offset + idx, buf + idx, len - idx, R_ANAL_OP_MASK_ESIL);
|
||||
esilstr = R_STRBUF_SAFEGET (&op.esil);
|
||||
opexstr = R_STRBUF_SAFEGET (&op.opex);
|
||||
char *mnem = strdup (asmop.buf_asm);
|
||||
char *mnem = strdup (r_asm_op_get_asm (&asmop));
|
||||
char *sp = strchr (mnem, ' ');
|
||||
if (sp) {
|
||||
*sp = 0;
|
||||
@ -1361,16 +1361,18 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int
|
||||
}
|
||||
size = (hint && hint->size)? hint->size: op.size;
|
||||
if (fmt == 'd') {
|
||||
char *opname = strdup (asmop.buf_asm);
|
||||
r_str_split (opname, ' ');
|
||||
char *d = r_asm_describe (core->assembler, opname);
|
||||
if (d && *d) {
|
||||
r_cons_printf ("%s: %s\n", opname, d);
|
||||
free (d);
|
||||
} else {
|
||||
eprintf ("Unknown opcode\n");
|
||||
char *opname = strdup (r_asm_op_get_asm (&asmop));
|
||||
if (opname) {
|
||||
r_str_split (opname, ' ');
|
||||
char *d = r_asm_describe (core->assembler, opname);
|
||||
if (d && *d) {
|
||||
r_cons_printf ("%s: %s\n", opname, d);
|
||||
free (d);
|
||||
} else {
|
||||
eprintf ("Unknown opcode\n");
|
||||
}
|
||||
free (opname);
|
||||
}
|
||||
free (opname);
|
||||
} else if (fmt == 'e') {
|
||||
if (*esilstr) {
|
||||
if (use_color) {
|
||||
@ -1398,13 +1400,13 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int
|
||||
} else {
|
||||
r_cons_print (",");
|
||||
}
|
||||
r_cons_printf ("{\"opcode\":\"%s\",", asmop.buf_asm);
|
||||
r_cons_printf ("{\"opcode\":\"%s\",", r_asm_op_get_asm (&asmop));
|
||||
{
|
||||
char strsub[128] = { 0 };
|
||||
// pc+33
|
||||
r_parse_varsub (core->parser, NULL,
|
||||
core->offset + idx,
|
||||
asmop.size, asmop.buf_asm,
|
||||
asmop.size, r_asm_op_get_asm (&asmop),
|
||||
strsub, sizeof (strsub));
|
||||
{
|
||||
ut64 killme = UT64_MAX;
|
||||
@ -1504,7 +1506,7 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int
|
||||
if (fmt) r_cons_printf (fmt, arg);\
|
||||
}
|
||||
printline ("address", "0x%" PFMT64x "\n", core->offset + idx);
|
||||
printline ("opcode", "%s\n", asmop.buf_asm);
|
||||
printline ("opcode", "%s\n", r_asm_op_get_asm (&asmop));
|
||||
printline ("mnemonic", "%s\n", mnem);
|
||||
if (hint) {
|
||||
if (hint->opcode) {
|
||||
@ -3051,8 +3053,7 @@ void cmd_anal_reg(RCore *core, const char *str) {
|
||||
break;
|
||||
case 'S': { // "arS"
|
||||
int sz;
|
||||
ut8 *buf = r_reg_get_bytes (
|
||||
core->anal->reg, R_REG_TYPE_GPR, &sz);
|
||||
ut8 *buf = r_reg_get_bytes (core->anal->reg, R_REG_TYPE_GPR, &sz);
|
||||
r_cons_printf ("%d\n", sz);
|
||||
free (buf);
|
||||
} break;
|
||||
@ -3071,7 +3072,6 @@ void cmd_anal_reg(RCore *core, const char *str) {
|
||||
}
|
||||
ut8 *buf = r_reg_get_bytes (core->dbg->reg, type, &len);
|
||||
if (buf) {
|
||||
//r_print_hexdump (core->print, 0LL, buf, len, 16, 16);
|
||||
r_print_hexdump (core->print, 0LL, buf, len, 32, 4, 1);
|
||||
free (buf);
|
||||
}
|
||||
@ -3080,8 +3080,7 @@ void cmd_anal_reg(RCore *core, const char *str) {
|
||||
// TODO: set flag values with drc zf=1
|
||||
{
|
||||
RRegItem *r;
|
||||
const char *name = str + 1;
|
||||
while (*name == ' ') name++;
|
||||
const char *name = r_str_trim_ro (str + 1);
|
||||
if (*name && name[1]) {
|
||||
r = r_reg_cond_get (core->dbg->reg, name);
|
||||
if (r) {
|
||||
@ -3434,7 +3433,6 @@ repeat:
|
||||
core->dbg->reg = reg;
|
||||
} else {
|
||||
r_anal_esil_parse (esil, R_STRBUF_SAFEGET (&op.esil));
|
||||
|
||||
if (core->anal->cur && core->anal->cur->esil_post_loop) {
|
||||
core->anal->cur->esil_post_loop (esil, &op);
|
||||
}
|
||||
@ -4806,7 +4804,7 @@ static void cmd_anal_aftertraps(RCore *core, const char *input) {
|
||||
int bufi, minop = 1; // 4
|
||||
ut8 *buf;
|
||||
RBinFile *binfile;
|
||||
RAnalOp op;
|
||||
RAnalOp op = {0};
|
||||
ut64 addr, addr_end;
|
||||
ut64 len = r_num_math (core->num, input);
|
||||
if (len > 0xffffff) {
|
||||
@ -5431,14 +5429,15 @@ static bool cmd_anal_refs(RCore *core, const char *input) {
|
||||
r_asm_disassemble (core->assembler, &asmop, buf, size);
|
||||
char str[512];
|
||||
fcn = r_anal_get_fcn_in (core->anal, ref->addr, 0);
|
||||
r_str_ncpy (str, r_asm_op_get_asm (&asmop), sizeof (str) - 1);
|
||||
if (asm_varsub) {
|
||||
r_parse_varsub (core->parser, fcn, ref->addr, asmop.size,
|
||||
asmop.buf_asm, asmop.buf_asm, sizeof (asmop.buf_asm));
|
||||
str, str, sizeof (str));
|
||||
}
|
||||
r_parse_filter (core->parser, core->flags,
|
||||
asmop.buf_asm, str, sizeof (str), core->print->big_endian);
|
||||
|
||||
r_cons_printf ("{\"from\":%" PFMT64u ",\"type\":\"%s\",\"opcode\":\"%s\"", ref->addr, r_anal_xrefs_type_tostring (ref->type), str);
|
||||
str, str, sizeof (str), core->print->big_endian);
|
||||
r_cons_printf ("{\"from\":%" PFMT64u ",\"type\":\"%s\",\"opcode\":\"%s\"",
|
||||
ref->addr, r_anal_xrefs_type_tostring (ref->type), str);
|
||||
if (fcn) {
|
||||
r_cons_printf (",\"fcn_addr\":%"PFMT64u",\"fcn_name\":\"%s\"", fcn->addr, fcn->name);
|
||||
}
|
||||
@ -5495,12 +5494,17 @@ static bool cmd_anal_refs(RCore *core, const char *input) {
|
||||
r_asm_disassemble (core->assembler, &asmop, buf, size);
|
||||
|
||||
fcn = r_anal_get_fcn_in (core->anal, ref->addr, 0);
|
||||
int ba_len = r_strbuf_length (&asmop.buf_asm) + 128;
|
||||
char *ba = malloc (ba_len);
|
||||
if (asm_varsub) {
|
||||
strcpy (ba, r_strbuf_get (&asmop.buf_asm));
|
||||
r_parse_varsub (core->parser, fcn, ref->addr, asmop.size,
|
||||
asmop.buf_asm, asmop.buf_asm, sizeof (asmop.buf_asm));
|
||||
ba, ba, sizeof (asmop.buf_asm));
|
||||
}
|
||||
r_parse_filter (core->parser, core->flags,
|
||||
asmop.buf_asm, str, sizeof (str), core->print->big_endian);
|
||||
ba, str, sizeof (str), core->print->big_endian);
|
||||
r_asm_op_set_asm (&asmop, ba);
|
||||
free (ba);
|
||||
if (has_color) {
|
||||
buf_asm = r_print_colorize_opcode (core->print, str,
|
||||
core->cons->pal.reg, core->cons->pal.num, false, fcn ? fcn->addr : 0);
|
||||
@ -5577,7 +5581,8 @@ static bool cmd_anal_refs(RCore *core, const char *input) {
|
||||
r_asm_set_pc (core->assembler, ref->at);
|
||||
r_asm_disassemble (core->assembler, &asmop, buf, 12);
|
||||
r_parse_filter (core->parser, core->flags,
|
||||
asmop.buf_asm, str, sizeof (str), core->print->big_endian);
|
||||
r_asm_op_get_asm (&asmop),
|
||||
str, sizeof (str), core->print->big_endian);
|
||||
if (has_color) {
|
||||
buf_asm = r_print_colorize_opcode (core->print, str,
|
||||
core->cons->pal.reg, core->cons->pal.num, false, fcn ? fcn->addr : 0);
|
||||
|
@ -326,7 +326,7 @@ static void cmd_cmp_watcher(RCore *core, const char *input) {
|
||||
|
||||
static int cmd_cmp_disasm(RCore *core, const char *input, int mode) {
|
||||
RAsmOp op, op2;
|
||||
int i, j, iseq;
|
||||
int i, j;
|
||||
char colpad[80];
|
||||
int hascolor = r_config_get_i (core->config, "scr.color");
|
||||
int cols = r_config_get_i (core->config, "hex.cols") * 2;
|
||||
@ -350,10 +350,10 @@ static int cmd_cmp_disasm(RCore *core, const char *input, int mode) {
|
||||
buf + j, core->blocksize - j);
|
||||
|
||||
// show output
|
||||
iseq = (!strcmp (op.buf_asm, op2.buf_asm));
|
||||
memset (colpad, ' ', sizeof(colpad));
|
||||
bool iseq = r_strbuf_equals (&op.buf_asm, &op2.buf_asm);
|
||||
memset (colpad, ' ', sizeof (colpad));
|
||||
{
|
||||
int pos = strlen (op.buf_asm);
|
||||
int pos = strlen (r_strbuf_get (&op.buf_asm));
|
||||
pos = (pos > cols)? 0: cols - pos;
|
||||
colpad[pos] = 0;
|
||||
}
|
||||
@ -390,7 +390,7 @@ static int cmd_cmp_disasm(RCore *core, const char *input, int mode) {
|
||||
buf + j, core->blocksize - j);
|
||||
|
||||
// show output
|
||||
iseq = (!strcmp (op.buf_asm, op2.buf_asm));
|
||||
bool iseq = r_strbuf_equals (&op.buf_asm, &op2.buf_asm); // (!strcmp (op.buf_asm, op2.buf_asm));
|
||||
if (iseq) {
|
||||
r_cons_printf (" 0x%08"PFMT64x " %s\n",
|
||||
core->offset + i, op.buf_asm);
|
||||
|
@ -794,15 +794,16 @@ static int step_until_inst(RCore *core, const char *instr, bool regex) {
|
||||
// TODO: speedup if instructions are in the same block as the previous
|
||||
r_io_read_at (core->io, pc, buf, sizeof (buf));
|
||||
ret = r_asm_disassemble (core->assembler, &asmop, buf, sizeof (buf));
|
||||
eprintf ("0x%08"PFMT64x" %d %s\n", pc, ret, asmop.buf_asm);
|
||||
eprintf ("0x%08"PFMT64x" %d %s\n", pc, ret, r_asm_op_get_asm (&asmop)); // asmop.buf_asm);
|
||||
if (ret > 0) {
|
||||
const char *buf_asm = r_asm_op_get_asm (&asmop);
|
||||
if (regex) {
|
||||
if (r_regex_match (instr, "e", asmop.buf_asm)) {
|
||||
if (r_regex_match (instr, "e", buf_asm)) {
|
||||
eprintf ("Stop.\n");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (strstr (asmop.buf_asm, instr)) {
|
||||
if (strstr (buf_asm, instr)) {
|
||||
eprintf ("Stop.\n");
|
||||
break;
|
||||
}
|
||||
|
@ -965,7 +965,8 @@ static RList *construct_rop_gadget(RCore *core, ut64 addr, ut8 *buf, int idx, co
|
||||
goto ret;
|
||||
} else {
|
||||
opsz = asmop.size;
|
||||
opst = asmop.buf_asm;
|
||||
// opsz = r_strbuf_length (asmop.buf);
|
||||
opst = r_asm_op_get_asm (&asmop);
|
||||
}
|
||||
if (!r_str_ncasecmp (opst, "invalid", strlen ("invalid")) ||
|
||||
!r_str_ncasecmp (opst, ".byte", strlen (".byte"))) {
|
||||
@ -1040,7 +1041,7 @@ static void print_rop(RCore *core, RList *hitlist, char mode, bool *json_first)
|
||||
RCoreAsmHit *hit = NULL;
|
||||
RListIter *iter;
|
||||
RList *ropList = NULL;
|
||||
char *buf_asm;
|
||||
char *buf_asm = NULL;
|
||||
unsigned int size = 0;
|
||||
RAnalOp analop = R_EMPTY;
|
||||
RAsmOp asmop;
|
||||
@ -1082,7 +1083,7 @@ static void print_rop(RCore *core, RList *hitlist, char mode, bool *json_first)
|
||||
}
|
||||
r_cons_printf ("{\"offset\":%"PFMT64d ",\"size\":%d,"
|
||||
"\"opcode\":\"%s\",\"type\":\"%s\"}%s",
|
||||
hit->addr, hit->len, asmop.buf_asm,
|
||||
hit->addr, hit->len, r_strbuf_get (&asmop.buf_asm),
|
||||
r_anal_optype_to_string (analop.type),
|
||||
iter->n? ",": "");
|
||||
free (buf);
|
||||
@ -1111,18 +1112,17 @@ static void print_rop(RCore *core, RList *hitlist, char mode, bool *json_first)
|
||||
size += hit->len;
|
||||
const char *opstr = R_STRBUF_SAFEGET (&analop.esil);
|
||||
if (analop.type != R_ANAL_OP_TYPE_RET) {
|
||||
char *opstr_n = r_str_newf (" %s", opstr);
|
||||
r_list_append (ropList, (void *) opstr_n);
|
||||
r_list_append (ropList, r_str_newf (" %s", opstr));
|
||||
}
|
||||
if (esil) {
|
||||
r_cons_printf ("%s\n", opstr);
|
||||
} else if (colorize) {
|
||||
buf_asm = r_print_colorize_opcode (core->print, asmop.buf_asm,
|
||||
buf_asm = r_print_colorize_opcode (core->print, r_strbuf_get (&asmop.buf_asm),
|
||||
core->cons->pal.reg, core->cons->pal.num, false, 0);
|
||||
r_cons_printf (" %s%s;", buf_asm, Color_RESET);
|
||||
free (buf_asm);
|
||||
} else {
|
||||
r_cons_printf (" %s;", asmop.buf_asm);
|
||||
r_cons_printf (" %s;", r_strbuf_get (&asmop.buf_asm));
|
||||
}
|
||||
free (buf);
|
||||
}
|
||||
@ -1143,6 +1143,9 @@ static void print_rop(RCore *core, RList *hitlist, char mode, bool *json_first)
|
||||
continue;
|
||||
}
|
||||
ut8 *buf = malloc (1 + hit->len);
|
||||
if (!buf) {
|
||||
break;
|
||||
}
|
||||
buf[hit->len] = 0;
|
||||
r_io_read_at (core->io, hit->addr, buf, hit->len);
|
||||
r_asm_set_pc (core->assembler, hit->addr);
|
||||
@ -1154,7 +1157,7 @@ static void print_rop(RCore *core, RList *hitlist, char mode, bool *json_first)
|
||||
r_list_append (ropList, (void *) opstr_n);
|
||||
}
|
||||
if (colorize) {
|
||||
buf_asm = r_print_colorize_opcode (core->print, asmop.buf_asm,
|
||||
char *buf_asm = r_print_colorize_opcode (core->print, r_strbuf_get (&asmop.buf_asm),
|
||||
core->cons->pal.reg, core->cons->pal.num, false, 0);
|
||||
otype = r_print_color_op_type (core->print, analop.type);
|
||||
if (comment) {
|
||||
@ -1168,10 +1171,10 @@ static void print_rop(RCore *core, RList *hitlist, char mode, bool *json_first)
|
||||
} else {
|
||||
if (comment) {
|
||||
r_cons_printf (" 0x%08"PFMT64x " %18s %s ; %s\n",
|
||||
hit->addr, asmop.buf_hex, asmop.buf_asm, comment);
|
||||
hit->addr, asmop.buf_hex, r_strbuf_get (&asmop.buf_asm), comment);
|
||||
} else {
|
||||
r_cons_printf (" 0x%08"PFMT64x " %18s %s\n",
|
||||
hit->addr, asmop.buf_hex, asmop.buf_asm);
|
||||
hit->addr, asmop.buf_hex, r_strbuf_get (&asmop.buf_asm));
|
||||
}
|
||||
}
|
||||
free (buf);
|
||||
@ -1217,7 +1220,6 @@ static int r_core_search_rop(RCore *core, RInterval search_itv, int opt, const c
|
||||
gadgetSdb = sdb_ns (core->sdb, "gadget_sdb", true);
|
||||
}
|
||||
}
|
||||
|
||||
if (max_count == 0) {
|
||||
max_count = -1;
|
||||
}
|
||||
@ -1319,15 +1321,17 @@ static int r_core_search_rop(RCore *core, RInterval search_itv, int opt, const c
|
||||
}
|
||||
#endif
|
||||
epair = R_NEW0 (struct endlist_pair);
|
||||
// If this arch has branch delay slots, add the next instr as well
|
||||
if (end_gadget.delay) {
|
||||
epair->instr_offset = i + increment;
|
||||
epair->delay_size = end_gadget.delay;
|
||||
} else {
|
||||
epair->instr_offset = (intptr_t) i;
|
||||
epair->delay_size = end_gadget.delay;
|
||||
if (epair) {
|
||||
// If this arch has branch delay slots, add the next instr as well
|
||||
if (end_gadget.delay) {
|
||||
epair->instr_offset = i + increment;
|
||||
epair->delay_size = end_gadget.delay;
|
||||
} else {
|
||||
epair->instr_offset = (intptr_t) i;
|
||||
epair->delay_size = end_gadget.delay;
|
||||
}
|
||||
r_list_append (end_list, (void *) (intptr_t) epair);
|
||||
}
|
||||
r_list_append (end_list, (void *) (intptr_t) epair);
|
||||
}
|
||||
r_anal_op_fini (&end_gadget);
|
||||
if (r_cons_is_breaked ()) {
|
||||
@ -1405,7 +1409,6 @@ static int r_core_search_rop(RCore *core, RInterval search_itv, int opt, const c
|
||||
if (align && (0 != ((from + i) % align))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (gadgetSdb) {
|
||||
RListIter *iter;
|
||||
|
||||
@ -1800,7 +1803,7 @@ static void do_ref_search(RCore *core, ut64 addr,ut64 from, ut64 to, struct sear
|
||||
RAnalRef *ref;
|
||||
RListIter *iter;
|
||||
ut8 buf[12];
|
||||
RAsmOp asmop;
|
||||
RAsmOp asmop;
|
||||
RList *list = r_anal_xrefs_get (core->anal, addr);
|
||||
if (list) {
|
||||
r_list_foreach (list, iter, ref) {
|
||||
@ -1808,8 +1811,8 @@ static void do_ref_search(RCore *core, ut64 addr,ut64 from, ut64 to, struct sear
|
||||
r_asm_set_pc (core->assembler, ref->addr);
|
||||
r_asm_disassemble (core->assembler, &asmop, buf, size);
|
||||
fcn = r_anal_get_fcn_in (core->anal, ref->addr, 0);
|
||||
r_parse_filter (core->parser, core->flags,
|
||||
asmop.buf_asm, str, sizeof (str), core->print->big_endian);
|
||||
r_parse_filter (core->parser, core->flags, r_strbuf_get (&asmop.buf_asm),
|
||||
str, sizeof (str), core->print->big_endian);
|
||||
comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, ref->addr);
|
||||
char *buf_fcn = comment
|
||||
? r_str_newf ("%s; %s", fcn ? fcn->name : "(nofunc)", strtok (comment, "\n"))
|
||||
|
@ -2560,11 +2560,12 @@ R_API int r_core_seek_align(RCore *core, ut64 align, int times) {
|
||||
R_API char *r_core_op_str(RCore *core, ut64 addr) {
|
||||
RAsmOp op = {0};
|
||||
ut8 buf[64];
|
||||
int ret;
|
||||
r_asm_set_pc (core->assembler, addr);
|
||||
r_io_read_at (core->io, addr, buf, sizeof (buf));
|
||||
ret = r_asm_disassemble (core->assembler, &op, buf, sizeof (buf));
|
||||
return (ret > 0)? strdup (op.buf_asm): NULL;
|
||||
int ret = r_asm_disassemble (core->assembler, &op, buf, sizeof (buf));
|
||||
char *str = (ret > 0)? strdup (r_strbuf_get (&op.buf_asm)): NULL;
|
||||
r_asm_op_fini (&op);
|
||||
return str;
|
||||
}
|
||||
|
||||
R_API RAnalOp *r_core_op_anal(RCore *core, ut64 addr) {
|
||||
|
@ -828,6 +828,7 @@ static void ds_free(RDisasmState *ds) {
|
||||
r_io_fd_close (ds->core->io, ds->stackFd);
|
||||
}
|
||||
}
|
||||
r_asm_op_fini (&ds->asmop);
|
||||
r_anal_op_fini (&ds->analop);
|
||||
r_anal_hint_free (ds->hint);
|
||||
ds_print_esil_anal_fini (ds);
|
||||
@ -847,7 +848,7 @@ static void ds_free(RDisasmState *ds) {
|
||||
/* XXX move to r_print */
|
||||
static char *colorize_asm_string(RCore *core, RDisasmState *ds, bool print_color) {
|
||||
char *spacer = NULL;
|
||||
char *source = ds->opstr? ds->opstr: ds->asmop.buf_asm;
|
||||
char *source = ds->opstr? ds->opstr: r_asm_op_get_asm (&ds->asmop);
|
||||
char *hlstr = r_meta_get_string (ds->core->anal, R_META_TYPE_HIGHLIGHT, ds->at);
|
||||
bool partial_reset = line_highlighted (ds) ? true : ((hlstr && *hlstr) ? true : false);
|
||||
RAnalFunction *f = ds->show_color_args ? fcnIn (ds, ds->vat, R_ANAL_FCN_TYPE_NULL) : NULL;
|
||||
@ -897,7 +898,7 @@ static bool ds_must_strip(RDisasmState *ds) {
|
||||
}
|
||||
|
||||
static void ds_highlight_word(RDisasmState * ds, char *word, char *color) {
|
||||
char *source = ds->opstr? ds->opstr: ds->asmop.buf_asm;
|
||||
char *source = ds->opstr? ds->opstr: r_asm_op_get_asm (&ds->asmop);
|
||||
const char *color_reset = line_highlighted (ds) ? ds->color_linehl : Color_RESET_BG;
|
||||
char *asm_str = r_str_highlight (source, word, color, color_reset);
|
||||
ds->opstr = asm_str? asm_str: source;
|
||||
@ -906,7 +907,7 @@ static void ds_highlight_word(RDisasmState * ds, char *word, char *color) {
|
||||
static void ds_build_op_str(RDisasmState *ds, bool print_color) {
|
||||
RCore *core = ds->core;
|
||||
if (!ds->opstr) {
|
||||
ds->opstr = strdup (ds->asmop.buf_asm);
|
||||
ds->opstr = strdup (r_asm_op_get_asm (&ds->asmop));
|
||||
}
|
||||
/* initialize */
|
||||
core->parser->hint = ds->hint;
|
||||
@ -1263,19 +1264,22 @@ static void ds_show_xrefs(RDisasmState *ds) {
|
||||
|
||||
static void ds_atabs_option(RDisasmState *ds) {
|
||||
int n, i = 0, comma = 0, word = 0;
|
||||
int size, brackets = 0;
|
||||
int brackets = 0;
|
||||
char *t, *b;
|
||||
if (!ds || !ds->atabs) {
|
||||
return;
|
||||
}
|
||||
size = strlen (ds->asmop.buf_asm) * (ds->atabs + 1) * 4;
|
||||
if (size < 1 || size < strlen (ds->asmop.buf_asm)) {
|
||||
int bufasm_len = r_strbuf_length (&ds->asmop.buf_asm);
|
||||
int size = bufasm_len * (ds->atabs + 1) * 4;
|
||||
if (size < 1 || size < bufasm_len) {
|
||||
return;
|
||||
}
|
||||
free (ds->opstr);
|
||||
ds->opstr = b = malloc (size + 1);
|
||||
strncpy (b, ds->asmop.buf_asm, R_MIN (size, R_ASM_BUFSIZE));
|
||||
b[size] = 0;
|
||||
if (!b) {
|
||||
return;
|
||||
}
|
||||
strcpy (b, r_asm_op_get_asm (&ds->asmop));
|
||||
for (; *b; b++, i++) {
|
||||
if (*b == '(' || *b == '[') {
|
||||
brackets++;
|
||||
@ -2099,6 +2103,7 @@ static int ds_disassemble(RDisasmState *ds, ut8 *buf, int len) {
|
||||
ds->opstr = strdup (ds->hint->opcode);
|
||||
return true;
|
||||
}
|
||||
r_asm_op_fini (&ds->asmop);
|
||||
ret = r_asm_disassemble (core->assembler, &ds->asmop, buf, len);
|
||||
if (ds->asmop.size < 1) {
|
||||
ds->asmop.size = 1;
|
||||
@ -2143,20 +2148,17 @@ static int ds_disassemble(RDisasmState *ds, ut8 *buf, int len) {
|
||||
}
|
||||
int sz = R_MIN (16, meta->size - (ds->at - meta->from));
|
||||
ds->asmop.size = sz;
|
||||
r_hex_bin2str (buf, sz, ds->asmop.buf_hex);
|
||||
r_asm_op_set_hexbuf (&ds->asmop, buf, sz);
|
||||
switch (meta->type) {
|
||||
case R_META_TYPE_STRING:
|
||||
snprintf (ds->asmop.buf_asm, sizeof (ds->asmop.buf_asm) - 11,
|
||||
".string \"%s\"", meta->str);
|
||||
r_asm_op_set_asm (&ds->asmop, sdb_fmt (".string \"%s\"", meta->str));
|
||||
break;
|
||||
// case R_META_TYPE_DATA:
|
||||
// break;
|
||||
default:
|
||||
snprintf (ds->asmop.buf_asm, sizeof (ds->asmop.buf_asm),
|
||||
".hex %.*s", (int)sizeof (ds->asmop.buf_asm) - 6, ds->asmop.buf_hex);
|
||||
r_asm_op_set_asm (&ds->asmop, sdb_fmt (".hex %s", r_asm_op_get_hex (&ds->asmop)));
|
||||
break;
|
||||
}
|
||||
ds->asmop.buf_asm[sizeof (ds->asmop.buf_asm) - 1] = 0;
|
||||
// strcpy (ds->asmop.buf_hex, "0102030405060708");
|
||||
//return i;
|
||||
ds->oplen = sz; //ds->asmop.size;
|
||||
@ -2165,7 +2167,7 @@ static int ds_disassemble(RDisasmState *ds, ut8 *buf, int len) {
|
||||
}
|
||||
|
||||
if (ds->show_nodup) {
|
||||
const char *opname = (ret < 1)? "invalid": ds->asmop.buf_asm;
|
||||
const char *opname = (ret < 1)? "invalid": r_asm_op_get_asm (&ds->asmop);
|
||||
if (ds->prev_ins && !strcmp (ds->prev_ins, opname)) {
|
||||
if (!ds->prev_ins_eq) {
|
||||
ds->prev_ins_eq = true;
|
||||
@ -2182,7 +2184,7 @@ static int ds_disassemble(RDisasmState *ds, ut8 *buf, int len) {
|
||||
if (ds->prev_ins) {
|
||||
R_FREE (ds->prev_ins);
|
||||
}
|
||||
ds->prev_ins = strdup (ds->asmop.buf_asm);
|
||||
ds->prev_ins = strdup (r_asm_op_get_asm (&ds->asmop));
|
||||
}
|
||||
ds->oplen = ds->asmop.size;
|
||||
|
||||
@ -2210,15 +2212,16 @@ static int ds_disassemble(RDisasmState *ds, ut8 *buf, int len) {
|
||||
if (ds->pseudo) {
|
||||
r_parse_parse (core->parser, ds->opstr
|
||||
? ds->opstr
|
||||
: ds->asmop.buf_asm,
|
||||
: r_asm_op_get_asm (&ds->asmop),
|
||||
ds->str);
|
||||
free (ds->opstr);
|
||||
ds->opstr = strdup (ds->str);
|
||||
}
|
||||
if (ds->acase) {
|
||||
r_str_case (ds->asmop.buf_asm, 1);
|
||||
r_str_case (r_asm_op_get_asm (&ds->asmop), 1);
|
||||
} else if (ds->capitalize) {
|
||||
ds->asmop.buf_asm[0] = toupper (ds->asmop.buf_asm[0]);
|
||||
char *ba = r_asm_op_get_asm (&ds->asmop);
|
||||
*ba = toupper (*ba);
|
||||
}
|
||||
if (info && mt_sz != UT64_MAX) {
|
||||
ds->oplen = mt_sz;
|
||||
@ -2920,7 +2923,7 @@ static void ds_print_show_bytes(RDisasmState *ds) {
|
||||
pad[j] = '\0';
|
||||
str = strdup ("");
|
||||
} else {
|
||||
str = strdup (ds->asmop.buf_hex);
|
||||
str = strdup (r_asm_op_get_hex (&ds->asmop));
|
||||
if (r_str_ansi_len (str) > ds->nb) {
|
||||
char *p = (char *)r_str_ansi_chrn (str, ds->nb);
|
||||
if (p) {
|
||||
@ -4359,7 +4362,7 @@ static void ds_print_comments_right(RDisasmState *ds) {
|
||||
RCore *core = ds->core;
|
||||
ds_print_relocs (ds);
|
||||
if (ds->asm_describe && !ds->has_description) {
|
||||
char *op, *locase = strdup (ds->asmop.buf_asm);
|
||||
char *op, *locase = strdup (r_asm_op_get_asm (&ds->asmop));
|
||||
if (!locase) {
|
||||
return;
|
||||
}
|
||||
@ -5097,9 +5100,9 @@ R_API int r_core_print_disasm_instructions(RCore *core, int nb_bytes, int nb_opc
|
||||
hasanal = true;
|
||||
}
|
||||
tmpopstr = r_anal_op_to_string (core->anal, &ds->analop);
|
||||
ds->opstr = (tmpopstr)? tmpopstr: strdup (ds->asmop.buf_asm);
|
||||
ds->opstr = (tmpopstr)? tmpopstr: strdup (r_asm_op_get_asm (&ds->asmop));
|
||||
} else if (ds->immtrim) {
|
||||
ds->opstr = strdup (ds->asmop.buf_asm);
|
||||
ds->opstr = strdup (r_asm_op_get_asm (&ds->asmop));
|
||||
r_parse_immtrim (ds->opstr);
|
||||
} else if (ds->use_esil) {
|
||||
if (!hasanal) {
|
||||
@ -5130,8 +5133,8 @@ R_API int r_core_print_disasm_instructions(RCore *core, int nb_bytes, int nb_opc
|
||||
}
|
||||
core->parser->hint = ds->hint;
|
||||
ds->hint = NULL;
|
||||
r_parse_filter (core->parser, core->flags, ds->asmop.buf_asm, ds->str,
|
||||
sizeof (ds->str), core->print->big_endian);
|
||||
r_parse_filter (core->parser, core->flags, r_asm_op_get_asm (&ds->asmop),
|
||||
ds->str, sizeof (ds->str), core->print->big_endian);
|
||||
ds->opstr = strdup (ds->str);
|
||||
asm_str = colorize_asm_string (core, ds, true);
|
||||
core->parser->flagspace = ofs;
|
||||
@ -5139,10 +5142,11 @@ R_API int r_core_print_disasm_instructions(RCore *core, int nb_bytes, int nb_opc
|
||||
ds->opstr = asm_str;
|
||||
core->parser->flagspace = ofs; // ???
|
||||
} else {
|
||||
ds->opstr = strdup (ds->asmop.buf_asm);
|
||||
ds->opstr = strdup (r_asm_op_get_asm (&ds->asmop));
|
||||
}
|
||||
if (ds->immtrim) {
|
||||
ds->opstr = strdup (ds->asmop.buf_asm);
|
||||
free (ds->opstr);
|
||||
ds->opstr = strdup (r_asm_op_get_asm (&ds->asmop));
|
||||
r_parse_immtrim (ds->opstr);
|
||||
}
|
||||
}
|
||||
@ -5291,22 +5295,30 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte
|
||||
result = true;
|
||||
continue;
|
||||
}
|
||||
char *opstr = strdup (asmop.buf_asm);
|
||||
char *opstr = strdup (r_asm_op_get_asm (&asmop));
|
||||
|
||||
ds->has_description = false;
|
||||
r_anal_op_fini (&ds->analop);
|
||||
r_anal_op (core->anal, &ds->analop, at, buf + i, nb_bytes - i, R_ANAL_OP_MASK_ALL);
|
||||
|
||||
if (ds->pseudo) {
|
||||
r_parse_parse (core->parser, asmop.buf_asm, asmop.buf_asm);
|
||||
char *aba = r_asm_op_get_asm (&asmop);
|
||||
r_parse_parse (core->parser, aba, aba);
|
||||
}
|
||||
|
||||
// f = r_anal_get_fcn_in (core->anal, at,
|
||||
f = fcnIn (ds, at, R_ANAL_FCN_TYPE_FCN | R_ANAL_FCN_TYPE_SYM);
|
||||
if (ds->varsub && f) {
|
||||
core->parser->varlist = r_anal_var_list_dynamic;
|
||||
r_parse_varsub (core->parser, f, at, ds->analop.size,
|
||||
asmop.buf_asm, asmop.buf_asm, sizeof (asmop.buf_asm));
|
||||
int ba_len = r_strbuf_length (&asmop.buf_asm) + 128;
|
||||
char *ba = malloc (ba_len);
|
||||
if (ba) {
|
||||
strcpy (ba, r_asm_op_get_asm (&asmop));
|
||||
r_parse_varsub (core->parser, f, at, ds->analop.size,
|
||||
ba, ba, ba_len);
|
||||
r_asm_op_set_asm (&asmop, ba);
|
||||
free (ba);
|
||||
}
|
||||
}
|
||||
oplen = r_asm_op_get_size (&asmop);
|
||||
ds->oplen = oplen;
|
||||
@ -5324,7 +5336,7 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte
|
||||
core->parser->relsub_addr = killme;
|
||||
}
|
||||
}
|
||||
r_parse_filter (core->parser, core->flags, asmop.buf_asm, str,
|
||||
r_parse_filter (core->parser, core->flags, r_asm_op_get_asm (&asmop), str,
|
||||
sizeof (str), core->print->big_endian);
|
||||
|
||||
r_cons_printf (j > 0 ? ",{" : "{");
|
||||
@ -5502,31 +5514,29 @@ R_API int r_core_print_disasm_all(RCore *core, ut64 addr, int l, int len, int mo
|
||||
count ++;
|
||||
switch (mode) {
|
||||
case 'i':
|
||||
r_parse_filter (core->parser, core->flags, asmop.buf_asm,
|
||||
r_parse_filter (core->parser, core->flags, r_asm_op_get_asm (&asmop),
|
||||
str, sizeof (str), core->print->big_endian);
|
||||
if (scr_color) {
|
||||
char *buf_asm;
|
||||
RAnalOp aop;
|
||||
RAnalFunction *f = fcnIn (ds, ds->vat, R_ANAL_FCN_TYPE_NULL);
|
||||
r_anal_op (core->anal, &aop, addr, buf+i, l-i, R_ANAL_OP_MASK_ALL);
|
||||
buf_asm = r_print_colorize_opcode (core->print, str,
|
||||
char *buf_asm = r_print_colorize_opcode (core->print, str,
|
||||
core->cons->pal.reg, core->cons->pal.num, false, f ? f->addr : 0);
|
||||
r_cons_printf ("%s%s\n",
|
||||
r_print_color_op_type (core->print, aop.type),
|
||||
buf_asm);
|
||||
free (buf_asm);
|
||||
if (buf_asm) {
|
||||
r_cons_printf ("%s%s\n", r_print_color_op_type (core->print, aop.type), buf_asm);
|
||||
free (buf_asm);
|
||||
}
|
||||
} else {
|
||||
r_cons_println (asmop.buf_asm);
|
||||
r_cons_println (r_asm_op_get_asm (&asmop));
|
||||
}
|
||||
break;
|
||||
case '=':
|
||||
if (i < 28) {
|
||||
char *str = r_str_newf ("0x%08"PFMT64x" %60s %s\n",
|
||||
ds->vat, "", asmop.buf_asm);
|
||||
char *str = r_str_newf ("0x%08"PFMT64x" %60s %s\n", ds->vat, "", r_asm_op_get_asm (&asmop));
|
||||
char *sp = strchr (str, ' ');
|
||||
if (sp) {
|
||||
char *end = sp + 60 + 1;
|
||||
const char *src = asmop.buf_hex;
|
||||
const char *src = r_asm_op_get_hex (&asmop);
|
||||
char *dst = sp + 1 + (i * 2);
|
||||
int len = strlen (src);
|
||||
if (dst < end) {
|
||||
@ -5543,11 +5553,12 @@ R_API int r_core_print_disasm_all(RCore *core, ut64 addr, int l, int len, int mo
|
||||
break;
|
||||
case 'j':
|
||||
r_cons_printf ("{\"addr\":%08"PFMT64d",\"bytes\":\"%s\",\"inst\":\"%s\"}%s",
|
||||
addr + i, asmop.buf_hex, asmop.buf_asm, ",");
|
||||
addr + i, r_asm_op_get_hex (&asmop), r_asm_op_get_asm (&asmop), ",");
|
||||
break;
|
||||
default:
|
||||
r_cons_printf ("0x%08"PFMT64x" %20s %s\n",
|
||||
addr + i, asmop.buf_hex, asmop.buf_asm);
|
||||
addr + i, r_asm_op_get_hex (&asmop),
|
||||
r_asm_op_get_asm (&asmop));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5967,7 +5978,7 @@ toro:
|
||||
r_cons_println (esil);
|
||||
} else {
|
||||
if (decode) {
|
||||
opstr = (tmpopstr)? tmpopstr: (asmop.buf_asm);
|
||||
opstr = tmpopstr? tmpopstr: r_asm_op_get_asm (&(asmop));
|
||||
} else if (esil) {
|
||||
opstr = (R_STRBUF_SAFEGET (&analop.esil));
|
||||
}
|
||||
|
@ -152,12 +152,12 @@ R_API bool r_core_visual_esil(RCore *core) {
|
||||
r_cons_printf ("r2's esil debugger:\n\n");
|
||||
r_cons_printf ("pos: %d\n", x);
|
||||
{
|
||||
char *res = r_print_hexpair (core->print, asmop.buf_hex, -1);
|
||||
char *res = r_print_hexpair (core->print, r_asm_op_get_hex (&asmop), -1);
|
||||
r_cons_printf ("hex: %s\n"Color_RESET, res);
|
||||
free (res);
|
||||
}
|
||||
{
|
||||
char *op = colorize_asm_string (core, asmop.buf_asm, analopType, core->offset);
|
||||
char *op = colorize_asm_string (core, r_asm_op_get_asm (&asmop), analopType, core->offset);
|
||||
r_cons_printf (Color_RESET"asm: %s\n"Color_RESET, op);
|
||||
free (op);
|
||||
}
|
||||
@ -290,7 +290,7 @@ static bool edit_bits (RCore *core) {
|
||||
analopType = analop.type & R_ANAL_OP_TYPE_MASK;
|
||||
r_cons_printf ("r2's bit editor:\n\n");
|
||||
{
|
||||
char *res = r_print_hexpair (core->print, asmop.buf_hex, -1);
|
||||
char *res = r_print_hexpair (core->print, r_asm_op_get_hex (&asmop), -1);
|
||||
r_cons_printf ("hex: %s\n"Color_RESET, res);
|
||||
free (res);
|
||||
}
|
||||
@ -300,7 +300,7 @@ static bool edit_bits (RCore *core) {
|
||||
r_cons_printf ("shift: >> %d << %d\n", word, (asmop.size * 8) - word - 1);
|
||||
}
|
||||
{
|
||||
char *op = colorize_asm_string (core, asmop.buf_asm, analopType, core->offset);
|
||||
char *op = colorize_asm_string (core, r_asm_op_get_asm (&asmop), analopType, core->offset);
|
||||
r_cons_printf (Color_RESET"asm: %s\n"Color_RESET, op);
|
||||
free (op);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ extern "C" {
|
||||
|
||||
R_LIB_VERSION_HEADER(r_asm);
|
||||
|
||||
// XXX too big!
|
||||
// XXX deprecate!!! too big!
|
||||
// the 256th character is left for the null terminator
|
||||
#define R_ASM_BUFSIZE 255
|
||||
|
||||
@ -66,21 +66,25 @@ enum {
|
||||
};
|
||||
|
||||
typedef struct r_asm_op_t {
|
||||
int size; // instruction size
|
||||
int bitsize; // instruction size in bits (or 0 if fits in 8bit bytes)
|
||||
int size; // instruction size (must be deprecated. just use buf.len
|
||||
int bitsize; // instruction size in bits (or 0 if fits in 8bit bytes) // wtf why dupe this field? :D
|
||||
int payload; // size of payload (opsize = (size-payload))
|
||||
// But this is pretty slow..so maybe we should add some accessors
|
||||
ut8 buf[R_ASM_BUFSIZE + 1];
|
||||
char buf_asm[R_ASM_BUFSIZE + 1];
|
||||
char buf_hex[R_ASM_BUFSIZE + 1];
|
||||
RBuffer *buf_inc;
|
||||
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;
|
||||
#else
|
||||
RAsmOp op; // we have those fields already inside RAsmOp
|
||||
#endif
|
||||
RList *equs; // TODO: must be a hash
|
||||
ut64 code_offset;
|
||||
ut64 data_offset;
|
||||
@ -120,7 +124,7 @@ typedef struct r_asm_t {
|
||||
int seggrn;
|
||||
} RAsm;
|
||||
|
||||
typedef int (*RAsmModifyCallback)(RAsm *a, ut8 *buf, int field, ut64 val);
|
||||
typedef bool (*RAsmModifyCallback)(RAsm *a, ut8 *buf, int field, ut64 val);
|
||||
|
||||
typedef struct r_asm_plugin_t {
|
||||
const char *name;
|
||||
@ -146,9 +150,8 @@ typedef struct r_asm_plugin_t {
|
||||
#ifdef R_API
|
||||
/* asm.c */
|
||||
R_API RAsm *r_asm_new(void);
|
||||
#define r_asm_op_free free
|
||||
R_API RAsm *r_asm_free(RAsm *a);
|
||||
R_API int r_asm_modify(RAsm *a, ut8 *buf, int field, ut64 val);
|
||||
R_API bool r_asm_modify(RAsm *a, ut8 *buf, int field, ut64 val);
|
||||
R_API char *r_asm_mnemonics(RAsm *a, int id, bool json);
|
||||
R_API int r_asm_mnemonics_byname(RAsm *a, const char *name);
|
||||
R_API void r_asm_set_user_ptr(RAsm *a, void *user);
|
||||
@ -187,10 +190,25 @@ 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);
|
||||
|
||||
/* op.c */
|
||||
R_API RAsmOp *r_asm_op_new();
|
||||
R_API void r_asm_op_free(RAsmOp *op);
|
||||
R_API void r_asm_op_init(RAsmOp *op);
|
||||
R_API void r_asm_op_fini(RAsmOp *op);
|
||||
R_API char *r_asm_op_get_hex(RAsmOp *op);
|
||||
R_API char *r_asm_op_get_asm(RAsmOp *op);
|
||||
R_API int r_asm_op_get_size(RAsmOp *op);
|
||||
R_API void r_asm_op_set_asm(RAsmOp *op, const char *str);
|
||||
R_API void r_asm_op_set_hex(RAsmOp *op, const char *str);
|
||||
R_API void r_asm_op_set_hexbuf(RAsmOp *op, const ut8 *buf, int len);
|
||||
R_API void r_asm_op_set_buf(RAsmOp *op, const ut8 *str, int len);
|
||||
|
||||
#if 0
|
||||
// accessors, to make bindings happy
|
||||
R_API char *r_asm_op_get_hex(RAsmOp *op);
|
||||
R_API char *r_asm_op_get_asm(RAsmOp *op);
|
||||
R_API int r_asm_op_get_size(RAsmOp *op);
|
||||
#endif
|
||||
|
||||
/* plugin pointers */
|
||||
extern RAsmPlugin r_asm_plugin_bf;
|
||||
|
@ -74,6 +74,7 @@ R_API int r_buf_fread_at(RBuffer *b, ut64 addr, ut8 *buf, const char *fmt, int n
|
||||
R_API int r_buf_write_at(RBuffer *b, ut64 addr, const ut8 *buf, int len);
|
||||
R_API int r_buf_fwrite_at(RBuffer *b, ut64 addr, ut8 *buf, const char *fmt, int n);
|
||||
R_API void r_buf_free(RBuffer *b);
|
||||
R_API void r_buf_fini(RBuffer *b);
|
||||
R_API char *r_buf_free_to_string(RBuffer *b);
|
||||
R_API const ut8 *r_buf_buffer(RBuffer *b);
|
||||
R_API ut64 r_buf_size(RBuffer *b);
|
||||
|
@ -6,24 +6,28 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
char buf[32];
|
||||
int len;
|
||||
char *ptr;
|
||||
int ptrlen;
|
||||
char buf[64];
|
||||
} RStrBuf;
|
||||
|
||||
#define R_STRBUF_SAFEGET(sb) (r_strbuf_get (sb) ? r_strbuf_get (sb) : "")
|
||||
R_API RStrBuf *r_strbuf_new(const char *s);
|
||||
R_API bool r_strbuf_set(RStrBuf *sb, const char *s);
|
||||
R_API bool r_strbuf_setbin(RStrBuf *sb, const ut8 *s, int len);
|
||||
R_API ut8* r_strbuf_getbin(RStrBuf *sb, int *len);
|
||||
R_API bool r_strbuf_setf(RStrBuf *sb, const char *fmt, ...);
|
||||
R_API int r_strbuf_append(RStrBuf *sb, const char *s);
|
||||
R_API int r_strbuf_append_n(RStrBuf *sb, const char *s, int l);
|
||||
R_API int r_strbuf_appendf(RStrBuf *sb, const char *fmt, ...);
|
||||
R_API char *r_strbuf_get(RStrBuf *sb);
|
||||
R_API char *r_strbuf_drain(RStrBuf *sb);
|
||||
R_API int r_strbuf_length(RStrBuf *sb);
|
||||
R_API void r_strbuf_free(RStrBuf *sb);
|
||||
R_API void r_strbuf_fini(RStrBuf *sb);
|
||||
R_API void r_strbuf_init(RStrBuf *sb);
|
||||
R_API bool r_strbuf_equals(RStrBuf *sa, RStrBuf *sb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -837,11 +837,14 @@ R_API void r_buf_deinit(RBuffer *b) {
|
||||
} else R_FREE (b->buf);
|
||||
}
|
||||
|
||||
R_API void r_buf_free(RBuffer *b) {
|
||||
R_API void r_buf_fini(RBuffer *b) {
|
||||
if (!b) {
|
||||
return;
|
||||
}
|
||||
if (b->parent) {
|
||||
if (b->parent == b) {
|
||||
return;
|
||||
}
|
||||
r_buf_free (b->parent);
|
||||
b->parent = NULL;
|
||||
}
|
||||
@ -852,7 +855,11 @@ R_API void r_buf_free(RBuffer *b) {
|
||||
if (!b->ro) {
|
||||
r_buf_deinit (b);
|
||||
}
|
||||
R_FREE (b);
|
||||
}
|
||||
|
||||
R_API void r_buf_free(RBuffer *b) {
|
||||
r_buf_fini (b);
|
||||
free (b);
|
||||
}
|
||||
|
||||
R_API int r_buf_append_string (RBuffer *b, const char *str) {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user