输出模式
radare2的一个核心功能就是以不同的格式显示分析的信息,目的在于以最好的方式展示二进制数据。
二进制数据可以以integer,short,long,float,timestamp,hexpair string, 或借助外部处理, 以更复杂的形式如C struct,反汇编,反编译表示...
下面是 p? 列出的所有输出模式:
[0x00005310]> p?
|Usage: p[=68abcdDfiImrstuxz] [arg|len] [@addr]
| p[b|B|xb] [len] ([S]) bindump N bits skipping S bytes
| p[iI][df] [len] print N ops/bytes (f=func) (see pi? and pdi)
| p[kK] [len] print key in randomart (K is for mosaic)
| p-[?][jh] [mode] bar|json|histogram blocks (mode: e?search.in)
| p2 [len] 8x8 2bpp-tiles
| p3 [file] print stereogram (3D)
| p6[de] [len] base64 decode/encode
| p8[?][j] [len] 8bit hexpair list of bytes
| p=[?][bep] [N] [L] [b] show entropy/printable chars/chars bars
| pa[edD] [arg] pa:assemble pa[dD]:disasm or pae: esil from hex
| pA[n_ops] show n_ops address and type
| pb[?] [n] bitstream of N bits
| pB[?] [n] bitstream of N bytes
| pc[?][p] [len] output C (or python) format
| pC[aAcdDxw] [rows] print disassembly in columns (see hex.cols and pdi)
| pd[?] [sz] [a] [b] disassemble N opcodes (pd) or N bytes (pD)
| pf[?][.nam] [fmt] print formatted data (pf.name, pf.name $<expr>)
| pF[?][apx] print asn1, pkcs7 or x509
| pg[?][x y w h] [cmd] create new visual gadget or print it (see pg? for details)
| ph[?][=|hash] ([len]) calculate hash for a block
| pj[?] [len] print as indented JSON
| pm[?] [magic] print libmagic data (see pm? and /m?)
| po[?] hex print operation applied to block (see po?)
| pp[?][sz] [len] print patterns, see pp? for more help
| pq[?][is] [len] print QR code with the first Nbytes
| pr[?][glx] [len] print N raw bytes (in lines or hexblocks, 'g'unzip)
| ps[?][pwz] [len] print pascal/wide/zero-terminated strings
| pt[?][dn] [len] print different timestamps
| pu[?][w] [len] print N url encoded bytes (w=wide)
| pv[?][jh] [mode] show variable/pointer/value in memory
| pwd display current working directory
| px[?][owq] [len] hexdump of N bytes (o=octal, w=32bit, q=64bit)
| pz[?] [len] print zoom view (see pz? for help)
[0x00005310]>Tips:当使用json格式作为输出格式时,可以在命令后面加上~{}将结果以更易读的形式输出:
有关~的神奇之处参见?@?输出的帮助信息,以及前面命令格式章节的内容。
Hexadecimal View
px gives a user-friendly output showing 16 pairs of numbers per row with offsets and raw representations:

Show Hexadecimal Words Dump (32 bits)

8 bits Hexpair List of Bytes
Show Hexadecimal Quad-words Dump (64 bits)

Date/Time Formats
Currently supported timestamp output modes are:
For example, you can 'view' the current buffer as timestamps in the ntfs time:
As you can see, the endianness affects the result. Once you have printed a timestamp, you can grep the output, for example, by year:
The default date format can be configured using the cfg.datefmt variable. Formatting rules for it follow the well known strftime(3) format. Check the manpage for more details, but these are the most important:
基本类型
这里有对应各种基本类型的输出模式,如果想使用更复杂的结构,查看pf??中关于格式化字符的帮助信息,以及pf???获取示例:
pf???可以获得使用格式化字符串的示例。
底下是一些例子:
高级语言视图
支持的语言及其对应的输出模式:
pcCpc*print 'wx' r2 commandspchC half-words (2 byte)pcwC words (4 byte)pcdC dwords (8 byte)pciC array of bytes with instructionspcaGAS .byte blobpcA.bytes with instructions in commentspcsstringpcSshellscript that reconstructs the binpcjjsonpcJjavascriptpcoObjective-CpcppythonpckkotlinpcrrustpcvJaVapcVV (vlang.io)pcyyarapczSwift
如果要创建一个包含二进制Blob的.c文件, 可以用pc命令。其默认大小与许多其他命令一样,同块大小保持一致,可以使用b命令更改。
还可以通过传递一个参数临时修改块的大小:
c风格字符串可以用于各种语言中,不局限于C。
Strings
字符串可能是逆向程序时最重要的突破口之一,因其通常会引用与函数执行操作相关的信息(例如assert,debug或者info messages...)。因此radare支持多种字符串格式:
大多数字符串是以NUL结尾的(zero-terminated),下面是一个用debugger执行至'open'系统调用的例子。当我们复现该过程时,我们可以获得传给系统调用的参数,%ebx中存储着指向该参数的指针。在此'open'调用的例子中,由于该参数字符串以NUL结尾,我们能够用psz检查它。
输出内存中的内容
使用pf命令能输出多种经压缩的数据类型:
这可以用来查看传递给函数的参数。为此,只需将“格式存储字符串”作为参数传递给pf,然后使用@临时更改当前搜索位置/偏移。也可以用pf命令,在格式字符串前面加上一个数字定义结构体数组。还可以通过附加空格分隔的参数列表来为结构的每个字段定义名称。
对二进制文件上使用GStreamer插件的pf一个实际示例:
Disassembly
pd用于反汇编代码,可以接受一个数字参数,指定反汇编多少条指令。pD命令相似但有一点不同,其参数代表解码多少字节。
d: disassembly N opcodes count of opcodesD: asm.arch disassembler bsize bytes
目标架构
反汇编程序的体系结构风格由asm.archeval变量定义,可以用e asm.arch = ??列出所有可用的体系结构。
配置反汇编器
有多个选项可用于配置反汇编程序的输出,所有这些选项都在e? asm.中。
注意asm.有136个配置变量,所以没有全部列出。
反汇编语法
asm.syntax变量用于更改反汇编程序引擎使用的汇编语法的样式,若要在Intel和AT&T表示法之间切换:
可以看看asm.pseudo,其是一个实验性质的伪代码视图。
asm.esil 可以输出 ESIL ('Evaluable Strings Intermediate Language'). ESIL的设计目的使每个操作码语义都具有人类可读的表示形式,然后可用此类表示形式模仿单个指令的效果。
最后更新于
这有帮助吗?