* Added mdisassemble into r_asm

* Update r_asm vapi
This commit is contained in:
Nibble 2009-04-27 00:34:54 +02:00
parent 8af1004c04
commit 438028a7ae
4 changed files with 26 additions and 9 deletions

View file

@ -233,6 +233,24 @@ R_API int r_asm_assemble(struct r_asm_t *a, struct r_asm_aop_t *aop, char *buf)
return ret;
}
R_API u64 r_asm_mdisassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64 len)
{
int ret;
u64 idx;
char buf_asm[R_ASM_BUFSIZE];
for(idx = ret = 0, buf_asm[0] = '\0'; idx < len; idx+=ret) {
r_asm_set_pc(a, a->pc + idx);
if (!(ret = r_asm_disassemble(a, aop, buf+idx, len-idx)))
return 0;
strcat(buf_asm, aop->buf_asm);
if (idx + ret < len) strcat(buf_asm, "\n");
}
strncpy(aop->buf_asm, buf_asm, R_ASM_BUFSIZE);
return idx;
}
R_API int r_asm_massemble(struct r_asm_t *a, struct r_asm_aop_t *aop, char *buf)
{
struct {

View file

@ -36,7 +36,7 @@ static int rasm_disasm(char *buf, u64 offset, u64 len, int ascii, int bin)
u8 *data;
char *ptr = buf;
int ret = 0;
u64 idx, word = 0, clen = 0;
u64 word = 0, clen = 0;
if (bin) {
clen = len; //XXX
@ -58,14 +58,11 @@ static int rasm_disasm(char *buf, u64 offset, u64 len, int ascii, int bin)
len = clen;
for(idx=ret=0; idx < len; idx+=ret) {
r_asm_set_pc(&a, offset + idx);
if (!(ret = r_asm_disassemble(&a, &aop, data+idx, len-idx)))
return 0;
printf("%s\n", aop.buf_asm);
}
if (!(ret = r_asm_mdisassemble(&a, &aop, data, len)))
return 0;
printf("%s\n", aop.buf_asm);
return (int)idx;
return ret;
}
static int rasm_asm(char *buf, u64 offset, u64 len, int bin)

View file

@ -42,7 +42,7 @@ struct r_asm_handle_t {
int (*fini)(void *user);
int (*disassemble)(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64 len);
int (*assemble)(struct r_asm_t *a, struct r_asm_aop_t *aop, char *buf);
int (*set_subarch)(struct r_asm_t *a, char *buf);
int (*set_subarch)(struct r_asm_t *a, const char *buf);
struct list_head list;
};
@ -60,6 +60,7 @@ R_API int r_asm_set_syntax(struct r_asm_t *a, int syntax);
R_API int r_asm_set_pc(struct r_asm_t *a, u64 pc);
R_API int r_asm_disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64 len);
R_API int r_asm_assemble(struct r_asm_t *a, struct r_asm_aop_t *aop, char *buf);
R_API u64 r_asm_mdisassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64 len);
R_API int r_asm_massemble(struct r_asm_t *a, struct r_asm_aop_t *aop, char *buf);
/* plugin pointers */

View file

@ -72,6 +72,7 @@ namespace Radare {
public bool set_parser(Asm.Parser parser, parse_cb cb, void *aux);
public int disassemble(out Aop aop, uint8 *buf, uint64 length);
public int assemble(out Aop aop, string buf);
public uint64 mdisassemble(out Aop aop, uint8 *buf, uint64 length);
public int massemble(out Aop aop, string buf);
public int parse();
public void free();