Big endian for arm.winedbg and addn randomart in rax2 -k

r_asm: Add support for big endian arm.winedbg
rax2: Add -k randomart to rax2, -k is now -B
rax2: Handle multiple flags on a single argument
rax2: update manpage
This commit is contained in:
pancake 2013-02-13 01:20:42 +01:00
parent b5ee410124
commit 766563cc6e
6 changed files with 79 additions and 50 deletions

View File

@ -1,6 +1,7 @@
/* radare - LGPL - Copyright 2007-2012 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2007-2013 - pancake */
#include <r_util.h>
#include <r_print.h>
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';

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2012 nibble */
/* radare - LGPL - Copyright 2009-2013 - nibble */
#include <stdio.h>
#include <stdarg.h>
@ -9,15 +9,21 @@
#include <r_asm.h>
#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;
}

View File

@ -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)

View File

@ -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_

View File

@ -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) {

View File

@ -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