The original and proper dumps are needed to know how best to convert one to the other. Since it's frowned upon to distribute the real file, the editing is done this way to avoid copyright infringement.
You can use the man page of dd to get an understanding of what the if, of (input, output file), count (copy how many input blocks), conv (notrunc--do not truncate file), skip (skip # blocks from input file), seek (skip # blocks from output file) mean. The UNIX utility hexdump can be used to inspect the output file for every command to get a clear understanding of what it does.
$1 is the input file. $2 is the output, patched file.
Use the following simpler files to see what the commands are doing:
Code:
dd if=/dev/zero bs=16 count=256 of=ddout
tr '\000' '\377' <ddout >ddin
ddin will have all FFs; ddout will have all 00s
Code:
~
bash> hexdump -C ddin
00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
*
00001000
~
bash> hexdump -C ddout
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
Every time the dd command is run the program starts from the beginning of $1 and does something to $2 or if there is no $1, it takes input from the printf command, which prints out a bunch of hexadecimal values through the \x format string.
The first command creates a hex-zeroed 4K file from /dev/zero (read from /dev/zero and write 16 bytes each time, 256 times)
Then it reads and writes the first 192 bytes (16 bytes 12 times) from $1 to $2. Notice that hexdump appears to only show the first 16 bytes changed but the * that follows means the pattern is repeated until 000000bf and at 000000c0 the pattern changes to all 00s until the end of the file at 00001000. Use some method to convert hexadecimal to decimal.
Code:
~
bash> dd if=ddin bs=16 count=12 of=ddout conv=notrunc
12+0 records in
12+0 records out
192 bytes copied, 0.0058357 s, 32.9 kB/s
~
bash> hexdump -C ddout
00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
*
000000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00001000
Read and write 16 bytes 5 times (80 bytes) from $1 to $2, but get the values starting at 000000c0 (16 * 12 [skip]) from the input file and place in the output file starting at 000000e0 (16 * 14 [seek] = 224 = 0xe0). Here I've created a file with all 03s as input for some clarity.
Code:
~
bash> dd if=dd003 bs=16 count=5 of=ddout skip=12 seek=14 conv=notrunc
5+0 records in
5+0 records out
80 bytes copied, 0.0058606 s, 13.7 kB/s
~
bash> hexdump -C ddout
00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
*
000000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
000000e0 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 |................|
*
00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00001000
The rest just replaces bytes in output file using printf statements at the corresponding locations. I've replaced some values so it is easier to identify.
Code:
~
bash> printf "\x20" | dd of=ddout bs=1 seek=1 count=1 conv=notrunc
1+0 records in
1+0 records out
1 byte copied, 0.0003106 s, 3.2 kB/s
~
bash> hexdump -C ddout
00000000 ff 20 ff ff ff ff ff ff ff ff ff ff ff ff ff ff |. ..............|
00000010 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
*
000000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
000000e0 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 |................|
*
00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00001000
~
bash> printf "\x21" | dd of=ddout bs=1 seek=5 count=1 conv=notrunc
1+0 records in
1+0 records out
1 byte copied, 0.0003142 s, 3.2 kB/s
~
bash> hexdump -C ddout
00000000 ff 20 ff ff ff 21 ff ff ff ff ff ff ff ff ff ff |. ...!..........|
00000010 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
*
000000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
000000e0 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 |................|
*
00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00001000
~
bash> printf "\x05\x0E\x02\x14\x06\x16\x07" | dd of=ddout bs=1 seek=15 count=7 conv=notrunc
7+0 records in
7+0 records out
7 bytes copied, 0.0004122 s, 17.0 kB/s
~
bash> hexdump -C ddout
00000000 ff 20 ff ff ff 21 ff ff ff ff ff ff ff ff ff 05 |. ...!..........|
00000010 0e 02 14 06 16 07 ff ff ff ff ff ff ff ff ff ff |................|
00000020 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
*
000000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
000000e0 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 |................|
*
00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00001000
~
bash> printf "\xFE\x1A\x00\x03\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFE" | dd of=ddout bs=1 seek=192 count=32 conv=notrunc
32+0 records in
32+0 records out
32 bytes copied, 0.0007791 s, 41.1 kB/s
~
bash> hexdump -C ddout
00000000 ff 20 ff ff ff 21 ff ff ff ff ff ff ff ff ff 05 |. ...!..........|
00000010 0e 02 14 06 16 07 ff ff ff ff ff ff ff ff ff ff |................|
00000020 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
*
000000c0 fe 1a 00 03 05 00 00 00 00 00 00 00 00 00 00 00 |................|
000000d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fe |................|
000000e0 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 |................|
*
00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00001000
~
bash> printf "\xFD\x12\x00\x01\x06\x00\x00\x00\x00\x01\x00\x00\x02\x88\x04\x04\x02\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0A\x00\x01\x07\x00\x00\x00\x00\x02\x10\x00\x00\x00\x00\xFD" | dd of=ddout bs=1 seek=320 count=48 conv=notrunc
48+0 records in
48+0 records out
48 bytes copied, 0.0009937 s, 48.3 kB/s
~
bash> hexdump -C ddout
00000000 ff 20 ff ff ff 21 ff ff ff ff ff ff ff ff ff 05 |. ...!..........|
00000010 0e 02 14 06 16 07 ff ff ff ff ff ff ff ff ff ff |................|
00000020 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
*
000000c0 fe 1a 00 03 05 00 00 00 00 00 00 00 00 00 00 00 |................|
000000d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fe |................|
000000e0 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 |................|
*
00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000140 fd 12 00 01 06 00 00 00 00 01 00 00 02 88 04 04 |................|
00000150 02 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000160 00 0a 00 01 07 00 00 00 00 02 10 00 00 00 00 fd |................|
00000170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00001000
~
bash> printf "\x4D\x53\x58\x36\x30\x31\x32\x46\x2D\x32\x42\x46\x53\x00" | dd of=ddout bs=1 seek=64 count=14 conv=notrunc
14+0 records in
14+0 records out
14 bytes copied, 0.0005051 s, 27.7 kB/s
~
bash> hexdump -C ddout
00000000 ff 20 ff ff ff 21 ff ff ff ff ff ff ff ff ff 05 |. ...!..........|
00000010 0e 02 14 06 16 07 ff ff ff ff ff ff ff ff ff ff |................|
00000020 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
*
00000040 4d 53 58 36 30 31 32 46 2d 32 42 46 53 00 ff ff |MSX6012F-2BFS...|
00000050 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
*
000000c0 fe 1a 00 03 05 00 00 00 00 00 00 00 00 00 00 00 |................|
000000d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fe |................|
000000e0 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 |................|
*
00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000140 fd 12 00 01 06 00 00 00 00 01 00 00 02 88 04 04 |................|
00000150 02 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000160 00 0a 00 01 07 00 00 00 00 02 10 00 00 00 00 fd |................|
00000170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00001000