Rizin
unix-like reverse engineering framework and cli tools
parse_wasm_pseudo.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2019 deroad <wargio@libero.it>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <rz_lib.h>
8 #include <rz_util.h>
9 #include <rz_flag.h>
10 #include <rz_analysis.h>
11 #include <rz_parse.h>
12 
13 static char *get_fcn_name(RzAnalysis *analysis, ut32 fcn_id) {
14  rz_cons_push();
15  char *s = analysis->coreb.cmdstrf(analysis->coreb.core, "is~FUNC[6:%u]", fcn_id);
16  rz_cons_pop();
17  if (s) {
18  size_t namelen = strlen(s);
19  s[namelen - 1] = 0;
20  }
21  return s;
22 }
23 
24 static bool subvar(RzParse *p, RzAnalysisFunction *f, RzAnalysisOp *op, char *data, char *str, int len) {
25  char *fcn_name = NULL;
26  str[0] = 0;
27  if (!strncmp(data, "call ", 5)) {
28  ut32 fcn_id = (ut32)rz_num_get(NULL, data + 5);
29  if (!(fcn_name = get_fcn_name(p->analb.analysis, fcn_id))) {
30  return false;
31  }
32  snprintf(str, len, "call sym.%s", fcn_name);
33  free(fcn_name);
34  return true;
35  }
36  return false;
37 }
38 
40  .name = "wasm.pseudo",
41  .desc = "WASM pseudo syntax",
42  .subvar = &subvar,
43 };
44 
45 #ifndef RZ_PLUGIN_INCORE
49  .version = RZ_VERSION
50 };
51 #endif
size_t len
Definition: 6502dis.c:15
RZ_API void rz_cons_pop(void)
Definition: cons.c:876
RZ_API void rz_cons_push(void)
Definition: cons.c:860
#define RZ_API
#define NULL
Definition: cris-opc.c:27
uint32_t ut32
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
snprintf
Definition: kernel.h:364
void * p
Definition: libc.cpp:67
static char * get_fcn_name(RzAnalysis *analysis, ut32 fcn_id)
static bool subvar(RzParse *p, RzAnalysisFunction *f, RzAnalysisOp *op, char *data, char *str, int len)
RZ_API RzLibStruct rizin_plugin
RzParsePlugin rz_parse_plugin_wasm_pseudo
static RzSocket * s
Definition: rtr.c:28
@ RZ_LIB_TYPE_PARSE
Definition: rz_lib.h:74
RZ_API ut64 rz_num_get(RzNum *num, const char *str)
Definition: unum.c:172
#define RZ_VERSION
Definition: rz_version.h:8
#define f(i)
Definition: sha256.c:46
RzCoreBind coreb
Definition: rz_analysis.h:580
RzCoreCmdStrF cmdstrf
Definition: rz_bind.h:35
void * core
Definition: rz_bind.h:31
Definition: dis.c:32