1 /* radare - LGPL - Copyright 2014-2018 condret, pancake */
2
3 #include <r_asm.h>
4 #include <r_types.h>
5 #include <r_lib.h>
6 #include <string.h>
7
mal_dis(ut64 c,const ut8 * buf,ut64 len)8 static const char *mal_dis(ut64 c, const ut8 *buf, ut64 len) {
9 if (len) {
10 switch ((buf[0] + c) % 94) {
11 case 4: return "jmp [d]";
12 case 5: return "out a";
13 case 23: return "in a";
14 case 39: return "rotr [d], mov a, [d]";
15 case 40: return "mov d, [d]";
16 case 62: return "crz [d], a, mov a, [d]";
17 case 81: return "end";
18 default: return "nop";
19 }
20 }
21 return NULL;
22 }
23
__disassemble(RAsm * a,RAsmOp * op,const ut8 * buf,int len)24 static int __disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
25 const char *opstr = mal_dis (a->pc, buf, len);
26 return op->size = opstr? 1: 0;
27 }
28
29 RAsmPlugin r_asm_plugin_malbolge = {
30 .name = "malbolge",
31 .desc = "Malbolge Ternary VM",
32 .arch = "malbolge",
33 .author = "condret",
34 .license = "LGPL3",
35 .bits = 32,
36 .endian = R_SYS_ENDIAN_NONE,
37 .disassemble = &__disassemble
38 };
39
40 #ifndef R2_PLUGIN_INCORE
41 R_API RLibStruct radare_plugin = {
42 .type = R_LIB_TYPE_ASM,
43 .data = &r_asm_plugin_malbolge,
44 .version = R2_VERSION
45 };
46 #endif
47