Rizin
unix-like reverse engineering framework and cli tools
wasm.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2017-2020 pancake <pancake@nopcode.org>
2 // SPDX-FileCopyrightText: 2017-2020 cgvwzq
3 // SPDX-License-Identifier: LGPL-3.0-only
4 
5 // http://webassembly.org/docs/binary-encoding/#module-structure
6 
7 #include <rz_asm.h>
8 #include <rz_lib.h>
9 #include <string.h>
10 
11 #include "wasm.h"
12 #include "../../../bin/format/wasm/wasm.h"
13 
14 static WasmOpDef opcodes[256] = {
15  [WASM_OP_TRAP] = { "trap", 1, 1 },
16  [WASM_OP_NOP] = { "nop", 1, 1 },
17  [WASM_OP_BLOCK] = { "block", 2, 2 },
18  [WASM_OP_LOOP] = { "loop", 2, 2 },
19  [WASM_OP_IF] = { "if", 2, 2 },
20  [WASM_OP_ELSE] = { "else", 1, 1 },
21  [WASM_OP_END] = { "end", 1, 1 },
22  [WASM_OP_BR] = { "br", 2, 2 },
23  [WASM_OP_BRIF] = { "br_if", 2, 2 },
24  [WASM_OP_BRTABLE] = { "brtable", 3, 0 },
25  [WASM_OP_RETURN] = { "return", 1, 1 },
26  [WASM_OP_CALL] = { "call", 2, 2 },
27  [WASM_OP_CALLINDIRECT] = { "call_indirect", 3, 3 },
28  [WASM_OP_DROP] = { "drop", 1, 1 },
29  [WASM_OP_SELECT] = { "select", 1, 1 },
30  [WASM_OP_GETLOCAL] = { "get_local", 2, 2 },
31  [WASM_OP_SETLOCAL] = { "set_local", 2, 2 },
32  [WASM_OP_TEELOCAL] = { "tee_local", 2, 2 },
33  [WASM_OP_GETGLOBAL] = { "get_global", 2, 2 },
34  [WASM_OP_SETGLOBAL] = { "set_global", 2, 2 },
35  [WASM_OP_I32LOAD] = { "i32.load", 3, 3 },
36  [WASM_OP_I64LOAD] = { "i64.load", 3, 3 },
37  [WASM_OP_F32LOAD] = { "f32.load", 3, 3 },
38  [WASM_OP_F64LOAD] = { "f64.load", 3, 3 },
39  [WASM_OP_I32LOAD8S] = { "i32.load8_s", 3, 3 },
40  [WASM_OP_I32LOAD8U] = { "i32.load8_u", 3, 3 },
41  [WASM_OP_I32LOAD16S] = { "i32.load16_s", 3, 3 },
42  [WASM_OP_I32LOAD16U] = { "i32.load_16_u", 3, 3 },
43  [WASM_OP_I64LOAD8S] = { "i64.load8_s", 3, 3 },
44  [WASM_OP_I64LOAD8U] = { "i64.load8_u", 3, 3 },
45  [WASM_OP_I64LOAD16S] = { "i64.load16_s", 3, 3 },
46  [WASM_OP_I64LOAD16U] = { "i64.load16_u", 3, 3 },
47  [WASM_OP_I64LOAD32S] = { "i64.load32_s", 3, 3 },
48  [WASM_OP_I64LOAD32U] = { "i64.load32_u", 3, 3 },
49  [WASM_OP_I32STORE] = { "i32.store", 3, 3 },
50  [WASM_OP_I64STORE] = { "i64.store", 3, 3 },
51  [WASM_OP_F32STORE] = { "f32.store", 3, 3 },
52  [WASM_OP_F64STORE] = { "f64.store", 3, 3 },
53  [WASM_OP_I32STORE8] = { "i32.store8", 3, 3 },
54  [WASM_OP_I32STORE16] = { "i32.store16", 3, 3 },
55  [WASM_OP_I64STORE8] = { "i64.store8", 3, 3 },
56  [WASM_OP_I64STORE16] = { "i64.store16", 3, 3 },
57  [WASM_OP_I64STORE32] = { "i64.store32", 3, 3 },
58  [WASM_OP_CURRENTMEMORY] = { "current_memory", 2, 2 },
59  [WASM_OP_GROWMEMORY] = { "grow_memory", 2, 2 },
60  [WASM_OP_I32CONST] = { "i32.const", 2, 2 },
61  [WASM_OP_I64CONST] = { "i64.const", 2, 2 },
62  [WASM_OP_F32CONST] = { "f32.const", 2, 2 },
63  [WASM_OP_F64CONST] = { "f64.const", 2, 2 },
64  [WASM_OP_I32EQZ] = { "i32.eqz", 1, 1 },
65  [WASM_OP_I32EQ] = { "i32.eq", 1, 1 },
66  [WASM_OP_I32NE] = { "i32.ne", 1, 1 },
67  [WASM_OP_I32LTS] = { "i32.lt_s", 1, 1 },
68  [WASM_OP_I32LTU] = { "i32.lt_u", 1, 1 },
69  [WASM_OP_I32GTS] = { "i32.gt_s", 1, 1 },
70  [WASM_OP_I32GTU] = { "i32.gt_u", 1, 1 },
71  [WASM_OP_I32LES] = { "i32.le_s", 1, 1 },
72  [WASM_OP_I32LEU] = { "i32.le_u", 1, 1 },
73  [WASM_OP_I32GES] = { "i32.ge_s", 1, 1 },
74  [WASM_OP_I32GEU] = { "i32.ge_u", 1, 1 },
75  [WASM_OP_I64EQZ] = { "i64.eqz", 1, 1 },
76  [WASM_OP_I64EQ] = { " i64.eq", 1, 1 },
77  [WASM_OP_I64NE] = { " i64.ne", 1, 1 },
78  [WASM_OP_I64LTS] = { "i64.lt_s", 1, 1 },
79  [WASM_OP_I64LTU] = { "i64.lt_u", 1, 1 },
80  [WASM_OP_I64GTS] = { "i64.gt_s", 1, 1 },
81  [WASM_OP_I64GTU] = { "i64.gt_u", 1, 1 },
82  [WASM_OP_I64LES] = { "i64.le_s", 1, 1 },
83  [WASM_OP_I64LEU] = { "i64.le_u", 1, 1 },
84  [WASM_OP_I64GES] = { "i64.ge_s", 1, 1 },
85  [WASM_OP_I64GEU] = { "i64.ge_u", 1, 1 },
86  [WASM_OP_F32EQ] = { "f32.eq", 1, 1 },
87  [WASM_OP_F32NE] = { "f32.ne", 1, 1 },
88  [WASM_OP_F32LT] = { "f32.lt", 1, 1 },
89  [WASM_OP_F32GT] = { "f32.gt", 1, 1 },
90  [WASM_OP_F32LE] = { "f32.le", 1, 1 },
91  [WASM_OP_F32GE] = { "f32.ge", 1, 1 },
92  [WASM_OP_F64EQ] = { "f64.eq", 1, 1 },
93  [WASM_OP_F64NE] = { "f64.ne", 1, 1 },
94  [WASM_OP_F64LT] = { "f64.lt", 1, 1 },
95  [WASM_OP_F64GT] = { "f64.gt", 1, 1 },
96  [WASM_OP_F64LE] = { "f64.le", 1, 1 },
97  [WASM_OP_F64GE] = { "f64.ge", 1, 1 },
98  [WASM_OP_I32CLZ] = { "i32.clz", 1, 1 },
99  [WASM_OP_I32CTZ] = { "i32.ctz", 1, 1 },
100  [WASM_OP_I32POPCNT] = { "i32.popcnt", 1, 1 },
101  [WASM_OP_I32ADD] = { "i32.add", 1, 1 },
102  [WASM_OP_I32SUB] = { "i32.sub", 1, 1 },
103  [WASM_OP_I32MUL] = { "i32.mul", 1, 1 },
104  [WASM_OP_I32DIVS] = { "i32.div_s", 1, 1 },
105  [WASM_OP_I32DIVU] = { "i32.div_u", 1, 1 },
106  [WASM_OP_I32REMS] = { "i32.rem_s", 1, 1 },
107  [WASM_OP_I32REMU] = { "i32.rem_u", 1, 1 },
108  [WASM_OP_I32AND] = { "i32.and", 1, 1 },
109  [WASM_OP_I32OR] = { "i32.or", 1, 1 },
110  [WASM_OP_I32XOR] = { "i32.xor", 1, 1 },
111  [WASM_OP_I32SHL] = { "i32.shl", 1, 1 },
112  [WASM_OP_I32SHRS] = { "i32.shr_s", 1, 1 },
113  [WASM_OP_I32SHRU] = { "i32.shr_u", 1, 1 },
114  [WASM_OP_I32ROTL] = { "i32.rotl", 1, 1 },
115  [WASM_OP_I32ROTR] = { "i32.rotr", 1, 1 },
116  [WASM_OP_I64CLZ] = { "i64.clz", 1, 1 },
117  [WASM_OP_I64CTZ] = { "i64.ctz", 1, 1 },
118  [WASM_OP_I64POPCNT] = { "i64.popcnt", 1, 1 },
119  [WASM_OP_I64ADD] = { "i64.add", 1, 1 },
120  [WASM_OP_I64SUB] = { "i64.sub", 1, 1 },
121  [WASM_OP_I64MUL] = { "i64.mul", 1, 1 },
122  [WASM_OP_I64DIVS] = { "i64.div_s", 1, 1 },
123  [WASM_OP_I64DIVU] = { "i64.div_u", 1, 1 },
124  [WASM_OP_I64REMS] = { "i64.rem_s", 1, 1 },
125  [WASM_OP_I64REMU] = { "i64.rem_u", 1, 1 },
126  [WASM_OP_I64AND] = { "i64.and", 1, 1 },
127  [WASM_OP_I64OR] = { "i64.or", 1, 1 },
128  [WASM_OP_I64XOR] = { "i64.xor", 1, 1 },
129  [WASM_OP_I64SHL] = { "i64.shl", 1, 1 },
130  [WASM_OP_I64SHRS] = { "i64.shr_s", 1, 1 },
131  [WASM_OP_I64SHRU] = { "i64.shr_u", 1, 1 },
132  [WASM_OP_I64ROTL] = { "i64.rotl", 1, 1 },
133  [WASM_OP_I64ROTR] = { "i64.rotr", 1, 1 },
134  [WASM_OP_F32ABS] = { "f32.abs", 1, 1 },
135  [WASM_OP_F32NEG] = { "f32.neg", 1, 1 },
136  [WASM_OP_F32CEIL] = { "f32.ceil", 1, 1 },
137  [WASM_OP_F32FLOOR] = { "f32.floor", 1, 1 },
138  [WASM_OP_F32TRUNC] = { "f32.trunc", 1, 1 },
139  [WASM_OP_F32NEAREST] = { "f32.nearest", 1, 1 },
140  [WASM_OP_F32SQRT] = { "f32.sqrt", 1, 1 },
141  [WASM_OP_F32ADD] = { "f32.add", 1, 1 },
142  [WASM_OP_F32SUB] = { "f32.sub", 1, 1 },
143  [WASM_OP_F32MUL] = { "f32.mul", 1, 1 },
144  [WASM_OP_F32DIV] = { "f32.div", 1, 1 },
145  [WASM_OP_F32MIN] = { "f32.min", 1, 1 },
146  [WASM_OP_F32MAX] = { "f32.max", 1, 1 },
147  [WASM_OP_F32COPYSIGN] = { " f32.copysign", 1, 1 },
148  [WASM_OP_F64ABS] = { "f64.abs", 1, 1 },
149  [WASM_OP_F64NEG] = { "f64.neg", 1, 1 },
150  [WASM_OP_F64CEIL] = { "f64.ceil", 1, 1 },
151  [WASM_OP_F64FLOOR] = { "f64.floor", 1, 1 },
152  [WASM_OP_F64TRUNC] = { "f64.trunc", 1, 1 },
153  [WASM_OP_F64NEAREST] = { "f64.nearest", 1, 1 },
154  [WASM_OP_F64SQRT] = { "f64.sqrt", 1, 1 },
155  [WASM_OP_F64ADD] = { "f64.add", 1, 1 },
156  [WASM_OP_F64SUB] = { "f64.sub", 1, 1 },
157  [WASM_OP_F64MUL] = { "f64.mul", 1, 1 },
158  [WASM_OP_F64DIV] = { "f64.div", 1, 1 },
159  [WASM_OP_F64MIN] = { "f64.min", 1, 1 },
160  [WASM_OP_F64MAX] = { "f64.max", 1, 1 },
161  [WASM_OP_F64COPYSIGN] = { "f64.copysign", 1, 1 },
162  [WASM_OP_I32WRAPI64] = { "i32.wrap/i64", 1, 1 },
163  [WASM_OP_I32TRUNCSF32] = { "i32.trunc_s/f32", 1, 1 },
164  [WASM_OP_I32TRUNCUF32] = { "i32.trunc_u/f32", 1, 1 },
165  [WASM_OP_I32TRUNCSF64] = { "i32.trunc_s/f64", 1, 1 },
166  [WASM_OP_I32TRUNCUF64] = { "i32.trunc_u/f64", 1, 1 },
167  [WASM_OP_I64EXTENDSI32] = { "i64.extend_s/i32", 1, 1 },
168  [WASM_OP_I64EXTENDUI32] = { "i64.extend_u/i32", 1, 1 },
169  [WASM_OP_I64TRUNCSF32] = { "i64.trunc_s/f32", 1, 1 },
170  [WASM_OP_I64TRUNCUF32] = { "i64.trunc_u/f32", 1, 1 },
171  [WASM_OP_I64TRUNCSF64] = { "i64.trunc_s/f64", 1, 1 },
172  [WASM_OP_I64TRUNCUF64] = { "i64.trunc_u/f64", 1, 1 },
173  [WASM_OP_F32CONVERTSI32] = { "f32.convert_s/i32", 1, 1 },
174  [WASM_OP_F32CONVERTUI32] = { "f32.convert_u/i32", 1, 1 },
175  [WASM_OP_F32CONVERTSI64] = { "f32.convert_s/i64", 1, 1 },
176  [WASM_OP_F32CONVERTUI64] = { "f32.convert_u/i64", 1, 1 },
177  [WASM_OP_F32DEMOTEF64] = { "f32.demote/f64", 1, 1 },
178  [WASM_OP_F64CONVERTSI32] = { "f64.convert_s/i32", 1, 1 },
179  [WASM_OP_F64CONVERTUI32] = { "f64.convert_u/i32", 1, 1 },
180  [WASM_OP_F64CONVERTSI64] = { "f64.convert_s/i64", 1, 1 },
181  [WASM_OP_F64CONVERTUI64] = { "f64.convert_u/i64", 1, 1 },
182  [WASM_OP_F64PROMOTEF32] = { "f64.promote/f32", 1, 1 },
183  [WASM_OP_I32REINTERPRETF32] = { "i32.reinterpret/f32", 1, 1 },
184  [WASM_OP_I64REINTERPRETF64] = { "i64.reinterpret/f64", 1, 1 },
185  [WASM_OP_F32REINTERPRETI32] = { "f32.reinterpret/i32", 1, 1 },
186  [WASM_OP_F64REINTERPRETI64] = { "f64.reinterpret/i64", 1, 1 }
187 };
188 
189 static WasmOpDef opcodes_threads[256] = {
190  [WASM_OP_ATOMICNOTIFY] = { "atomic.notify", 1, 1 },
191  [WASM_OP_I32ATOMICWAIT] = { "i32.atomic.wait", 1, 1 },
192  [WASM_OP_I64ATOMICWAIT] = { "i64.atomic.wait", 1, 1 },
193  [WASM_OP_I32ATOMICLOAD] = { "i32.atomic.load", 3, 3 },
194  [WASM_OP_I64ATOMICLOAD] = { "i64.atomic.load", 3, 3 },
195  [WASM_OP_I32ATOMICLOAD16U] = { "i32.atomic.load16_u", 3, 3 },
196  [WASM_OP_I64ATOMICLOAD8U] = { "i64.atomic.load8_u", 3, 3 },
197  [WASM_OP_I64ATOMICLOAD16U] = { "i64.atomic.load16_u", 3, 3 },
198  [WASM_OP_I64ATOMICLOAD32U] = { "i64.atomic.load32_u", 3, 3 },
199  [WASM_OP_I32ATOMICSTORE] = { "i32.atomic.store", 3, 3 },
200  [WASM_OP_I64ATOMICSTORE] = { "i64.atomic.store", 3, 3 },
201  [WASM_OP_I32ATOMICSTORE8] = { "i32.atomic.store8", 3, 3 },
202  [WASM_OP_I32ATOMICSTORE16] = { "i32.atomic.store16", 3, 3 },
203  [WASM_OP_I64ATOMICSTORE8] = { "i64.atomic.store8", 3, 3 },
204  [WASM_OP_I64ATOMICSTORE16] = { "i64.atomic.store16", 3, 3 },
205  [WASM_OP_I64ATOMICSTORE32] = { "i64.atomic.store32", 3, 3 },
206  [WASM_OP_I32ATOMICRMWADD] = { "i32.atomic.rmw.add", 3, 3 },
207  [WASM_OP_I64ATOMICRMWADD] = { "i64.atomic.rmw.add", 3, 3 },
208  [WASM_OP_I32ATOMICRMW8UADD] = { "i32.atomic.rmw8_u.add", 3, 3 },
209  [WASM_OP_I32ATOMICRMW16UADD] = { "i32.atomic.rmw16_u.add", 3, 3 },
210  [WASM_OP_I64ATOMICRMW8UADD] = { "i64.atomic.rmw8_u.add", 3, 3 },
211  [WASM_OP_I64ATOMICRMW16UADD] = { "i64.atomic.rmw16_u.add", 3, 3 },
212  [WASM_OP_I64ATOMICRMW32UADD] = { "i64.atomic.rmw32_u.add", 3, 3 },
213  [WASM_OP_I32ATOMICRMW8USUB] = { "i32.atomic.rmw8_u.sub", 3, 3 },
214  [WASM_OP_I32ATOMICRMW16USUB] = { "i32.atomic.rmw16_u.sub", 3, 3 },
215  [WASM_OP_I32ATOMICRMWSUB] = { "i32.atomic.rmw.sub", 3, 3 },
216  [WASM_OP_I64ATOMICRMW8USUB] = { "i64.atomic.rmw8_u.sub", 3, 3 },
217  [WASM_OP_I64ATOMICRMW16USUB] = { "i64.atomic.rmw16_u.sub", 3, 3 },
218  [WASM_OP_I64ATOMICRMW32USUB] = { "i64.atomic.rmw32_u.sub", 3, 3 },
219  [WASM_OP_I64ATOMICRMWSUB] = { "i64.atomic.rmw.sub", 3, 3 },
220  [WASM_OP_I32ATOMICRMWAND] = { "i32.atomic.rmw.and", 3, 3 },
221  [WASM_OP_I64ATOMICRMWAND] = { "i64.atomic.rmw.and", 3, 3 },
222  [WASM_OP_I32ATOMICRMW8UAND] = { "i32.atomic.rmw8_u.and", 3, 3 },
223  [WASM_OP_I32ATOMICRMW16UAND] = { "i32.atomic.rmw16_u.and", 3, 3 },
224  [WASM_OP_I64ATOMICRMW8UAND] = { "i64.atomic.rmw8_u.and", 3, 3 },
225  [WASM_OP_I64ATOMICRMW16UAND] = { "i64.atomic.rmw16_u.and", 3, 3 },
226  [WASM_OP_I64ATOMICRMW32UAND] = { "i64.atomic.rmw32_u.and", 3, 3 },
227  [WASM_OP_I32ATOMICRMWOR] = { "i32.atomic.rmw.or", 3, 3 },
228  [WASM_OP_I64ATOMICRMWOR] = { "i64.atomic.rmw.or", 3, 3 },
229  [WASM_OP_I32ATOMICRMW8UOR] = { "i32.atomic.rmw8_u.or", 3, 3 },
230  [WASM_OP_I32ATOMICRMW16UOR] = { "i32.atomic.rmw16_u.or", 3, 3 },
231  [WASM_OP_I64ATOMICRMW8UOR] = { "i64.atomic.rmw8_u.or", 3, 3 },
232  [WASM_OP_I64ATOMICRMW16UOR] = { "i64.atomic.rmw16_u.or", 3, 3 },
233  [WASM_OP_I64ATOMICRMW32UOR] = { "i64.atomic.rmw32_u.or", 3, 3 },
234  [WASM_OP_I32ATOMICRMWXOR] = { "i32.atomic.rmw.xor", 3, 3 },
235  [WASM_OP_I64ATOMICRMWXOR] = { "i64.atomic.rmw.xor", 3, 3 },
236  [WASM_OP_I32ATOMICRMW8UXOR] = { "i32.atomic.rmw8_u.xor", 3, 3 },
237  [WASM_OP_I32ATOMICRMW16UXOR] = { "i32.atomic.rmw16_u.xor", 3, 3 },
238  [WASM_OP_I64ATOMICRMW8UXOR] = { "i64.atomic.rmw8_u.xor", 3, 3 },
239  [WASM_OP_I64ATOMICRMW16UXOR] = { "i64.atomic.rmw16_u.xor", 3, 3 },
240  [WASM_OP_I64ATOMICRMW32UXOR] = { "i64.atomic.rmw32_u.xor", 3, 3 },
241  [WASM_OP_I32ATOMICRMWXCHG] = { "i32.atomic.rmw.xchg", 3, 3 },
242  [WASM_OP_I64ATOMICRMWXCHG] = { "i64.atomic.rmw.xchg", 3, 3 },
243  [WASM_OP_I32ATOMICRMW8UXCHG] = { "i32.atomic.rmw8_u.xchg", 3, 3 },
244  [WASM_OP_I32ATOMICRMW16UXCHG] = { "i32.atomic.rmw16_u.xchg", 3, 3 },
245  [WASM_OP_I64ATOMICRMW8UXCHG] = { "i64.atomic.rmw8_u.xchg", 3, 3 },
246  [WASM_OP_I64ATOMICRMW16UXCHG] = { "i64.atomic.rmw16_u.xchg", 3, 3 },
247  [WASM_OP_I64ATOMICRMW32UXCHG] = { "i64.atomic.rmw32_u.xchg", 3, 3 },
248  [WASM_OP_I32ATOMICRMWCMPXCHG] = { "i32.atomic.rmw.cmpxchg", 3, 3 },
249  [WASM_OP_I64ATOMICRMWCMPXCHG] = { "i64.atomic.rmw.cmpxchg", 3, 3 },
250  [WASM_OP_I32ATOMICRMW8UCMPXCHG] = { "i32.atomic.rmw8_u.cmpxchg", 3, 3 },
251  [WASM_OP_I32ATOMICRMW16UCMPXCHG] = { "i32.atomic.rmw16_u.cmpxchg", 3, 3 },
252  [WASM_OP_I64ATOMICRMW8UCMPXCHG] = { "i64.atomic.rmw8_u.cmpxchg", 3, 3 },
253  [WASM_OP_I64ATOMICRMW16UCMPXCHG] = { "i64.atomic.rmw16_u.cmpxchg", 3, 3 },
254  [WASM_OP_I64ATOMICRMW32UCMPXCHG] = { "i64.atomic.rmw32_u.cmpxchg", 3, 3 }
255 };
256 
257 static WasmOpDef opcodes_simd[256] = {
258  [WASM_OP_V128LOAD] = { "v128.load", 6, 6 },
259  [WASM_OP_V128STORE] = { "v128.store", 2, 6 },
260  [WASM_OP_V128CONST] = { "v128.const", 2, 6 },
261  [WASM_OP_I8X16SPLAT] = { "i8x16.splat", 2, 6 },
262  [WASM_OP_I8X16EXTRACTLANES] = { "i8x16.extract_lane_s", 2, 6 },
263  [WASM_OP_I8X16EXTRACTLANEU] = { "i8x16.extract_lane_u", 2, 6 },
264  [WASM_OP_I8X16REPLACELANE] = { "i8x16.replace_lane", 2, 6 },
265  [WASM_OP_I16X8SPLAT] = { "i16x8.splat", 2, 6 },
266  [WASM_OP_I16X8EXTRACTLANES] = { "i16x8.extract_lane_s", 2, 6 },
267  [WASM_OP_I16X8EXTRACTLANEU] = { "i16x8.extract_lane_u", 2, 6 },
268  [WASM_OP_I16X8REPLACELANE] = { "i16x8.replace_lane", 2, 6 },
269  [WASM_OP_I32X4SPLAT] = { "i32x4.splat", 2, 6 },
270  [WASM_OP_I32X4EXTRACTLANE] = { "i32x4.extract_lane", 2, 6 },
271  [WASM_OP_I32X4REPLACELANE] = { "i32x4.replace_lane", 2, 6 },
272  [WASM_OP_I64X2SPLAT] = { "i64x2.splat", 2, 6 },
273  [WASM_OP_I64X2EXTRACTLANE] = { "i64x2.extract_lane", 2, 6 },
274  [WASM_OP_I64X2REPLACELANE] = { "i64x2.replace_lane", 2, 6 },
275  [WASM_OP_F32X4SPLAT] = { "f32x4.splat", 2, 6 },
276  [WASM_OP_F32X4EXTRACTLANE] = { "f32x4.extract_lane", 2, 6 },
277  [WASM_OP_F32X4REPLACELANE] = { "f32x4.replace_lane", 2, 6 },
278  [WASM_OP_F64X2SPLAT] = { "f64x2.splat", 2, 6 },
279  [WASM_OP_F64X2EXTRACTLANE] = { "f64x2.extract_lane", 2, 6 },
280  [WASM_OP_F64X2REPLACELANE] = { "f64x2.replace_lane", 2, 6 },
281  [WASM_OP_I8X16EQ] = { "i8x16.eq", 2, 6 },
282  [WASM_OP_I8X16NE] = { "i8x16.ne", 2, 6 },
283  [WASM_OP_I8X16LTS] = { "i8x16.lt_s", 2, 6 },
284  [WASM_OP_I8X16LTU] = { "i8x16.lt_u", 2, 6 },
285  [WASM_OP_I8X16GTS] = { "i8x16.gt_s", 2, 6 },
286  [WASM_OP_I8X16GTU] = { "i8x16.gt_u", 2, 6 },
287  [WASM_OP_I8X16LES] = { "i8x16.le_s", 2, 6 },
288  [WASM_OP_I8X16LEU] = { "i8x16.le_u", 2, 6 },
289  [WASM_OP_I8X16GES] = { "i8x16.ge_s", 2, 6 },
290  [WASM_OP_I8X16GEU] = { "i8x16.ge_u", 2, 6 },
291  [WASM_OP_I16X8EQ] = { "i16x8.eq", 2, 6 },
292  [WASM_OP_I16X8NE] = { "i16x8.ne", 2, 6 },
293  [WASM_OP_I16X8LTS] = { "i16x8.lt_s", 2, 6 },
294  [WASM_OP_I16X8LTU] = { "i16x8.lt_u", 2, 6 },
295  [WASM_OP_I16X8GTS] = { "i16x8.gt_s", 2, 6 },
296  [WASM_OP_I16X8GTU] = { "i16x8.gt_u", 2, 6 },
297  [WASM_OP_I16X8LES] = { "i16x8.le_s", 2, 6 },
298  [WASM_OP_I16X8LEU] = { "i16x8.le_u", 2, 6 },
299  [WASM_OP_I16X8GES] = { "i16x8.ge_s", 2, 6 },
300  [WASM_OP_I16X8GEU] = { "i16x8.ge_u", 2, 6 },
301  [WASM_OP_I32X4EQ] = { "i32x4.eq", 2, 6 },
302  [WASM_OP_I32X4NE] = { "i32x4.ne", 2, 6 },
303  [WASM_OP_I32X4LTS] = { "i32x4.lt_s", 2, 6 },
304  [WASM_OP_I32X4LTU] = { "i32x4.lt_u", 2, 6 },
305  [WASM_OP_I32X4GTS] = { "i32x4.gt_s", 2, 6 },
306  [WASM_OP_I32X4GTU] = { "i32x4.gt_u", 2, 6 },
307  [WASM_OP_I32X4LES] = { "i32x4.le_s", 2, 6 },
308  [WASM_OP_I32X4LEU] = { "i32x4.le_u", 2, 6 },
309  [WASM_OP_I32X4GES] = { "i32x4.ge_s", 2, 6 },
310  [WASM_OP_I32X4GEU] = { "i32x4.ge_u", 2, 6 },
311  [WASM_OP_F32X4EQ] = { "f32x4.eq", 2, 6 },
312  [WASM_OP_F32X4NE] = { "f32x4.ne", 2, 6 },
313  [WASM_OP_F32X4LT] = { "f32x4.lt", 2, 6 },
314  [WASM_OP_F32X4GT] = { "f32x4.gt", 2, 6 },
315  [WASM_OP_F32X4LE] = { "f32x4.le", 2, 6 },
316  [WASM_OP_F32X4GE] = { "f32x4.ge", 2, 6 },
317  [WASM_OP_F64X2EQ] = { "f64x2.eq", 2, 6 },
318  [WASM_OP_F64X2NE] = { "f64x2.ne", 2, 6 },
319  [WASM_OP_F64X2LT] = { "f64x2.lt", 2, 6 },
320  [WASM_OP_F64X2GT] = { "f64x2.gt", 2, 6 },
321  [WASM_OP_F64X2LE] = { "f64x2.le", 2, 6 },
322  [WASM_OP_F64X2GE] = { "f64x2.ge", 2, 6 },
323  [WASM_OP_V128NOT] = { "v128.not", 2, 6 },
324  [WASM_OP_V128AND] = { "v128.and", 2, 6 },
325  [WASM_OP_V128OR] = { "v128.or", 2, 6 },
326  [WASM_OP_V128XOR] = { "v128.xor", 2, 6 },
327  [WASM_OP_V128BITSELECT] = { "v128.bitselect", 2, 6 },
328  [WASM_OP_I8X16NEG] = { "i8x16.neg", 2, 6 },
329  [WASM_OP_I8X16ANYTRUE] = { "i8x16.any_true", 2, 6 },
330  [WASM_OP_I8X16ALLTRUE] = { "i8x16.all_true", 2, 6 },
331  [WASM_OP_I8X16SHL] = { "i8x16.shl", 2, 6 },
332  [WASM_OP_I8X16SHRS] = { "i8x16.shr_s", 2, 6 },
333  [WASM_OP_I8X16SHRU] = { "i8x16.shr_u", 2, 6 },
334  [WASM_OP_I8X16ADD] = { "i8x16.add", 2, 6 },
335  [WASM_OP_I8X16ADDSATURATES] = { "i8x16.add_saturate_s", 2, 6 },
336  [WASM_OP_I8X16ADDSATURATEU] = { "i8x16.add_saturate_u", 2, 6 },
337  [WASM_OP_I8X16SUB] = { "i8x16.sub", 2, 6 },
338  [WASM_OP_I8X16SUBSATURATES] = { "i8x16.sub_saturate_s", 2, 6 },
339  [WASM_OP_I8X16SUBSATURATEU] = { "i8x16.sub_saturate_u", 2, 6 },
340  [WASM_OP_I8X16MINS] = { "i8x16.min_s", 2, 6 },
341  [WASM_OP_I8X16MINU] = { "i8x16.min_u", 2, 6 },
342  [WASM_OP_I8X16MAXS] = { "i8x16.max_s", 2, 6 },
343  [WASM_OP_I8X16MAXU] = { "i8x16.max_u", 2, 6 },
344  [WASM_OP_I16X8NEG] = { "i16x8.neg", 2, 6 },
345  [WASM_OP_I16X8ANYTRUE] = { "i16x8.any_true", 2, 6 },
346  [WASM_OP_I16X8ALLTRUE] = { "i16x8.all_true", 2, 6 },
347  [WASM_OP_I16X8SHL] = { "i16x8.shl", 2, 6 },
348  [WASM_OP_I16X8SHRS] = { "i16x8.shr_s", 2, 6 },
349  [WASM_OP_I16X8SHRU] = { "i16x8.shr_u", 2, 6 },
350  [WASM_OP_I16X8ADD] = { "i16x8.add", 2, 6 },
351  [WASM_OP_I16X8ADDSATURATES] = { "i16x8.add_saturate_s", 2, 6 },
352  [WASM_OP_I16X8ADDSATURATEU] = { "i16x8.add_saturate_u", 2, 6 },
353  [WASM_OP_I16X8SUB] = { "i16x8.sub", 2, 6 },
354  [WASM_OP_I16X8SUBSATURATES] = { "i16x8.sub_saturate_s", 2, 6 },
355  [WASM_OP_I16X8SUBSATURATEU] = { "i16x8.sub_saturate_u", 2, 6 },
356  [WASM_OP_I16X8MUL] = { "i16x8.mul", 2, 6 },
357  [WASM_OP_I16X8MINS] = { "i16x8.min_s", 2, 6 },
358  [WASM_OP_I16X8MINU] = { "i16x8.min_u", 2, 6 },
359  [WASM_OP_I16X8MAXS] = { "i16x8.max_s", 2, 6 },
360  [WASM_OP_I16X8MAXU] = { "i16x8.max_u", 2, 6 },
361  [WASM_OP_I32X4NEG] = { "i32x4.neg", 2, 6 },
362  [WASM_OP_I32X4ANYTRUE] = { "i32x4.any_true", 2, 6 },
363  [WASM_OP_I32X4ALLTRUE] = { "i32x4.all_true", 2, 6 },
364  [WASM_OP_I32X4SHL] = { "i32x4.shl", 2, 6 },
365  [WASM_OP_I32X4SHRS] = { "i32x4.shr_s", 2, 6 },
366  [WASM_OP_I32X4SHRU] = { "i32x4.shr_u", 2, 6 },
367  [WASM_OP_I32X4ADD] = { "i32x4.add", 2, 6 },
368  [WASM_OP_I32X4SUB] = { "i32x4.sub", 2, 6 },
369  [WASM_OP_I32X4MUL] = { "i32x4.mul", 2, 6 },
370  [WASM_OP_I32X4MINS] = { "i32x4.min_s", 2, 6 },
371  [WASM_OP_I32X4MINU] = { "i32x4.min_u", 2, 6 },
372  [WASM_OP_I32X4MAXS] = { "i32x4.max_s", 2, 6 },
373  [WASM_OP_I32X4MAXU] = { "i32x4.max_u", 2, 6 },
374  [WASM_OP_I64X2NEG] = { "i64x2.neg", 2, 6 },
375  [WASM_OP_I64X2SHL] = { "i64x2.shl", 2, 6 },
376  [WASM_OP_I64X2SHRS] = { "i64x2.shr_s", 2, 6 },
377  [WASM_OP_I64X2SHRU] = { "i64x2.shr_u", 2, 6 },
378  [WASM_OP_I64X2ADD] = { "i64x2.add", 2, 6 },
379  [WASM_OP_I64X2SUB] = { "i64x2.sub", 2, 6 },
380  [WASM_OP_I64X2MUL] = { "i64x2.mul", 2, 6 },
381  [WASM_OP_F32X4ABS] = { "f32x4.abs", 2, 6 },
382  [WASM_OP_F32X4NEG] = { "f32x4.neg", 2, 6 },
383  [WASM_OP_F32X4SQRT] = { "f32x4.sqrt", 2, 6 },
384  [WASM_OP_F32X4ADD] = { "f32x4.add", 2, 6 },
385  [WASM_OP_F32X4SUB] = { "f32x4.sub", 2, 6 },
386  [WASM_OP_F32X4MUL] = { "f32x4.mul", 2, 6 },
387  [WASM_OP_F32X4DIV] = { "f32x4.div", 2, 6 },
388  [WASM_OP_F32X4MIN] = { "f32x4.min", 2, 6 },
389  [WASM_OP_F32X4MAX] = { "f32x4.max", 2, 6 },
390  [WASM_OP_F64X2ABS] = { "f64x2.abs", 2, 6 },
391  [WASM_OP_F64X2NEG] = { "f64x2.neg", 2, 6 },
392  [WASM_OP_F64X2SQRT] = { "f64x2.sqrt", 2, 6 },
393  [WASM_OP_F64X2ADD] = { "f64x2.add", 2, 6 },
394  [WASM_OP_F64X2SUB] = { "f64x2.sub", 2, 6 },
395  [WASM_OP_F64X2MUL] = { "f64x2.mul", 2, 6 },
396  [WASM_OP_F64X2DIV] = { "f64x2.div", 2, 6 },
397  [WASM_OP_F64X2MIN] = { "f64x2.min", 2, 6 },
398  [WASM_OP_F64X2MAX] = { "f64x2.max", 2, 6 },
399  [WASM_OP_I32X4TRUNCSATF32X4S] = { "i32x4.trunc_sat_f32x4_s", 2, 6 },
400  [WASM_OP_I32X4TRUNCSATF32X4U] = { "i32x4.trunc_sat_f32x4_u", 2, 6 },
401  [WASM_OP_F32X4CONVERTI32X4S] = { "f32x4.convert_i32x4_s", 2, 6 },
402  [WASM_OP_F32X4CONVERTI32X4U] = { "f32x4.convert_i32x4_u", 2, 6 },
403  [WASM_OP_V8X16SWIZZLE] = { "v8x16.swizzle", 2, 6 },
404  [WASM_OP_V8X16SHUFFLE] = { "v8x16.shuffle", 2, 6 },
405  [WASM_OP_V8X16LOADSPLAT] = { "v8x16.load_splat", 2, 6 },
406  [WASM_OP_V16X8LOADSPLAT] = { "v16x8.load_splat", 2, 6 },
407  [WASM_OP_V32X4LOADSPLAT] = { "v32x4.load_splat", 2, 6 },
408  [WASM_OP_V64X2LOADSPLAT] = { "v64x2.load_splat", 2, 6 },
409  [WASM_OP_I8X16NARROWI16X8S] = { "i8x16.narrow_i16x8_s", 2, 6 },
410  [WASM_OP_I8X16NARROWI16X8U] = { "i8x16.narrow_i16x8_u", 2, 6 },
411  [WASM_OP_I16X8NARROWI32X4S] = { "i16x8.narrow_i32x4_s", 2, 6 },
412  [WASM_OP_I16X8NARROWI32X4U] = { "i16x8.narrow_i32x4_u", 2, 6 },
413  [WASM_OP_I16X8WIDENLOWI8X16S] = { "i16x8.widen_low_i8x16_s", 2, 6 },
414  [WASM_OP_I16X8WIDENHIGHI8X16S] = { "i16x8.widen_high_i8x16_s", 2, 6 },
415  [WASM_OP_I16X8WIDENLOWI8X16U] = { "i16x8.widen_low_i8x16_u", 2, 6 },
416  [WASM_OP_I16X8WIDENHIGHI8X16U] = { "i16x8.widen_high_i8x16_u", 2, 6 },
417  [WASM_OP_I32X4WIDENLOWI16X8S] = { "i32x4.widen_low_i16x8_s", 2, 6 },
418  [WASM_OP_I32X4WIDENHIGHI16X8S] = { "i32x4.widen_high_i16x8_s", 2, 6 },
419  [WASM_OP_I32X4WIDENLOWI16X8U] = { "i32x4.widen_low_i16x8_u", 2, 6 },
420  [WASM_OP_I32X4WIDENHIGHI16X8U] = { "i32x4.widen_high_i16x8_u", 2, 6 },
421  [WASM_OP_I16X8LOAD8X8S] = { "i16x8.load8x8_s", 2, 6 },
422  [WASM_OP_I16X8LOAD8X8U] = { "i16x8.load8x8_u", 2, 6 },
423  [WASM_OP_I32X4LOAD16X4S] = { "i32x4.load16x4_s", 2, 6 },
424  [WASM_OP_I32X4LOAD16X4U] = { "i32x4.load16x4_u", 2, 6 },
425  [WASM_OP_I64X2LOAD32X2S] = { "i64x2.load32x2_s", 2, 6 },
426  [WASM_OP_I64X2LOAD32X2U] = { "i64x2.load32x2_u", 2, 6 },
427  [WASM_OP_V128ANDNOT] = { "v128.andnot", 2, 6 },
428  [WASM_OP_I8X16AVGRU] = { "i8x16.avgr_u", 2, 6 },
429  [WASM_OP_I16X8AVGRU] = { "i16x8.avgr_u", 2, 6 },
430  [WASM_OP_I8X16ABS] = { "i8x16.abs", 2, 6 },
431  [WASM_OP_I16X8ABS] = { "i16x8.abs", 2, 6 },
432 };
433 
434 #ifndef WASM_NO_ASM
435 // assembles the given line of wasm assembly.
436 RZ_IPI int wasm_asm(const char *str, unsigned char *buf, int buf_len) {
437  int i = 0, len = 0;
438  char tmp[256];
439  WasmOpDef *opdef = NULL;
440  while ((i < sizeof(tmp) - 1) && str[i] && str[i] != ' ') {
441  tmp[i] = str[i];
442  i++;
443  }
444  tmp[i] = 0;
445  // Find opcode
446  for (i = 0; i < 0xff; i++) {
447  opdef = &opcodes[i];
448  if (opdef->txt) {
449  if (!strcmp(opdef->txt, tmp)) {
450  buf[len++] = i;
451  break;
452  }
453  }
454  }
455  // Check extensions
456  if (len == 0) {
457  for (i = 0; i < 0xff; i++) {
458  opdef = &opcodes_threads[i];
459  if (opdef->txt) {
460  if (!strcmp(opdef->txt, tmp)) {
461  buf[len++] = 0xfe;
462  buf[len++] = i;
463  break;
464  }
465  }
466  }
467  }
468  // Abort
469  if (len == 0)
470  goto err;
471  // TODO: parse immediates
472  return len;
473 err:
474  return -1;
475 }
476 #endif
477 
478 // disassemble an instruction from the given buffer.
479 RZ_IPI int wasm_dis(WasmOp *op, const unsigned char *buf, int buf_len) {
480  RzStrBuf *sb = rz_strbuf_new("");
481  int id = buf[0];
482  if (id < 0xc0) {
483  op->type = WASM_TYPE_OP_CORE;
484  op->op.core = id;
485  op->len = 1;
486  WasmOpDef *opdef = &opcodes[id];
487  switch (id) {
488  case WASM_OP_TRAP:
489  case WASM_OP_NOP:
490  case WASM_OP_ELSE:
491  case WASM_OP_RETURN:
492  case WASM_OP_DROP:
493  case WASM_OP_SELECT:
494  case WASM_OP_I32EQZ:
495  case WASM_OP_I32EQ:
496  case WASM_OP_I32NE:
497  case WASM_OP_I32LTS:
498  case WASM_OP_I32LTU:
499  case WASM_OP_I32GTS:
500  case WASM_OP_I32GTU:
501  case WASM_OP_I32LES:
502  case WASM_OP_I32LEU:
503  case WASM_OP_I32GES:
504  case WASM_OP_I32GEU:
505  case WASM_OP_I64EQZ:
506  case WASM_OP_I64EQ:
507  case WASM_OP_I64NE:
508  case WASM_OP_I64LTS:
509  case WASM_OP_I64LTU:
510  case WASM_OP_I64GTS:
511  case WASM_OP_I64GTU:
512  case WASM_OP_I64LES:
513  case WASM_OP_I64LEU:
514  case WASM_OP_I64GES:
515  case WASM_OP_I64GEU:
516  case WASM_OP_F32EQ:
517  case WASM_OP_F32NE:
518  case WASM_OP_F32LT:
519  case WASM_OP_F32GT:
520  case WASM_OP_F32LE:
521  case WASM_OP_F32GE:
522  case WASM_OP_F64EQ:
523  case WASM_OP_F64NE:
524  case WASM_OP_F64LT:
525  case WASM_OP_F64GT:
526  case WASM_OP_F64LE:
527  case WASM_OP_F64GE:
528  case WASM_OP_I32CLZ:
529  case WASM_OP_I32CTZ:
530  case WASM_OP_I32POPCNT:
531  case WASM_OP_I32ADD:
532  case WASM_OP_I32SUB:
533  case WASM_OP_I32MUL:
534  case WASM_OP_I32DIVS:
535  case WASM_OP_I32DIVU:
536  case WASM_OP_I32REMS:
537  case WASM_OP_I32REMU:
538  case WASM_OP_I32AND:
539  case WASM_OP_I32OR:
540  case WASM_OP_I32XOR:
541  case WASM_OP_I32SHL:
542  case WASM_OP_I32SHRS:
543  case WASM_OP_I32SHRU:
544  case WASM_OP_I32ROTL:
545  case WASM_OP_I32ROTR:
546  case WASM_OP_I64CLZ:
547  case WASM_OP_I64CTZ:
548  case WASM_OP_I64POPCNT:
549  case WASM_OP_I64ADD:
550  case WASM_OP_I64SUB:
551  case WASM_OP_I64MUL:
552  case WASM_OP_I64DIVS:
553  case WASM_OP_I64DIVU:
554  case WASM_OP_I64REMS:
555  case WASM_OP_I64REMU:
556  case WASM_OP_I64AND:
557  case WASM_OP_I64OR:
558  case WASM_OP_I64XOR:
559  case WASM_OP_I64SHL:
560  case WASM_OP_I64SHRS:
561  case WASM_OP_I64SHRU:
562  case WASM_OP_I64ROTL:
563  case WASM_OP_I64ROTR:
564  case WASM_OP_F32ABS:
565  case WASM_OP_F32NEG:
566  case WASM_OP_F32CEIL:
567  case WASM_OP_F32FLOOR:
568  case WASM_OP_F32TRUNC:
569  case WASM_OP_F32NEAREST:
570  case WASM_OP_F32SQRT:
571  case WASM_OP_F32ADD:
572  case WASM_OP_F32SUB:
573  case WASM_OP_F32MUL:
574  case WASM_OP_F32DIV:
575  case WASM_OP_F32MIN:
576  case WASM_OP_F32MAX:
577  case WASM_OP_F32COPYSIGN:
578  case WASM_OP_F64ABS:
579  case WASM_OP_F64NEG:
580  case WASM_OP_F64CEIL:
581  case WASM_OP_F64FLOOR:
582  case WASM_OP_F64TRUNC:
583  case WASM_OP_F64NEAREST:
584  case WASM_OP_F64SQRT:
585  case WASM_OP_F64ADD:
586  case WASM_OP_F64SUB:
587  case WASM_OP_F64MUL:
588  case WASM_OP_F64DIV:
589  case WASM_OP_F64MIN:
590  case WASM_OP_F64MAX:
591  case WASM_OP_F64COPYSIGN:
592  case WASM_OP_I32WRAPI64:
617  case WASM_OP_END: {
618  rz_strbuf_set(sb, opdef->txt);
619  } break;
620  case WASM_OP_BLOCK:
621  case WASM_OP_LOOP:
622  case WASM_OP_IF: {
623  st32 val = 0;
624  size_t n = read_i32_leb128(buf + 1, buf + buf_len, &val);
625  if (!(n > 0 && n < buf_len)) {
626  goto err;
627  }
628  switch (0x80 - val) {
630  rz_strbuf_set(sb, opdef->txt);
631  break;
633  rz_strbuf_setf(sb, "%s (result i32)", opdef->txt);
634  break;
636  rz_strbuf_setf(sb, "%s (result i64)", opdef->txt);
637  break;
639  rz_strbuf_setf(sb, "%s (result f32)", opdef->txt);
640  break;
642  rz_strbuf_setf(sb, "%s (result f64)", opdef->txt);
643  break;
645  rz_strbuf_setf(sb, "%s (result v128)", opdef->txt);
646  break;
647  default:
648  rz_strbuf_setf(sb, "%s (result ?)", opdef->txt);
649  break;
650  }
651  op->len += n;
652  } break;
653  case WASM_OP_BR:
654  case WASM_OP_BRIF:
655  case WASM_OP_CALL: {
656  ut32 val = 0;
657  size_t n = read_u32_leb128(buf + 1, buf + buf_len, &val);
658  if (!(n > 0 && n < buf_len)) {
659  goto err;
660  }
661  rz_strbuf_setf(sb, "%s %d", opdef->txt, val);
662  op->len += n;
663  } break;
664  case WASM_OP_BRTABLE: {
665  ut32 count = 0, *table = NULL, def = 0;
666  size_t n = read_u32_leb128(buf + 1, buf + buf_len, &count);
667  if (!(n > 0 && n < buf_len && count < 0xffff)) {
668  goto err;
669  }
670  if (!(table = calloc(count, sizeof(ut32)))) {
671  goto err;
672  }
673  int i = 0;
674  op->len += n;
675  for (i = 0; i < count; i++) {
676  n = read_u32_leb128(buf + op->len, buf + buf_len, &table[i]);
677  if (!(op->len + n <= buf_len)) {
678  goto beach;
679  }
680  if (n < 1) {
681  break;
682  }
683  op->len += n;
684  }
685  n = read_u32_leb128(buf + op->len, buf + buf_len, &def);
686  if (!(n > 0 && n + op->len < buf_len)) {
687  goto beach;
688  }
689  op->len += n;
690  rz_strbuf_setf(sb, "%s %d ", opdef->txt, count);
691  for (i = 0; i < count; i++) {
692  rz_strbuf_appendf(sb, "%d ", table[i]);
693  }
694  rz_strbuf_appendf(sb, "%d", def);
695  free(table);
696  break;
697  beach:
698  free(table);
699  goto err;
700  } break;
701  case WASM_OP_CALLINDIRECT: {
702  ut32 val = 0, reserved = 0;
703  size_t n = read_u32_leb128(buf + 1, buf + buf_len, &val);
704  if (!(n > 0 && n < buf_len)) {
705  goto err;
706  }
707  op->len += n;
708  n = read_u32_leb128(buf + op->len, buf + buf_len, &reserved);
709  if (!(n == 1 && op->len + n <= buf_len)) {
710  goto err;
711  }
712  reserved &= 0x1;
713  rz_strbuf_setf(sb, "%s %d %d", opdef->txt, val, reserved);
714  op->len += n;
715  } break;
716  case WASM_OP_GETLOCAL:
717  case WASM_OP_SETLOCAL:
718  case WASM_OP_TEELOCAL:
719  case WASM_OP_GETGLOBAL:
720  case WASM_OP_SETGLOBAL: {
721  ut32 val = 0;
722  size_t n = read_u32_leb128(buf + 1, buf + buf_len, &val);
723  if (!(n > 0 && n < buf_len)) {
724  goto err;
725  }
726  rz_strbuf_setf(sb, "%s %d", opdef->txt, val);
727  op->len += n;
728  } break;
729  case WASM_OP_I32LOAD:
730  case WASM_OP_I64LOAD:
731  case WASM_OP_F32LOAD:
732  case WASM_OP_F64LOAD:
733  case WASM_OP_I32LOAD8S:
734  case WASM_OP_I32LOAD8U:
735  case WASM_OP_I32LOAD16S:
736  case WASM_OP_I32LOAD16U:
737  case WASM_OP_I64LOAD8S:
738  case WASM_OP_I64LOAD8U:
739  case WASM_OP_I64LOAD16S:
740  case WASM_OP_I64LOAD16U:
741  case WASM_OP_I64LOAD32S:
742  case WASM_OP_I64LOAD32U:
743  case WASM_OP_I32STORE:
744  case WASM_OP_I64STORE:
745  case WASM_OP_F32STORE:
746  case WASM_OP_F64STORE:
747  case WASM_OP_I32STORE8:
748  case WASM_OP_I32STORE16:
749  case WASM_OP_I64STORE8:
750  case WASM_OP_I64STORE16:
751  case WASM_OP_I64STORE32: {
752  ut32 flag = 0, offset = 0;
753  size_t n = read_u32_leb128(buf + 1, buf + buf_len, &flag);
754  if (!(n > 0 && n < buf_len)) {
755  goto err;
756  }
757  op->len += n;
758  n = read_u32_leb128(buf + op->len, buf + buf_len, &offset);
759  if (!(n > 0 && op->len + n <= buf_len)) {
760  goto err;
761  }
762  rz_strbuf_setf(sb, "%s %d %d", opdef->txt, flag, offset);
763  op->len += n;
764  } break;
766  case WASM_OP_GROWMEMORY: {
767  ut32 reserved = 0;
768  size_t n = read_u32_leb128(buf + 1, buf + buf_len, &reserved);
769  if (!(n == 1 && n < buf_len)) {
770  goto err;
771  }
772  reserved &= 0x1;
773  rz_strbuf_setf(sb, "%s %d", opdef->txt, reserved);
774  op->len += n;
775  } break;
776  case WASM_OP_I32CONST: {
777  st32 val = 0;
778  size_t n = read_i32_leb128(buf + 1, buf + buf_len, &val);
779  if (!(n > 0 && n < buf_len)) {
780  goto err;
781  }
782  rz_strbuf_setf(sb, "%s %" PFMT32d, opdef->txt, val);
783  op->len += n;
784  } break;
785  case WASM_OP_I64CONST: {
786  st64 val = 0;
787  size_t n = read_i64_leb128(buf + 1, buf + buf_len, &val);
788  if (!(n > 0 && n < buf_len)) {
789  goto err;
790  }
791  rz_strbuf_setf(sb, "%s %" PFMT64d, opdef->txt, val);
792  op->len += n;
793  } break;
794  case WASM_OP_F32CONST:
795  if (buf_len > 4) {
796  union fi {
797  ut32 v;
798  float f;
799  } u;
800  u.v = rz_read_at_le32(buf, 1);
801  rz_strbuf_setf(sb, "%s %f", opdef->txt, u.f);
802  op->len += 4;
803  } else {
804  goto err;
805  }
806  break;
807  case WASM_OP_F64CONST:
808  if (buf_len > 8) {
809  union di {
810  ut64 v;
811  double f;
812  } u;
813  u.v = rz_read_at_le64(buf, 1);
814  rz_strbuf_setf(sb, "%s %f", opdef->txt, u.f);
815  op->len += 8;
816  } else {
817  goto err;
818  }
819  break;
820  default:
821  goto err;
822  }
823  } else if (id == 0xfe) {
824  op->type = WASM_TYPE_OP_ATOMIC;
825  if (buf_len < 2)
826  goto err;
827  op->len = 2;
828  id = buf[1]; // skip 0xfe
829  op->op.atomic = id;
830  WasmOpDef *opdef = &opcodes_threads[id];
831  switch (id) {
888  ut32 flag = 0, offset = 0;
889  size_t n = read_u32_leb128(buf + 2, buf + buf_len, &flag);
890  if (!(n > 0 && n < buf_len)) {
891  goto err;
892  }
893  op->len += n;
894  n = read_u32_leb128(buf + op->len, buf + buf_len, &offset);
895  if (!(n > 0 && op->len + n <= buf_len)) {
896  goto err;
897  }
898  rz_strbuf_setf(sb, "%s %d %d", opdef->txt, flag, offset);
899  op->len += n;
900  } break;
901  default:
902  goto err;
903  }
904  } else if (id == 0xfd) {
905  if (buf_len < 2) {
906  goto err;
907  }
908  ut32 simdop;
909  op->type = WASM_TYPE_OP_SIMD;
910  size_t simdop_size = read_u32_leb128(buf + 1, buf + buf_len, &simdop);
911  if (simdop_size > buf_len) {
912  goto err;
913  }
914  op->len = 1 + simdop_size;
915  op->op.simd = simdop;
916  id = simdop; // this isn't great because we're losing the sign
917  // but it should never cause problems
918  WasmOpDef *opdef = &opcodes_simd[id];
919  switch (id) {
920  case WASM_OP_I8X16SPLAT:
921  case WASM_OP_I16X8SPLAT:
922  case WASM_OP_I32X4SPLAT:
923  case WASM_OP_I64X2SPLAT:
924  case WASM_OP_F32X4SPLAT:
925  case WASM_OP_F64X2SPLAT:
926  case WASM_OP_I8X16EQ:
927  case WASM_OP_I8X16NE:
928  case WASM_OP_I8X16LTS:
929  case WASM_OP_I8X16LTU:
930  case WASM_OP_I8X16GTS:
931  case WASM_OP_I8X16GTU:
932  case WASM_OP_I8X16LES:
933  case WASM_OP_I8X16LEU:
934  case WASM_OP_I8X16GES:
935  case WASM_OP_I8X16GEU:
936  case WASM_OP_I16X8EQ:
937  case WASM_OP_I16X8NE:
938  case WASM_OP_I16X8LTS:
939  case WASM_OP_I16X8LTU:
940  case WASM_OP_I16X8GTS:
941  case WASM_OP_I16X8GTU:
942  case WASM_OP_I16X8LES:
943  case WASM_OP_I16X8LEU:
944  case WASM_OP_I16X8GES:
945  case WASM_OP_I16X8GEU:
946  case WASM_OP_I32X4EQ:
947  case WASM_OP_I32X4NE:
948  case WASM_OP_I32X4LTS:
949  case WASM_OP_I32X4LTU:
950  case WASM_OP_I32X4GTS:
951  case WASM_OP_I32X4GTU:
952  case WASM_OP_I32X4LES:
953  case WASM_OP_I32X4LEU:
954  case WASM_OP_I32X4GES:
955  case WASM_OP_I32X4GEU:
956  case WASM_OP_F32X4EQ:
957  case WASM_OP_F32X4NE:
958  case WASM_OP_F32X4LT:
959  case WASM_OP_F32X4GT:
960  case WASM_OP_F32X4LE:
961  case WASM_OP_F32X4GE:
962  case WASM_OP_F64X2EQ:
963  case WASM_OP_F64X2NE:
964  case WASM_OP_F64X2LT:
965  case WASM_OP_F64X2GT:
966  case WASM_OP_F64X2LE:
967  case WASM_OP_F64X2GE:
968  case WASM_OP_V128NOT:
969  case WASM_OP_V128AND:
970  case WASM_OP_V128OR:
971  case WASM_OP_V128XOR:
973  case WASM_OP_I8X16NEG:
976  case WASM_OP_I8X16SHL:
977  case WASM_OP_I8X16SHRS:
978  case WASM_OP_I8X16SHRU:
979  case WASM_OP_I8X16ADD:
982  case WASM_OP_I8X16SUB:
985  case WASM_OP_I8X16MINS:
986  case WASM_OP_I8X16MINU:
987  case WASM_OP_I8X16MAXS:
988  case WASM_OP_I8X16MAXU:
989  case WASM_OP_I16X8NEG:
992  case WASM_OP_I16X8SHL:
993  case WASM_OP_I16X8SHRS:
994  case WASM_OP_I16X8SHRU:
995  case WASM_OP_I16X8ADD:
998  case WASM_OP_I16X8SUB:
1001  case WASM_OP_I16X8MUL:
1002  case WASM_OP_I16X8MINS:
1003  case WASM_OP_I16X8MINU:
1004  case WASM_OP_I16X8MAXS:
1005  case WASM_OP_I16X8MAXU:
1006  case WASM_OP_I32X4NEG:
1007  case WASM_OP_I32X4ANYTRUE:
1008  case WASM_OP_I32X4ALLTRUE:
1009  case WASM_OP_I32X4SHL:
1010  case WASM_OP_I32X4SHRS:
1011  case WASM_OP_I32X4SHRU:
1012  case WASM_OP_I32X4ADD:
1013  case WASM_OP_I32X4SUB:
1014  case WASM_OP_I32X4MUL:
1015  case WASM_OP_I32X4MINS:
1016  case WASM_OP_I32X4MINU:
1017  case WASM_OP_I32X4MAXS:
1018  case WASM_OP_I32X4MAXU:
1019  case WASM_OP_I64X2NEG:
1020  case WASM_OP_I64X2SHL:
1021  case WASM_OP_I64X2SHRS:
1022  case WASM_OP_I64X2SHRU:
1023  case WASM_OP_I64X2ADD:
1024  case WASM_OP_I64X2SUB:
1025  case WASM_OP_I64X2MUL:
1026  case WASM_OP_F32X4ABS:
1027  case WASM_OP_F32X4NEG:
1028  case WASM_OP_F32X4SQRT:
1029  case WASM_OP_F32X4ADD:
1030  case WASM_OP_F32X4SUB:
1031  case WASM_OP_F32X4MUL:
1032  case WASM_OP_F32X4DIV:
1033  case WASM_OP_F32X4MIN:
1034  case WASM_OP_F32X4MAX:
1035  case WASM_OP_F64X2ABS:
1036  case WASM_OP_F64X2NEG:
1037  case WASM_OP_F64X2SQRT:
1038  case WASM_OP_F64X2ADD:
1039  case WASM_OP_F64X2SUB:
1040  case WASM_OP_F64X2MUL:
1041  case WASM_OP_F64X2DIV:
1042  case WASM_OP_F64X2MIN:
1043  case WASM_OP_F64X2MAX:
1048  case WASM_OP_V8X16SWIZZLE:
1061  case WASM_OP_V128ANDNOT:
1062  case WASM_OP_I8X16AVGRU:
1063  case WASM_OP_I16X8AVGRU:
1064  case WASM_OP_I8X16ABS:
1065  case WASM_OP_I16X8ABS:
1066  case WASM_OP_I32X4ABS: {
1067  rz_strbuf_set(sb, opdef->txt);
1068  } break;
1069  case WASM_OP_V128LOAD:
1070  case WASM_OP_I16X8LOAD8X8S:
1071  case WASM_OP_I16X8LOAD8X8U:
1080  case WASM_OP_V128STORE: {
1081  ut32 offset = 0, align = 0;
1082  size_t n = read_u32_leb128(buf + 1 + simdop_size, buf + buf_len, &offset);
1083  op->len += n;
1084  if (!(n > 0 && n < buf_len)) {
1085  goto err;
1086  }
1087  n = read_u32_leb128(buf + 1 + simdop_size + n, buf + buf_len, &align);
1088  op->len += n;
1089  if (!(n > 0 && n < buf_len)) {
1090  goto err;
1091  }
1092  rz_strbuf_setf(sb, "%s o:%d a:2^%d", opdef->txt, offset, align);
1093  } break;
1094  case WASM_OP_V128CONST:
1095  case WASM_OP_V8X16SHUFFLE: {
1096  if (buf_len < 18) {
1097  goto err;
1098  }
1099  op->len += 16;
1100  unsigned char bytes[16] = { 0 };
1101  int i;
1102  for (i = 0; i < 16; ++i) {
1103  bytes[i] = buf[i + 1 + simdop_size];
1104  }
1105  rz_strbuf_setf(sb, "%s %02x %02x %02x %02x %02x %02x %02x "
1106  "%02x %02x %02x %02x %02x %02x %02x %02x %02x",
1107  opdef->txt, bytes[0], bytes[1], bytes[2], bytes[3],
1108  bytes[4], bytes[5], bytes[6], bytes[7], bytes[8],
1109  bytes[9], bytes[10], bytes[11], bytes[12], bytes[13],
1110  bytes[14], bytes[15]);
1111  } break;
1125  case WASM_OP_F64X2REPLACELANE: {
1126  if (buf_len < 3) {
1127  goto err;
1128  }
1129  unsigned char lane = buf[1 + simdop_size];
1130  ++op->len;
1131  rz_strbuf_setf(sb, "%s %d", opdef->txt, lane);
1132  } break;
1133  }
1134  } else {
1135  goto err;
1136  }
1137  op->txt = rz_strbuf_drain(sb);
1138  return op->len;
1139 
1140 err:
1141  op->len = 1;
1142  rz_strbuf_set(sb, "invalid");
1143  op->txt = rz_strbuf_drain(sb);
1144  return op->len;
1145 }
size_t len
Definition: 6502dis.c:15
#define RZ_IPI
Definition: analysis_wasm.c:11
lzma_index ** i
Definition: index.h:629
ut16 val
Definition: armass64_const.h:6
static bool err
Definition: armass.c:435
RZ_IPI int wasm_dis(WasmOp *op, const unsigned char *buf, int buf_len)
Definition: wasm.c:479
static WasmOpDef opcodes[256]
Definition: wasm.c:14
static WasmOpDef opcodes_threads[256]
Definition: wasm.c:189
static WasmOpDef opcodes_simd[256]
Definition: wasm.c:257
@ WASM_OP_CALL
Definition: wasm.h:27
@ WASM_OP_F32LOAD
Definition: wasm.h:44
@ WASM_OP_I32TRUNCUF64
Definition: wasm.h:181
@ WASM_OP_I64LES
Definition: wasm.h:93
@ WASM_OP_F64CONVERTUI32
Definition: wasm.h:194
@ WASM_OP_LOOP
Definition: wasm.h:17
@ WASM_OP_I32REMU
Definition: wasm.h:120
@ WASM_OP_I64EQ
Definition: wasm.h:87
@ WASM_OP_SELECT
Definition: wasm.h:32
@ WASM_OP_F32SUB
Definition: wasm.h:155
@ WASM_OP_I64LOAD
Definition: wasm.h:43
@ WASM_OP_I32LOAD16S
Definition: wasm.h:48
@ WASM_OP_GROWMEMORY
Definition: wasm.h:66
@ WASM_OP_I64DIVU
Definition: wasm.h:136
@ WASM_OP_I64GTU
Definition: wasm.h:92
@ WASM_OP_F32NEG
Definition: wasm.h:148
@ WASM_OP_I64LTS
Definition: wasm.h:89
@ WASM_OP_I64LOAD8S
Definition: wasm.h:50
@ WASM_OP_I32GTS
Definition: wasm.h:80
@ WASM_OP_F32EQ
Definition: wasm.h:97
@ WASM_OP_F64REINTERPRETI64
Definition: wasm.h:203
@ WASM_OP_I64STORE
Definition: wasm.h:57
@ WASM_OP_I64LOAD32U
Definition: wasm.h:55
@ WASM_OP_I64SHL
Definition: wasm.h:142
@ WASM_OP_BLOCK
Definition: wasm.h:16
@ WASM_OP_F32REINTERPRETI32
Definition: wasm.h:202
@ WASM_OP_I64ROTR
Definition: wasm.h:146
@ WASM_OP_F32FLOOR
Definition: wasm.h:150
@ WASM_OP_TRAP
Definition: wasm.h:14
@ WASM_OP_I64ROTL
Definition: wasm.h:145
@ WASM_OP_F64FLOOR
Definition: wasm.h:164
@ WASM_OP_F64LOAD
Definition: wasm.h:45
@ WASM_OP_F64GT
Definition: wasm.h:106
@ WASM_OP_I32SUB
Definition: wasm.h:115
@ WASM_OP_BRIF
Definition: wasm.h:22
@ WASM_OP_F32MIN
Definition: wasm.h:158
@ WASM_OP_I32MUL
Definition: wasm.h:116
@ WASM_OP_SETGLOBAL
Definition: wasm.h:39
@ WASM_OP_I32LTS
Definition: wasm.h:78
@ WASM_OP_F32ADD
Definition: wasm.h:154
@ WASM_OP_I32LOAD16U
Definition: wasm.h:49
@ WASM_OP_F64SUB
Definition: wasm.h:169
@ WASM_OP_F32CONVERTUI32
Definition: wasm.h:189
@ WASM_OP_F32CONVERTSI32
Definition: wasm.h:188
@ WASM_OP_I64DIVS
Definition: wasm.h:135
@ WASM_OP_I32POPCNT
Definition: wasm.h:113
@ WASM_OP_I32EQ
Definition: wasm.h:76
@ WASM_OP_I32CONST
Definition: wasm.h:69
@ WASM_OP_I32GES
Definition: wasm.h:84
@ WASM_OP_ELSE
Definition: wasm.h:19
@ WASM_OP_F32CEIL
Definition: wasm.h:149
@ WASM_OP_F64CONVERTSI32
Definition: wasm.h:193
@ WASM_OP_I32GTU
Definition: wasm.h:81
@ WASM_OP_I64STORE16
Definition: wasm.h:63
@ WASM_OP_F64MUL
Definition: wasm.h:170
@ WASM_OP_I64REINTERPRETF64
Definition: wasm.h:201
@ WASM_OP_I64REMS
Definition: wasm.h:137
@ WASM_OP_I64LOAD16U
Definition: wasm.h:53
@ WASM_OP_F64STORE
Definition: wasm.h:59
@ WASM_OP_I64AND
Definition: wasm.h:139
@ WASM_OP_I32AND
Definition: wasm.h:121
@ WASM_OP_F32DIV
Definition: wasm.h:157
@ WASM_OP_CURRENTMEMORY
Definition: wasm.h:65
@ WASM_OP_F32DEMOTEF64
Definition: wasm.h:192
@ WASM_OP_I32LOAD8S
Definition: wasm.h:46
@ WASM_OP_I64EXTENDUI32
Definition: wasm.h:183
@ WASM_OP_F32TRUNC
Definition: wasm.h:151
@ WASM_OP_F32NEAREST
Definition: wasm.h:152
@ WASM_OP_I32EQZ
Definition: wasm.h:75
@ WASM_OP_END
Definition: wasm.h:20
@ WASM_OP_I64SUB
Definition: wasm.h:133
@ WASM_OP_I64SHRU
Definition: wasm.h:144
@ WASM_OP_I32LOAD8U
Definition: wasm.h:47
@ WASM_OP_GETLOCAL
Definition: wasm.h:35
@ WASM_OP_I64CONST
Definition: wasm.h:70
@ WASM_OP_CALLINDIRECT
Definition: wasm.h:28
@ WASM_OP_F64SQRT
Definition: wasm.h:167
@ WASM_OP_GETGLOBAL
Definition: wasm.h:38
@ WASM_OP_I64LOAD32S
Definition: wasm.h:54
@ WASM_OP_I32STORE8
Definition: wasm.h:60
@ WASM_OP_I32NE
Definition: wasm.h:77
@ WASM_OP_I32LEU
Definition: wasm.h:83
@ WASM_OP_I32TRUNCUF32
Definition: wasm.h:179
@ WASM_OP_F32LE
Definition: wasm.h:101
@ WASM_OP_I32ROTR
Definition: wasm.h:128
@ WASM_OP_I64SHRS
Definition: wasm.h:143
@ WASM_OP_I32TRUNCSF64
Definition: wasm.h:180
@ WASM_OP_F32GT
Definition: wasm.h:100
@ WASM_OP_F64CEIL
Definition: wasm.h:163
@ WASM_OP_I64NE
Definition: wasm.h:88
@ WASM_OP_F32CONVERTUI64
Definition: wasm.h:191
@ WASM_OP_I32CTZ
Definition: wasm.h:112
@ WASM_OP_I64GES
Definition: wasm.h:95
@ WASM_OP_I32ROTL
Definition: wasm.h:127
@ WASM_OP_I32LOAD
Definition: wasm.h:42
@ WASM_OP_NOP
Definition: wasm.h:15
@ WASM_OP_F64CONST
Definition: wasm.h:72
@ WASM_OP_F64LE
Definition: wasm.h:107
@ WASM_OP_I64GEU
Definition: wasm.h:96
@ WASM_OP_I64TRUNCUF32
Definition: wasm.h:185
@ WASM_OP_I32OR
Definition: wasm.h:122
@ WASM_OP_I32ADD
Definition: wasm.h:114
@ WASM_OP_I64TRUNCSF64
Definition: wasm.h:186
@ WASM_OP_F32CONST
Definition: wasm.h:71
@ WASM_OP_I32SHRS
Definition: wasm.h:125
@ WASM_OP_F64NEG
Definition: wasm.h:162
@ WASM_OP_F32SQRT
Definition: wasm.h:153
@ WASM_OP_I64MUL
Definition: wasm.h:134
@ WASM_OP_F32STORE
Definition: wasm.h:58
@ WASM_OP_F32GE
Definition: wasm.h:102
@ WASM_OP_I64REMU
Definition: wasm.h:138
@ WASM_OP_F32ABS
Definition: wasm.h:147
@ WASM_OP_F64NE
Definition: wasm.h:104
@ WASM_OP_F64PROMOTEF32
Definition: wasm.h:197
@ WASM_OP_I64STORE8
Definition: wasm.h:62
@ WASM_OP_I32REMS
Definition: wasm.h:119
@ WASM_OP_F64CONVERTSI64
Definition: wasm.h:195
@ WASM_OP_F64EQ
Definition: wasm.h:103
@ WASM_OP_I32CLZ
Definition: wasm.h:111
@ WASM_OP_I32XOR
Definition: wasm.h:123
@ WASM_OP_SETLOCAL
Definition: wasm.h:36
@ WASM_OP_F64ADD
Definition: wasm.h:168
@ WASM_OP_BRTABLE
Definition: wasm.h:23
@ WASM_OP_I32REINTERPRETF32
Definition: wasm.h:200
@ WASM_OP_F32MAX
Definition: wasm.h:159
@ WASM_OP_F64DIV
Definition: wasm.h:171
@ WASM_OP_F64LT
Definition: wasm.h:105
@ WASM_OP_I32STORE16
Definition: wasm.h:61
@ WASM_OP_BR
Definition: wasm.h:21
@ WASM_OP_I32STORE
Definition: wasm.h:56
@ WASM_OP_F32LT
Definition: wasm.h:99
@ WASM_OP_I64CTZ
Definition: wasm.h:130
@ WASM_OP_I64ADD
Definition: wasm.h:132
@ WASM_OP_I64LEU
Definition: wasm.h:94
@ WASM_OP_I32LTU
Definition: wasm.h:79
@ WASM_OP_I64POPCNT
Definition: wasm.h:131
@ WASM_OP_I64TRUNCSF32
Definition: wasm.h:184
@ WASM_OP_F32MUL
Definition: wasm.h:156
@ WASM_OP_I32DIVS
Definition: wasm.h:117
@ WASM_OP_I64STORE32
Definition: wasm.h:64
@ WASM_OP_F64ABS
Definition: wasm.h:161
@ WASM_OP_F32NE
Definition: wasm.h:98
@ WASM_OP_I32TRUNCSF32
Definition: wasm.h:178
@ WASM_OP_F64MAX
Definition: wasm.h:173
@ WASM_OP_I64GTS
Definition: wasm.h:91
@ WASM_OP_I64TRUNCUF64
Definition: wasm.h:187
@ WASM_OP_I32LES
Definition: wasm.h:82
@ WASM_OP_F64GE
Definition: wasm.h:108
@ WASM_OP_I32DIVU
Definition: wasm.h:118
@ WASM_OP_F64MIN
Definition: wasm.h:172
@ WASM_OP_I32GEU
Definition: wasm.h:85
@ WASM_OP_I32SHRU
Definition: wasm.h:126
@ WASM_OP_F64NEAREST
Definition: wasm.h:166
@ WASM_OP_I64LOAD16S
Definition: wasm.h:52
@ WASM_OP_I64OR
Definition: wasm.h:140
@ WASM_OP_I64EXTENDSI32
Definition: wasm.h:182
@ WASM_OP_I64LTU
Definition: wasm.h:90
@ WASM_OP_DROP
Definition: wasm.h:31
@ WASM_OP_I64XOR
Definition: wasm.h:141
@ WASM_OP_I32WRAPI64
Definition: wasm.h:177
@ WASM_OP_TEELOCAL
Definition: wasm.h:37
@ WASM_OP_F32COPYSIGN
Definition: wasm.h:160
@ WASM_OP_I64EQZ
Definition: wasm.h:86
@ WASM_OP_F32CONVERTSI64
Definition: wasm.h:190
@ WASM_OP_I64LOAD8U
Definition: wasm.h:51
@ WASM_OP_I64CLZ
Definition: wasm.h:129
@ WASM_OP_F64TRUNC
Definition: wasm.h:165
@ WASM_OP_F64COPYSIGN
Definition: wasm.h:174
@ WASM_OP_IF
Definition: wasm.h:18
@ WASM_OP_F64CONVERTUI64
Definition: wasm.h:196
@ WASM_OP_I32SHL
Definition: wasm.h:124
@ WASM_OP_RETURN
Definition: wasm.h:24
@ WASM_OP_I16X8ADDSATURATEU
Definition: wasm.h:419
@ WASM_OP_I8X16SUBSATURATEU
Definition: wasm.h:398
@ WASM_OP_F64X2SPLAT
Definition: wasm.h:315
@ WASM_OP_I32X4MAXS
Definition: wasm.h:445
@ WASM_OP_I32X4WIDENLOWI16X8U
Definition: wasm.h:435
@ WASM_OP_I16X8GTU
Definition: wasm.h:347
@ WASM_OP_I32X4MINU
Definition: wasm.h:444
@ WASM_OP_I32X4ADD
Definition: wasm.h:440
@ WASM_OP_I16X8SHL
Definition: wasm.h:414
@ WASM_OP_I32X4SHRU
Definition: wasm.h:439
@ WASM_OP_I64X2NEG
Definition: wasm.h:447
@ WASM_OP_V128BITSELECT
Definition: wasm.h:381
@ WASM_OP_F32X4SPLAT
Definition: wasm.h:314
@ WASM_OP_I8X16LTU
Definition: wasm.h:335
@ WASM_OP_F32X4GT
Definition: wasm.h:365
@ WASM_OP_I16X8NARROWI32X4U
Definition: wasm.h:409
@ WASM_OP_F64X2NE
Definition: wasm.h:369
@ WASM_OP_I8X16SPLAT
Definition: wasm.h:310
@ WASM_OP_I32X4MINS
Definition: wasm.h:443
@ WASM_OP_V128STORE
Definition: wasm.h:304
@ WASM_OP_F32X4MUL
Definition: wasm.h:459
@ WASM_OP_I8X16GEU
Definition: wasm.h:341
@ WASM_OP_I32X4SUB
Definition: wasm.h:441
@ WASM_OP_I16X8LOAD8X8U
Definition: wasm.h:295
@ WASM_OP_F32X4ADD
Definition: wasm.h:457
@ WASM_OP_F64X2MUL
Definition: wasm.h:468
@ WASM_OP_V32X4LOADSPLAT
Definition: wasm.h:302
@ WASM_OP_V128AND
Definition: wasm.h:377
@ WASM_OP_I8X16EXTRACTLANES
Definition: wasm.h:316
@ WASM_OP_I64X2EXTRACTLANE
Definition: wasm.h:324
@ WASM_OP_I8X16ANYTRUE
Definition: wasm.h:386
@ WASM_OP_I16X8SUB
Definition: wasm.h:420
@ WASM_OP_I32X4ALLTRUE
Definition: wasm.h:432
@ WASM_OP_F64X2NEG
Definition: wasm.h:464
@ WASM_OP_I32X4GEU
Definition: wasm.h:361
@ WASM_OP_I64X2SHRS
Definition: wasm.h:449
@ WASM_OP_F32X4ABS
Definition: wasm.h:454
@ WASM_OP_I8X16SHL
Definition: wasm.h:390
@ WASM_OP_F32X4CONVERTI32X4U
Definition: wasm.h:477
@ WASM_OP_F64X2REPLACELANE
Definition: wasm.h:329
@ WASM_OP_I8X16EXTRACTLANEU
Definition: wasm.h:317
@ WASM_OP_I16X8ABS
Definition: wasm.h:404
@ WASM_OP_F64X2SQRT
Definition: wasm.h:465
@ WASM_OP_V16X8LOADSPLAT
Definition: wasm.h:301
@ WASM_OP_V128CONST
Definition: wasm.h:305
@ WASM_OP_F32X4NE
Definition: wasm.h:363
@ WASM_OP_V8X16LOADSPLAT
Definition: wasm.h:300
@ WASM_OP_F64X2MAX
Definition: wasm.h:471
@ WASM_OP_I32X4ABS
Definition: wasm.h:429
@ WASM_OP_I8X16LTS
Definition: wasm.h:334
@ WASM_OP_I8X16AVGRU
Definition: wasm.h:403
@ WASM_OP_I16X8ANYTRUE
Definition: wasm.h:406
@ WASM_OP_F32X4DIV
Definition: wasm.h:460
@ WASM_OP_I32X4LTU
Definition: wasm.h:355
@ WASM_OP_V8X16SHUFFLE
Definition: wasm.h:308
@ WASM_OP_F32X4MAX
Definition: wasm.h:462
@ WASM_OP_I16X8WIDENLOWI8X16S
Definition: wasm.h:410
@ WASM_OP_I8X16NEG
Definition: wasm.h:385
@ WASM_OP_I16X8AVGRU
Definition: wasm.h:428
@ WASM_OP_I32X4ANYTRUE
Definition: wasm.h:431
@ WASM_OP_F32X4CONVERTI32X4S
Definition: wasm.h:476
@ WASM_OP_I64X2SHL
Definition: wasm.h:448
@ WASM_OP_I32X4TRUNCSATF32X4S
Definition: wasm.h:474
@ WASM_OP_I8X16GES
Definition: wasm.h:340
@ WASM_OP_V128LOAD
Definition: wasm.h:293
@ WASM_OP_I8X16EQ
Definition: wasm.h:332
@ WASM_OP_V128NOT
Definition: wasm.h:376
@ WASM_OP_I16X8EXTRACTLANEU
Definition: wasm.h:320
@ WASM_OP_I16X8MAXU
Definition: wasm.h:427
@ WASM_OP_I64X2REPLACELANE
Definition: wasm.h:325
@ WASM_OP_I32X4MAXU
Definition: wasm.h:446
@ WASM_OP_F32X4SQRT
Definition: wasm.h:456
@ WASM_OP_I32X4SHL
Definition: wasm.h:437
@ WASM_OP_F64X2ABS
Definition: wasm.h:463
@ WASM_OP_I32X4SHRS
Definition: wasm.h:438
@ WASM_OP_F32X4SUB
Definition: wasm.h:458
@ WASM_OP_F32X4EQ
Definition: wasm.h:362
@ WASM_OP_I16X8MINS
Definition: wasm.h:424
@ WASM_OP_I16X8ALLTRUE
Definition: wasm.h:407
@ WASM_OP_I64X2LOAD32X2U
Definition: wasm.h:299
@ WASM_OP_I8X16NARROWI16X8S
Definition: wasm.h:388
@ WASM_OP_F64X2LT
Definition: wasm.h:370
@ WASM_OP_I64X2SUB
Definition: wasm.h:452
@ WASM_OP_I64X2LOAD32X2S
Definition: wasm.h:298
@ WASM_OP_I8X16ADD
Definition: wasm.h:393
@ WASM_OP_I8X16ADDSATURATES
Definition: wasm.h:394
@ WASM_OP_I32X4TRUNCSATF32X4U
Definition: wasm.h:475
@ WASM_OP_F32X4REPLACELANE
Definition: wasm.h:327
@ WASM_OP_I16X8SPLAT
Definition: wasm.h:311
@ WASM_OP_I8X16NARROWI16X8U
Definition: wasm.h:389
@ WASM_OP_I16X8ADD
Definition: wasm.h:417
@ WASM_OP_I32X4WIDENHIGHI16X8U
Definition: wasm.h:436
@ WASM_OP_F64X2MIN
Definition: wasm.h:470
@ WASM_OP_I16X8SHRU
Definition: wasm.h:416
@ WASM_OP_I64X2SHRU
Definition: wasm.h:450
@ WASM_OP_F64X2LE
Definition: wasm.h:372
@ WASM_OP_F64X2SUB
Definition: wasm.h:467
@ WASM_OP_I32X4LTS
Definition: wasm.h:354
@ WASM_OP_I32X4REPLACELANE
Definition: wasm.h:323
@ WASM_OP_I32X4MUL
Definition: wasm.h:442
@ WASM_OP_I32X4NEG
Definition: wasm.h:430
@ WASM_OP_I16X8SUBSATURATEU
Definition: wasm.h:422
@ WASM_OP_I16X8EXTRACTLANES
Definition: wasm.h:319
@ WASM_OP_I8X16SHRU
Definition: wasm.h:392
@ WASM_OP_I8X16ADDSATURATEU
Definition: wasm.h:395
@ WASM_OP_F32X4NEG
Definition: wasm.h:455
@ WASM_OP_I32X4GTU
Definition: wasm.h:357
@ WASM_OP_F64X2DIV
Definition: wasm.h:469
@ WASM_OP_I16X8LEU
Definition: wasm.h:349
@ WASM_OP_I32X4GES
Definition: wasm.h:360
@ WASM_OP_V128XOR
Definition: wasm.h:380
@ WASM_OP_I16X8GEU
Definition: wasm.h:351
@ WASM_OP_I8X16SUBSATURATES
Definition: wasm.h:397
@ WASM_OP_I16X8NEG
Definition: wasm.h:405
@ WASM_OP_I16X8MINU
Definition: wasm.h:425
@ WASM_OP_I32X4LOAD16X4U
Definition: wasm.h:297
@ WASM_OP_V64X2LOADSPLAT
Definition: wasm.h:303
@ WASM_OP_I32X4LOAD16X4S
Definition: wasm.h:296
@ WASM_OP_I16X8GES
Definition: wasm.h:350
@ WASM_OP_I16X8LTU
Definition: wasm.h:345
@ WASM_OP_I8X16ALLTRUE
Definition: wasm.h:387
@ WASM_OP_I64X2ADD
Definition: wasm.h:451
@ WASM_OP_I16X8WIDENHIGHI8X16S
Definition: wasm.h:411
@ WASM_OP_I8X16GTS
Definition: wasm.h:336
@ WASM_OP_I8X16REPLACELANE
Definition: wasm.h:318
@ WASM_OP_I32X4EQ
Definition: wasm.h:352
@ WASM_OP_I16X8LES
Definition: wasm.h:348
@ WASM_OP_I16X8LOAD8X8S
Definition: wasm.h:294
@ WASM_OP_V8X16SWIZZLE
Definition: wasm.h:309
@ WASM_OP_I32X4WIDENLOWI16X8S
Definition: wasm.h:433
@ WASM_OP_I16X8GTS
Definition: wasm.h:346
@ WASM_OP_I32X4SPLAT
Definition: wasm.h:312
@ WASM_OP_I16X8MAXS
Definition: wasm.h:426
@ WASM_OP_F64X2GE
Definition: wasm.h:373
@ WASM_OP_I16X8WIDENLOWI8X16U
Definition: wasm.h:412
@ WASM_OP_I16X8ADDSATURATES
Definition: wasm.h:418
@ WASM_OP_I8X16NE
Definition: wasm.h:333
@ WASM_OP_I64X2SPLAT
Definition: wasm.h:313
@ WASM_OP_I8X16LEU
Definition: wasm.h:339
@ WASM_OP_F32X4GE
Definition: wasm.h:367
@ WASM_OP_I8X16SHRS
Definition: wasm.h:391
@ WASM_OP_I32X4GTS
Definition: wasm.h:356
@ WASM_OP_V128ANDNOT
Definition: wasm.h:378
@ WASM_OP_I32X4WIDENHIGHI16X8S
Definition: wasm.h:434
@ WASM_OP_I16X8SUBSATURATES
Definition: wasm.h:421
@ WASM_OP_I8X16LES
Definition: wasm.h:338
@ WASM_OP_F64X2EQ
Definition: wasm.h:368
@ WASM_OP_V128OR
Definition: wasm.h:379
@ WASM_OP_F32X4LE
Definition: wasm.h:366
@ WASM_OP_I32X4LEU
Definition: wasm.h:359
@ WASM_OP_I8X16GTU
Definition: wasm.h:337
@ WASM_OP_F64X2GT
Definition: wasm.h:371
@ WASM_OP_F32X4MIN
Definition: wasm.h:461
@ WASM_OP_I16X8WIDENHIGHI8X16U
Definition: wasm.h:413
@ WASM_OP_F64X2EXTRACTLANE
Definition: wasm.h:328
@ WASM_OP_F32X4EXTRACTLANE
Definition: wasm.h:326
@ WASM_OP_I8X16MAXS
Definition: wasm.h:401
@ WASM_OP_I32X4LES
Definition: wasm.h:358
@ WASM_OP_I8X16MINU
Definition: wasm.h:400
@ WASM_OP_I8X16MINS
Definition: wasm.h:399
@ WASM_OP_I16X8LTS
Definition: wasm.h:344
@ WASM_OP_F64X2ADD
Definition: wasm.h:466
@ WASM_OP_I32X4NE
Definition: wasm.h:353
@ WASM_OP_I16X8MUL
Definition: wasm.h:423
@ WASM_OP_I32X4EXTRACTLANE
Definition: wasm.h:322
@ WASM_OP_F32X4LT
Definition: wasm.h:364
@ WASM_OP_I8X16MAXU
Definition: wasm.h:402
@ WASM_OP_I16X8REPLACELANE
Definition: wasm.h:321
@ WASM_OP_I8X16ABS
Definition: wasm.h:384
@ WASM_OP_I64X2MUL
Definition: wasm.h:453
@ WASM_OP_I8X16SUB
Definition: wasm.h:396
@ WASM_OP_I16X8EQ
Definition: wasm.h:342
@ WASM_OP_I16X8SHRS
Definition: wasm.h:415
@ WASM_OP_I16X8NE
Definition: wasm.h:343
@ WASM_OP_I16X8NARROWI32X4S
Definition: wasm.h:408
@ WASM_OP_I32ATOMICRMWSUB
Definition: wasm.h:243
@ WASM_OP_I32ATOMICRMW16UOR
Definition: wasm.h:258
@ WASM_OP_I32ATOMICWAIT
Definition: wasm.h:214
@ WASM_OP_I64ATOMICLOAD16U
Definition: wasm.h:223
@ WASM_OP_I32ATOMICRMW16USUB
Definition: wasm.h:242
@ WASM_OP_I64ATOMICLOAD32U
Definition: wasm.h:224
@ WASM_OP_I32ATOMICRMW8UAND
Definition: wasm.h:250
@ WASM_OP_I64ATOMICLOAD8U
Definition: wasm.h:222
@ WASM_OP_I32ATOMICRMW8UXOR
Definition: wasm.h:264
@ WASM_OP_I64ATOMICRMW32UOR
Definition: wasm.h:261
@ WASM_OP_I64ATOMICRMW32UCMPXCHG
Definition: wasm.h:284
@ WASM_OP_I32ATOMICRMW8UOR
Definition: wasm.h:257
@ WASM_OP_I64ATOMICRMW8UAND
Definition: wasm.h:252
@ WASM_OP_I64ATOMICRMW8UOR
Definition: wasm.h:259
@ WASM_OP_I64ATOMICRMW16UADD
Definition: wasm.h:239
@ WASM_OP_I32ATOMICRMWOR
Definition: wasm.h:255
@ WASM_OP_I64ATOMICRMW32UADD
Definition: wasm.h:240
@ WASM_OP_I32ATOMICSTORE16
Definition: wasm.h:228
@ WASM_OP_I32ATOMICRMW8UADD
Definition: wasm.h:236
@ WASM_OP_I64ATOMICLOAD
Definition: wasm.h:219
@ WASM_OP_I64ATOMICSTORE32
Definition: wasm.h:231
@ WASM_OP_ATOMICNOTIFY
Definition: wasm.h:213
@ WASM_OP_I32ATOMICRMW16UCMPXCHG
Definition: wasm.h:281
@ WASM_OP_I64ATOMICRMW8UXCHG
Definition: wasm.h:273
@ WASM_OP_I32ATOMICRMW8USUB
Definition: wasm.h:241
@ WASM_OP_I32ATOMICSTORE
Definition: wasm.h:225
@ WASM_OP_I32ATOMICRMWXOR
Definition: wasm.h:262
@ WASM_OP_I32ATOMICRMW16UADD
Definition: wasm.h:237
@ WASM_OP_I64ATOMICSTORE8
Definition: wasm.h:229
@ WASM_OP_I64ATOMICRMW32UXOR
Definition: wasm.h:268
@ WASM_OP_I32ATOMICLOAD16U
Definition: wasm.h:221
@ WASM_OP_I64ATOMICRMWXCHG
Definition: wasm.h:270
@ WASM_OP_I32ATOMICLOAD8U
Definition: wasm.h:220
@ WASM_OP_I32ATOMICRMW8UCMPXCHG
Definition: wasm.h:280
@ WASM_OP_I64ATOMICRMW16UAND
Definition: wasm.h:253
@ WASM_OP_I64ATOMICRMW32UAND
Definition: wasm.h:254
@ WASM_OP_I64ATOMICRMW16UXOR
Definition: wasm.h:267
@ WASM_OP_I32ATOMICRMWXCHG
Definition: wasm.h:269
@ WASM_OP_I64ATOMICRMWOR
Definition: wasm.h:256
@ WASM_OP_I64ATOMICRMWAND
Definition: wasm.h:249
@ WASM_OP_I32ATOMICSTORE8
Definition: wasm.h:227
@ WASM_OP_I64ATOMICSTORE16
Definition: wasm.h:230
@ WASM_OP_I32ATOMICRMW16UAND
Definition: wasm.h:251
@ WASM_OP_I64ATOMICRMWCMPXCHG
Definition: wasm.h:279
@ WASM_OP_I64ATOMICRMW8UADD
Definition: wasm.h:238
@ WASM_OP_I32ATOMICRMWAND
Definition: wasm.h:248
@ WASM_OP_I64ATOMICSTORE
Definition: wasm.h:226
@ WASM_OP_I32ATOMICRMW16UXCHG
Definition: wasm.h:272
@ WASM_OP_I64ATOMICRMW16UOR
Definition: wasm.h:260
@ WASM_OP_I32ATOMICLOAD
Definition: wasm.h:218
@ WASM_OP_I64ATOMICRMW16UXCHG
Definition: wasm.h:274
@ WASM_OP_I32ATOMICRMW8UXCHG
Definition: wasm.h:271
@ WASM_OP_I64ATOMICRMW32USUB
Definition: wasm.h:246
@ WASM_OP_I64ATOMICRMW32UXCHG
Definition: wasm.h:275
@ WASM_OP_I64ATOMICRMW8USUB
Definition: wasm.h:244
@ WASM_OP_I32ATOMICRMW16UXOR
Definition: wasm.h:265
@ WASM_OP_I64ATOMICRMW8UXOR
Definition: wasm.h:266
@ WASM_OP_I64ATOMICRMW16UCMPXCHG
Definition: wasm.h:283
@ WASM_OP_I32ATOMICRMWADD
Definition: wasm.h:234
@ WASM_OP_I32ATOMICRMWCMPXCHG
Definition: wasm.h:278
@ WASM_OP_I64ATOMICRMW8UCMPXCHG
Definition: wasm.h:282
@ WASM_OP_I64ATOMICWAIT
Definition: wasm.h:215
@ WASM_OP_I64ATOMICRMWSUB
Definition: wasm.h:247
@ WASM_OP_I64ATOMICRMWADD
Definition: wasm.h:235
@ WASM_OP_I64ATOMICRMWXOR
Definition: wasm.h:263
@ WASM_OP_I64ATOMICRMW16USUB
Definition: wasm.h:245
RZ_IPI int wasm_asm(const char *str, unsigned char *buf, int buf_len)
@ WASM_TYPE_OP_ATOMIC
Definition: wasm.h:482
@ WASM_TYPE_OP_SIMD
Definition: wasm.h:483
@ WASM_TYPE_OP_CORE
Definition: wasm.h:481
static ut8 bytes[32]
Definition: asm_arc.c:23
static int buf_len
Definition: asm_arc.c:22
@ RZ_BIN_WASM_VALUETYPE_v128
Definition: wasm.h:39
@ RZ_BIN_WASM_VALUETYPE_i32
Definition: wasm.h:35
@ RZ_BIN_WASM_VALUETYPE_f64
Definition: wasm.h:38
@ RZ_BIN_WASM_VALUETYPE_f32
Definition: wasm.h:37
@ RZ_BIN_WASM_VALUETYPE_i64
Definition: wasm.h:36
@ RZ_BIN_WASM_VALUETYPE_EMPTY
Definition: wasm.h:42
static SblHeader sb
Definition: bin_mbn.c:26
#define NULL
Definition: cris-opc.c:27
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
uint32_t ut32
const char * v
Definition: dsignal.c:12
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf uLong offset
Definition: ioapi.h:144
voidpf void * buf
Definition: ioapi.h:138
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
@ reserved
Definition: lm32_isa.h:94
int n
Definition: mipsasm.c:19
int id
Definition: op.c:540
static ut64 rz_read_at_le64(const void *src, size_t offset)
Definition: rz_endian.h:272
static ut32 rz_read_at_le32(const void *src, size_t offset)
Definition: rz_endian.h:248
RZ_API RZ_OWN char * rz_strbuf_drain(RzStrBuf *sb)
Definition: strbuf.c:342
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
Definition: strbuf.c:153
RZ_API const char * rz_strbuf_setf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API RzStrBuf * rz_strbuf_new(const char *s)
Definition: strbuf.c:8
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
#define PFMT64d
Definition: rz_types.h:394
#define PFMT32d
Definition: rz_types.h:408
#define st64
Definition: rz_types_base.h:10
#define st32
Definition: rz_types_base.h:12
RZ_API size_t read_i32_leb128(const ut8 *p, const ut8 *max, st32 *out_val)
Definition: uleb128.c:211
RZ_API size_t read_i64_leb128(const ut8 *p, const ut8 *max, st64 *out_val)
Definition: uleb128.c:282
RZ_API size_t read_u32_leb128(const ut8 *p, const ut8 *max, ut32 *out_val)
Definition: uleb128.c:186
#define f(i)
Definition: sha256.c:46
const char * txt
Definition: wasm.h:498
Definition: wasm.h:486
Definition: dis.c:32
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
int def(FILE *source, FILE *dest, int level)
Definition: zpipe.c:36