RZ_AX(1)

NAME
rz-ax - rizin base converter

SYNOPSIS
rz-ax [-abBdDeEfFhHiIklLmnNopqrsStuvwWx] [expr ...]

DESCRIPTION
This command is part of the Rizin project.

This command allows you to convert values between positive and negative integer, float, octal, binary, ternary, and hexadecimal values. It also evaluates arithmetic expressions written in the RzNum expression language - the same one used throughout Rizin - with operators, fixed-width bit-vectors, arbitrary-precision big numbers, and built-in functions.

OPTIONS

-a  Show ASCII table

-b  Convert from binary to string (rz-ax -b 01000101 01110110)

-B  Convert from string to binary (rz-ax -B hello)

-d  Force output as integer (rz-ax -d 3 outputs 3 instead of 0x3)

-D  Base64 decode

-e  Swap endianness (rz-ax -e 0x33)

-E  Base64 encode

-f  Floating point arithmetic (rz-ax -f 6.3+2.1)

-F  Read C strings from stdin and output in hexpairs. Useful to load shellcodes (rz-ax -F < shellcode.[c/py/js])

-h  Show the short help: the usage line and the option list

-H  Show the long help: everything in -h plus the conversion table, expression examples, the operator list and the literal forms

-i  Dump stdin to C array in stdout (rz-ax -i < bytes)

-I  Convert LONG to/from IP ADDRESS (rz-ax -I 3530468537)

-k  Keep the same base as the input data (rz-ax -k 33+3 -> 36)

-l  Append newline to the decoded output

-L  Convert binary to hexadecimal (rz-ax -L 111111111 outputs 0x1ff)

-n  Show hexpairs from integer value (rz-ax -n 0x1234 # 34120000)

-N  Show hex C string from integer value (rz-ax -N 0x1234 # \x34\x12\x00\x00)

-o  Convert from octal string to char (rz-ax -o \162 \172 # rz)

-r  Rz style output (rz-ax -r 0x1234)

-s  Convert from hex string to character (rz-ax -s 43 4a 50)

-S  Convert from character to hex string (rz-ax -S < /bin/ls > ls.hex)

-t  Convert Unix timestamp to string (rz-ax -t 1234567890)

-m  Convert MS-DOS timestamp to string (rz-ax -m 0x12345678)

-W  Convert Win32 timestamp to string (rz-ax -W 1234567890)

-u  Convert given value to human readable units format (rz-ax -u 389289238 # 371.3M)

-v  Show version information

-w  Convert signed word (rz-ax -w 16 0xffff)

-x  Convert a string into a hash (rz-ax -x linux osx)

-p  Show position of set bits in the binary representation (rz-ax -p 0xb3)

OUTPUT BASE
By default a bare literal written in a non-decimal base prints as decimal and everything else - decimal literals and every compound expression - prints as hexadecimal.

$ rz-ax 3 0x3 $ rz-ax 0x12121212 303174162 $ rz-ax 0b1010 10 $ rz-ax 0x3+0b11+3 0x9

Prefix an argument with = to force the output base for the arguments that follow it:

=2 binary =3 ternary =8 octal =10 decimal =16 hexadecimal

-d forces base 10 and -k keeps the input base.

CONVERSIONS
int -> hex rz-ax 10 hex -> int rz-ax 0xa -int -> hex rz-ax -77 -hex -> int rz-ax 0xffffffb3 int -> bin rz-ax b30 int -> ternary rz-ax t42 int -> oct rz-ax Ox12 (O is a letter) bin -> int rz-ax 0b1010 oct -> int rz-ax 0o17 ternary -> int rz-ax 0t212 float -> hex rz-ax 3.33f hex -> float rz-ax Fx40551ed8 hex -> bin rz-ax Bx63 hex -> ternary rz-ax Tx23 raw -> hex rz-ax -S < /binfile hex -> raw rz-ax -s 414141

The trailing base suffixes (101b, 35o, 212t) are deprecated in favour of the 0b, 0o and 0t prefixes; rz-ax still accepts them but prints a warning.

EXPRESSION SYNTAX
Arguments are evaluated in the RzNum expression language, the same one used by the rizin % command and by every command argument that takes a number. Quote an expression containing spaces so it stays a single argument; otherwise each argument is converted on its own.

$ rz-ax '3 * (10 + 2)' 0x24 $ rz-ax 10 0x20 0xa 32

  Operators
Listed from highest to lowest precedence; the precedence matches C.

** power (2**10); note ^ is XOR, not power * / % multiply, divide, modulo sdiv smod signed divide, signed modulo + - add, subtract (unary - negates) << >> logical shift left, right sar arithmetic (sign-extending) shift right <<< >>> rotate left, right & | ^ ~ and, or, xor, not < <= > >= == != comparisons, yielding 0 or 1 ?: ternary (cond ? a : b) ; sequence; the value is that of the last expression

  Literals
0x1f hexadecimal 0o17 octal 0t212 ternary 0b1010 binary 017 C style octal (a leading zero before a digit) 3.5 1e3 0x1.8p3 floating point, including hex floats 4KiB 2MB size units: KiB MiB GiB TiB PiB EiB and KB MB GB TB PB EB "AB" a string, taken as its bytes

  Bit-vectors
A u suffix followed by a bit count makes a fixed-width bit-vector, which is printed with its width and bit pattern instead of as a plain number. Any width from 1 to 65536 is accepted.

$ rz-ax 8u7 hex 0x08 binary 0b0001000 width 7 bits $ rz-ax 5u8+3u8 hex 0x08 binary 0b00001000 width 8 bits

  Big numbers
A result that does not fit in 64 bits is promoted to an arbitrary-precision integer automatically; no suffix is needed.

$ rz-ax 2**64 decimal 18446744073709551616

  Functions
abs ceil clz ctz floor gcd len ln log log10 log2 max min popcount round sqrt

$ rz-ax 'gcd(12,18)' 0x6 $ rz-ax 'popcount(0xff)' 0x8

  Variables
An assignment binds a name for the rest of the expression.

$ rz-ax 'x=7;x*x' 0x31

  Typed address dereference
When a host supplies an IO backend - inside rizin, not in standalone - a numeric address followed by a colon and a width reads memory at that address:

0x1234:le32 little-endian unsigned 32-bit 0xDEADBEEF:be64 big-endian unsigned 64-bit 0x1000:8 native-endian unsigned 8-bit 0x1000:s32 native-endian signed 32-bit 0x1000:lef32 little-endian 32-bit float 0x1000:f16 native-endian half-precision float

The width is one of 8, 16, 32, 64 or 128 for integer reads and 16, 32 or 64 for float reads; le or be selects the endianness and s marks a signed read.

STANDARD INPUT
With no argument, rz-ax reads one expression per line from standard input.

$ printf '33x41 | rz-ax 0x21 65

EXIT STATUS
rz-ax exits 0 when every argument was converted, and 1 when any of them failed to parse or evaluate. A diagnostic naming the failure is printed on standard error.

$ rz-ax 'nosuchthing' rz-ax: cannot resolve 'nosuchthing' $ echo $? 1

EXAMPLES
Unpack a hexpair encoded string:

$ rz-ax -s 41 42 43 ABC

Get the byte encoding of a value:

$ rz-ax -N 0x1234 \x34\x12\x00\x00

Find which bits are set:

$ rz-ax -p 0xb3 [0-1]: 1 [4-5]: 1 [7]: 1

Convert a value to human readable units:

$ rz-ax -u 389289238 371.3M

SEE ALSO
rizin(1), rz-asm(1), rz-bin(1), rz-diff(1), rz-find(1), rz-gg(1), rz-hash(1), rz-run(1), rz-sign(1)

AUTHORS
pancake <pancake@nopcode.org>

byteninjaa0