Rizin
unix-like reverse engineering framework and cli tools
parse_sh_pseudo.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <rz_lib.h>
#include <rz_util.h>
#include <rz_flag.h>
#include <rz_analysis.h>
#include <rz_parse.h>
#include "parse_common.c"

Go to the source code of this file.

Functions

static RzListsh_tokenize (const char *assembly, size_t length)
 
static bool parse (RzParse *parse, const char *assembly, RzStrBuf *sb)
 

Variables

static const RzPseudoGrammar sh_lexicon []
 
static const RzPseudoReplace sh_replace []
 
static const RzPseudoConfig sh_config = RZ_PSEUDO_DEFINE_CONFIG_NO_DIRECT(sh_lexicon, sh_replace, 4, sh_tokenize)
 
RzParsePlugin rz_parse_plugin_sh_pseudo
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ parse()

static bool parse ( RzParse parse,
const char *  assembly,
RzStrBuf sb 
)
static

Definition at line 171 of file parse_sh_pseudo.c.

171  {
172  return rz_pseudo_convert(&sh_config, assembly, sb);
173 }
static SblHeader sb
Definition: bin_mbn.c:26
static bool rz_pseudo_convert(const RzPseudoConfig *config, const char *assembly, RzStrBuf *sb)
Definition: parse_common.c:103
static const RzPseudoConfig sh_config

References rz_pseudo_convert(), sb, and sh_config.

◆ sh_tokenize()

RzList * sh_tokenize ( const char *  assembly,
size_t  length 
)
static

Definition at line 132 of file parse_sh_pseudo.c.

132  {
133  size_t i, p;
134  char *buf = NULL;
135  bool ignore_comma = false;
136  RzList *tokens = NULL;
137 
138  buf = rz_str_ndup(assembly, length);
139  if (!buf) {
140  return NULL;
141  }
142 
143  for (i = 0, p = 0; p < length; ++i, ++p) {
144  if (buf[p] == ',' && !ignore_comma) {
145  p++;
146  } else if (buf[p] == '(') {
147  ignore_comma = true;
148  } else if (buf[p] == ')') {
149  ignore_comma = false;
150  }
151  if (p > i) {
152  buf[i] = buf[p];
153  }
154  }
155  buf[i] = 0;
156 
157  tokens = rz_str_split_duplist(buf, " ", true);
158  free(buf);
159  if (!tokens) {
160  return NULL;
161  }
162 
163  RzListIter *it;
164  rz_list_foreach (tokens, it, buf) {
165  it->data = rz_str_replace(buf, ",", " + ", 1);
166  }
167 
168  return tokens;
169 }
lzma_index ** i
Definition: index.h:629
#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 static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void * buf
Definition: ioapi.h:138
void * p
Definition: libc.cpp:67
RZ_API char * rz_str_ndup(RZ_NULLABLE const char *ptr, int len)
Create new copy of string ptr limited to size len.
Definition: str.c:1006
RZ_API RzList * rz_str_split_duplist(const char *str, const char *c, bool trim)
Split the string str according to the substring c and returns a RzList with the result.
Definition: str.c:3464
RZ_API char * rz_str_replace(char *str, const char *key, const char *val, int g)
Definition: str.c:1110
void * data
Definition: rz_list.h:14

References rz_list_iter_t::data, free(), i, length, NULL, p, rz_str_ndup(), rz_str_replace(), and rz_str_split_duplist().

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.version = RZ_VERSION
}
RzParsePlugin rz_parse_plugin_sh_pseudo
@ RZ_LIB_TYPE_PARSE
Definition: rz_lib.h:74
#define RZ_VERSION
Definition: rz_version.h:8

Definition at line 182 of file parse_sh_pseudo.c.

◆ rz_parse_plugin_sh_pseudo

RzParsePlugin rz_parse_plugin_sh_pseudo
Initial value:
= {
.name = "sh.pseudo",
.desc = "SH-4 pseudo syntax",
.parse = parse
}
Definition: regcomp.c:57

Definition at line 175 of file parse_sh_pseudo.c.

◆ sh_config

Definition at line 130 of file parse_sh_pseudo.c.

Referenced by parse().

◆ sh_lexicon

const RzPseudoGrammar sh_lexicon[]
static

Definition at line 18 of file parse_sh_pseudo.c.

◆ sh_replace

const RzPseudoReplace sh_replace[]
static
Initial value:
= {
RZ_PSEUDO_DEFINE_REPLACE("+ -", "- ", 1),
}
#define RZ_PSEUDO_DEFINE_REPLACE(x, y, f)
Definition: parse_common.c:64

Definition at line 126 of file parse_sh_pseudo.c.