Reputation: 5055
I have a binary file and i want to replace the value A2
at address DEADBEEF
with some other value, say A1
.
How can I do this with dd
? If there are other tools that can do this, please suggest. But I plan to do this on iPhone so I can only work with most basic Unix tools.
Upvotes: 31
Views: 25365
Reputation: 635
(Same answer, but doesn't fit into a comment:)
I wanted to preview the file content before applying the patch I wanted; dd
uses different sets of arguments for input and output files, so remember to use if
and 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 |[email protected]..@.|
0000000c
And a multi-byte patch (dd
will just overwrite with whatever stdin gives it, so no need to specify length):
% 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
Upvotes: 1
Reputation: 223213
printf '\xa1' | dd of=somefile bs=1 seek=$((0xdeadbeef)) conv=notrunc
Upvotes: 52