Rizin
unix-like reverse engineering framework and cli tools
egg.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2011-2018 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_egg.h>
5 #include <config.h>
6 
7 RZ_LIB_VERSION(rz_egg);
8 
9 // TODO: must be plugins
10 extern RzEggEmit emit_x86;
11 extern RzEggEmit emit_x64;
12 extern RzEggEmit emit_arm;
13 extern RzEggEmit emit_trace;
14 
16 
17 struct egg_patch_t {
19  int off;
20 };
21 
22 void egg_patch_free(void *p) {
23  struct egg_patch_t *ep = (struct egg_patch_t *)p;
24  rz_buf_free(ep->b);
25  free(ep);
26 }
27 
28 RZ_API const char *rz_egg_os_as_string(int os) {
29  switch (os) {
30  case RZ_EGG_OS_LINUX: return "linux";
31  case RZ_EGG_OS_OSX: return "osx";
32  case RZ_EGG_OS_DARWIN: return "darwin";
33  case RZ_EGG_OS_WATCHOS: return "watchos";
34  case RZ_EGG_OS_IOS: return "ios";
35  case RZ_EGG_OS_MACOS: return "macos";
36  case RZ_EGG_OS_W32: return "win32";
37  case RZ_EGG_OS_WINDOWS: return "windows";
38  case RZ_EGG_OS_BEOS: return "beos";
39  case RZ_EGG_OS_FREEBSD: return "freebsd";
40  default: return "linux";
41  }
42 }
43 
45  int i;
46  RzEgg *egg = RZ_NEW0(RzEgg);
47  if (!egg) {
48  return NULL;
49  }
50  egg->src = rz_buf_new_with_bytes(NULL, 0);
51  if (!egg->src) {
52  goto beach;
53  }
54  egg->buf = rz_buf_new_with_bytes(NULL, 0);
55  if (!egg->buf) {
56  goto beach;
57  }
58  egg->bin = rz_buf_new_with_bytes(NULL, 0);
59  if (!egg->bin) {
60  goto beach;
61  }
62  egg->remit = &emit_x86;
63  egg->syscall = rz_syscall_new();
64  if (!egg->syscall) {
65  goto beach;
66  }
67  egg->rasm = rz_asm_new();
68  if (!egg->rasm) {
69  goto beach;
70  }
71  egg->bits = 0;
72  egg->endian = 0;
73  egg->db = sdb_new(NULL, NULL, 0);
74  if (!egg->db) {
75  goto beach;
76  }
78  if (!egg->patches) {
79  goto beach;
80  }
81  egg->plugins = rz_list_new();
82  for (i = 0; i < RZ_ARRAY_SIZE(egg_static_plugins); i++) {
84  }
85  return egg;
86 
87 beach:
88  rz_egg_free(egg);
89  return NULL;
90 }
91 
94  RzAsmPlugin *h;
95  if (!foo->name) {
96  return false;
97  }
98  rz_list_foreach (a->plugins, iter, h) {
99  if (!strcmp(h->name, foo->name)) {
100  return false;
101  }
102  }
103  rz_list_append(a->plugins, foo);
104  return true;
105 }
106 
108  return rz_buf_to_string(egg->buf);
109 }
110 
112  if (!egg) {
113  return;
114  }
115  rz_buf_free(egg->src);
116  rz_buf_free(egg->buf);
117  rz_buf_free(egg->bin);
118  rz_list_free(egg->list);
119  rz_asm_free(egg->rasm);
120  rz_syscall_free(egg->syscall);
121  sdb_free(egg->db);
122  rz_list_free(egg->plugins);
123  rz_list_free(egg->patches);
124  rz_egg_lang_free(egg);
125  free(egg);
126 }
127 
130  rz_buf_free(egg->src);
131  rz_buf_free(egg->buf);
132  rz_buf_free(egg->bin);
133  egg->src = rz_buf_new_with_bytes(NULL, 0);
134  egg->buf = rz_buf_new_with_bytes(NULL, 0);
135  egg->bin = rz_buf_new_with_bytes(NULL, 0);
136  rz_list_purge(egg->patches);
137 }
138 
139 RZ_API bool rz_egg_setup(RzEgg *egg, const char *arch, int bits, int endian, const char *os) {
140  const char *asmcpu = NULL; // TODO
141  egg->remit = NULL;
142 
143  egg->os = os ? rz_str_djb2_hash(os) : RZ_EGG_OS_DEFAULT;
144  if (!strcmp(arch, "x86")) {
145  egg->arch = RZ_SYS_ARCH_X86;
146  switch (bits) {
147  case 32:
148  rz_syscall_setup(egg->syscall, arch, bits, asmcpu, os);
149  egg->remit = &emit_x86;
150  egg->bits = bits;
151  break;
152  case 64:
153  rz_syscall_setup(egg->syscall, arch, bits, asmcpu, os);
154  egg->remit = &emit_x64;
155  egg->bits = bits;
156  break;
157  }
158  } else if (!strcmp(arch, "arm")) {
159  egg->arch = RZ_SYS_ARCH_ARM;
160  switch (bits) {
161  case 16:
162  case 32:
163  case 64:
164  rz_syscall_setup(egg->syscall, arch, bits, asmcpu, os);
165  egg->remit = &emit_arm;
166  egg->bits = bits;
167  egg->endian = endian;
168  break;
169  }
170  } else if (!strcmp(arch, "trace")) {
171  // rz_syscall_setup (egg->syscall, arch, os, bits);
172  egg->remit = &emit_trace;
173  egg->bits = bits;
174  egg->endian = endian;
175  } else {
176  return false;
177  }
178  return true;
179 }
180 
181 RZ_API int rz_egg_include(RzEgg *egg, const char *file, int format) {
182  size_t sz;
183  const ut8 *foo = (const ut8 *)rz_file_slurp(file, &sz);
184  if (!foo) {
185  return 0;
186  }
187  // XXX: format breaks compiler layers
188  switch (format) {
189  case 'r': // raw
190  rz_egg_raw(egg, foo, (int)sz);
191  break;
192  case 'a': // assembly
193  rz_buf_append_bytes(egg->buf, foo, (ut64)sz);
194  break;
195  default:
196  rz_buf_append_bytes(egg->src, foo, (ut64)sz);
197  }
198  free((void *)foo);
199  return 1;
200 }
201 
202 RZ_API void rz_egg_load(RzEgg *egg, const char *code, int format) {
204  switch (format) {
205  case 'a': // assembly
206  rz_buf_append_bytes(egg->buf, (const ut8 *)code, strlen(code));
207  break;
208  default:
209  rz_buf_append_bytes(egg->src, (const ut8 *)code, strlen(code));
210  break;
211  }
212 }
213 
214 RZ_API bool rz_egg_load_file(RzEgg *egg, const char *file) {
215  rz_return_val_if_fail(file, false);
216  // We have to reset the RzEgg state first
217  rz_egg_reset(egg);
218  if (rz_str_endswith(file, ".c")) {
219  char *fileSanitized = strdup(file);
220  rz_str_sanitize(fileSanitized);
221  const char *arch = rz_sys_arch_str(egg->arch);
222  const char *os = rz_egg_os_as_string(egg->os);
223  char *textFile = rz_egg_Cfile_parser(fileSanitized, arch, os, egg->bits);
224  if (!textFile) {
225  RZ_LOG_ERROR("Failure while parsing '%s'\n", fileSanitized);
226  free(fileSanitized);
227  return false;
228  }
229  size_t l;
230  char *buf = rz_file_slurp(textFile, &l);
231  if (buf && l > 0) {
232  rz_egg_raw(egg, (const ut8 *)buf, (int)l);
233  } else {
234  RZ_LOG_ERROR("Error loading '%s'\n", textFile);
235  }
236  rz_file_rm(textFile);
237  free(fileSanitized);
238  free(textFile);
239  free(buf);
240  } else {
241  int fmt;
242  if (rz_str_endswith(file, ".s") || rz_str_endswith(file, ".asm")) {
243  fmt = 'a';
244  } else {
245  fmt = 0;
246  }
247  if (!rz_egg_include(egg, file, fmt)) {
248  RZ_LOG_ERROR("Cannot open '%s'\n", file);
249  return false;
250  }
251  }
252  return true;
253 }
254 
255 RZ_API void rz_egg_syscall(RzEgg *egg, const char *arg, ...) {
256  RzSyscallItem *item = rz_syscall_get(egg->syscall,
257  rz_syscall_get_num(egg->syscall, arg), -1);
258  if (!strcmp(arg, "close")) {
259  // egg->remit->syscall_args ();
260  }
261  if (!item) {
262  return;
263  }
264  egg->remit->syscall(egg, item->num);
265  rz_syscall_item_free(item);
266 }
267 
268 RZ_API void rz_egg_alloc(RzEgg *egg, int n) {
269  // add esp, n
270 }
271 
272 RZ_API void rz_egg_label(RzEgg *egg, const char *name) {
273  rz_egg_printf(egg, "%s:\n", name);
274 }
275 
276 RZ_API void rz_egg_math(RzEgg *egg) { //, char eq, const char *vs, char type, const char *sr
277  // TODO
278  // e->mathop (egg, op, type, eq, p);
279 }
280 
281 RZ_API int rz_egg_raw(RzEgg *egg, const ut8 *b, int len) {
282  int outlen = len * 2; // two hexadecimal digits per byte
283  char *out = malloc(outlen + 1);
284  if (!out) {
285  return false;
286  }
287  (void)rz_hex_bin2str(b, len, out);
288  rz_buf_append_bytes(egg->buf, (const ut8 *)".hex ", 5);
289  rz_buf_append_bytes(egg->buf, (const ut8 *)out, outlen);
290  rz_buf_append_bytes(egg->buf, (const ut8 *)"\n", 1);
291  free(out);
292  return true;
293 }
294 
295 static int rz_egg_raw_prepend(RzEgg *egg, const ut8 *b, int len) {
296  int outlen = len * 2; // two hexadecimal digits per byte
297  char *out = malloc(outlen + 1);
298  if (!out) {
299  return false;
300  }
301  rz_hex_bin2str(b, len, out);
302  rz_buf_prepend_bytes(egg->buf, (const ut8 *)"\n", 1);
303  rz_buf_prepend_bytes(egg->buf, (const ut8 *)out, outlen);
304  rz_buf_prepend_bytes(egg->buf, (const ut8 *)".hex ", 5);
305  free(out);
306  return true;
307 }
308 
309 static int rz_egg_prepend_bytes(RzEgg *egg, const ut8 *b, int len) {
310  if (!rz_egg_raw_prepend(egg, b, len)) {
311  return false;
312  }
313  if (!rz_buf_prepend_bytes(egg->bin, b, len)) {
314  return false;
315  }
316  return true;
317 }
318 
319 static int rz_egg_append_bytes(RzEgg *egg, const ut8 *b, int len) {
320  if (!rz_egg_raw(egg, b, len)) {
321  return false;
322  }
323 
324  if (!rz_buf_append_bytes(egg->bin, b, len)) {
325  return false;
326  }
327 
328  return true;
329 }
330 
331 // rz_egg_block (egg, FRAME | IF | ELSE | ENDIF | FOR | WHILE, sz)
332 RZ_API void rz_egg_if(RzEgg *egg, const char *reg, char cmp, int v) {
333  // egg->depth++;
334 }
335 
336 RZ_API void rz_egg_printf(RzEgg *egg, const char *fmt, ...) {
337  va_list ap;
338  int len;
339  char buf[1024];
340  va_start(ap, fmt);
341  len = vsnprintf(buf, sizeof(buf), fmt, ap);
342  rz_buf_append_bytes(egg->buf, (const ut8 *)buf, len);
343  va_end(ap);
344 }
345 
346 RZ_API bool rz_egg_assemble_asm(RzEgg *egg, char **asm_list) {
347  RzAsmCode *asmcode = NULL;
348  char *code = NULL;
349  char *asm_name = NULL;
350 
351  if (asm_list) {
352  char **asm_;
353 
354  for (asm_ = asm_list; *asm_; asm_ += 2) {
355  if (!strcmp(egg->remit->arch, asm_[0])) {
356  asm_name = asm_[1];
357  break;
358  }
359  }
360  }
361  if (!asm_name) {
362  if (egg->remit == &emit_x86 || egg->remit == &emit_x64) {
363  asm_name = "x86.nz";
364  } else if (egg->remit == &emit_arm) {
365  asm_name = "arm";
366  }
367  }
368  if (asm_name) {
369  rz_asm_use(egg->rasm, asm_name);
370  rz_asm_set_bits(egg->rasm, egg->bits);
371  rz_asm_set_big_endian(egg->rasm, egg->endian);
373  code = rz_buf_to_string(egg->buf);
374  asmcode = rz_asm_massemble(egg->rasm, code);
375  if (asmcode) {
376  if (asmcode->len > 0) {
377  rz_buf_append_bytes(egg->bin, asmcode->bytes, asmcode->len);
378  }
379  // LEAK rz_asm_code_free (asmcode);
380  } else {
381  eprintf("fail assembling\n");
382  }
383  }
384  bool ret = code ? asmcode != NULL : true;
385  free(code);
386  rz_asm_code_free(asmcode);
387  return ret;
388 }
389 
391  return rz_egg_assemble_asm(egg, NULL);
392 }
393 
395  rz_buf_seek(egg->src, 0, RZ_BUF_SET);
396  char b;
397  int r = rz_buf_read(egg->src, (ut8 *)&b, sizeof(b));
398  if (r != sizeof(b) || !egg->remit) {
399  return true;
400  }
401  // only emit begin if code is found
402  rz_egg_lang_init(egg);
403  for (; b;) {
404  rz_egg_lang_parsechar(egg, b);
405  if (egg->lang.elem_n >= sizeof(egg->lang.elem)) {
406  eprintf("ERROR: elem too large.\n");
407  break;
408  }
409  int r = rz_buf_read(egg->src, (ut8 *)&b, sizeof(b));
410  if (r != sizeof(b)) {
411  break;
412  }
413  // XXX: some parse fail errors are false positives :(
414  }
415  if (egg->context > 0) {
416  eprintf("ERROR: expected '}' at the end of the file. %d left\n", egg->context);
417  return false;
418  }
419  // TODO: handle errors here
420  return true;
421 }
422 
424  // TODO increment reference
425  return egg->bin;
426 }
427 
428 // RZ_API int rz_egg_dump (RzEgg *egg, const char *file) { }
429 
431  return rz_buf_to_string(egg->src);
432 }
433 
435  return rz_buf_to_string(egg->buf);
436 }
437 
438 RZ_API void rz_egg_append(RzEgg *egg, const char *src) {
439  rz_buf_append_bytes(egg->src, (const ut8 *)src, strlen(src));
440 }
441 
442 /* JIT : TODO: accept arguments here */
444  ut64 tmpsz;
445  const ut8 *tmp = rz_buf_data(egg->bin, &tmpsz);
446  bool res = rz_sys_run(tmp, tmpsz);
447  return res;
448 }
449 
451  ut64 sz;
452  const ut8 *tmp = rz_buf_data(egg->bin, &sz);
453  return rz_sys_run_rop(tmp, sz);
454 }
455 
456 #define RZ_EGG_FILL_TYPE_TRAP
457 #define RZ_EGG_FILL_TYPE_NOP
458 #define RZ_EGG_FILL_TYPE_CHAR
459 #define RZ_EGG_FILL_TYPE_SEQ
460 #define RZ_EGG_FILL_TYPE_SEQ
461 
462 static inline char *eon(char *n) {
463  while (*n && (*n >= '0' && *n <= '9')) {
464  n++;
465  }
466  return n;
467 }
468 
469 /* padding looks like:
470  ([snatSNAT][0-9]+)*
471 */
472 RZ_API int rz_egg_padding(RzEgg *egg, const char *pad) {
473  int number;
474  ut8 *buf, padding_byte;
475  char *p, *o = strdup(pad);
476 
477  for (p = o; *p;) { // parse pad string
478  const char f = *p++;
479  number = strtol(p, NULL, 10);
480 
481  if (number < 1) {
482  eprintf("Invalid padding length at %d\n", number);
483  free(o);
484  return false;
485  }
486  p = eon(p);
487 
488  switch (f) {
489  case 's':
490  case 'S': padding_byte = 0; break;
491  case 'n':
492  case 'N': padding_byte = 0x90; break;
493  case 'a':
494  case 'A': padding_byte = 'A'; break;
495  case 't':
496  case 'T': padding_byte = 0xcc; break;
497  default:
498  eprintf("Invalid padding format (%c)\n", *p);
499  eprintf("Valid ones are:\n");
500  eprintf(" s S : NULL byte");
501  eprintf(" n N : nop");
502  eprintf(" a A : 0x41");
503  eprintf(" t T : trap (0xcc)");
504  free(o);
505  return false;
506  }
507 
508  buf = malloc(number);
509  if (!buf) {
510  free(o);
511  return false;
512  }
513 
514  memset(buf, padding_byte, number);
515  if (f >= 'a' && f <= 'z') {
516  rz_egg_prepend_bytes(egg, buf, number);
517  } else {
518  rz_egg_append_bytes(egg, buf, number);
519  }
520  free(buf);
521  }
522  free(o);
523  return true;
524 }
525 
526 RZ_API void rz_egg_fill(RzEgg *egg, int pos, int type, int argc, int length) {
527  // TODO
528 }
529 
530 RZ_API void rz_egg_option_set(RzEgg *egg, const char *key, const char *val) {
531  sdb_set(egg->db, key, val, 0);
532 }
533 
534 RZ_API char *rz_egg_option_get(RzEgg *egg, const char *key) {
535  return sdb_get(egg->db, key, NULL);
536 }
537 
538 RZ_API int rz_egg_shellcode(RzEgg *egg, const char *name) {
539  RzEggPlugin *p;
540  RzListIter *iter;
541  RzBuffer *b;
542  rz_list_foreach (egg->plugins, iter, p) {
543  if (p->type == RZ_EGG_PLUGIN_SHELLCODE && !strcmp(name, p->name)) {
544  b = p->build(egg);
545  if (!b) {
546  eprintf("%s Shellcode has failed\n", p->name);
547  return false;
548  }
549  ut64 tmpsz;
550  const ut8 *tmp = rz_buf_data(b, &tmpsz);
551  rz_egg_raw(egg, tmp, tmpsz);
552  return true;
553  }
554  }
555  return false;
556 }
557 
558 RZ_API int rz_egg_encode(RzEgg *egg, const char *name) {
559  RzEggPlugin *p;
560  RzListIter *iter;
561  RzBuffer *b;
562  rz_list_foreach (egg->plugins, iter, p) {
563  if (p->type == RZ_EGG_PLUGIN_ENCODER && !strcmp(name, p->name)) {
564  b = p->build(egg);
565  if (!b) {
566  return false;
567  }
568  rz_buf_free(egg->bin);
569  egg->bin = b;
570  return true;
571  }
572  }
573  return false;
574 }
575 
576 RZ_API int rz_egg_patch(RzEgg *egg, int off, const ut8 *buf, int len) {
577  struct egg_patch_t *ep = RZ_NEW(struct egg_patch_t);
578  if (!ep) {
579  return false;
580  }
581  ep->b = rz_buf_new_with_bytes(buf, len);
582  if (!ep->b) {
583  egg_patch_free(ep);
584  return false;
585  }
586  ep->off = off;
587  rz_list_append(egg->patches, ep);
588  return true;
589 }
590 
592  rz_return_val_if_fail(egg && bits <= 64, false);
593  ut8 buf[8] = { 0 };
594  rz_write_ble(buf, num, egg->endian, bits);
595  return rz_egg_patch(egg, off, buf, bits / 8);
596 }
597 
599  struct egg_patch_t *ep;
600  RzListIter *iter;
601  if (!egg->bin) {
602  rz_buf_free(egg->bin);
603  egg->bin = rz_buf_new_with_bytes(NULL, 0);
604  }
605  rz_list_foreach (egg->patches, iter, ep) {
606  if (ep->off < 0) {
607  ut64 sz;
608  const ut8 *buf = rz_buf_data(ep->b, &sz);
609  rz_egg_append_bytes(egg, buf, sz);
610  } else if (ep->off < rz_buf_size(egg->bin)) {
611  ut64 sz;
612  const ut8 *buf = rz_buf_data(ep->b, &sz);
613  int r = rz_buf_write_at(egg->bin, ep->off, buf, sz);
614  if (r < sz) {
615  eprintf("Error during patch\n");
616  return;
617  }
618  } else {
619  eprintf("Cannot patch outside\n");
620  return;
621  }
622  }
623 }
624 
625 RZ_API void rz_egg_pattern(RzEgg *egg, int size) {
626  char *ret = rz_debruijn_pattern((int)size, 0, NULL);
627  if (ret) {
628  rz_egg_prepend_bytes(egg, (const ut8 *)ret, strlen(ret));
629  free(ret);
630  } else {
631  eprintf("Invalid debruijn pattern length.\n");
632  }
633 }
size_t len
Definition: 6502dis.c:15
RZ_API void * rz_asm_code_free(RzAsmCode *acode)
Definition: acode.c:11
lzma_index ** i
Definition: index.h:629
lzma_index * src
Definition: index.h:567
static RzILOpEffect * cmp(cs_insn *insn, bool is_thumb)
Definition: arm_il32.c:942
ut16 val
Definition: armass64_const.h:6
RZ_API void rz_asm_free(RzAsm *a)
Definition: asm.c:315
RZ_API bool rz_asm_set_big_endian(RzAsm *a, bool b)
Definition: asm.c:496
RZ_API RzAsm * rz_asm_new(void)
Definition: asm.c:262
RZ_DEPRECATE RZ_API int rz_asm_set_bits(RzAsm *a, int bits)
Definition: asm.c:488
RZ_API bool rz_asm_set_syntax(RzAsm *a, int syntax)
Definition: asm.c:518
RZ_API RzAsmCode * rz_asm_massemble(RzAsm *a, const char *assembly)
Definition: asm.c:814
RZ_API bool rz_asm_use(RzAsm *a, const char *name)
Puts an Asm plugin in use and disables the previous one.
Definition: asm.c:429
int bits(struct state *s, int need)
Definition: blast.c:72
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
#define RZ_EGG_STATIC_PLUGINS
Definition: config.h:15
#define RZ_API
#define NULL
Definition: cris-opc.c:27
#define r
Definition: crypto_rc6.c:12
cs_arch arch
Definition: cstool.c:13
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 key
Definition: sflib.h:118
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
uint32_t ut32
const char * v
Definition: dsignal.c:12
RZ_API int rz_egg_shellcode(RzEgg *egg, const char *name)
Definition: egg.c:538
RZ_API int rz_egg_run_rop(RzEgg *egg)
Definition: egg.c:450
static int rz_egg_append_bytes(RzEgg *egg, const ut8 *b, int len)
Definition: egg.c:319
RZ_LIB_VERSION(rz_egg)
RZ_API void rz_egg_reset(RzEgg *egg)
Definition: egg.c:128
RZ_API char * rz_egg_get_source(RzEgg *egg)
Definition: egg.c:430
RZ_API char * rz_egg_to_string(RzEgg *egg)
Definition: egg.c:107
RZ_API void rz_egg_append(RzEgg *egg, const char *src)
Definition: egg.c:438
static int rz_egg_prepend_bytes(RzEgg *egg, const ut8 *b, int len)
Definition: egg.c:309
static char * eon(char *n)
Definition: egg.c:462
RZ_API void rz_egg_free(RzEgg *egg)
Definition: egg.c:111
RZ_API void rz_egg_finalize(RzEgg *egg)
Definition: egg.c:598
RZ_API RzEgg * rz_egg_new(void)
Definition: egg.c:44
static int rz_egg_raw_prepend(RzEgg *egg, const ut8 *b, int len)
Definition: egg.c:295
RZ_API bool rz_egg_patch_num(RzEgg *egg, int off, ut64 num, ut32 bits)
Definition: egg.c:591
RZ_API bool rz_egg_load_file(RzEgg *egg, const char *file)
Definition: egg.c:214
RZ_API char * rz_egg_option_get(RzEgg *egg, const char *key)
Definition: egg.c:534
RZ_API int rz_egg_padding(RzEgg *egg, const char *pad)
Definition: egg.c:472
RZ_API int rz_egg_run(RzEgg *egg)
Definition: egg.c:443
RzEggEmit emit_x86
RzEggEmit emit_x64
RZ_API void rz_egg_syscall(RzEgg *egg, const char *arg,...)
Definition: egg.c:255
RZ_API void rz_egg_fill(RzEgg *egg, int pos, int type, int argc, int length)
Definition: egg.c:526
RZ_API int rz_egg_add(RzEgg *a, RzEggPlugin *foo)
Definition: egg.c:92
RZ_API int rz_egg_patch(RzEgg *egg, int off, const ut8 *buf, int len)
Definition: egg.c:576
RZ_API void rz_egg_pattern(RzEgg *egg, int size)
Definition: egg.c:625
RZ_API bool rz_egg_assemble_asm(RzEgg *egg, char **asm_list)
Definition: egg.c:346
static RzEggPlugin * egg_static_plugins[]
Definition: egg.c:15
RZ_API void rz_egg_alloc(RzEgg *egg, int n)
Definition: egg.c:268
RZ_API void rz_egg_label(RzEgg *egg, const char *name)
Definition: egg.c:272
RZ_API void rz_egg_if(RzEgg *egg, const char *reg, char cmp, int v)
Definition: egg.c:332
void egg_patch_free(void *p)
Definition: egg.c:22
RzEggEmit emit_arm
RZ_API void rz_egg_math(RzEgg *egg)
Definition: egg.c:276
RZ_API char * rz_egg_get_assembly(RzEgg *egg)
Definition: egg.c:434
RZ_API int rz_egg_encode(RzEgg *egg, const char *name)
Definition: egg.c:558
RZ_API const char * rz_egg_os_as_string(int os)
Definition: egg.c:28
RZ_API void rz_egg_printf(RzEgg *egg, const char *fmt,...)
Definition: egg.c:336
RZ_API int rz_egg_compile(RzEgg *egg)
Definition: egg.c:394
RzEggEmit emit_trace
RZ_API RzBuffer * rz_egg_get_bin(RzEgg *egg)
Definition: egg.c:423
RZ_API void rz_egg_option_set(RzEgg *egg, const char *key, const char *val)
Definition: egg.c:530
RZ_API void rz_egg_load(RzEgg *egg, const char *code, int format)
Definition: egg.c:202
RZ_API int rz_egg_include(RzEgg *egg, const char *file, int format)
Definition: egg.c:181
RZ_API bool rz_egg_assemble(RzEgg *egg)
Definition: egg.c:390
RZ_API bool rz_egg_setup(RzEgg *egg, const char *arch, int bits, int endian, const char *os)
Definition: egg.c:139
RZ_API int rz_egg_raw(RzEgg *egg, const ut8 *b, int len)
Definition: egg.c:281
RZ_API char * rz_egg_Cfile_parser(const char *file, const char *arch, const char *os, int bits)
Definition: egg_Cfile.c:247
RZ_API void rz_egg_lang_init(RzEgg *egg)
Definition: egg_lang.c:126
RZ_API int rz_egg_lang_parsechar(RzEgg *egg, char c)
Definition: egg_lang.c:1235
RZ_API void rz_egg_lang_include_init(RzEgg *egg)
Definition: egg_lang.c:164
RZ_API void rz_egg_lang_free(RzEgg *egg)
Definition: egg_lang.c:136
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
vsnprintf
Definition: kernel.h:366
#define reg(n)
uint8_t ut8
Definition: lh5801.h:11
return memset(p, 0, total)
void * p
Definition: libc.cpp:67
static RzMain foo[]
Definition: main.c:11
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 RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
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
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
RZ_API void rz_list_purge(RZ_NONNULL RzList *list)
Empties the list without freeing the list pointer.
Definition: list.c:120
void * malloc(size_t size)
Definition: malloc.c:123
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
int type
Definition: mipsasm.c:17
int off
Definition: pal.c:13
static void pad(RzStrBuf *sb, ut32 count)
Definition: protobuf.c:36
#define eprintf(x, y...)
Definition: rlcc.c:7
@ RZ_ASM_SYNTAX_INTEL
Definition: rz_asm.h:50
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API bool rz_buf_prepend_bytes(RZ_NONNULL RzBuffer *b, RZ_NONNULL const ut8 *buf, ut64 len)
Prepend an array of bytes to the buffer.
Definition: buf.c:846
RZ_API bool rz_buf_append_bytes(RZ_NONNULL RzBuffer *b, RZ_NONNULL const ut8 *buf, ut64 len)
Append an array of bytes to the buffer.
Definition: buf.c:732
RZ_API st64 rz_buf_seek(RZ_NONNULL RzBuffer *b, st64 addr, int whence)
Modify the current cursor position in the buffer.
Definition: buf.c:1166
RZ_API st64 rz_buf_write_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL const ut8 *buf, ut64 len)
Write len bytes of the buffer at the specified address.
Definition: buf.c:1197
#define RZ_BUF_SET
Definition: rz_buf.h:14
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
Definition: buf.c:1253
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_bytes(RZ_NULLABLE RZ_BORROW const ut8 *bytes, ut64 len)
Creates a new buffer with a bytes array.
Definition: buf.c:465
RZ_API st64 rz_buf_read(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
RZ_DEPRECATE RZ_API RZ_BORROW ut8 * rz_buf_data(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_OUT ut64 *size)
Return a borrowed array of bytes representing the buffer data.
Definition: buf.c:1287
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
RZ_API RZ_OWN char * rz_buf_to_string(RZ_NONNULL RzBuffer *b)
Stringify the buffer.
Definition: buf.c:642
RZ_API RZ_OWN char * rz_debruijn_pattern(int size, int start, const char *charset)
Generate a cyclic pattern following the Debruijn pattern.
Definition: debruijn.c:80
#define RZ_EGG_OS_IOS
Definition: rz_egg.h:131
#define RZ_EGG_PLUGIN_SHELLCODE
Definition: rz_egg.h:19
#define RZ_EGG_OS_DEFAULT
Definition: rz_egg.h:147
#define RZ_EGG_OS_WATCHOS
Definition: rz_egg.h:130
#define RZ_EGG_OS_DARWIN
Definition: rz_egg.h:129
#define RZ_EGG_OS_WINDOWS
Definition: rz_egg.h:134
#define RZ_EGG_PLUGIN_ENCODER
Definition: rz_egg.h:20
#define RZ_EGG_OS_MACOS
Definition: rz_egg.h:132
#define RZ_EGG_OS_BEOS
Definition: rz_egg.h:135
#define RZ_EGG_OS_OSX
Definition: rz_egg.h:128
#define RZ_EGG_OS_W32
Definition: rz_egg.h:133
#define RZ_EGG_OS_FREEBSD
Definition: rz_egg.h:136
#define RZ_EGG_OS_LINUX
Definition: rz_egg.h:127
static void rz_write_ble(void *dst, ut64 val, bool big_endian, int size)
Definition: rz_endian.h:548
RZ_API RZ_OWN char * rz_file_slurp(const char *str, RZ_NULLABLE size_t *usz)
Definition: file.c:454
RZ_API bool rz_file_rm(const char *file)
Definition: file.c:865
RZ_API int rz_hex_bin2str(const ut8 *in, int len, char *out)
Definition: hex.c:382
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API ut64 rz_str_djb2_hash(const char *str)
Definition: str.c:383
RZ_API bool rz_str_endswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string ends with a specifc sequence of characters (case sensitive)
Definition: str.c:3329
RZ_API void rz_str_sanitize(char *c)
Definition: str.c:1381
RZ_API int rz_sys_run_rop(const ut8 *buf, int len)
Definition: sys.c:861
RZ_API int rz_sys_run(const ut8 *buf, int len)
Definition: sys.c:809
RZ_API const char * rz_sys_arch_str(int arch)
Definition: sys.c:798
#define RZ_NEW0(x)
Definition: rz_types.h:284
@ RZ_SYS_ARCH_X86
Definition: rz_types.h:532
@ RZ_SYS_ARCH_ARM
Definition: rz_types.h:533
#define RZ_NEW(x)
Definition: rz_types.h:285
#define RZ_ARRAY_SIZE(x)
Definition: rz_types.h:300
RZ_API Sdb * sdb_new(const char *path, const char *name, int lock)
Definition: sdb.c:47
RZ_API int sdb_set(Sdb *s, const char *key, const char *val, ut32 cas)
Definition: sdb.c:611
RZ_API char * sdb_get(Sdb *s, const char *key, ut32 *cas)
Definition: sdb.c:290
RZ_API bool sdb_free(Sdb *s)
Definition: sdb.c:206
#define b(i)
Definition: sha256.c:42
#define f(i)
Definition: sha256.c:46
#define a(i)
Definition: sha256.c:41
#define h(i)
Definition: sha256.c:48
Definition: inftree9.h:24
int off
Definition: egg.c:19
RzBuffer * b
Definition: egg.c:18
Definition: gzappend.c:170
Definition: z80asm.h:102
ut8 * bytes
Definition: rz_asm.h:80
char *(* syscall)(RzEgg *egg, int num)
Definition: rz_egg.h:163
const char * arch
Definition: rz_egg.h:153
int elem_n
Definition: rz_egg.h:52
char elem[1024]
Definition: rz_egg.h:50
RzAsm * rasm
Definition: rz_egg.h:99
RzList * plugins
Definition: rz_egg.h:103
int context
Definition: rz_egg.h:110
int endian
Definition: rz_egg.h:107
struct rz_egg_emit_t * remit
Definition: rz_egg.h:105
int bits
Definition: rz_egg.h:108
RzBuffer * bin
Definition: rz_egg.h:96
RzEggLang lang
Definition: rz_egg.h:101
RzSyscall * syscall
Definition: rz_egg.h:100
RzList * patches
Definition: rz_egg.h:104
int arch
Definition: rz_egg.h:106
Sdb * db
Definition: rz_egg.h:102
RzBuffer * buf
Definition: rz_egg.h:95
RzBuffer * src
Definition: rz_egg.h:94
ut32 os
Definition: rz_egg.h:109
RzList * list
Definition: rz_egg.h:97
const char * name
Definition: rz_main.h:17
int pos
Definition: main.c:11
RZ_API RzSyscall * rz_syscall_new(void)
Creates a new RzSyscall type.
Definition: syscall.c:67
RZ_API void rz_syscall_free(RzSyscall *s)
Frees an RzSyscall type.
Definition: syscall.c:79
RZ_API void rz_syscall_item_free(RzSyscallItem *si)
Definition: syscall.c:325
RZ_API int rz_syscall_get_num(RzSyscall *s, const char *str)
Definition: syscall.c:376
RZ_API RzSyscallItem * rz_syscall_get(RzSyscall *s, int num, int swi)
Definition: syscall.c:345
RZ_API bool rz_syscall_setup(RzSyscall *s, const char *arch, int bits, const char *cpu, const char *os)
Definition: syscall.c:234
ut64(WINAPI *w32_GetEnabledXStateFeatures)()