手机启动镜像boot.img的解包(压)(用split_bootimg.pl)和问题gzip: boot.img-ramdisk.gz: not in gzip format解决

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

下载工具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
参数说明:

    <
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

知行电子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值