
別のバイナリ内のバイナリを所定の位置に置き換えることはできますか?たとえば、圧縮されたファームウェア.binファイルには次のものが含まれます。
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
392 0x188 uImage header, header size: 64 bytes, header CRC: 0x15075729, created: 1969-12-31 23:59:59, image size: 1572736 bytes, Data Address: 0x20008000, Entry Point: 0x20008000, data CRC: 0x1DCD72E0, OS: Linux, CPU: ARM, image type: OS Kernel Image, compression type: none, image name: "abcd_rom_bin"
13596 0x351C gzip compressed data, maximum compression, from Unix, last modified: 2017-08-02 06:04:47
1573192 0x180148 uImage header, header size: 64 bytes, header CRC: 0x6FFB9B98, created: 1969-12-31 23:59:59, image size: 8376320 bytes, Data Address: 0x0, Entry Point: 0x0, data CRC: 0xC95886CF, OS: Linux, CPU: ARM, image type: Filesystem Image, compression type: none, image name: "abcd_rom_bin"
1573256 0x180188 Squashfs filesystem, little endian, non-standard signature, version 3.1, size: 8372772 bytes, 1028 inodes, blocksize: 131072 bytes, created: 2017-08-02 06:39:51
これらのバイナリの1つには、busyboxバイナリも含まれています。完全に解凍せずに交換する方法はありますか?
答え1
file.gz
オフセット13596に何かを書きたい場合firmware.bin
(すでに存在するものを上書きする)、次のようにすることができます。
zsh
:
zmodload zsh/system
{ sysseek -u1 13596 && cat; } < file.gz 1<> firmware.bin
ksh93
:
cat < file.gz 1<> firmware.bin >#((13596))
dd
、すべてのシェル、しかし一度に1バイトずつ読み書きします。
dd conv=notrunc bs=1 seek=13596 if=file.gz of=firmware.bin
GNU dd
、すべてのシェル、より効率的
dd bs=64k conv=notrunc oflag=seek_bytes seek=13596 if=file.gz of=firmware.bin
または、1573192 - 13596の長さまでゼロで埋めます(算術拡張のためのPOSIX sh構文)。
dd bs=64k conv=notrunc,sync bs="$((1573192 - 13596))" count=1 \
oflag=seek_bytes seek=13596 if=file.gz of=firmware.bin
これで、すでに持っているpedファイルと同じ大きさでなけれfile.gz
ばなりません。gzip
もしそうならヘッダーチェックサムのさまざまな部分が含まれているため、チェックサムも計算して更新する必要があります。