我有一个包含 Linux 映像的 CPIO 档案。binwalk
我可以看到有以下块:
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
0 0x0 ASCII cpio archive (SVR4 with no CRC), file name: "kernel", file name length: "0x00000007", file size: "0x00000000"
120 0x78 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86", file name length: "0x0000000B", file size: "0x00000000"
244 0xF4 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86/microcode", file name length: "0x00000015", file size: "0x00000000"
376 0x178 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86/microcode/.enuineIntel.align.0123456789abc", file name length: "0x00000036", file size: "0x00000000"
540 0x21C ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86/microcode/GenuineIntel.bin", file name length: "0x00000026", file size: "0x001A3800"
1718960 0x1A3AB0 ASCII cpio archive (SVR4 with no CRC), file name: "TRAILER!!!", file name length: "0x0000000B", file size: "0x00000000"
1719296 0x1A3C00 gzip compressed data, NULL date (1970-01-01 00:00:00)
32277012 0x1EC8214 Zlib compressed data, default compression
70217888 0x42F70A0 Unix path: /usr/local/go/src/runtime/runtime-gdb.py
85577309 0x519CE5D MySQL MISAM compressed data file Version 3
96044561 0x5B98611 Unix path: /usr/local/go/src/runtime/runtime-gdb.py
100702073 0x6009779 Zlib compressed data, default compression
106454594 0x6585E42 MySQL MISAM compressed data file Version 7
110250207 0x69248DF Unix path: /usr/local/go/src/runtime/runtime-gdb.py
115809787 0x6E71DFB Unix path: /usr/local/go/src/runtime/runtime-gdb.py
我需要提取gzip压缩包:
1719296 0x1A3C00 gzip compressed data, NULL date (1970-01-01 00:00:00)
并替换其中的单个二进制文件,然后重新打包图像。
该 gzip 压缩内容是另一个 CPIO 图像。
做到这一点的最好/最简单的方法是什么?
答案1
这个问题的另一个答案是不完整的,因为它只描述了如何从 cpio 档案中提取单个文件。
在我看来,cpio 档案无法就地修改,因此您必须提取然后创建一个新的档案:
mkdir tmp && pushd tmp
cpio -idm < ../archive.cpio
find . | cpio -o > ../archive-new.cpio
popd && rm -Rf tmp
如果您关心文件所有权,您可能希望以 root 身份运行这些命令。
由于您正在使用,binwalk
您可能对档案文件格式如果您确实想进行手术替换而不干扰其他条目。
这个问题最好放在Unix 和 Linux StackExchange。