-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Malbolge disasm and analysis
- Loading branch information
Showing
10 changed files
with
148 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <r_anal.h> | ||
#include <r_types.h> | ||
#include <r_lib.h> | ||
|
||
static int mal_anal(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len) | ||
{ | ||
memset(op, '\0', sizeof(RAnalOp)); | ||
if(len) { | ||
switch ((data[0]+addr)%94) { | ||
case 4: | ||
op->type = R_ANAL_OP_TYPE_UJMP; | ||
break; | ||
case 5: | ||
case 23: | ||
op->type = R_ANAL_OP_TYPE_IO; | ||
break; | ||
case 39: | ||
op->type = R_ANAL_OP_TYPE_ROR; | ||
// op->type2 = R_ANAL_OP_TYPE_LOAD; | ||
break; | ||
case 40: | ||
op->type = R_ANAL_OP_TYPE_LOAD; | ||
break; | ||
case 62: | ||
op->type = R_ANAL_OP_TYPE_XOR; | ||
// op->type2 = R_ANAL_OP_TYPE_LOAD; | ||
break; | ||
case 81: | ||
op->type = R_ANAL_OP_TYPE_TRAP; | ||
break; | ||
default: | ||
op->type = R_ANAL_OP_TYPE_NOP; | ||
} | ||
return op->size = 1; | ||
} | ||
return R_FALSE; | ||
} | ||
|
||
struct r_anal_plugin_t r_anal_plugin_malbolge = { | ||
.name = "malbolge", | ||
.desc = "Malbolge analysis plugin", | ||
.arch = R_SYS_ARCH_BF, | ||
.license = "LGPL3", | ||
.bits = 32, | ||
.init = NULL, | ||
.fini = NULL, | ||
.op = &mal_anal, | ||
.set_reg_profile = NULL, | ||
.fingerprint_bb = NULL, | ||
.fingerprint_fcn = NULL, | ||
.diff_bb = NULL, | ||
.diff_fcn = NULL, | ||
.diff_eval = NULL | ||
}; | ||
|
||
#ifndef CORELIB | ||
struct r_lib_struct_t radare_plugin = { | ||
.type = R_LIB_TYPE_ANAL, | ||
.data = &r_anal_plugin_malbolge | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
OBJ_MALBOLGE=anal_malbolge.o | ||
|
||
STATIC_OBJ+=${OBJ_MALBOLGE} | ||
TARGET_MALBOLGE=anal_malbolge.${EXT_SO} | ||
|
||
ALL_TARGETS+=${TARGET_MALBOLGE} | ||
|
||
${TARGET_MALBOLGE}: ${OBJ_MALBOLGE} | ||
${CC} $(call libname,anal_malbolge) ${LDFLAGS} ${CFLAGS} -o anal_malbolge.${EXT_SO} ${OBJ_MALBOLGE} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <r_asm.h> | ||
#include <r_types.h> | ||
#include <r_lib.h> | ||
#include <string.h> | ||
|
||
static int mal_dis(RAsmOp *op, ut64 c, 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],\tmov a, [d]"); | ||
break; | ||
case 40: | ||
sprintf(op->buf_asm, "mov d, [d]"); | ||
break; | ||
case 62: | ||
sprintf(op->buf_asm, "crz [d], a,\tmov a, [d]"); | ||
break; | ||
case 81: | ||
sprintf(op->buf_asm, "end"); | ||
break; | ||
default: | ||
sprintf(op->buf_asm, "nop"); | ||
} | ||
return R_TRUE; | ||
} | ||
return R_FALSE; | ||
} | ||
|
||
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, ut64 len) | ||
{ | ||
return op->size = mal_dis(op, a->pc, buf, len); | ||
} | ||
|
||
|
||
RAsmPlugin r_asm_plugin_malbolge = { | ||
.name = "malbolge", | ||
.desc = "Malbolge disassembler plugin", | ||
.arch = "malbolge", | ||
.license = "LGPL3", | ||
.bits = 32, | ||
.init = NULL, | ||
.fini = NULL, | ||
.disassemble = &disassemble, | ||
.assemble = NULL, | ||
}; | ||
|
||
#ifndef CORELIB | ||
struct r_lib_struct_t radare_plugin = { | ||
.type = R_LIB_TYPE_ASM, | ||
.data = &r_asm_plugin_malbolge | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
OBJ_MALBOLGE=asm_malbolge.o | ||
|
||
STATIC_OBJ+=${OBJ_MALBOLGE} | ||
TARGET_MALBOLGE=asm_malbolge.${EXT_SO} | ||
|
||
ALL_TARGETS+=${TARGET_MALBOLGE} | ||
|
||
${TARGET_MALBOLGE}: ${OBJ_MALBOLGE} | ||
${CC} ${call libname,asm_malbolge} ${CFLAGS} -o ${TARGET_MALBOLGE} ${OBJ_MALBOLGE} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters