Break ABI. r_asm_disassemble's length is now 'int'

This commit is contained in:
pancake 2013-04-09 22:54:04 +02:00
parent 189e5553cc
commit 5285d1bdea
28 changed files with 54 additions and 63 deletions

View file

@ -281,7 +281,7 @@ R_API int r_asm_set_pc(RAsm *a, ut64 pc) {
return R_TRUE;
}
R_API int r_asm_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, ut64 len) {
R_API int r_asm_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
int ret = op->payload = 0;
if (a->cur && a->cur->disassemble)
ret = a->cur->disassemble (a, op, buf, len);
@ -328,7 +328,7 @@ R_API int r_asm_assemble(RAsm *a, RAsmOp *op, const char *buf) {
return ret;
}
R_API RAsmCode* r_asm_mdisassemble(RAsm *a, ut8 *buf, ut64 len) {
R_API RAsmCode* r_asm_mdisassemble(RAsm *a, ut8 *buf, int len) {
RAsmCode *acode;
int ret, slen;
RAsmOp op;

View file

@ -9,8 +9,7 @@
#include <r_asm.h>
#include "../arch/8051/8051.c"
// ut64 for length here is overkill!
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, ut64 len) {
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
Op8051 o = do8051struct (buf, len);
if (!o.name) return 0; // invalid instruction
do8051disasm (o, op->buf_asm, sizeof (op->buf_asm));

View file

@ -48,7 +48,7 @@ static int buf_fprintf(void *stream, const char *format, ...) {
}
int decodeInstr (bfd_vma address, disassemble_info * info);
static int disassemble(RAsm *a, struct r_asm_op_t *op, const ut8 *buf, ut64 len) {
static int disassemble(RAsm *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;

View file

@ -53,7 +53,7 @@ static int buf_fprintf(void *stream, const char *format, ...) {
return R_TRUE;
}
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, ut64 len) {
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
struct disassemble_info obj;
if (len<(a->bits/8)) return -1;

View file

@ -9,7 +9,7 @@
#include <r_asm.h>
#include "../arch/arm/winedbg/be_arm.h"
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, ut64 len) {
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
char buf2[4];
struct arm_insn *arminsn = arm_new();
arm_set_pc (arminsn, a->pc);

View file

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2010 pancake <@nopcode.org> */
/* radare - LGPL - Copyright 2010-2013 - pancake */
#include <stdio.h>
#include <stdarg.h>
@ -11,7 +11,7 @@
#include "../arch/avr/disasm.c"
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, ut64 len) {
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
return op->inst_len = avrdis (op->buf_asm, a->pc, buf, len);
}

View file

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2012 - pancake, nibble */
/* radare - LGPL - Copyright 2009-2013 - pancake, nibble */
#include <stdio.h>
#include <string.h>
@ -8,7 +8,7 @@
#include <r_asm.h>
static int disassemble(struct r_asm_t *a, struct r_asm_op_t *op, const ut8 *buf, ut64 len) {
static int disassemble(RAsm *a, struct r_asm_op_t *op, const ut8 *buf, int len) {
char *buf_cp, *b;
int i;

View file

@ -1,7 +1,6 @@
/* radare - LGPL - Copyright 2009-2010 nibble<.ds@gmail.com> */
/* radare - LGPL - Copyright 2009-2013 - nibble */
#include <stdio.h>
#include <r_types.h>
#include <r_lib.h>
#include <r_util.h>
@ -29,7 +28,7 @@ static int arch_csr_disasm(char *str, const unsigned char *buf, ut64 seek) {
#endif
return 0;
}
static int disassemble(struct r_asm_t *a, struct r_asm_op_t *op, const ut8 *buf, ut64 len) {
static int disassemble(RAsm *a, struct r_asm_op_t *op, const ut8 *buf, int len) {
arch_csr_disasm (op->buf_asm, buf, a->pc);
return (op->inst_len=2);
}

View file

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2012 - earada, pancake */
/* radare - LGPL - Copyright 2009-2013 - earada, pancake */
#include <stdio.h>
#include <string.h>
@ -9,7 +9,7 @@
#include <dalvik/opcode.h>
static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, ut64 len) {
static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
int i = (int) buf[0];
int vA, vB, vC;
char str[1024];

View file

@ -1,4 +1,4 @@
/* radare2 - LGPL - Copyright 2012 pancake<nopcode.org> */
/* radare2 - LGPL - Copyright 2012-2013 pancake */
#include <stdio.h>
#include <stdarg.h>
@ -10,7 +10,7 @@
#include "../arch/dcpu16/dcpu16.h"
// ut64 for length here is overkill!
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, ut64 len) {
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
if (len<2) return -1; // at least 2 bytes!
op->inst_len = dcpu16_disasm (op->buf_asm, (const ut16*)buf, len, NULL);
if (op->inst_len == -1)

View file

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2010-2011 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2010-2013 - pancake */
#include <r_types.h>
#include <r_util.h>
@ -6,11 +6,14 @@
#include <r_asm.h>
// XXX: TODO Implement
static int assemble(struct r_asm_t *a, struct r_asm_op_t *op, const char *buf) {
static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
int len = 0;
char cmd[R_ASM_BUFSIZE];
ut8 *out;
sprintf(cmd, "gas /dev/stdin -o /dev/stdout <<__\nBITS %i\nORG 0x%"PFMT64x"\n%s\n__", a->bits, a->pc, buf);
snprintf (cmd, sizeof (cmd),
"gas /dev/stdin -o /dev/stdout <<__\n"
"BITS %i\nORG 0x%"PFMT64x"\n%s\n__",
a->bits, a->pc, buf);
out = (ut8 *)r_sys_cmd_str(cmd, "", &len);
if (out) {
memcpy(op->buf, out, len<=R_ASM_BUFSIZE?len:R_ASM_BUFSIZE);

View file

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2012 - Alexander */
/* radare - LGPL - Copyright 2012-2013 - Alexander */
#include <r_types.h>
#include <r_util.h>
@ -7,7 +7,7 @@
#include "../arch/i8080/i8080dis.c"
static int do_disassemble(struct r_asm_t *a, struct r_asm_op_t *op, const ut8 *buf, ut64 len) {
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->inst_len = dlen;

View file

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2012 - nibble, pancake */
/* radare - LGPL - Copyright 2009-2013 - nibble, pancake */
#include <r_types.h>
#include <r_util.h>
@ -9,8 +9,7 @@
#include "../../shlr/java/code.h"
#include <r_core.h>
//static const char *lastfile = NULL;
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, ut64 len) {
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
//void *cp;
RBinJavaObj *obj = NULL;
RBin *b = a->binb.bin;
@ -20,15 +19,6 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, ut64 len) {
if (obj) r_java_setcp (obj->cp_items, obj->cf.cp_count);
}
}
// XXX: crossmodule dependency
// TODO: get class info from rbin if loaded
#if 0
RCore *core = (RCore*)a->user;
if (core && core->file && lastfile != core->file->filename) {
lastfile = core->file->filename;
java_classdump (lastfile, 0);
} else javasm_init ();
#endif
return op->inst_len = r_java_disasm (a->pc, buf,
op->buf_asm, sizeof (op->buf_asm));
}

View file

@ -1,4 +1,4 @@
/* radare - GPL3 - Copyright 2009-2012 nibble<.ds@gmail.com> */
/* radare - GPL3 - Copyright 2009-2013 - nibble */
#include <stdio.h>
#include <string.h>
@ -10,7 +10,7 @@
#include "m68k/m68k_disasm/m68k_disasm.h"
static int disassemble(RAsm *a, RAsmOp *aop, const ut8 *buf, ut64 len) {
static int disassemble(RAsm *a, RAsmOp *aop, const ut8 *buf, int len) {
m68k_word bof[4];
m68k_word iaddr = (m68k_word)a->pc;
char opcode[256];

View file

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2012 - pancake, nibble */
/* radare - LGPL - Copyright 2009-2013 - pancake, nibble */
#include <stdio.h>
#include <stdarg.h>
@ -55,7 +55,7 @@ static int buf_fprintf(void *stream, const char *format, ...) {
return R_TRUE;
}
static int disassemble(struct r_asm_t *a, struct r_asm_op_t *op, const ut8 *buf, ut64 len) {
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;
@ -63,7 +63,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_op_t *op, const ut8 *buf,
memcpy (bytes, buf, 4); // TODO handle thumb
/* prepare disassembler */
memset (&disasm_obj,'\0', sizeof(struct disassemble_info));
memset (&disasm_obj,'\0', sizeof (struct disassemble_info));
mips_mode = a->bits;
disasm_obj.arch = CPU_LOONGSON_2F;
disasm_obj.buffer = bytes;

View file

@ -20,7 +20,7 @@ static int arch_msil_disasm(char *str, const ut8 *buf, ut64 seek) {
return 0;
}
static int disassemble(struct r_asm_t *a, struct r_asm_op_t *op, const ut8 *buf, ut64 len) {
static int disassemble(RAsm *a, struct r_asm_op_t *op, const ut8 *buf, int len) {
arch_msil_disasm (op->buf_asm, buf, a->pc);
return (op->inst_len=2);
}

View file

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2010 nibble<.ds@gmail.com> */
/* radare - LGPL - Copyright 2009-2013 - nibble */
#include <stdio.h>
#include <stdarg.h>
@ -57,7 +57,7 @@ static int buf_fprintf(void *stream, const char *format, ...) {
return 0;
}
static int disassemble(struct r_asm_t *a, struct r_asm_op_t *op, const ut8 *buf, ut64 len) {
static int disassemble(RAsm *a, struct r_asm_op_t *op, const ut8 *buf, int len) {
static struct disassemble_info disasm_obj;
if (len<4)
return -1;

View file

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2010 nibble<.ds@gmail.com> */
/* radare - LGPL - Copyright 2009-2013 - nibble */
#include <r_types.h>
#include <r_util.h>
@ -6,14 +6,14 @@
#include <r_asm.h>
#include <psosvm/vmas/vmas.h>
static int disassemble(struct r_asm_t *a, struct r_asm_op_t *op, const ut8 *buf, ut64 len) {
static int disassemble(RAsm *a, struct r_asm_op_t *op, const ut8 *buf, int len) {
psosvmasm_init();
op->inst_len = psosvm_disasm(buf, op->buf_asm);
return op->inst_len;
}
static int assemble(struct r_asm_t *a, struct r_asm_op_t *op, const char *buf) {
static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
op->inst_len = psosvm_assemble(op->buf, buf);
return op->inst_len;
}

View file

@ -9,7 +9,7 @@
#include <r_asm.h>
#include "../../shlr/rar/all.c"
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, ut64 len) {
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
// TODO: support bitsize opcodes
// rarvm_disassemble (&b, str);
return 0;

View file

@ -52,7 +52,7 @@ static int buf_fprintf(void *stream, const char *format, ...) {
return ret;
}
static int disassemble(RAsm *a, struct r_asm_op_t *op, const ut8 *buf, ut64 len) {
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;

View file

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2011 - nibble */
/* radare - LGPL - Copyright 2009-2013 - nibble */
#include <stdio.h>
#include <stdarg.h>
@ -47,7 +47,7 @@ static int buf_fprintf(void *stream, const char *format, ...) {
return 0;
}
static int disassemble(RAsm *a, struct r_asm_op_t *op, const ut8 *buf, ut64 len) {
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
static struct disassemble_info disasm_obj;
if (len<4) return -1;
buf_global = op->buf_asm;

View file

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2012 - nibble */
/* radare - LGPL - Copyright 2009-2013 - nibble */
#include <stdio.h>
#include <string.h>
@ -43,7 +43,7 @@ static int modify(RAsm *a, ut8 *buf, int field, ut64 val) {
return ret;
}
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, ut64 len) {
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
static ud_t disasm_obj;
ud_init (&disasm_obj);
ud_set_syntax (&disasm_obj,

View file

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2011-2013 pancake */
#include <r_types.h>
#include <r_util.h>

View file

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2011 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2009-2013 - pancake */
#include <r_types.h>
#include <r_util.h>

View file

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2012 pancake, nibble */
/* radare - LGPL - Copyright 2009-2013 - pancake, nibble */
#include <stdio.h>
#include <string.h>
@ -9,7 +9,7 @@
#include "x86/ollyasm/disasm.h"
static int disassemble(struct r_asm_t *a, struct r_asm_op_t *op, const ut8 *buf, ut64 len) {
static int disassemble(struct r_asm_t *a, struct r_asm_op_t *op, const ut8 *buf, int len) {
t_disasm disasm_obj;
op->inst_len = Disasm_olly(buf, len, a->pc, &disasm_obj, DISASM_FILE);

View file

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2012 - pancake */
/* radare - LGPL - Copyright 2012-2013 - pancake */
#include <r_types.h>
#include <r_util.h>
@ -11,7 +11,7 @@ static int do_assemble(RAsm *a, RAsmOp *op, const char *buf) {
return op->inst_len = z80asm (op->buf, buf);
}
static int do_disassemble(struct r_asm_t *a, struct r_asm_op_t *op, const ut8 *buf, ut64 len) {
static int do_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
int dlen = z80dis (0, buf, op->buf_asm, len);
if (dlen<0) dlen = 0;
op->inst_len = dlen;

View file

@ -102,7 +102,7 @@ typedef struct r_asm_plugin_t {
int *bits;
int (*init)(void *user);
int (*fini)(void *user);
int (*disassemble)(RAsm *a, RAsmOp *op, const ut8 *buf, ut64 len);
int (*disassemble)(RAsm *a, RAsmOp *op, const ut8 *buf, int len);
int (*assemble)(RAsm *a, RAsmOp *op, const char *buf);
RAsmModifyCallback modify;
int (*set_subarch)(RAsm *a, const char *buf);
@ -122,9 +122,9 @@ R_API int r_asm_set_bits(RAsm *a, int bits);
R_API int r_asm_set_big_endian(RAsm *a, int boolean);
R_API int r_asm_set_syntax(RAsm *a, int syntax);
R_API int r_asm_set_pc(RAsm *a, ut64 pc);
R_API int r_asm_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, ut64 len);
R_API int r_asm_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len);
R_API int r_asm_assemble(RAsm *a, RAsmOp *op, const char *buf);
R_API RAsmCode* r_asm_mdisassemble(RAsm *a, ut8 *buf, ut64 len);
R_API RAsmCode* r_asm_mdisassemble(RAsm *a, ut8 *buf, int len);
R_API RAsmCode* r_asm_mdisassemble_hexstr(RAsm *a, const char *hexstr);
R_API RAsmCode* r_asm_massemble(RAsm *a, const char *buf);
R_API RAsmCode* r_asm_assemble_file(RAsm *a, const char *file);

View file

@ -161,9 +161,9 @@ public class RAsm {
public bool set_pc(uint64 addr);
public bool set_big_endian(bool big);
// TODO: Use Code? instead of op??
public int disassemble(out Op op, uint8* buf, uint64 length);
public int disassemble(out Op op, uint8* buf, int length);
public int assemble(out Op op, string buf);
public Code? mdisassemble(uint8 *buf, uint64 length);
public Code? mdisassemble(uint8 *buf, int length);
public Code? mdisassemble_hexstr(string hexstr);
public Code? massemble(string buf);
public Code? assemble_file(string file);