forked from radareorg/radare2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WASM analysis - initial stub (radareorg#9091)
- Loading branch information
Showing
9 changed files
with
454 additions
and
359 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* radare2 - LGPL - Copyright 2017 - xvilka */ | ||
#include <string.h> | ||
#include <r_types.h> | ||
#include <r_lib.h> | ||
#include <r_asm.h> | ||
#include <r_anal.h> | ||
#include "../../asm/arch/wasm/wasm.h" | ||
#include "../../bin/format/wasm/wasm.h" | ||
|
||
ut64 cf_stack [128] = { 0 }; | ||
int cf_stack_ptr = 0; | ||
|
||
static ut64 get_cf_offset(RAnal *anal, const ut8 *data) | ||
{ | ||
char flgname[64] = {0}; | ||
st32 n; | ||
read_i32_leb128 (data, data + 1, &n); | ||
sprintf(flgname, "fcn.%d", n); | ||
RFlagItem *fi = anal->flb.get (anal->flb.f, flgname); | ||
if (fi) return fi->offset; | ||
return (ut64)-1; | ||
} | ||
|
||
static int wasm_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len) { | ||
WasmOp wop = {0}; | ||
|
||
memset (op, '\0', sizeof (RAnalOp)); | ||
int ret = wasm_dis (&wop, data, len); | ||
op->size = ret; | ||
op->addr = addr; | ||
op->type = R_ANAL_OP_TYPE_UNK; | ||
op->id = wop.op; | ||
switch (wop.op) { | ||
/* Calls here are using index instead of address */ | ||
case WASM_OP_BLOCK: | ||
cf_stack_ptr++; | ||
break; | ||
case WASM_OP_CALL: | ||
case WASM_OP_CALLINDIRECT: | ||
op->type = R_ANAL_OP_TYPE_CALL; | ||
op->jump = get_cf_offset (anal, data); | ||
break; | ||
case WASM_OP_BR: | ||
op->type = R_ANAL_OP_TYPE_JMP; | ||
op->jump = get_cf_offset (anal, data); | ||
break; | ||
case WASM_OP_BRIF: | ||
op->type = R_ANAL_OP_TYPE_CJMP; | ||
op->jump = get_cf_offset (anal, data); | ||
break; | ||
default: | ||
break; | ||
} | ||
return op->size; | ||
} | ||
|
||
RAnalPlugin r_anal_plugin_wasm = { | ||
.name = "wasm", | ||
.desc = "WebAssembly analysis plugin", | ||
.license = "LGPL3", | ||
.arch = "wasm", | ||
.bits = 64, | ||
.op = &wasm_op, | ||
.esil = false, | ||
}; | ||
|
||
#ifndef CORELIB | ||
RLibStruct radare_plugin = { | ||
.type = R_LIB_TYPE_ANAL, | ||
.data = &r_anal_plugin_wasm, | ||
.version = R2_VERSION | ||
}; | ||
#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,12 @@ | ||
WASM_ROOT=../../asm/arch/wasm | ||
OBJ_WASM=anal_wasm.o | ||
OBJ_WASM+=$(WASM_ROOT)/wasm.o | ||
CFLAGS+=-I$(WASM_ROOT) | ||
|
||
STATIC_OBJ+=${OBJ_WASM} | ||
TARGET_WASM=anal_wasm.${EXT_SO} | ||
|
||
ALL_TARGETS+=${TARGET_WASM} | ||
|
||
${TARGET_WASM}: ${OBJ_WASM} | ||
${CC} $(call libname,anal_wasm) ${LDFLAGS} ${CFLAGS} -o anal_wasm.${EXT_SO} ${OBJ_WASM} |
Oops, something went wrong.