Rax2

The rax2 utility comes with the radare framework and aims to be a minimalistic expression evaluator for the shell. It is useful for making base conversions between floating point values, hexadecimal representations, hexpair strings to ascii, octal to integer. It supports endianness and can be used as a shell if no arguments are given.

This is the help message of rax2, this tool can be used in the command-line or interactively (reading the values from stdin), so it can be used as a multi-base calculator.

Inside r2, the functionality of rax2 is available under the ? command. For example:

  1. [0x00000000]> ? 3+4

As you can see, the numeric expressions can contain mathematical expressions like addition, substraction, .. as well as group operations with parenthesis.

The syntax in which the numbers are represented define the base, for example:

  • 3 : decimal, base 10
  • 0xface : hexadecimal, base 16
  • 0472 : octal, base 8
  • 2M : units, 2 megabytes

This is the help message of rax2 -h, which will show you a bunch more syntaxes

  1. $ rax2 -h
  2. Usage: rax2 [options] [expr ...]
  3. =[base] ; rax2 =10 0x46 -> output in base 10
  4. int -> hex ; rax2 10
  5. hex -> int ; rax2 0xa
  6. -int -> hex ; rax2 -77
  7. -hex -> int ; rax2 0xffffffb3
  8. int -> bin ; rax2 b30
  9. int -> ternary ; rax2 t42
  10. bin -> int ; rax2 1010d
  11. ternary -> int ; rax2 1010dt
  12. float -> hex ; rax2 3.33f
  13. hex -> float ; rax2 Fx40551ed8
  14. oct -> hex ; rax2 35o
  15. hex -> oct ; rax2 Ox12 (O is a letter)
  16. bin -> hex ; rax2 1100011b
  17. hex -> bin ; rax2 Bx63
  18. ternary -> hex ; rax2 212t
  19. hex -> ternary ; rax2 Tx23
  20. raw -> hex ; rax2 -S < /binfile
  21. hex -> raw ; rax2 -s 414141
  22. -l ; append newline to output (for -E/-D/-r/..
  23. -a show ascii table ; rax2 -a
  24. -b bin -> str ; rax2 -b 01000101 01110110
  25. -B str -> bin ; rax2 -B hello
  26. -d force integer ; rax2 -d 3 -> 3 instead of 0x3
  27. -e swap endianness ; rax2 -e 0x33
  28. -D base64 decode ;
  29. -E base64 encode ;
  30. -f floating point ; rax2 -f 6.3+2.1
  31. -F stdin slurp code hex ; rax2 -F < shellcode.[c/py/js]
  32. -h help ; rax2 -h
  33. -i dump as C byte array ; rax2 -i < bytes
  34. -k keep base ; rax2 -k 33+3 -> 36
  35. -K randomart ; rax2 -K 0x34 1020304050
  36. -L bin -> hex(bignum) ; rax2 -L 111111111 # 0x1ff
  37. -n binary number ; rax2 -n 0x1234 # 34120000
  38. -N binary number ; rax2 -N 0x1234 # \x34\x12\x00\x00
  39. -r r2 style output ; rax2 -r 0x1234
  40. -s hexstr -> raw ; rax2 -s 43 4a 50
  41. -S raw -> hexstr ; rax2 -S < /bin/ls > ls.hex
  42. -t tstamp -> str ; rax2 -t 1234567890
  43. -x hash string ; rax2 -x linux osx
  44. -u units ; rax2 -u 389289238 # 317.0M
  45. -w signed word ; rax2 -w 16 0xffff
  46. -v version ; rax2 -v

Some examples:

  1. $ rax2 3+0x80
  2. 0x83
  1. $ rax2 0x80+3
  2. 131
  1. $ echo 0x80+3 | rax2
  2. 131
  1. $ rax2 -s 4142
  2. AB
  1. $ rax2 -S AB
  2. 4142
  1. $ rax2 -S < bin.foo
  2. ...
  1. $ rax2 -e 33
  2. 0x21000000
  1. $ rax2 -e 0x21000000
  2. 33
  1. $ rax2 -K 90203010
  2. +--[0x10302090]---+
  3. |Eo. . |
  4. | . . . . |
  5. | o |
  6. | . |
  7. | S |
  8. | |
  9. | |
  10. | |
  11. | |
  12. +-----------------+