diff --git a/binr/rax2/rax2.c b/binr/rax2/rax2.c index c5b95e8ab8..951d1b6720 100644 --- a/binr/rax2/rax2.c +++ b/binr/rax2/rax2.c @@ -1,6 +1,7 @@ -/* radare - LGPL - Copyright 2007-2012 pancake */ +/* radare - LGPL - Copyright 2007-2013 - pancake */ #include +#include static ut64 flags = 0; @@ -57,14 +58,16 @@ static int help () { " -S raw -> hexstr ; rax2 -S C J P\n" " -v version ; rax2 -V\n" " -x hash string ; rax2 -x linux osx\n" - " -k keep base ; rax2 -k 33+3 -> 36\n" + " -k randomart ; rax2 -k 0x34 1020304050\n" + " -B keep base ; rax2 -B 33+3 -> 36\n" " -h help ; rax2 -h\n"); return R_TRUE; } static int rax (char *str, int len, int last) { float f; - char *p, *buf, out_mode = (flags&128)?'I':'0'; + ut8 *buf; + char *p, out_mode = (flags&128)?'I':'0'; int i; if (!len) len = strlen (str); @@ -72,37 +75,59 @@ static int rax (char *str, int len, int last) { if ((flags & 4)) goto dotherax; if (*str=='-') { - switch (str[1]) { - case 's': flags ^= 1; break; - case 'e': flags ^= 2; break; - case 'S': flags ^= 4; break; - case 'b': flags ^= 8; break; - case 'x': flags ^= 16; break; - case 'k': flags ^= 32; break; - case 'f': flags ^= 64; break; - case 'd': flags ^=128; break; - case 'v': printf ("rax2 v"R2_VERSION"\n"); break; - case '\0': return use_stdin (); - default: - if (str[1]>='0' && str[1]<='9') - return format_output (out_mode, str); - printf ("Usage: rax2 [options] [expression]\n"); - return help (); + while (str[1] && str[1]!=' ') { + switch (str[1]) { + case 's': flags ^= 1; break; + case 'e': flags ^= 2; break; + case 'S': flags ^= 4; break; + case 'b': flags ^= 8; break; + case 'x': flags ^= 16; break; + case 'B': flags ^= 32; break; + case 'f': flags ^= 64; break; + case 'd': flags ^=128; break; + case 'k': flags ^=256; break; + case 'v': printf ("rax2 v"R2_VERSION"\n"); break; + case '\0': return use_stdin (); + default: + if (str[1]>='0' && str[1]<='9') + return format_output (out_mode, str); + printf ("Usage: rax2 [options] [expression]\n"); + return help (); + } + str++; } if (last) return use_stdin (); return R_TRUE; - } else - if (*str=='q') + } else if (*str=='q') return R_FALSE; - else - if (*str=='h' || *str=='?') + else if (*str=='h' || *str=='?') return help (); dotherax: - if (flags & 1) { + if (flags & 256) { // -k + int n = ((strlen (str))>>1)+1; + char *s; + ut32 *m; + buf = (ut8*) malloc (n); + m = (ut32 *) buf; + memset (buf, '\0', n); + n = r_hex_str2bin (str, (ut8*)buf); + if (n<1 || !memcmp (str, "0x", 2)) { + ut64 q = r_num_math (num, str); + s = r_print_randomart ((ut8*)&q, sizeof (q), q); + printf ("%s\n", s); + free (s); + } else { + s = r_print_randomart ((ut8*)buf, n, *m); + printf ("%s\n", s); + free (s); + } + return R_TRUE; + } + if (flags & 1) { // -s ut64 n = ((strlen (str))>>1)+1; - buf = malloc (sizeof (char) * n); + buf = malloc (n); memset (buf, '\0', n); n = r_hex_str2bin (str, (ut8*)buf); write (1, buf, n); @@ -131,11 +156,8 @@ static int rax (char *str, int len, int last) { } #define KB (flags&32) - if (flags & 64) { - out_mode = 'f'; - } else - if (KB) - out_mode = 'I'; + if (flags & 64) { out_mode = 'f'; + } else if (KB) out_mode = 'I'; if (str[0]=='0' && str[1]=='x') { out_mode = (KB)? '0': 'I'; } else if (str[0]=='b') { @@ -170,15 +192,13 @@ static int rax (char *str, int len, int last) { return R_TRUE; } -static char buf[254096]; // TODO: remove this limit +static char buf[354096]; // TODO: remove this limit static int use_stdin () { while (!feof (stdin)) { - //int n = fread (buf, 1, sizeof (buf)-1, stdin); int n = read (0, buf, sizeof (buf)); if (n<1) break; buf[n] = 0; - //fgets (buf, sizeof (buf), stdin); if (feof (stdin)) break; if ((flags & 4) && strlen (buf) < sizeof (buf)) // -S buf[strlen (buf)] = '\0'; diff --git a/libr/asm/p/asm_arm_winedbg.c b/libr/asm/p/asm_arm_winedbg.c index 4d78a9356e..e9f04f13af 100644 --- a/libr/asm/p/asm_arm_winedbg.c +++ b/libr/asm/p/asm_arm_winedbg.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2009-2012 nibble */ +/* radare - LGPL - Copyright 2009-2013 - nibble */ #include #include @@ -9,15 +9,21 @@ #include #include "../arch/arm/winedbg/be_arm.h" -static int disassemble(struct r_asm_t *a, struct r_asm_op_t *op, const ut8 *buf, ut64 len) { +static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, ut64 len) { + char buf2[4]; struct arm_insn *arminsn = arm_new(); - arm_set_pc(arminsn, a->pc); - arm_set_thumb(arminsn, a->bits == 16); - arm_set_input_buffer(arminsn, buf); - op->inst_len = arm_disasm_one_insn(arminsn); - strncpy (op->buf_asm, arm_insn_asm(arminsn), R_ASM_BUFSIZE); - strncpy (op->buf_hex, arm_insn_hex(arminsn), R_ASM_BUFSIZE); - arm_free(arminsn); + arm_set_pc (arminsn, a->pc); + arm_set_thumb (arminsn, a->bits == 16); + if (a->big_endian && a->bits == 32) { + r_mem_copyendian (buf2, buf, 4, 0); + arm_set_input_buffer (arminsn, buf2); + } else { + arm_set_input_buffer (arminsn, buf); + } + op->inst_len = arm_disasm_one_insn (arminsn); + strncpy (op->buf_asm, arm_insn_asm (arminsn), R_ASM_BUFSIZE); + strncpy (op->buf_hex, arm_insn_hex (arminsn), R_ASM_BUFSIZE); + arm_free (arminsn); return op->inst_len; } diff --git a/libr/bin/bin.c b/libr/bin/bin.c index 7bf92851e9..1826b6f545 100644 --- a/libr/bin/bin.c +++ b/libr/bin/bin.c @@ -21,7 +21,7 @@ static void get_strings_range(RBinArch *arch, RList *list, int min, ut64 from, u if (arch && arch->buf && to > arch->buf->length) to = arch->buf->length; if (to > 0xf00000) { - eprintf ("WARNING: bin_strings buffer is too big\n"); + eprintf ("WARNING: bin_strings buffer is too big at 0x%08"PFMT64x"\n", from); return; } if (to == 0) diff --git a/libr/include/r_asm.h b/libr/include/r_asm.h index d374e984cd..4283e6ddd9 100644 --- a/libr/include/r_asm.h +++ b/libr/include/r_asm.h @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2009-2012 - nibble, pancake */ +/* radare - LGPL - Copyright 2009-2013 - nibble, pancake */ #ifndef _INCLUDE_R_ASM_H_ #define _INCLUDE_R_ASM_H_ diff --git a/libr/util/mem.c b/libr/util/mem.c index 1ebc671c35..c3285ebffe 100644 --- a/libr/util/mem.c +++ b/libr/util/mem.c @@ -149,6 +149,7 @@ R_API int r_mem_set_num (ut8 *dest, int dest_size, ut64 num, int endian) { } /* XXX TODO check and use system endian */ +// TODO: rename to r_mem_swap() */ R_API void r_mem_copyendian (ut8 *dest, const ut8 *orig, int size, int endian) { ut8 buffer[8]; if (endian) { diff --git a/man/rax2.1 b/man/rax2.1 index 539123128f..ccf2f7909b 100644 --- a/man/rax2.1 +++ b/man/rax2.1 @@ -1,4 +1,4 @@ -.Dd Mar 12, 2010 +.Dd Mar 12, 2013 .Dt RAX2 1 .Os .Sh NAME @@ -6,7 +6,7 @@ .Nd radare base converter .Sh SYNOPSIS .Nm rax2 -.Op Fl ebsSvxkh +.Op Fl ebBsSvxkh .Op [value] ... .Sh DESCRIPTION This command is part of the radare project. @@ -14,10 +14,14 @@ This command is part of the radare project. This command allows you to convert values between positive and negative integer, float octal, binary and hexadecimal values. .Sh OPTIONS .Bl -tag -width Fl -.It Fl e -Swap endian. .It Fl b Convert from binary string to caracter (rax2 \-b 01000101) +.It Fl B +Keep de same base as the input data +.It Fl e +Swap endian. +.It Fl k +Show randomart key asciiart for values or hexpairs .It Fl s Convert from hex string to caracter (rax2 \-s 43 4a 50) .It Fl S @@ -26,8 +30,6 @@ Convert from hex string to caracter (rax2 \-S C J P) Show program version .It Fl x Convert a string into a hash -.It Fl k -Keep de same base as the input data .It Fl h Show usage help message .El