Rizin
unix-like reverse engineering framework and cli tools
asm_wasm.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2017-2018 pancake <pancake@nopcode.org>
2 // SPDX-FileCopyrightText: 2017-2018 cgvwzq
3 // SPDX-License-Identifier: LGPL-3.0-only
4 
5 // http://webassembly.org/docs/binary-encoding/#module-structure
6 
7 #include <stdio.h>
8 #include <string.h>
9 #include <rz_types.h>
10 #include <rz_lib.h>
11 #include <rz_asm.h>
12 
13 #include "../arch/wasm/wasm.h"
14 
15 static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
16  WasmOp wop = { { 0 } };
17  int ret = wasm_dis(&wop, buf, len);
18  rz_asm_op_set_asm(op, wop.txt);
19  free(wop.txt);
20  op->size = ret;
21  return op->size;
22 }
23 
24 static int assemble(RzAsm *a, RzAsmOp *op, const char *buf) {
25  ut8 *opbuf = (ut8 *)rz_strbuf_get(&op->buf);
26  op->size = wasm_asm(buf, opbuf, 32); // XXX hardcoded opsize
27  return op->size;
28 }
29 
31  .name = "wasm",
32  .author = "cgvwzq",
33  .version = "0.1.0",
34  .arch = "wasm",
35  .license = "MIT",
36  .bits = 32,
37  .endian = RZ_SYS_ENDIAN_LITTLE,
38  .desc = "WebAssembly",
39  .disassemble = &disassemble,
40  .assemble = &assemble
41 };
42 
43 #ifndef RZ_PLUGIN_INCORE
46  .data = &rz_asm_plugin_wasm,
48 };
49 #endif
size_t len
Definition: 6502dis.c:15
RZ_API void rz_asm_op_set_asm(RzAsmOp *op, const char *str)
Definition: aop.c:53
RZ_IPI int wasm_dis(WasmOp *op, const unsigned char *buf, int buf_len)
Definition: wasm.c:479
RZ_IPI int wasm_asm(const char *str, unsigned char *buf, int buf_len)
RZ_API RzLibStruct rizin_plugin
Definition: asm_wasm.c:44
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm_wasm.c:15
RzAsmPlugin rz_asm_plugin_wasm
Definition: asm_wasm.c:30
static int assemble(RzAsm *a, RzAsmOp *op, const char *buf)
Definition: asm_wasm.c:24
#define RZ_API
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
@ RZ_LIB_TYPE_ASM
Definition: rz_lib.h:72
RZ_API char * rz_strbuf_get(RzStrBuf *sb)
Definition: strbuf.c:321
#define RZ_SYS_ENDIAN_LITTLE
Definition: rz_types.h:526
#define RZ_VERSION
Definition: rz_version.h:8
#define a(i)
Definition: sha256.c:41
Definition: wasm.h:486
char * txt
Definition: wasm.h:494
const char * name
Definition: rz_asm.h:130
const char * version
Definition: rz_asm.h:133
Definition: dis.c:32