写入数据

Radare可以通过多种方式处理已加载的二进制文件。您可以调整文件大小,移动和复制/粘贴字节,插入新字节(将数据移至块或文件的末尾),或覆盖字节。新数据可以是宽字符串、汇编程序指令, 也可以是从另一个文件中读取的数据。

使用r命令调整文件大小。它接受数字作为参数。若为正数则为文件设置新的大小, 为负数则将文件截断至当前位置往前N个字节的位置。

r 1024      ; resize the file to 1024 bytes
r -10 @ 33  ; strip 10 bytes at offset 33

使用w命令写入字节,该命令接受多种输入格式, 例如内联汇编、字节序友好型dword, 文件, 十六进制文件, 宽字符串。

[0x00404888]> w?
Usage: w[x] [str] [<file] [<<EOF] [@addr]  
| w[1248][+-][n]       increment/decrement byte,word..
| w foobar             write string 'foobar'
| w0 [len]             write 'len' bytes with value 0x00
| w6[de] base64/hex    write base64 [d]ecoded or [e]ncoded string
| wa[?] push ebp       write opcode, separated by ';' (use '"' around the command)
| waf f.asm            assemble file and write bytes
| waF f.asm            assemble file and write bytes and show 'wx' op with hexpair bytes of assembled code
| wao[?] op            modify opcode (change conditional of jump. nop, etc)
| wA[?] r 0            alter/modify opcode at current seek (see wA?)
| wb 010203            fill current block with cyclic hexpairs
| wB[-]0xVALUE         set or unset bits with given value
| wc                   list all write changes
| wc[?][jir+-*?]       write cache undo/commit/reset/list (io.cache)
| wd [off] [n]         duplicate N bytes from offset at current seek (memcpy) (see y?)
| we[?] [nNsxX] [arg]  extend write operations (insert instead of replace)
| wf[fs] -|file        write contents of file at current offset
| wh r2                whereis/which shell command
| wm f0ff              set binary mask hexpair to be used as cyclic write mask
| wo[?] hex            write in block with operation. 'wo?' fmi
| wp[?] -|file         apply radare patch file. See wp? fmi
| wr 10                write 10 random bytes
| ws pstring           write 1 byte for length and then the string
| wt[f][?] file [sz]   write to file (from current seek, blocksize or sz bytes)
| wts host:port [sz]   send data to remote host:port via tcp://
| ww foobar            write wide string 'f\x00o\x00o\x00b\x00a\x00r\x00'
| wx[?][fs] 9090       write two intel nops (from wxfile or wxseek)
| wv[?] eip+34         write 32-64 bit value honoring cfg.bigendian
| wz string            write zero terminated string (like w + \x00)

一些示例:

改写

wo命令有多个子命令, 每个子命令都使用算符将现有数据与新数据结合起来,该命令将作用于当前块上。目前支持的算符有XOR,ADD,SUB...

可以用radare2核心原语以及wo实现加密算法,下面这个例子展示了xor(90) + add(01,02)这种加密算法的操作。

最后更新于

这有帮助吗?