Skip to content

Commit

Permalink
added debruijn offset to ragg2
Browse files Browse the repository at this point in the history
  • Loading branch information
four0four authored and crowell committed Jul 22, 2015
1 parent c5a03b3 commit 1d949d4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
24 changes: 21 additions & 3 deletions binr/ragg2/ragg2.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ static int usage (int v) {
" -p [padding] add padding after compilation (padding=n10s32)\n"
" ntas : begin nop, trap, 'a', sequence\n"
" NTAS : same as above, but at the end\n"
" -P [size] prepend debrujn pattern\n"
" -P [size] prepend debruijn pattern\n"
" -q [fragment] debruijn pattern offset\n"
" -r show raw bytes instead of hexpairs\n"
" -s show assembler\n"
" -v show version\n"
Expand Down Expand Up @@ -105,8 +106,10 @@ int main(int argc, char **argv) {
int show_raw = 0;
int append = 0;
int show_str = 0;
ut64 get_offset = 0;
char *shellcode = NULL;
char *encoder = NULL;
char *sequence = NULL;
int bits = (R_SYS_BITS & R_SYS_BITS_64)? 64: 32;
int fmt = 0;
const char *ofile = NULL;
Expand All @@ -117,7 +120,7 @@ int main(int argc, char **argv) {

//egg->bin = r_buf_new ();

while ((c = getopt (argc, argv, "n:N:he:a:b:f:o:sxrk:FOI:Li:c:p:P:B:C:vd:D:w:z")) != -1) {
while ((c = getopt (argc, argv, "n:N:he:a:b:f:o:sxrk:FOI:Li:c:p:P:B:C:vd:D:w:zq:")) != -1) {
switch (c) {
case 'a':
arch = optarg;
Expand Down Expand Up @@ -257,12 +260,16 @@ int main(int argc, char **argv) {
case 'z':
show_str = 1;
break;
case 'q':
get_offset = 1;
sequence = strdup (optarg);
break;
default:
return 1;
}
}

if (optind == argc && !shellcode && !bytes && !contents && !encoder && !padding && !pattern && !append) {
if (optind == argc && !shellcode && !bytes && !contents && !encoder && !padding && !pattern && !append && !get_offset) {
return usage (0);
} else file = argv[optind];

Expand All @@ -273,6 +280,17 @@ int main(int argc, char **argv) {
format = "elf64";
}

// catch this first
if (get_offset) {
get_offset = r_num_math (0, sequence);
printf ("Little endian: %d\n",
r_debruijn_offset (get_offset, 1));
printf ("Big endian: %d\n",
r_debruijn_offset (get_offset, 0));
free (sequence);
return 0;
}

// initialize egg
r_egg_setup (egg, arch, bits, 0, os);
if (file) {
Expand Down
2 changes: 2 additions & 0 deletions man/ragg2.1
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ Append a 64bit number in little endian
Specify generic paddings with a format string.
.It Fl P Ar size
Prepend debruijn sequence of given length.
.It Fl q Ar fragment
Output offset of debruijn sequence fragment.
.It Fl F
autodetect native file format (osx=mach0, linux=elf, ..)
.It Fl O
Expand Down

0 comments on commit 1d949d4

Please sign in to comment.