下载工具split_bootimg.pl :
此脚本在github很多,如gist.github.com/amartinz/84c7ebc64f126bd6b3a8
用split_bootimg.pl解包boot.img
命令:split_bootimg.pl boot.img
$ ls
boot.img split_bootimg.pl
$ ./split_bootimg.pl boot.img
Page size: 2048 (0x00000800)
Kernel size: 4113352 (0x003ec3c8)
Ramdisk size: 682322 (0x000a6952)
Second size: 0 (0x00000000)
Board name: 27
Command line: product.version=PD1304BT_A_1.10.0
Writing boot.img-kernel ... complete.
Writing boot.img-ramdisk.gz ... complete.
以上数据中的page size , command line在打包时会用到(应该还有个base, padding size的,这里好像没有)
得到2个文件:
boot.img-kernel , boot.img-ramdisk.gz
$ ls
boot.img boot.img-kernel boot.img-ramdisk.gz split_bootimg.pl
解压boot.img-ramdisk.gz :
问题:gzip: boot.img-ramdisk.gz: not in gzip format
$ gzip -d boot.img-ramdisk.gz
gzip: boot.img-ramdisk.gz: not in gzip format
明明是gz文件却解压不了,此时把压缩文件格式标记1f 8b 08之前的数据去掉即可。
查看文件属性:
$ file boot.img-ramdisk.gz
boot.img-ramdisk.gz: data
gz压缩文件的起始标记是:1f 8b 08
我们可以通过以下两种方式定位此标记:
第一种:
二进制数据查找命令:
od -A x -t x1 boot.img-ramdisk.gz | grep “1f 8b 08”
od命令主要用来查看文件中不能直接显示在终端的字符
- -A x表示地址用十六进制显示
- -A d表示地址用十进制显示
- -t x1表示十六进制的输出格式
地址用16进制:
$ od -A x -t x1 boot.img-ramdisk.gz | grep "1f 8b 08"
000200 1f 8b 08 00 00 00 00 00 00 03 ec bc 79 7c 54 45
地址用10进制:
$ od -A d -t x1 boot.img-ramdisk.gz | grep "1f 8b 08"
0000512 1f 8b 08 00 00 00 00 00 00 03 ec bc 79 7c 54 45
地址为0000512说明标记出现在第513个字节处(0开始的),去掉前面512字节的数据即可
第二种:
用WinHex打开压缩文件,打开查找功能来定位

去除前面512字节的数据:
命令:dd if=./boot.img-ramdisk.gz of=ramdisk.gz bs=512 skip=1
参数说明:
-
<

本文详细介绍了如何使用split_bootimg.pl脚本解包和打包Android boot.img文件,包括处理gzip压缩问题、cpio还原数据以及mkbootfs和mkbootimg工具的使用。在解压过程中遇到gzip格式错误,通过查找文件头标记并使用dd命令修复。最后,文章讨论了在打包过程中可能出现的问题及解决方案,并展示了mkbootimg工具的使用,包括指定参数创建新的boot.img文件。
1万+

被折叠的 条评论
为什么被折叠?



