Rizin
unix-like reverse engineering framework and cli tools
egg.c File Reference
#include <rz_egg.h>
#include <config.h>

Go to the source code of this file.

Classes

struct  egg_patch_t
 

Macros

#define RZ_EGG_FILL_TYPE_TRAP
 
#define RZ_EGG_FILL_TYPE_NOP
 
#define RZ_EGG_FILL_TYPE_CHAR
 
#define RZ_EGG_FILL_TYPE_SEQ
 
#define RZ_EGG_FILL_TYPE_SEQ
 

Functions

 RZ_LIB_VERSION (rz_egg)
 
void egg_patch_free (void *p)
 
RZ_API const char * rz_egg_os_as_string (int os)
 
RZ_API RzEggrz_egg_new (void)
 
RZ_API int rz_egg_add (RzEgg *a, RzEggPlugin *foo)
 
RZ_API char * rz_egg_to_string (RzEgg *egg)
 
RZ_API void rz_egg_free (RzEgg *egg)
 
RZ_API void rz_egg_reset (RzEgg *egg)
 
RZ_API bool rz_egg_setup (RzEgg *egg, const char *arch, int bits, int endian, const char *os)
 
RZ_API int rz_egg_include (RzEgg *egg, const char *file, int format)
 
RZ_API void rz_egg_load (RzEgg *egg, const char *code, int format)
 
RZ_API bool rz_egg_load_file (RzEgg *egg, const char *file)
 
RZ_API void rz_egg_syscall (RzEgg *egg, const char *arg,...)
 
RZ_API void rz_egg_alloc (RzEgg *egg, int n)
 
RZ_API void rz_egg_label (RzEgg *egg, const char *name)
 
RZ_API void rz_egg_math (RzEgg *egg)
 
RZ_API int rz_egg_raw (RzEgg *egg, const ut8 *b, int len)
 
static int rz_egg_raw_prepend (RzEgg *egg, const ut8 *b, int len)
 
static int rz_egg_prepend_bytes (RzEgg *egg, const ut8 *b, int len)
 
static int rz_egg_append_bytes (RzEgg *egg, const ut8 *b, int len)
 
RZ_API void rz_egg_if (RzEgg *egg, const char *reg, char cmp, int v)
 
RZ_API void rz_egg_printf (RzEgg *egg, const char *fmt,...)
 
RZ_API bool rz_egg_assemble_asm (RzEgg *egg, char **asm_list)
 
RZ_API bool rz_egg_assemble (RzEgg *egg)
 
RZ_API int rz_egg_compile (RzEgg *egg)
 
RZ_API RzBufferrz_egg_get_bin (RzEgg *egg)
 
RZ_API char * rz_egg_get_source (RzEgg *egg)
 
RZ_API char * rz_egg_get_assembly (RzEgg *egg)
 
RZ_API void rz_egg_append (RzEgg *egg, const char *src)
 
RZ_API int rz_egg_run (RzEgg *egg)
 
RZ_API int rz_egg_run_rop (RzEgg *egg)
 
static char * eon (char *n)
 
RZ_API int rz_egg_padding (RzEgg *egg, const char *pad)
 
RZ_API void rz_egg_fill (RzEgg *egg, int pos, int type, int argc, int length)
 
RZ_API void rz_egg_option_set (RzEgg *egg, const char *key, const char *val)
 
RZ_API char * rz_egg_option_get (RzEgg *egg, const char *key)
 
RZ_API int rz_egg_shellcode (RzEgg *egg, const char *name)
 
RZ_API int rz_egg_encode (RzEgg *egg, const char *name)
 
RZ_API int rz_egg_patch (RzEgg *egg, int off, const ut8 *buf, int len)
 
RZ_API bool rz_egg_patch_num (RzEgg *egg, int off, ut64 num, ut32 bits)
 
RZ_API void rz_egg_finalize (RzEgg *egg)
 
RZ_API void rz_egg_pattern (RzEgg *egg, int size)
 

Variables

RzEggEmit emit_x86
 
RzEggEmit emit_x64
 
RzEggEmit emit_arm
 
RzEggEmit emit_trace
 
static RzEggPluginegg_static_plugins [] = { RZ_EGG_STATIC_PLUGINS }
 

Macro Definition Documentation

◆ RZ_EGG_FILL_TYPE_CHAR

#define RZ_EGG_FILL_TYPE_CHAR

Definition at line 458 of file egg.c.

◆ RZ_EGG_FILL_TYPE_NOP

#define RZ_EGG_FILL_TYPE_NOP

Definition at line 457 of file egg.c.

◆ RZ_EGG_FILL_TYPE_SEQ [1/2]

#define RZ_EGG_FILL_TYPE_SEQ

Definition at line 460 of file egg.c.

◆ RZ_EGG_FILL_TYPE_SEQ [2/2]

#define RZ_EGG_FILL_TYPE_SEQ

Definition at line 460 of file egg.c.

◆ RZ_EGG_FILL_TYPE_TRAP

#define RZ_EGG_FILL_TYPE_TRAP

Definition at line 456 of file egg.c.

Function Documentation

◆ egg_patch_free()

void egg_patch_free ( void *  p)

Definition at line 22 of file egg.c.

22  {
23  struct egg_patch_t *ep = (struct egg_patch_t *)p;
24  rz_buf_free(ep->b);
25  free(ep);
26 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
void * p
Definition: libc.cpp:67
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
Definition: buf.c:1253
RzBuffer * b
Definition: egg.c:18

References egg_patch_t::b, free(), p, and rz_buf_free().

Referenced by rz_egg_new(), and rz_egg_patch().

◆ eon()

static char* eon ( char *  n)
inlinestatic

Definition at line 462 of file egg.c.

462  {
463  while (*n && (*n >= '0' && *n <= '9')) {
464  n++;
465  }
466  return n;
467 }
int n
Definition: mipsasm.c:19

References n.

Referenced by rz_egg_padding().

◆ rz_egg_add()

RZ_API int rz_egg_add ( RzEgg a,
RzEggPlugin foo 
)

Definition at line 92 of file egg.c.

92  {
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 }
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
#define a(i)
Definition: sha256.c:41
#define h(i)
Definition: sha256.c:48
const char * name
Definition: rz_main.h:17

References a, foo, h, rz_main_t::name, and rz_list_append().

Referenced by rz_egg_new().

◆ rz_egg_alloc()

RZ_API void rz_egg_alloc ( RzEgg egg,
int  n 
)

Definition at line 268 of file egg.c.

268  {
269  // add esp, n
270 }

◆ rz_egg_append()

RZ_API void rz_egg_append ( RzEgg egg,
const char *  src 
)

Definition at line 438 of file egg.c.

438  {
439  rz_buf_append_bytes(egg->src, (const ut8 *)src, strlen(src));
440 }
lzma_index * src
Definition: index.h:567
uint8_t ut8
Definition: lh5801.h:11
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
RzBuffer * src
Definition: rz_egg.h:94

References rz_buf_append_bytes(), rz_egg_t::src, and src.

◆ rz_egg_append_bytes()

static int rz_egg_append_bytes ( RzEgg egg,
const ut8 b,
int  len 
)
static

Definition at line 319 of file egg.c.

319  {
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 }
size_t len
Definition: 6502dis.c:15
RZ_API int rz_egg_raw(RzEgg *egg, const ut8 *b, int len)
Definition: egg.c:281
#define b(i)
Definition: sha256.c:42
RzBuffer * bin
Definition: rz_egg.h:96

References b, rz_egg_t::bin, len, rz_buf_append_bytes(), and rz_egg_raw().

Referenced by rz_egg_finalize(), and rz_egg_padding().

◆ rz_egg_assemble()

RZ_API bool rz_egg_assemble ( RzEgg egg)

Definition at line 390 of file egg.c.

390  {
391  return rz_egg_assemble_asm(egg, NULL);
392 }
#define NULL
Definition: cris-opc.c:27
RZ_API bool rz_egg_assemble_asm(RzEgg *egg, char **asm_list)
Definition: egg.c:346

References NULL, and rz_egg_assemble_asm().

Referenced by egg_compile(), rz_core_syscall(), and rz_main_rz_gg().

◆ rz_egg_assemble_asm()

RZ_API bool rz_egg_assemble_asm ( RzEgg egg,
char **  asm_list 
)

Definition at line 346 of file egg.c.

346  {
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 }
RZ_API void * rz_asm_code_free(RzAsmCode *acode)
Definition: acode.c:11
RZ_API bool rz_asm_set_big_endian(RzAsm *a, bool b)
Definition: asm.c:496
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
RzEggEmit emit_x86
RzEggEmit emit_x64
RzEggEmit emit_arm
#define eprintf(x, y...)
Definition: rlcc.c:7
@ RZ_ASM_SYNTAX_INTEL
Definition: rz_asm.h:50
RZ_API RZ_OWN char * rz_buf_to_string(RZ_NONNULL RzBuffer *b)
Stringify the buffer.
Definition: buf.c:642
Definition: inftree9.h:24
ut8 * bytes
Definition: rz_asm.h:80
const char * arch
Definition: rz_egg.h:153
RzAsm * rasm
Definition: rz_egg.h:99
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 * buf
Definition: rz_egg.h:95

References rz_egg_emit_t::arch, rz_egg_t::bin, rz_egg_t::bits, rz_egg_t::buf, rz_asm_code_t::bytes, emit_arm, emit_x64, emit_x86, rz_egg_t::endian, eprintf, free(), rz_asm_code_t::len, NULL, rz_egg_t::rasm, rz_egg_t::remit, rz_asm_code_free(), rz_asm_massemble(), rz_asm_set_big_endian(), rz_asm_set_bits(), rz_asm_set_syntax(), RZ_ASM_SYNTAX_INTEL, rz_asm_use(), rz_buf_append_bytes(), and rz_buf_to_string().

Referenced by rz_egg_assemble().

◆ rz_egg_compile()

RZ_API int rz_egg_compile ( RzEgg egg)

Definition at line 394 of file egg.c.

394  {
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 }
#define r
Definition: crypto_rc6.c:12
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 st64 rz_buf_seek(RZ_NONNULL RzBuffer *b, st64 addr, int whence)
Modify the current cursor position in the buffer.
Definition: buf.c:1166
#define RZ_BUF_SET
Definition: rz_buf.h:14
RZ_API st64 rz_buf_read(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
int elem_n
Definition: rz_egg.h:52
char elem[1024]
Definition: rz_egg.h:50
int context
Definition: rz_egg.h:110
RzEggLang lang
Definition: rz_egg.h:101

References b, rz_egg_t::context, rz_egg_lang_t::elem, rz_egg_lang_t::elem_n, eprintf, rz_egg_t::lang, r, rz_egg_t::remit, rz_buf_read(), rz_buf_seek(), RZ_BUF_SET, rz_egg_lang_init(), rz_egg_lang_parsechar(), and rz_egg_t::src.

Referenced by egg_compile(), rz_cmd_debug(), rz_core_syscall(), and rz_main_rz_gg().

◆ rz_egg_encode()

RZ_API int rz_egg_encode ( RzEgg egg,
const char *  name 
)

Definition at line 558 of file egg.c.

558  {
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 }
#define RZ_EGG_PLUGIN_ENCODER
Definition: rz_egg.h:20
Definition: z80asm.h:102
RzList * plugins
Definition: rz_egg.h:103

References b, rz_egg_t::bin, p, rz_egg_t::plugins, rz_buf_free(), and RZ_EGG_PLUGIN_ENCODER.

Referenced by egg_compile(), and rz_main_rz_gg().

◆ rz_egg_fill()

RZ_API void rz_egg_fill ( RzEgg egg,
int  pos,
int  type,
int  argc,
int  length 
)

Definition at line 526 of file egg.c.

526  {
527  // TODO
528 }

◆ rz_egg_finalize()

RZ_API void rz_egg_finalize ( RzEgg egg)

Definition at line 598 of file egg.c.

598  {
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 }
static int rz_egg_append_bytes(RzEgg *egg, const ut8 *b, int len)
Definition: egg.c:319
voidpf void * buf
Definition: ioapi.h:138
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
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_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
int off
Definition: egg.c:19
RzList * patches
Definition: rz_egg.h:104
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References egg_patch_t::b, rz_egg_t::bin, eprintf, NULL, egg_patch_t::off, rz_egg_t::patches, r, rz_buf_data(), rz_buf_free(), rz_buf_new_with_bytes(), rz_buf_size(), rz_buf_write_at(), rz_egg_append_bytes(), and ut64().

Referenced by rz_main_rz_gg().

◆ rz_egg_free()

RZ_API void rz_egg_free ( RzEgg egg)

Definition at line 111 of file egg.c.

111  {
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 }
RZ_API void rz_asm_free(RzAsm *a)
Definition: asm.c:315
RZ_API void rz_egg_lang_free(RzEgg *egg)
Definition: egg_lang.c:136
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
RZ_API bool sdb_free(Sdb *s)
Definition: sdb.c:206
RzSyscall * syscall
Definition: rz_egg.h:100
Sdb * db
Definition: rz_egg.h:102
RzList * list
Definition: rz_egg.h:97
RZ_API void rz_syscall_free(RzSyscall *s)
Frees an RzSyscall type.
Definition: syscall.c:79

References rz_egg_t::bin, rz_egg_t::buf, rz_egg_t::db, free(), rz_egg_t::list, rz_egg_t::patches, rz_egg_t::plugins, rz_egg_t::rasm, rz_asm_free(), rz_buf_free(), rz_egg_lang_free(), rz_list_free(), rz_syscall_free(), sdb_free(), rz_egg_t::src, and rz_egg_t::syscall.

Referenced by rz_core_fini(), rz_debug_free(), rz_egg_new(), and rz_main_rz_gg().

◆ rz_egg_get_assembly()

RZ_API char* rz_egg_get_assembly ( RzEgg egg)

Definition at line 434 of file egg.c.

434  {
435  return rz_buf_to_string(egg->buf);
436 }

References rz_egg_t::buf, and rz_buf_to_string().

Referenced by rz_main_rz_gg().

◆ rz_egg_get_bin()

RZ_API RzBuffer* rz_egg_get_bin ( RzEgg egg)

Definition at line 423 of file egg.c.

423  {
424  // TODO increment reference
425  return egg->bin;
426 }

References rz_egg_t::bin.

Referenced by egg_compile(), rz_cmd_debug(), rz_core_syscall(), and rz_main_rz_gg().

◆ rz_egg_get_source()

RZ_API char* rz_egg_get_source ( RzEgg egg)

Definition at line 430 of file egg.c.

430  {
431  return rz_buf_to_string(egg->src);
432 }

References rz_buf_to_string(), and rz_egg_t::src.

◆ rz_egg_if()

RZ_API void rz_egg_if ( RzEgg egg,
const char *  reg,
char  cmp,
int  v 
)

Definition at line 332 of file egg.c.

332  {
333  // egg->depth++;
334 }

◆ rz_egg_include()

RZ_API int rz_egg_include ( RzEgg egg,
const char *  file,
int  format 
)

Definition at line 181 of file egg.c.

181  {
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 }
RZ_API RZ_OWN char * rz_file_slurp(const char *str, RZ_NULLABLE size_t *usz)
Definition: file.c:454
Definition: gzappend.c:170

References rz_egg_t::buf, foo, free(), rz_buf_append_bytes(), rz_egg_raw(), rz_file_slurp(), rz_egg_t::src, and ut64().

Referenced by rz_egg_load_file().

◆ rz_egg_label()

RZ_API void rz_egg_label ( RzEgg egg,
const char *  name 
)

Definition at line 272 of file egg.c.

272  {
273  rz_egg_printf(egg, "%s:\n", name);
274 }
RZ_API void rz_egg_printf(RzEgg *egg, const char *fmt,...)
Definition: egg.c:336

References rz_egg_printf().

◆ rz_egg_load()

RZ_API void rz_egg_load ( RzEgg egg,
const char *  code,
int  format 
)

Definition at line 202 of file egg.c.

202  {
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 }
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100

References rz_egg_t::buf, rz_buf_append_bytes(), rz_return_if_fail, and rz_egg_t::src.

Referenced by rz_cmd_debug(), rz_core_syscall(), and rz_main_rz_gg().

◆ rz_egg_load_file()

RZ_API bool rz_egg_load_file ( RzEgg egg,
const char *  file 
)

Definition at line 214 of file egg.c.

214  {
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 }
cs_arch arch
Definition: cstool.c:13
RZ_API void rz_egg_reset(RzEgg *egg)
Definition: egg.c:128
RZ_API const char * rz_egg_os_as_string(int os)
Definition: egg.c:28
RZ_API int rz_egg_include(RzEgg *egg, const char *file, int format)
Definition: egg.c:181
RZ_API char * rz_egg_Cfile_parser(const char *file, const char *arch, const char *os, int bits)
Definition: egg_Cfile.c:247
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")
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API bool rz_file_rm(const char *file)
Definition: file.c:865
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
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 const char * rz_sys_arch_str(int arch)
Definition: sys.c:798
int arch
Definition: rz_egg.h:106
ut32 os
Definition: rz_egg.h:109

References rz_egg_t::arch, arch, rz_egg_t::bits, free(), rz_egg_t::os, rz_egg_Cfile_parser(), rz_egg_include(), rz_egg_os_as_string(), rz_egg_raw(), rz_egg_reset(), rz_file_rm(), rz_file_slurp(), RZ_LOG_ERROR, rz_return_val_if_fail, rz_str_endswith(), rz_str_sanitize(), rz_sys_arch_str(), and strdup().

Referenced by rz_core_egg_compile_file(), and rz_main_rz_gg().

◆ rz_egg_math()

RZ_API void rz_egg_math ( RzEgg egg)

Definition at line 276 of file egg.c.

276  { //, char eq, const char *vs, char type, const char *sr
277  // TODO
278  // e->mathop (egg, op, type, eq, p);
279 }

◆ rz_egg_new()

RZ_API RzEgg* rz_egg_new ( void  )

Definition at line 44 of file egg.c.

44  {
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 }
lzma_index ** i
Definition: index.h:629
RZ_API RzAsm * rz_asm_new(void)
Definition: asm.c:262
RZ_API void rz_egg_free(RzEgg *egg)
Definition: egg.c:111
RZ_API int rz_egg_add(RzEgg *a, RzEggPlugin *foo)
Definition: egg.c:92
static RzEggPlugin * egg_static_plugins[]
Definition: egg.c:15
void egg_patch_free(void *p)
Definition: egg.c:22
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
#define RZ_NEW0(x)
Definition: rz_types.h:284
#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 RzSyscall * rz_syscall_new(void)
Creates a new RzSyscall type.
Definition: syscall.c:67

References rz_egg_t::bin, rz_egg_t::bits, rz_egg_t::buf, rz_egg_t::db, egg_patch_free(), egg_static_plugins, emit_x86, rz_egg_t::endian, i, NULL, rz_egg_t::patches, rz_egg_t::plugins, rz_egg_t::rasm, rz_egg_t::remit, RZ_ARRAY_SIZE, rz_asm_new(), rz_buf_new_with_bytes(), rz_egg_add(), rz_egg_free(), rz_list_new(), rz_list_newf(), RZ_NEW0, rz_syscall_new(), sdb_new(), rz_egg_t::src, and rz_egg_t::syscall.

Referenced by rz_core_init(), rz_debug_new(), and rz_main_rz_gg().

◆ rz_egg_option_get()

RZ_API char* rz_egg_option_get ( RzEgg egg,
const char *  key 
)

Definition at line 534 of file egg.c.

534  {
535  return sdb_get(egg->db, key, NULL);
536 }
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
RZ_API char * sdb_get(Sdb *s, const char *key, ut32 *cas)
Definition: sdb.c:290

References rz_egg_t::db, key, NULL, and sdb_get().

Referenced by build(), egg_compile(), egg_option(), rz_core_egg_compile(), rz_egg_config_handler(), and rz_egg_show_config_handler().

◆ rz_egg_option_set()

RZ_API void rz_egg_option_set ( RzEgg egg,
const char *  key,
const char *  val 
)

Definition at line 530 of file egg.c.

530  {
531  sdb_set(egg->db, key, val, 0);
532 }
ut16 val
Definition: armass64_const.h:6
RZ_API int sdb_set(Sdb *s, const char *key, const char *val, ut32 cas)
Definition: sdb.c:611

References rz_egg_t::db, key, sdb_set(), and val.

Referenced by egg_option(), rz_core_egg_compile(), rz_egg_config_handler(), rz_egg_encoder_handler(), rz_egg_padding_handler(), rz_egg_type_handler(), and rz_main_rz_gg().

◆ rz_egg_os_as_string()

RZ_API const char* rz_egg_os_as_string ( int  os)

Definition at line 28 of file egg.c.

28  {
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 }
#define RZ_EGG_OS_IOS
Definition: rz_egg.h:131
#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_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

References RZ_EGG_OS_BEOS, RZ_EGG_OS_DARWIN, RZ_EGG_OS_FREEBSD, RZ_EGG_OS_IOS, RZ_EGG_OS_LINUX, RZ_EGG_OS_MACOS, RZ_EGG_OS_OSX, RZ_EGG_OS_W32, RZ_EGG_OS_WATCHOS, and RZ_EGG_OS_WINDOWS.

Referenced by rz_egg_load_file().

◆ rz_egg_padding()

RZ_API int rz_egg_padding ( RzEgg egg,
const char *  pad 
)

Definition at line 472 of file egg.c.

472  {
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 }
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
return memset(p, 0, total)
void * malloc(size_t size)
Definition: malloc.c:123
static void pad(RzStrBuf *sb, ut32 count)
Definition: protobuf.c:36
#define f(i)
Definition: sha256.c:46

References eon(), eprintf, f, free(), malloc(), memset(), NULL, p, pad(), rz_egg_append_bytes(), rz_egg_prepend_bytes(), and strdup().

Referenced by egg_compile(), and rz_main_rz_gg().

◆ rz_egg_patch()

RZ_API int rz_egg_patch ( RzEgg egg,
int  off,
const ut8 buf,
int  len 
)

Definition at line 576 of file egg.c.

576  {
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 }
int off
Definition: pal.c:13
#define RZ_NEW(x)
Definition: rz_types.h:285

References egg_patch_t::b, egg_patch_free(), len, off, egg_patch_t::off, rz_egg_t::patches, rz_buf_new_with_bytes(), rz_list_append(), and RZ_NEW.

Referenced by rz_egg_patch_num(), and rz_main_rz_gg().

◆ rz_egg_patch_num()

RZ_API bool rz_egg_patch_num ( RzEgg egg,
int  off,
ut64  num,
ut32  bits 
)

Definition at line 591 of file egg.c.

591  {
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 }
int bits(struct state *s, int need)
Definition: blast.c:72
RZ_API int rz_egg_patch(RzEgg *egg, int off, const ut8 *buf, int len)
Definition: egg.c:576
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
static void rz_write_ble(void *dst, ut64 val, bool big_endian, int size)
Definition: rz_endian.h:548

References bits(), rz_egg_t::endian, num, off, rz_egg_patch(), rz_return_val_if_fail, and rz_write_ble().

Referenced by rz_main_rz_gg().

◆ rz_egg_pattern()

RZ_API void rz_egg_pattern ( RzEgg egg,
int  size 
)

Definition at line 625 of file egg.c.

625  {
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 }
voidpf void uLong size
Definition: ioapi.h:138
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

References eprintf, free(), NULL, rz_debruijn_pattern(), and rz_egg_prepend_bytes().

Referenced by rz_main_rz_gg().

◆ rz_egg_prepend_bytes()

static int rz_egg_prepend_bytes ( RzEgg egg,
const ut8 b,
int  len 
)
static

Definition at line 309 of file egg.c.

309  {
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 }
static int rz_egg_raw_prepend(RzEgg *egg, const ut8 *b, int len)
Definition: egg.c:295
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

References b, rz_egg_t::bin, len, rz_buf_prepend_bytes(), and rz_egg_raw_prepend().

Referenced by rz_egg_padding(), and rz_egg_pattern().

◆ rz_egg_printf()

RZ_API void rz_egg_printf ( RzEgg egg,
const char *  fmt,
  ... 
)

◆ rz_egg_raw()

RZ_API int rz_egg_raw ( RzEgg egg,
const ut8 b,
int  len 
)

Definition at line 281 of file egg.c.

281  {
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 }
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
RZ_API int rz_hex_bin2str(const ut8 *in, int len, char *out)
Definition: hex.c:382

References b, rz_egg_t::buf, free(), len, malloc(), out, rz_buf_append_bytes(), and rz_hex_bin2str().

Referenced by rz_egg_append_bytes(), rz_egg_include(), rz_egg_load_file(), rz_egg_shellcode(), and rz_main_rz_gg().

◆ rz_egg_raw_prepend()

static int rz_egg_raw_prepend ( RzEgg egg,
const ut8 b,
int  len 
)
static

Definition at line 295 of file egg.c.

295  {
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 }

References b, rz_egg_t::buf, free(), len, malloc(), out, rz_buf_prepend_bytes(), and rz_hex_bin2str().

Referenced by rz_egg_prepend_bytes().

◆ rz_egg_reset()

RZ_API void rz_egg_reset ( RzEgg egg)

Definition at line 128 of file egg.c.

128  {
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 }
RZ_API void rz_egg_lang_include_init(RzEgg *egg)
Definition: egg_lang.c:164
RZ_API void rz_list_purge(RZ_NONNULL RzList *list)
Empties the list without freeing the list pointer.
Definition: list.c:120

References rz_egg_t::bin, rz_egg_t::buf, NULL, rz_egg_t::patches, rz_buf_free(), rz_buf_new_with_bytes(), rz_egg_lang_include_init(), rz_list_purge(), and rz_egg_t::src.

Referenced by rz_cmd_debug(), rz_core_egg_compile(), rz_core_syscall(), and rz_egg_load_file().

◆ rz_egg_run()

RZ_API int rz_egg_run ( RzEgg egg)

Definition at line 443 of file egg.c.

443  {
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 }
RZ_API int rz_sys_run(const ut8 *buf, int len)
Definition: sys.c:809

References rz_egg_t::bin, rz_buf_data(), rz_sys_run(), autogen_x86imm::tmp, and ut64().

Referenced by rz_main_rz_gg().

◆ rz_egg_run_rop()

RZ_API int rz_egg_run_rop ( RzEgg egg)

Definition at line 450 of file egg.c.

450  {
451  ut64 sz;
452  const ut8 *tmp = rz_buf_data(egg->bin, &sz);
453  return rz_sys_run_rop(tmp, sz);
454 }
RZ_API int rz_sys_run_rop(const ut8 *buf, int len)
Definition: sys.c:861

References rz_egg_t::bin, rz_buf_data(), rz_sys_run_rop(), autogen_x86imm::tmp, and ut64().

Referenced by rz_main_rz_gg().

◆ rz_egg_setup()

RZ_API bool rz_egg_setup ( RzEgg egg,
const char *  arch,
int  bits,
int  endian,
const char *  os 
)

Definition at line 139 of file egg.c.

139  {
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 }
RzEggEmit emit_trace
#define RZ_EGG_OS_DEFAULT
Definition: rz_egg.h:147
RZ_API ut64 rz_str_djb2_hash(const char *str)
Definition: str.c:383
@ RZ_SYS_ARCH_X86
Definition: rz_types.h:532
@ RZ_SYS_ARCH_ARM
Definition: rz_types.h:533
RZ_API bool rz_syscall_setup(RzSyscall *s, const char *arch, int bits, const char *cpu, const char *os)
Definition: syscall.c:234

References rz_egg_t::arch, arch, rz_egg_t::bits, bits(), emit_arm, emit_trace, emit_x64, emit_x86, rz_egg_t::endian, NULL, rz_egg_t::os, rz_egg_t::remit, RZ_EGG_OS_DEFAULT, rz_str_djb2_hash(), RZ_SYS_ARCH_ARM, RZ_SYS_ARCH_X86, rz_syscall_setup(), and rz_egg_t::syscall.

Referenced by cb_asmarch(), rz_cmd_debug(), rz_core_egg_setup(), rz_core_init(), rz_debug_new(), and rz_main_rz_gg().

◆ rz_egg_shellcode()

RZ_API int rz_egg_shellcode ( RzEgg egg,
const char *  name 
)

Definition at line 538 of file egg.c.

538  {
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 }
#define RZ_EGG_PLUGIN_SHELLCODE
Definition: rz_egg.h:19

References b, eprintf, p, rz_egg_t::plugins, rz_buf_data(), RZ_EGG_PLUGIN_SHELLCODE, rz_egg_raw(), autogen_x86imm::tmp, and ut64().

Referenced by rz_core_egg_compile(), and rz_main_rz_gg().

◆ rz_egg_syscall()

RZ_API void rz_egg_syscall ( RzEgg egg,
const char *  arg,
  ... 
)

Definition at line 255 of file egg.c.

255  {
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 }
char *(* syscall)(RzEgg *egg, int num)
Definition: rz_egg.h:163
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

References rz_syscall_item_t::num, rz_egg_t::remit, rz_syscall_get(), rz_syscall_get_num(), rz_syscall_item_free(), rz_egg_t::syscall, and rz_egg_emit_t::syscall.

◆ rz_egg_to_string()

RZ_API char* rz_egg_to_string ( RzEgg egg)

Definition at line 107 of file egg.c.

107  {
108  return rz_buf_to_string(egg->buf);
109 }

References rz_egg_t::buf, and rz_buf_to_string().

◆ RZ_LIB_VERSION()

RZ_LIB_VERSION ( rz_egg  )

Variable Documentation

◆ egg_static_plugins

RzEggPlugin* egg_static_plugins[] = { RZ_EGG_STATIC_PLUGINS }
static

Definition at line 15 of file egg.c.

Referenced by rz_egg_new().

◆ emit_arm

RzEggEmit emit_arm
extern

◆ emit_trace

RzEggEmit emit_trace
extern

Referenced by rz_egg_setup().

◆ emit_x64

RzEggEmit emit_x64
extern

◆ emit_x86

RzEggEmit emit_x86
extern