我有一个二进制文件,想要替换地址为DEADBEEF
处的值A2
为另一个值A1
。
我该如何使用dd
命令进行操作?如果有其他工具可以实现此功能,请给出建议。但我计划在iPhone上进行操作,因此只能使用最基本的Unix工具。
printf '\xa1' | dd of=somefile bs=1 seek=$((0xdeadbeef)) conv=notrunc
dd
在输入和输出文件上使用不同的参数集,所以记得使用if
和iseek
:% dd if=somefile bs=1 iseek=4488884 count=12 conv=notrunc | hexdump -C
12+0 records in
12+0 records out
12 bytes copied, 0.000131 s, 91.6 kB/s
00000000 1f 04 00 71 40 02 00 54 a1 02 40 f9 |...q@..T..@.|
0000000c
dd
将会用stdin提供的任何内容进行覆盖,所以不需要指定长度):% printf '\x40\x02\x00\x54' | dd of=somefile bs=1 seek=4488888 conv=notrunc
4+0 records in
4+0 records out
4 bytes copied, 0.000251 s, 15.9 kB/s
somefile
文件最终被截断了。 - gromainconv=notrunc
在命令的末尾时它可以工作。printf '\xa1' | dd of=somefile bs=1 seek=$((0xdeadbeef)) conv=notrunc
- gromain