Rizin
unix-like reverse engineering framework and cli tools
parse.c File Reference
#include <stdio.h>
#include <rz_types.h>
#include <rz_parse.h>
#include <config.h>

Go to the source code of this file.

Functions

 RZ_LIB_VERSION (rz_parse)
 
RZ_API RzParserz_parse_new (void)
 
RZ_API void rz_parse_free (RzParse *p)
 
RZ_API bool rz_parse_add (RzParse *p, RzParsePlugin *foo)
 
RZ_API bool rz_parse_use (RzParse *p, const char *name)
 
RZ_API bool rz_parse_assemble (RzParse *p, char *data, char *str)
 
RZ_API char * rz_parse_pseudocode (RzParse *p, const char *assembly)
 Converts the assembly line into pseudocode. More...
 
RZ_API char * rz_parse_immtrim (char *opstr)
 
RZ_API bool rz_parse_subvar (RzParse *p, RZ_NULLABLE RzAnalysisFunction *f, RZ_NONNULL RzAnalysisOp *op, RZ_NONNULL RZ_IN char *data, RZ_BORROW RZ_NONNULL RZ_OUT char *str, int len)
 
RZ_API void rz_parse_set_user_ptr (RzParse *p, void *user)
 

Variables

static RzParsePluginparse_static_plugins [] = { RZ_PARSE_STATIC_PLUGINS }
 

Function Documentation

◆ RZ_LIB_VERSION()

RZ_LIB_VERSION ( rz_parse  )

◆ rz_parse_add()

RZ_API bool rz_parse_add ( RzParse p,
RzParsePlugin foo 
)

Definition at line 45 of file parse.c.

45  {
46  bool itsFine = true;
47  if (foo->init) {
48  itsFine = foo->init(p, p->user);
49  }
50  if (itsFine) {
51  rz_list_append(p->parsers, foo);
52  }
53  return true;
54 }
void * p
Definition: libc.cpp:67
static RzMain foo[]
Definition: main.c:11
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288

References foo, p, and rz_list_append().

Referenced by rz_parse_new().

◆ rz_parse_assemble()

RZ_API bool rz_parse_assemble ( RzParse p,
char *  data,
char *  str 
)

Definition at line 72 of file parse.c.

72  {
73  char *in = strdup(str);
74  bool ret = false;
75  char *s, *o;
76 
77  data[0] = '\0';
78  if (p->cur && p->cur->assemble) {
79  o = data + strlen(data);
80  do {
81  s = strchr(str, ';');
82  if (s) {
83  *s = '\0';
84  }
85  ret = p->cur->assemble(p, o, str);
86  if (!ret) {
87  break;
88  }
89  if (s) {
90  str = s + 1;
91  o += strlen(data);
92  o[0] = '\n';
93  o[1] = '\0';
94  o++;
95  }
96  } while (s);
97  }
98  free(in);
99  return ret;
100 }
const lzma_allocator const uint8_t * in
Definition: block.h:527
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
static RzSocket * s
Definition: rtr.c:28

References free(), in, p, s, cmd_descs_generate::str, and strdup().

◆ rz_parse_free()

RZ_API void rz_parse_free ( RzParse p)

Definition at line 40 of file parse.c.

40  {
41  rz_list_free(p->parsers);
42  free(p);
43 }
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137

References free(), p, and rz_list_free().

Referenced by rz_asm_sub_names_input(), rz_asm_sub_names_output(), rz_core_fini(), and rz_parse_new().

◆ rz_parse_immtrim()

RZ_API char* rz_parse_immtrim ( char *  opstr)

Definition at line 127 of file parse.c.

127  {
128  if (!opstr || !*opstr) {
129  return NULL;
130  }
131  char *n = strstr(opstr, "0x");
132  if (n) {
133  char *p = n + 2;
134  while (IS_HEXCHAR(*p)) {
135  p++;
136  }
137  memmove(n, p, strlen(p) + 1);
138  }
139  if (strstr(opstr, " - ]")) {
140  opstr = rz_str_replace(opstr, " - ]", "]", 1);
141  }
142  if (strstr(opstr, " + ]")) {
143  opstr = rz_str_replace(opstr, " + ]", "]", 1);
144  }
145  if (strstr(opstr, ", ]")) {
146  opstr = rz_str_replace(opstr, ", ]", "]", 1);
147  }
148  if (strstr(opstr, " - ")) {
149  opstr = rz_str_replace(opstr, " - ", "-", 1);
150  }
151  if (strstr(opstr, " + ")) {
152  opstr = rz_str_replace(opstr, " + ", "+", 1);
153  }
154  return opstr;
155 }
static int opstr(RzAsm *a, ut8 *data, const Opcode *op)
Definition: asm_x86_nz.c:4054
#define NULL
Definition: cris-opc.c:27
int n
Definition: mipsasm.c:19
RZ_API char * rz_str_replace(char *str, const char *key, const char *val, int g)
Definition: str.c:1110
#define IS_HEXCHAR(x)
Definition: rz_str_util.h:9

References IS_HEXCHAR, n, NULL, opstr(), p, and rz_str_replace().

Referenced by ds_build_op_str(), rz_core_disasm_pdi_with_buf(), and rz_core_print_disasm_instructions_with_buf().

◆ rz_parse_new()

RZ_API RzParse* rz_parse_new ( void  )

Definition at line 16 of file parse.c.

16  {
17  int i;
19  if (!p) {
20  return NULL;
21  }
22  p->parsers = rz_list_newf(NULL); // memleak
23  if (!p->parsers) {
25  return NULL;
26  }
27  p->notin_flagspace = NULL;
28  p->flagspace = NULL;
29  p->pseudo = false;
30  p->subrel = false;
31  p->subtail = false;
32  p->minval = 0x100;
33  p->localvar_only = false;
34  for (i = 0; i < RZ_ARRAY_SIZE(parse_static_plugins); i++) {
36  }
37  return p;
38 }
lzma_index ** i
Definition: index.h:629
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API void rz_parse_free(RzParse *p)
Definition: parse.c:40
RZ_API bool rz_parse_add(RzParse *p, RzParsePlugin *foo)
Definition: parse.c:45
static RzParsePlugin * parse_static_plugins[]
Definition: parse.c:14
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_ARRAY_SIZE(x)
Definition: rz_types.h:300

References i, NULL, p, parse_static_plugins, RZ_ARRAY_SIZE, rz_list_newf(), RZ_NEW0, rz_parse_add(), and rz_parse_free().

Referenced by rz_asm_sub_names_input(), rz_asm_sub_names_output(), and rz_core_init().

◆ rz_parse_pseudocode()

RZ_API char* rz_parse_pseudocode ( RzParse p,
const char *  assembly 
)

Converts the assembly line into pseudocode.

Converts the assembly line into pseudocode

Definition at line 107 of file parse.c.

107  {
109  if (RZ_STR_ISEMPTY(assembly)) {
110  return NULL;
111  }
112 
113  RzStrBuf *sb = rz_strbuf_new("");
114  if (!sb) {
115  return NULL;
116  }
117 
118  rz_strbuf_reserve(sb, 128);
119  if (!p->cur || !p->cur->parse || !p->cur->parse(p, assembly, sb)) {
121  return NULL;
122  }
123 
124  return rz_strbuf_drain(sb);
125 }
static SblHeader sb
Definition: bin_mbn.c:26
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67
RZ_API RZ_OWN char * rz_strbuf_drain(RzStrBuf *sb)
Definition: strbuf.c:342
RZ_API bool rz_strbuf_reserve(RzStrBuf *sb, size_t len)
Definition: strbuf.c:67
RZ_API RzStrBuf * rz_strbuf_new(const char *s)
Definition: strbuf.c:8
RZ_API void rz_strbuf_free(RzStrBuf *sb)
Definition: strbuf.c:358

References NULL, p, rz_return_val_if_fail, RZ_STR_ISEMPTY, rz_strbuf_drain(), rz_strbuf_free(), rz_strbuf_new(), rz_strbuf_reserve(), and sb.

Referenced by ds_build_op_str(), ds_disassemble(), parseHeap(), rz_asm_assemble(), rz_asm_mdisassemble_hexstr(), and rz_core_analysis_bytes().

◆ rz_parse_set_user_ptr()

RZ_API void rz_parse_set_user_ptr ( RzParse p,
void *  user 
)

Definition at line 175 of file parse.c.

175  {
176  p->user = user;
177 }

References p.

Referenced by rz_core_init().

◆ rz_parse_subvar()

RZ_API bool rz_parse_subvar ( RzParse p,
RZ_NULLABLE RzAnalysisFunction f,
RZ_NONNULL RzAnalysisOp op,
RZ_NONNULL RZ_IN char *  data,
RZ_BORROW RZ_NONNULL RZ_OUT char *  str,
int  len 
)

Definition at line 166 of file parse.c.

166  {
167  rz_return_val_if_fail(op && data && str, false);
168  if (p->cur && p->cur->subvar) {
169  return p->cur->subvar(p, f, op, data, str, len);
170  }
171  return false;
172 }
size_t len
Definition: 6502dis.c:15
#define f(i)
Definition: sha256.c:46
Definition: dis.c:32

References f, len, p, rz_return_val_if_fail, and cmd_descs_generate::str.

Referenced by ds_build_op_str(), rz_core_analysis_bytes(), and rz_core_disasm_instruction().

◆ rz_parse_use()

RZ_API bool rz_parse_use ( RzParse p,
const char *  name 
)

Definition at line 56 of file parse.c.

56  {
59  rz_return_val_if_fail(p && name, false);
60  rz_list_foreach (p->parsers, iter, h) {
61  if (!strcmp(h->name, name)) {
62  p->cur = h;
63  return true;
64  }
65  }
66  p->cur = NULL;
67  return false;
68 }
#define h(i)
Definition: sha256.c:48
Definition: z80asm.h:102

References h, NULL, p, and rz_return_val_if_fail.

Referenced by cb_asmparser(), rz_asm_sub_names_input(), and rz_asm_sub_names_output().

Variable Documentation

◆ parse_static_plugins

RzParsePlugin* parse_static_plugins[] = { RZ_PARSE_STATIC_PLUGINS }
static

Definition at line 14 of file parse.c.

Referenced by rz_parse_new().