The Official Radare2 Book | страница 12



-u set bin.filter=false to get raw sym/sec/cls names

-v, -V show radare2 version (-V show lib versions)

-w open file in write mode

-x open without exec-flag (asm.emu will not work), See io.exec

-X same as -e bin.usextr=false (useful for dyldcache)

-z, -zz do not load strings or load them even in raw

Open a file in write mode without parsing the file format headers.

$ r2 -nw file

Quickly get into an r2 shell without opening any file.

$ r2 -

Specify which sub-binary you want to select when opening a fatbin file:

$ r2 -a ppc -b 32 ls.fat

Run a script before showing interactive command-line prompt:

$ r2 -i patch.r2 target.bin

Execute a command and quit without entering the interactive mode:

$ r2 -qc ij hi.bin > imports.json

Set the configuration variable:

$ r2 -e scr.color=0 blah.bin

Debug a program:

$ r2 -d ls

Use an existing project file:

$ r2 -p test

A general format for radare2 commands is as follows:

[.][times][cmd][~grep][@[@iter]addr!size][|>pipe] ;

People who use Vim daily and are familiar with its commands will find themselves at home. You will see this format used throughout the book. Commands are identified by a single case-sensitive character [a-zA-Z].

To repeatedly execute a command, prefix the command with a number:

px # run px

3px # run px 3 times

The ! prefix is used to execute a command in shell context. If you want to use the cmd callback from the I/O plugin you must prefix with =!.

Note that a single exclamation mark will run the command and print the output through the RCons API. This means that the execution will be blocking and not interactive. Use double exclamation marks -- !! -- to run a standard system call.

All the socket, filesystem and execution APIs can be restricted with the cfg.sandbox configuration variable.

A few examples:

ds ; call the debugger's 'step' command

px 200 @ esp ; show 200 hex bytes at esp

pc > file.c ; dump buffer as a C byte array to file.c

wx 90 @@ sym.* ; write a nop on every symbol

pd 2000 | grep eax ; grep opcodes that use the 'eax' register

px 20 ; pd 3 ; px 40 ; multiple commands in a single line

The standard UNIX pipe | is also available in the radare2 shell. You can use it to filter the output of an r2 command with any shell program that reads from stdin, such as grep, less, wc. If you do not want to spawn anything, or you can't, or the target system does not have the basic UNIX tools you need (Windows or embedded users), you can also use the built-in grep (~).