mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-11 23:16:05 +00:00
Support longer wopD.. still not complete
This commit is contained in:
parent
75fd458df8
commit
d001066eb4
@ -2225,6 +2225,7 @@ static void cmd_esil_mem(RCore *core, const char *input) {
|
||||
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, "wopD 0x%"PFMT64x" @ 0x%"PFMT64x, size, addr);
|
||||
r_core_seek (core, curoff, 0);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2015 - pancake */
|
||||
/* radare - LGPL - Copyright 2009-2016 - pancake */
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -206,14 +206,19 @@ static void cmd_write_op (RCore *core, const char *input) {
|
||||
bits = ((ut64)1) << i;
|
||||
const char *name = r_hash_name (bits);
|
||||
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");
|
||||
for (i = 0; ; i++) {
|
||||
bits = ((ut64)1) << i;
|
||||
const char *name = r_crypto_name (bits);
|
||||
if (!name || !*name) break;
|
||||
printf (" %s\n", name);
|
||||
printf (" %s\n", name);
|
||||
}
|
||||
}
|
||||
free (args);
|
||||
@ -222,12 +227,26 @@ static void cmd_write_op (RCore *core, const char *input) {
|
||||
case 'p': // debrujin patterns
|
||||
switch (input[2]) {
|
||||
case 'D': // "wopD"
|
||||
len = (int)(input[3]==' ')?
|
||||
r_num_math (core->num, input + 3): core->blocksize;
|
||||
len = (int)(input[3]==' ')
|
||||
? r_num_math (core->num, input + 3)
|
||||
: core->blocksize;
|
||||
if (len > 0) {
|
||||
/* XXX This seems to fail at generating long patterns (wopD 512K) */
|
||||
buf = (ut8*)r_debruijn_pattern (len, 0, NULL); //debruijn_charset);
|
||||
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);
|
||||
} else {
|
||||
eprintf ("Couldn't generate pattern of length %d\n", len);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2014 - crowell */
|
||||
/* radare - LGPL - Copyright 2014-2016 - crowell, pancake */
|
||||
|
||||
#include <r_util.h>
|
||||
|
||||
@ -12,20 +12,16 @@ static const char* debruijn_charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmno
|
||||
|
||||
// Generate a De Bruijn sequence.
|
||||
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,
|
||||
const char* charset) {
|
||||
int maxlen, int size, int* prenecklace_a, char* sequence, const char* charset) {
|
||||
int j;
|
||||
if (!charset || !sequence) {
|
||||
return;
|
||||
}
|
||||
if (strlen(sequence) == maxlen) {
|
||||
if (!charset || !sequence || strlen (sequence) == maxlen) {
|
||||
return;
|
||||
}
|
||||
if (prenecklace_len_t > order) {
|
||||
if (order % lyndon_prefix_len_p == 0) {
|
||||
for (j = 1; j <= lyndon_prefix_len_p; ++j) {
|
||||
sequence[strlen(sequence)] = charset[prenecklace_a[j]];
|
||||
if (strlen(sequence) == maxlen) {
|
||||
if (strlen (sequence) == maxlen) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -38,7 +34,7 @@ static void de_bruijn_seq(int prenecklace_len_t, int lyndon_prefix_len_p, int or
|
||||
for (j = prenecklace_a[prenecklace_len_t - lyndon_prefix_len_p] + 1;
|
||||
j < size; ++j) {
|
||||
prenecklace_a[prenecklace_len_t] = j;
|
||||
de_bruijn_seq(prenecklace_len_t + 1, prenecklace_len_t, order, maxlen,
|
||||
de_bruijn_seq (prenecklace_len_t + 1, prenecklace_len_t, order, maxlen,
|
||||
size, prenecklace_a, sequence, charset);
|
||||
}
|
||||
}
|
||||
@ -72,10 +68,11 @@ R_API char* r_debruijn_pattern(int size, int start, const char* charset) {
|
||||
if (start >= size) {
|
||||
return (char*)NULL;
|
||||
}
|
||||
pat = de_bruijn(charset, 3 /*subsequence length*/, size);
|
||||
pat = de_bruijn (charset, 3 /*subsequence length*/, size);
|
||||
if (!pat) return NULL;
|
||||
if (start == 0)
|
||||
if (start == 0) {
|
||||
return pat;
|
||||
}
|
||||
pat2 = calloc ((size - start) + 1, sizeof(char));
|
||||
if (!pat2) {
|
||||
free (pat);
|
||||
@ -87,15 +84,6 @@ R_API char* r_debruijn_pattern(int size, int start, const char* charset) {
|
||||
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.
|
||||
// Guest 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) {
|
||||
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) {
|
||||
buf[7] = value & 0xff;
|
||||
|
Loading…
Reference in New Issue
Block a user