Support longer wopD.. still not complete

This commit is contained in:
pancake 2016-08-15 01:40:34 +02:00
parent 75fd458df8
commit d001066eb4
3 changed files with 36 additions and 27 deletions

View file

@ -2225,6 +2225,7 @@ static void cmd_esil_mem(RCore *core, const char *input) {
if (!r_io_section_get_name (core->io, "esil_stack")) { if (!r_io_section_get_name (core->io, "esil_stack")) {
r_core_cmdf (core, "S 0x%"PFMT64x" 0x%"PFMT64x" %d %d esil_stack", addr, addr, size, size); r_core_cmdf (core, "S 0x%"PFMT64x" 0x%"PFMT64x" %d %d esil_stack", addr, addr, size, size);
} }
// r_core_cmdf (core, "wopD 0x%"PFMT64x" @ 0x%"PFMT64x, size, addr);
r_core_seek (core, curoff, 0); r_core_seek (core, curoff, 0);
} }

View file

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2015 - pancake */ /* radare - LGPL - Copyright 2009-2016 - pancake */
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
@ -208,6 +208,11 @@ static void cmd_write_op (RCore *core, const char *input) {
if (!name || !*name) break; if (!name || !*name) break;
printf (" %s\n", name); printf (" %s\n", name);
} }
eprintf ("Available Encoders/Decoders: \n");
// TODO: do not hardcode
eprintf (" base64\n");
eprintf (" base91\n");
eprintf (" punycode\n");
eprintf ("Currently supported crypto algos:\n"); eprintf ("Currently supported crypto algos:\n");
for (i = 0; ; i++) { for (i = 0; ; i++) {
bits = ((ut64)1) << i; bits = ((ut64)1) << i;
@ -222,12 +227,26 @@ static void cmd_write_op (RCore *core, const char *input) {
case 'p': // debrujin patterns case 'p': // debrujin patterns
switch (input[2]) { switch (input[2]) {
case 'D': // "wopD" case 'D': // "wopD"
len = (int)(input[3]==' ')? len = (int)(input[3]==' ')
r_num_math (core->num, input + 3): core->blocksize; ? r_num_math (core->num, input + 3)
: core->blocksize;
if (len > 0) { if (len > 0) {
/* XXX This seems to fail at generating long patterns (wopD 512K) */
buf = (ut8*)r_debruijn_pattern (len, 0, NULL); //debruijn_charset); buf = (ut8*)r_debruijn_pattern (len, 0, NULL); //debruijn_charset);
if (buf) { if (buf) {
r_core_write_at (core, core->offset, buf, len); const ut8 *ptr = buf;
ut64 addr = core->offset;
while (true) {
int res = r_core_write_at (core, addr, ptr, len);
if (res < 1 || len == res) {
break;
}
if (res < len) {
ptr += res;
len -= res;
addr += res;
}
}
free (buf); free (buf);
} else { } else {
eprintf ("Couldn't generate pattern of length %d\n", len); eprintf ("Couldn't generate pattern of length %d\n", len);

View file

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2014 - crowell */ /* radare - LGPL - Copyright 2014-2016 - crowell, pancake */
#include <r_util.h> #include <r_util.h>
@ -12,13 +12,9 @@ static const char* debruijn_charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmno
// Generate a De Bruijn sequence. // Generate a De Bruijn sequence.
static void de_bruijn_seq(int prenecklace_len_t, int lyndon_prefix_len_p, int order, static void de_bruijn_seq(int prenecklace_len_t, int lyndon_prefix_len_p, int order,
int maxlen, int size, int* prenecklace_a, char* sequence, int maxlen, int size, int* prenecklace_a, char* sequence, const char* charset) {
const char* charset) {
int j; int j;
if (!charset || !sequence) { if (!charset || !sequence || strlen (sequence) == maxlen) {
return;
}
if (strlen(sequence) == maxlen) {
return; return;
} }
if (prenecklace_len_t > order) { if (prenecklace_len_t > order) {
@ -74,8 +70,9 @@ R_API char* r_debruijn_pattern(int size, int start, const char* charset) {
} }
pat = de_bruijn (charset, 3 /*subsequence length*/, size); pat = de_bruijn (charset, 3 /*subsequence length*/, size);
if (!pat) return NULL; if (!pat) return NULL;
if (start == 0) if (start == 0) {
return pat; return pat;
}
pat2 = calloc ((size - start) + 1, sizeof(char)); pat2 = calloc ((size - start) + 1, sizeof(char));
if (!pat2) { if (!pat2) {
free (pat); free (pat);
@ -87,15 +84,6 @@ R_API char* r_debruijn_pattern(int size, int start, const char* charset) {
return pat2; return pat2;
} }
// Generate a cyclic pattern of 0x10000 long.
// The returned string is malloced, and it is the responsibility of the caller
// to free the memory.
static char* cyclic_pattern_long() {
// 0x10000 should be long enough. This is how peda works, and nobody
// complains.
return r_debruijn_pattern (0x10000, 0, debruijn_charset);
}
// Finds the offset of a given value in a cyclic pattern of an integer. // Finds the offset of a given value in a cyclic pattern of an integer.
// Guest endian = 1 if little, 0 if big. // Guest endian = 1 if little, 0 if big.
// Host endian = 1 if little, 0 if big. // Host endian = 1 if little, 0 if big.
@ -107,7 +95,8 @@ R_API int r_debruijn_offset(ut64 value, int big_endian) {
if (value == 0) { if (value == 0) {
return -1; return -1;
} }
pattern = cyclic_pattern_long (); // 0x10000 should be long enough. This is how peda works, and nobody complains
pattern = r_debruijn_pattern (0x10000, 0, debruijn_charset);
if (big_endian) { if (big_endian) {
buf[7] = value & 0xff; buf[7] = value & 0xff;