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



The | operation (pipe) is similar to what you are used to expect from it in a *NIX shell: an output of one command as input to another.

[0x4A13B8C0]> f | grep section | grep text

0x0805f3b0 512 section._text

0x080d24b0 512 section._text_end

You can pass several commands in a single line by separating them with a semicolon ;:

> px ; dr

Using _, you can print the result that was obtained by the last command.

[0x00001060]> axt 0x00002004

main 0x1181 [DATA] lea rdi, str.argv__2d_:__s

[0x00001060]> _

main 0x1181 [DATA] lea rdi, str.argv__2d_:__s

To move around the file we are inspecting we will need to change the offset at which we are using the s command.

The argument is a math expression that can contain flag names, parenthesis, addition, substraction, multiplication of immediates of contents of memory using brackets.

Some example commands:

[0x00000000]> s 0x10

[0x00000010]> s+4

[0x00000014]> s-

[0x00000010]> s+

[0x00000014]>

Observe how the prompt offset changes. The first line moves the current offset to the address 0x10.

The second does a relative seek 4 bytes forward.

And finally, the last 2 commands are undoing, and redoing the last seek operations.

Instead of using just numbers, we can use complex expressions, or basic arithmetic operations to represent the address to seek.

To do this, check the ?$? Help message which describes the internal variables that can be used in the expressions. For example, this is the same as doing s+4 .

[0x00000000]> s $$+4

From the debugger (or when emulating) we can also use the register names as references. They are loaded as flags with the .dr* command, which happens under the hood.

[0x00000000]> s rsp+0x40

Here's the full help of the s command. We will explain in more detail below.

[0x00000000]> s?

Usage: s # Help for the seek commands. See ?$? to see all variables

| s Print current address

| s.hexoff Seek honoring a base from core->offset

| s:pad Print current address with N padded zeros (defaults to 8)

| s addr Seek to address

| s- Undo seek

| s-* Reset undo seek history

| s- n Seek n bytes backward

| s--[n] Seek blocksize bytes backward (/=n)

| s+ Redo seek

| s+ n Seek n bytes forward

| s++[n] Seek blocksize bytes forward (/=n)

| s[j*=!] List undo seek history (JSON, =list, *r2, !=names, s==)

| s/ DATA Search for next occurrence of 'DATA'