mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-27 15:10:53 +00:00
Add rax2 -w to wrap sign bit
This commit is contained in:
parent
462bd1da4c
commit
44b2e44f3d
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2007-2015 - pancake */
|
||||
/* radare - LGPL - Copyright 2007-2016 - pancake */
|
||||
|
||||
#include <r_util.h>
|
||||
#include <r_print.h>
|
||||
@ -77,6 +77,7 @@ static int help () {
|
||||
" -B keep base ; rax2 -B 33+3 -> 36\n"
|
||||
" -d force integer ; rax2 -d 3 -> 3 instead of 0x3\n"
|
||||
" -e swap endianness ; rax2 -e 0x33\n"
|
||||
" -E base64 encode ;\n"
|
||||
" -f floating point ; rax2 -f 6.3+2.1\n"
|
||||
" -F stdin slurp C hex ; rax2 -F < shellcode.c\n"
|
||||
" -h help ; rax2 -h\n"
|
||||
@ -88,6 +89,7 @@ static int help () {
|
||||
" -t tstamp -> str ; rax2 -t 1234567890\n"
|
||||
" -x hash string ; rax2 -x linux osx\n"
|
||||
" -u units ; rax2 -u 389289238 # 317.0M\n"
|
||||
" -w signed word ; rax2 -w 16 0xffff\n"
|
||||
" -v version ; rax2 -V\n"
|
||||
);
|
||||
return true;
|
||||
@ -96,7 +98,7 @@ static int help () {
|
||||
static int rax (char *str, int len, int last) {
|
||||
float f;
|
||||
ut8 *buf;
|
||||
char *p, out_mode = (flags&128)? 'I': '0';
|
||||
char *p, out_mode = (flags & 128)? 'I': '0';
|
||||
int i;
|
||||
if (!(flags & 4) || !len)
|
||||
len = strlen (str);
|
||||
@ -126,12 +128,13 @@ static int rax (char *str, int len, int last) {
|
||||
case 'd': flags ^= 1<<7; break;
|
||||
case 'k': flags ^= 1<<8; break;
|
||||
case 'n': flags ^= 1<<9; break;
|
||||
case 'u': flags ^=1<<10; break;
|
||||
case 't': flags ^=1<<11; break;
|
||||
case 'E': flags ^=1<<12; break;
|
||||
case 'D': flags ^=1<<13; break;
|
||||
case 'F': flags ^=1<<14; break;
|
||||
case 'N': flags ^=1<<15; break;
|
||||
case 'u': flags ^= 1<<10; break;
|
||||
case 't': flags ^= 1<<11; break;
|
||||
case 'E': flags ^= 1<<12; break;
|
||||
case 'D': flags ^= 1<<13; break;
|
||||
case 'F': flags ^= 1<<14; break;
|
||||
case 'N': flags ^= 1<<15; break;
|
||||
case 'w': flags ^= 1<<16; break;
|
||||
case 'v': blob_version ("rax2"); return 0;
|
||||
case '\0': return !use_stdin ();
|
||||
default:
|
||||
@ -234,6 +237,19 @@ static int rax (char *str, int len, int last) {
|
||||
}
|
||||
fflush (stdout);
|
||||
return true;
|
||||
} else if (flags & (1<<16)) { // -w
|
||||
ut64 n = r_num_math (num, str);
|
||||
if (n >> 31) {
|
||||
// is >32bit
|
||||
n = (st64)(st32)n;
|
||||
} else if (n>>14) {
|
||||
n = (st64)(st16)n;
|
||||
} else if (n>>7) {
|
||||
n = (st64)(st8)n;
|
||||
}
|
||||
printf ("%"PFMT64d"\n", n);
|
||||
fflush (stdout);
|
||||
return true;
|
||||
} else if (flags & (1<<15)) { // -N
|
||||
ut64 n = r_num_math (num, str);
|
||||
if (n>>32) {
|
||||
@ -246,8 +262,8 @@ static int rax (char *str, int len, int last) {
|
||||
np[4], np[5], np[6], np[7]);
|
||||
} else {
|
||||
/* is 32 bit value */
|
||||
ut32 n32 = (ut32)(n&UT32_MAX);
|
||||
ut8 *np = (ut8*)&n32;
|
||||
ut32 n32 = (ut32)(n & UT32_MAX);
|
||||
ut8 *np = (ut8*) & n32;
|
||||
if (flags & 1) fwrite (&n32, sizeof (n32), 1, stdout);
|
||||
else printf ("\\x%02x\\x%02x\\x%02x\\x%02x\n",
|
||||
np[0], np[1], np[2], np[3]);
|
||||
|
Loading…
Reference in New Issue
Block a user