Rizin
unix-like reverse engineering framework and cli tools
parse_att2intel.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>

Go to the source code of this file.

Functions

static int replace (int argc, const char *argv[], char *newstr)
 
static bool parse (RzParse *p, const char *data, RzStrBuf *sb)
 

Variables

RzParsePlugin rz_parse_plugin_att2intel
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ parse()

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

Definition at line 71 of file parse_att2intel.c.

71  {
72  int i, n;
73  char w0[32];
74  char w1[32];
75  char w2[32];
76  char w3[32];
77  char str[1024] = { 0 };
78  char *buf, *ptr, *optr, *num;
79 
80  // malloc can be slow here :?
81  buf = strdup(data);
82  if (!buf) {
83  return false;
84  }
86 
87  ptr = strchr(buf, '#');
88  if (ptr) {
89  *ptr = 0;
91  }
92  if (*buf == '.' || buf[strlen(buf) - 1] == ':') {
93  free(buf);
94  strcpy(str, data);
95  return true;
96  }
97  rz_str_replace_char(buf, '$', 0);
98  rz_str_replace_char(buf, '%', 0);
99  rz_str_replace_char(buf, '\t', ' ');
100  rz_str_replace_char(buf, '(', '[');
101  rz_str_replace_char(buf, ')', ']');
102  ptr = strchr(buf, '[');
103  if (ptr) {
104  *ptr = 0;
105  num = (char *)rz_str_lchr(buf, ' ');
106  if (!num) {
107  num = (char *)rz_str_lchr(buf, ',');
108  }
109  if (num) {
110  n = atoi(num + 1);
111  *ptr = '[';
112  rz_str_cpy(num + 1, ptr);
113  ptr = (char *)rz_str_lchr(buf, ']');
114  if (n && ptr) {
115  char *rest = strdup(ptr + 1);
116  size_t dist = strlen(data) + 1 - (ptr - buf);
117  snprintf(ptr, dist, "%+d]%s", n, rest);
118  free(rest);
119  }
120  } else {
121  *ptr = '[';
122  }
123  }
124 
125  if (*buf) {
126  *w0 = *w1 = *w2 = *w3 = 0;
127  ptr = strchr(buf, ' ');
128  if (!ptr) {
129  ptr = strchr(buf, '\t');
130  }
131  if (ptr) {
132  *ptr = '\0';
133  for (++ptr; *ptr == ' '; ptr++) {
134  ;
135  }
136  strncpy(w0, buf, sizeof(w0) - 1);
137  strncpy(w1, ptr, sizeof(w1) - 1);
138 
139  optr = ptr;
140  ptr = strchr(ptr, ',');
141  if (ptr) {
142  *ptr = '\0';
143  for (++ptr; *ptr == ' '; ptr++) {
144  ;
145  }
146  strncpy(w1, optr, sizeof(w1) - 1);
147  strncpy(w2, ptr, sizeof(w2) - 1);
148  ptr = strchr(ptr, ',');
149  if (ptr) {
150  *ptr = '\0';
151  for (++ptr; *ptr == ' '; ptr++) {
152  ;
153  }
154  strncpy(w2, optr, sizeof(w2) - 1);
155  strncpy(w3, ptr, sizeof(w3) - 1);
156  }
157  }
158  }
159  {
160  const char *wa[] = { w0, w1, w2, w3 };
161  int nw = 0;
162  for (i = 0; i < 4; i++) {
163  if (wa[i][0] != '\0') {
164  nw++;
165  }
166  }
167  replace(nw, wa, str);
168  }
169  }
170  free(buf);
171  rz_strbuf_set(sb, str);
172  return true;
173 }
lzma_index ** i
Definition: index.h:629
static SblHeader sb
Definition: bin_mbn.c:26
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void * buf
Definition: ioapi.h:138
snprintf
Definition: kernel.h:364
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who const char struct statfs static buf unsigned unsigned num
Definition: sflib.h:126
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")
int n
Definition: mipsasm.c:19
static int replace(int argc, const char *argv[], char *newstr)
RZ_API const char * rz_str_lchr(const char *str, char chr)
Definition: str.c:669
RZ_API void rz_str_trim_head(RZ_NONNULL char *str)
Removes whitespace characters (space, tab, newline etc.) from the end of a string....
Definition: str_trim.c:110
#define rz_str_cpy(x, y)
Definition: rz_str.h:109
RZ_API void rz_str_trim(RZ_NONNULL RZ_INOUT char *str)
Removes whitespace characters (space, tab, newline etc.) from the beginning and end of a string.
Definition: str_trim.c:190
RZ_API int rz_str_replace_char(char *s, int a, int b)
Definition: str.c:169
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
Definition: strbuf.c:153

References free(), i, n, num, replace(), rz_str_cpy, rz_str_lchr(), rz_str_replace_char(), rz_str_trim(), rz_str_trim_head(), rz_strbuf_set(), sb, snprintf, cmd_descs_generate::str, strdup(), w0, w1, w2, and w3.

◆ replace()

static int replace ( int  argc,
const char *  argv[],
char *  newstr 
)
static

Definition at line 14 of file parse_att2intel.c.

14  {
15  int i, j, k;
16  struct {
17  char *op;
18  char *str;
19  } ops[] = {
20  { "cmpl", "cmp 2, 1" },
21  { "testl", "test 2, 1" },
22  { "leal", "lea 2, 1" },
23  { "movl", "mov 2, 1" },
24  { "xorl", "xor 2, 1" },
25  { "andl", "and 2, 1" },
26  { "orl", "or 2, 1" },
27  { "addl", "add 2, 1" },
28  { "incl", "inc 1" },
29  { "decl", "dec 1" },
30  { "subl", "sub 2, 1" },
31  { "mull", "mul 2, 1" },
32  { "divl", "div 2, 1" },
33  { "pushl", "push 1" },
34  { "popl", "pop 1" },
35  { "ret", "ret" },
36  { NULL }
37  };
38 
39  for (i = 0; ops[i].op != NULL; i++) {
40  if (!strcmp(ops[i].op, argv[0])) {
41  if (newstr != NULL) {
42  for (j = k = 0; ops[i].str[j] != '\0'; j++, k++) {
43  if (ops[i].str[j] >= '0' && ops[i].str[j] <= '9') {
44  const char *w = argv[ops[i].str[j] - '0'];
45  if (w != NULL) {
46  strcpy(newstr + k, w);
47  k += strlen(w) - 1;
48  }
49  } else {
50  newstr[k] = ops[i].str[j];
51  }
52  }
53  newstr[k] = '\0';
54  }
55  return true;
56  }
57  }
58 
59  /* TODO: this is slow */
60  if (newstr != NULL) {
61  newstr[0] = '\0';
62  for (i = 0; i < argc; i++) {
63  strcat(newstr, argv[i]);
64  strcat(newstr, (i == 0 || i == argc - 1) ? " " : ",");
65  }
66  }
67 
68  return false;
69 }
static struct @29 ops[]
ut8 op
Definition: 6502dis.c:13
static RASN1String * newstr(const char *string)
Definition: astr.c:23
#define NULL
Definition: cris-opc.c:27
#define w
Definition: crypto_rc6.c:13
const char * k
Definition: dsignal.c:11
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
Definition: dis.c:32

References argv, i, k, newstr(), NULL, op, ops, cmd_descs_generate::str, and w.

Referenced by parse().

Variable Documentation

◆ rizin_plugin

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

Definition at line 184 of file parse_att2intel.c.

◆ rz_parse_plugin_att2intel

RzParsePlugin rz_parse_plugin_att2intel
Initial value:
= {
.name = "att2intel",
.desc = "X86 att 2 intel plugin",
.init = NULL,
.fini = NULL,
.parse = &parse,
}
static bool parse(RzParse *p, const char *data, RzStrBuf *sb)

Definition at line 175 of file parse_att2intel.c.