mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-20 12:18:18 +00:00
777235bb87
- Added arm plugin - Added bf plugin - Added csr plugin - Added m68k plugin - Added mips plugin - Added ppc plugin - Added sparc plugin - Removed deprecated test programs - Updated rasm2 (not working) * r_parse - Initial import --HG-- rename : libr/asm/arch/arm/asm.c => libr/asm/p/asm_arm.c rename : libr/asm/arch/bf/asm.c => libr/asm/p/asm_bf.c rename : libr/asm/arch/csr/asm.c => libr/asm/p/asm_csr.c rename : libr/asm/arch/m68k/asm.c => libr/asm/p/asm_m68k.c rename : libr/asm/arch/mips/asm.c => libr/asm/p/asm_mips.c rename : libr/asm/arch/ppc/asm.c => libr/asm/p/asm_ppc.c rename : libr/asm/arch/sparc/asm.c => libr/asm/p/asm_sparc.c rename : libr/asm/arch/x86/pseudo.c => libr/parse/pseudo.c
80 lines
1.7 KiB
C
80 lines
1.7 KiB
C
/* radare - LGPL - Copyright 2009 pancake <youterm.com> - nibble<.ds@gmail.com> */
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include <r_types.h>
|
|
#include <r_lib.h>
|
|
#include <r_asm.h>
|
|
|
|
|
|
static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64 len)
|
|
{
|
|
int i;
|
|
char *buf_cp, *b;
|
|
|
|
if ((b = buf_cp = alloca(len+1)) == NULL)
|
|
return 0;
|
|
memcpy(buf_cp, buf, len+1);
|
|
|
|
for(i=0;b[0] == b[1] && i<len; b=b+1,i++); b[1] = '\0';
|
|
|
|
strncpy(aop->buf_hex, buf_cp, 256);
|
|
|
|
switch(buf[0]) {
|
|
case '[':
|
|
strcpy(aop->buf_asm, "[ loop {");
|
|
break;
|
|
case ']':
|
|
strcpy(aop->buf_asm, "] }"); // TODO: detect clause and put label name
|
|
break;
|
|
case '>':
|
|
if (i>1) strcpy(aop->buf_asm, "> add [ptr]");
|
|
else strcpy(aop->buf_asm, "> inc [ptr]");
|
|
break;
|
|
case '<':
|
|
if (i>1) strcpy(aop->buf_asm, "< sub [ptr]");
|
|
else strcpy(aop->buf_asm, "< dec [ptr]");
|
|
break;
|
|
case '+':
|
|
if (i>1) strcpy(aop->buf_asm, "+ add [ptr]");
|
|
else strcpy(aop->buf_asm, "+ inc [ptr]");
|
|
break;
|
|
case '-':
|
|
if (i>1) strcpy(aop->buf_asm, "- sub [ptr]");
|
|
else strcpy(aop->buf_asm, "- dec [ptr]");
|
|
break;
|
|
case ',':
|
|
strcpy(aop->buf_asm, ", [ptr] = getch()");
|
|
break;
|
|
case '.':
|
|
strcpy(aop->buf_asm, ". print( [ptr] )");
|
|
break;
|
|
case '\x00':
|
|
strcpy(aop->buf_asm, " trap");
|
|
break;
|
|
default:
|
|
strcpy(aop->buf_asm, " nop");
|
|
break;
|
|
}
|
|
|
|
if (i>0) sprintf(aop->buf_asm, "%s, %d", aop->buf_asm, i+1);
|
|
if (i<1) i=1; else i++;
|
|
|
|
return i;
|
|
}
|
|
|
|
static struct r_asm_handle_t r_asm_plugin_bf = {
|
|
.name = "asm_bf",
|
|
.desc = "BF disassembly plugin",
|
|
.init = NULL,
|
|
.fini = NULL,
|
|
.disassemble = &disassemble,
|
|
.assemble = NULL
|
|
};
|
|
|
|
struct r_lib_struct_t radare_plugin = {
|
|
.type = R_LIB_TYPE_ASM,
|
|
.data = &r_asm_plugin_bf
|
|
};
|