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



0xff, 0xff, 0x5a, 0x8d, 0x24, 0x84, 0x29, 0xc2 };

That cstring can be used in many programming languages, not just C.

[0x7fcd6a891630]>

pcs

"\x48\x89\xe7\xe8\x68\x39\x00\x00\x49\x89\xc4\x8b\x05\xef\x16\x22\x00\x5a\x48\x8d\x24\xc4\x29\xc2\x52\x48\x89\xd6\x49\x89\xe5\x48\x83\xe4\xf0\x48\x8b\x3d\x06\x1a

Strings are probably one of the most important entry points when starting to reverse engineer a program because they usually reference information about functions' actions (asserts, debug or info messages...). Therefore, radare supports various string formats:

[0x00000000]> ps?

|Usage: ps[bijqpsuwWxz+] [N] Print String

| ps print string

| ps+[j] print libc++ std::string (same-endian, ascii, zero-terminated)

| psb print strings in current block

| psi print string inside curseek

| psj print string in JSON format

| psp[j] print pascal string

| psq alias for pqs

| pss print string in screen (wrap width)

| psu[zj] print utf16 unicode (json)

| psw[j] print 16bit wide string

| psW[j] print 32bit wide string

| psx show string with escaped chars

| psz[j] print zero-terminated string

Most strings are zero-terminated. Below there is an example using the debugger to continue the execution of a program until it executes the 'open' syscall. When we recover the control over the process, we get the arguments passed to the syscall, pointed by %ebx. In the case of the 'open' call, it is a zero terminated string which we can inspect using psz.

[0x4A13B8C0]> dcs open

0x4a14fc24 syscall(5) open ( 0x4a151c91 0x00000000 0x00000000 ) = 0xffffffda

[0x4A13B8C0]> dr

eax 0xffffffda esi 0xffffffff eip 0x4a14fc24

ebx 0x4a151c91 edi 0x4a151be1 oeax 0x00000005

ecx 0x00000000 esp 0xbfbedb1c eflags 0x200246

edx 0x00000000 ebp 0xbfbedbb0 cPaZstIdor0 (PZI)

[0x4A13B8C0]>

[0x4A13B8C0]> psz @ 0x4a151c91

/etc/ld.so.cache

It is also possible to print various packed data types using the pf command:

[0xB7F08810]> pf xxS @ rsp

0x7fff0d29da30 = 0x00000001

0x7fff0d29da34 = 0x00000000

0x7fff0d29da38 = 0x7fff0d29da38 -> 0x0d29f7ee /bin/ls

This can be used to look at the arguments passed to a function. To achieve this, simply pass a 'format memory string' as an argument to pf, and temporally change the current seek position/offset using @. It is also possible to define arrays of structures with pf. To do this, prefix the format string with a numeric value. You can also define a name for each field of the structure by appending them as a space-separated arguments list.