вторник, 28 апреля 2015 г.

Pad file with zeroes (or 0xFF)


So you need to add zeroes (or 0xFF) to the end of file and make resulting file be exact size.
For example, we will make 128kb file from 84kb file with 0xFF at the end.

So basically we open special device /dev/zero and getting zeroes from it. Then we change every 0x00 to 0xFF(tr). then we create 128k size file full of 0xFF(first dd invocation). Then we use dd again to replace beginning of file with our own file - breed-mt7620-reset1.bin. Then just rename our padded file to correct name. Pretty simple.
$ tr "00" "\377" < /dev/zero | dd ibs=1k count=128 of=paddedFile.bin
128+0 records in
256+0 records out
131072 bytes transferred in 0.020307 secs (6454503 bytes/sec)
$ dd if=breed-mt7620-reset1.bin of=paddedFile.bin conv=notrunc
163+1 records in
163+1 records out
83566 bytes transferred in 0.004907 secs (17029502 bytes/sec)
$ mv paddedFile.bin breed-mt7620-reset1_128k.bin
$

Комментариев нет:

Отправить комментарий