11 printf(
"Usage: rz-gg [-FOLsrxhvz] [-a arch] [-b bits] [-k os] [-o file] [-I path]\n"
12 " [-i sc] [-e enc] [-B hex] [-c k=v] [-C file] [-p pad] [-q off]\n"
13 " [-S string] [-f fmt] [-nN dword] [-dDw off:hex] file|f.asm|-\n");
16 " -a [arch] select architecture (x86, mips, arm)\n"
17 " -b [bits] register size (32, 64, ..)\n"
18 " -B [hexpairs] append some hexpair bytes\n"
19 " -c [k=v] set configuration options\n"
20 " -C [file] append contents of file\n"
21 " -d [off:dword] patch dword (4 bytes) at given offset\n"
22 " -D [off:qword] patch qword (8 bytes) at given offset\n"
23 " -e [encoder] use specific encoder. see -L\n"
24 " -f [format] output format (raw, c, pe, elf, mach0, python, javascript)\n"
25 " -F output native format (osx=mach0, linux=elf, ..)\n"
26 " -h show this help\n"
27 " -i [shellcode] include shellcode plugin, uses options. see -L\n"
28 " -I [path] add include path\n"
29 " -k [os] operating system's kernel (linux,bsd,osx,w32)\n"
30 " -L list all plugins (shellcodes and encoders)\n"
31 " -n [dword] append 32bit number (4 bytes)\n"
32 " -N [dword] append 64bit number (8 bytes)\n"
33 " -o [file] output file\n"
34 " -O use default output file (filename without extension or a.out)\n"
35 " -p [padding] add padding after compilation (padding=n10s32)\n"
36 " ntas : begin nop, trap, 'a', sequence\n"
37 " NTAS : same as above, but at the end\n"
38 " -P [size] prepend debruijn pattern\n"
39 " -q [fragment] debruijn pattern offset\n"
40 " -r show raw bytes instead of hexpairs\n"
41 " -s show assembler\n"
42 " -S [string] append a string\n"
44 " -w [off:hex] patch hexpairs at given offset\n"
46 " -X [hexpairs] execute rop chain, using the stack provided\n"
47 " -z output in C string syntax\n");
58 printf(
"%10s : %s\n",
p->name,
p->desc);
64 printf(
"%10s : %s\n",
p->name,
p->desc);
79 eprintf(
"Failed to write buffer\n");
83 eprintf(
"Cannot create binary for this format '%s'.\n", format);
103 int r = _chsize(
fd, 0);
114 #define ISEXEC (fmt != 'r')
118 const char *padding =
NULL;
119 const char *pattern =
NULL;
122 const char *contents =
NULL;
125 const char *format =
"raw";
126 bool show_execute =
false;
127 bool show_execute_rop =
false;
134 const char *shellcode =
NULL;
135 const char *encoder =
NULL;
136 char *sequence =
NULL;
146 rz_getopt_init(&opt, argc,
argv,
"n:N:he:a:b:f:o:sxXrk:FOI:Li:c:p:P:B:C:vd:D:w:zq:S:");
151 if (!strcmp(
arch,
"trace")) {
167 eprintf(
"Cannot open empty contents path\n");
176 char *
p = strchr(
arg,
':');
187 eprintf(
"Invalid hexstr for -w\n");
191 eprintf(
"Missing colon in -w\n");
205 char *
p = strchr(opt.
arg,
':');
215 eprintf(
"Missing colon in -%c\n",
c);
229 eprintf(
"Cannot open empty include path\n");
246 char *
p = strchr(opt.
arg,
'=');
285 show_execute_rop = 1;
323 if (!strcmp(format,
"mach0")) {
325 }
else if (!strcmp(format,
"elf")) {
332 if (strncmp(sequence,
"0x", 2)) {
333 eprintf(
"Need hex value with `0x' prefix e.g. 0x41414142\n");
351 eprintf(
"Cannot open empty path\n");
354 if (!strcmp(
file,
"-")) {
357 if (!fgets(
buf,
sizeof(
buf), stdin)) {
375 eprintf(
"rz_egg_compile: fail\n");
397 eprintf(
"Error loading '%s'\n", contents);
405 eprintf(
"Unknown shellcode '%s'\n", shellcode);
416 eprintf(
"Unknown '%s'\n", shellcode);
421 eprintf(
"Invalid hexpair string for -B\n");
432 if ((o = strchr(
p,
'.'))) {
433 while ((q = strchr(o + 1,
'.'))) {
461 eprintf(
"rz_egg_assemble: invalid assembly\n");
466 eprintf(
"Invalid encoder '%s'\n", encoder);
486 eprintf(
"rz_egg_get_bin: invalid egg :(\n");
495 if (show_raw || show_hex || show_execute) {
498 if (show_execute_rop) {
511 eprintf(
"Failed to write buffer\n");
516 eprintf(
"No format specified\n");
536 for (
i = 0;
i < tmpsz;
i++) {
540 }
else if (show_hex) {
542 for (
i = 0;
i < tmpsz;
i++) {
549 if (strlen(format) >= 2 && format[1] ==
'y') {
560 eprintf(
"unknown executable format (%s)\n", format);
RZ_API RzBin * rz_bin_new(void)
RZ_API void rz_bin_arch_options_init(RzBinArchOptions *opt, const char *arch, int bits)
RZ_API RzBuffer * rz_bin_create(RzBin *bin, const char *p, const ut8 *code, int codelen, const ut8 *data, int datalen, RzBinArchOptions *opt)
RZ_API void rz_bin_free(RzBin *bin)
static ut64 get_offset(RzBinFile *bf, int type, int index)
int bits(struct state *s, int need)
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
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 ftruncate
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 fchmod
static static fork const void static count close
RZ_API int rz_egg_shellcode(RzEgg *egg, const char *name)
RZ_API int rz_egg_run_rop(RzEgg *egg)
RZ_API void rz_egg_free(RzEgg *egg)
RZ_API void rz_egg_finalize(RzEgg *egg)
RZ_API RzEgg * rz_egg_new(void)
RZ_API bool rz_egg_patch_num(RzEgg *egg, int off, ut64 num, ut32 bits)
RZ_API bool rz_egg_load_file(RzEgg *egg, const char *file)
RZ_API int rz_egg_padding(RzEgg *egg, const char *pad)
RZ_API int rz_egg_run(RzEgg *egg)
RZ_API int rz_egg_patch(RzEgg *egg, int off, const ut8 *buf, int len)
RZ_API void rz_egg_pattern(RzEgg *egg, int size)
RZ_API char * rz_egg_get_assembly(RzEgg *egg)
RZ_API int rz_egg_encode(RzEgg *egg, const char *name)
RZ_API int rz_egg_compile(RzEgg *egg)
RZ_API RzBuffer * rz_egg_get_bin(RzEgg *egg)
RZ_API void rz_egg_option_set(RzEgg *egg, const char *key, const char *val)
RZ_API void rz_egg_load(RzEgg *egg, const char *code, int format)
RZ_API bool rz_egg_assemble(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_raw(RzEgg *egg, const ut8 *b, int len)
RZ_API void rz_egg_lang_include_path(RzEgg *egg, const char *path)
RZ_API void Ht_() free(HtName_(Ht) *ht)
static int openfile(const char *f, int x)
static int create(const char *format, const char *arch, int bits, const ut8 *code, int codelen)
RZ_API int rz_main_rz_gg(int argc, const char **argv)
static void list(RzEgg *egg)
void * malloc(size_t size)
static static fork const void static count static fd const char const char static newpath char char argv
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 static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname unsigned long static filedes void static end_data_segment static handler static getegid char static len static pgid const char static path dup2
RZ_API st64 rz_buf_seek(RZ_NONNULL RzBuffer *b, st64 addr, int whence)
Modify the current cursor position in the buffer.
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
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.
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.
RZ_API int rz_debruijn_offset(int start, const char *charset, ut64 value, bool is_big_endian)
Finds the offset of a given value in a debrujn sequence.
#define RZ_EGG_PLUGIN_SHELLCODE
#define RZ_EGG_PLUGIN_ENCODER
RZ_API RZ_OWN char * rz_file_slurp(const char *str, RZ_NULLABLE size_t *usz)
RZ_API void rz_getopt_init(RzGetopt *go, int argc, const char **argv, const char *ostr)
RZ_API int rz_getopt_next(RzGetopt *opt)
RZ_API int rz_hex_str2bin(const char *in, ut8 *out)
Convert an input string in into the binary form in out.
RZ_API RZ_OWN char * rz_lang_byte_array(RZ_NONNULL const ut8 *buffer, size_t size, RzLangByteArrayType type)
@ RZ_LANG_BYTE_ARRAY_C_CPP_BYTES
@ RZ_LANG_BYTE_ARRAY_PYTHON
@ RZ_LANG_BYTE_ARRAY_JSON
RZ_API int rz_main_version_print(const char *program)
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
RZ_API char * rz_str_append(char *ptr, const char *string)
#define RZ_STR_ISEMPTY(x)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static const z80_opcode fd[]