The Official Radare2 Book — страница 21 из 64

You can use Visual Mode to assemble code using A. For example let's replace the push by a jmp:

Notice the preview of the disassembly and arrows:

You need to open the file in writing mode (r2 -w or oo+) in order to patch the file. You can also use the cache mode: e io.cache = true and wc?.

Remember that patching files in debug mode only patch the memory not the file.

Visual Configuration Editor

Ve or e in visual mode allows you to edit radare2 configuration visually. For example, if you want to change the assembly display just select asm in the list and choose your assembly display flavor.

Example switch to pseudo disassembly:

Visual Panels

Concept

Visual Panels is characterized by the following core functionalities:

   1. Split Screen

   2. Display multiple screens such as Symbols, Registers, Stack, as well as custom panels

   3. Menu will cover all those commonly used commands for you so that you don't have to memorize any of them

CUI met some useful GUI as the menu, that is Visual Panels.

Panels can be accessed by using v or by using ! from the visual mode.

Overview

Commands

|Visual Ascii Art Panels:

| | split the current panel vertically

| - split the current panel horizontally

| : run r2 command in prompt

| ; add/remove comment

| _ start the hud input mode

| \ show the user-friendly hud

| ? show this help

| ! run r2048 game

| . seek to PC or entrypoint

| * show decompiler in the current panel

| " create a panel from the list and replace the current one

| / highlight the keyword

| ( toggle snow

| & toggle cache

| [1-9] follow jmp/call identified by shortcut (like ;[1])

| ' ' (space) toggle graph / panels

| tab go to the next panel

| Enter start Zoom mode

| a toggle auto update for decompiler

| b browse symbols, flags, configurations, classes, ...

| c toggle cursor

| C toggle color

| d define in the current address. Same as Vd

| D show disassembly in the current panel

| e change title and command of current panel

| f set/add filter keywords

| F remove all the filters

| g go/seek to given offset

| G go/seek to highlight

| i insert hex

| hjkl move around (left-down-up-right)

| HJKL move around (left-down-up-right) by page

| m select the menu panel

| M open new custom frame

| n/N seek next/prev function/flag/hit (scr.nkey)

| p/P rotate panel layout

| q quit, or close a tab

| Q close all the tabs and quit

| r toggle callhints/jmphints/leahints

| R randomize color palette (ecr)

| s/S step in / step over

| t/T tab prompt / close a tab

| u/U undo / redo seek

| w start Window mode

| V go to the graph mode

| xX show xrefs/refs of current function from/to data/code

| z swap current panel with the first one

Basic Usage

Use tab to move around the panels until you get to the targeted panel. Then, use hjkl, just like in vim, to scroll the panel you are currently on. Use S and s to step over/in, and all the panels should be updated dynamically while you are debugging. Either in the Registers or Stack panels, you can edit the values by inserting hex. This will be explained later. While hitting tab can help you moving between panels, it is highly recommended to use m to open the menu. As usual, you can use hjkl to move around the menu and will find tons of useful stuff there. You can also press " to quickly browse through the different options View offers and change the contents of the selected panel.

Split Screen

| is for the vertical and - is for the horizontal split. You can delete any panel by pressing X.

Split panels can be resized from Window Mode, which is accessed with w.

Window Mode Commands

|Panels Window mode help:

| ? show this help

| ?? show the user-friendly hud

| Enter start Zoom mode

| c toggle cursor

| hjkl move around (left-down-up-right)

| JK resize panels vertically

| HL resize panels horizontally

| q quit Window mode

Edit Values

Either in the Register or Stack panel, you can edit the values. Use c to activate cursor mode and you can move the cursor by pressing hjkl, as usual. Then, hit i, just like the insert mode of vim, to insert a value.

Tabs

Visual Panels also offer tabs to quickly access multiple forms of information easily. Press t to enter Tab Mode. All the tabs numbers will be visible in the top right corner.

By default you will have one tab and you can press t to create a new tab with the same panels and T to create a new panel from scratch.

For traversing through the tabs, you can type in the tab number while in Tab Mode.

And pressing - deletes the tab you are in.

Saving layouts

You can save your custom layout of your visual panels either by picking the option 'Save Layout' from the File menu of the menu bar or by running:

v= test

Where test is the name with which you'd like to save it.

You can open a saved layout by passing the name as the parameter to v:

v test

More about that can be found under v?.

Searching for Bytes

The radare2 search engine is based on work done by esteve, plus multiple features implemented on top of it. It supports multiple keyword searches, binary masks, and hexadecimal values. It automatically creates flags for search hit locations ease future referencing.

Search is initiated by / command.

[0x00000000]> /?

|Usage: /[!bf] [arg]Search stuff (see 'e??search' for options)

|Use io.va for searching in non virtual addressing spaces

| / foo\x00 search for string 'foo\0'

| /j foo\x00 search for string 'foo\0' (json output)

| /! ff search for first occurrence not matching, command modifier

| /!x 00 inverse hexa search (find first byte != 0x00)

| /+ /bin/sh construct the string with chunks

| // repeat last search

| /a jmp eax assemble opcode and search its bytes

| /A jmp find analyzed instructions of this type (/A? for help)

| /b search backwards, command modifier, followed by other command

| /B search recognized RBin headers

| /c jmp [esp] search for asm code matching the given string

| /ce rsp,rbp search for esil expressions matching

| /C[ar] search for crypto materials

| /d 101112 search for a deltified sequence of bytes

| /e /E.F/i match regular expression

| /E esil-expr offset matching given esil expressions %%= here

| /f search forwards, command modifier, followed by other command

| /F file [off] [sz] search contents of file with offset and size

| /g[g] [from] find all graph paths A to B (/gg follow jumps, see search.count and

anal.depth)

| /h[t] [hash] [len] find block matching this hash. See ph

| /i foo search for string 'foo' ignoring case

| /m magicfile search for matching magic file (use blocksize)

| /M search for known filesystems and mount them automatically

| /o [n] show offset of n instructions backward

| /O [n] same as /o, but with a different fallback if anal cannot be used

| /p patternsize search for pattern of given size

| /P patternsize search similar blocks

| /r[erwx][?] sym.printf analyze opcode reference an offset (/re for esil)

| /R [grepopcode] search for matching ROP gadgets, semicolon-separated

| /s search for all syscalls in a region (EXPERIMENTAL)

| /v[1248] value look for an `cfg.bigendian` 32bit value

| /V[1248] min max look for an `cfg.bigendian` 32bit value in range

| /w foo search for wide string 'f\0o\0o\0'

| /wi foo search for wide string ignoring case 'f\0o\0o\0'

| /x ff..33 search for hex string ignoring some nibbles

| /x ff0033 search for hex string

| /x ff43:ffd0 search for hexpair with mask