从安卓系统USB升级包里提取system.img、boot.img和recovery.img在内的镜像文件

2023-05-16

1.前言

如果你拿到一个USB升级包,你会发现升级包的结构基本相似。

但是里面并不是直接就有包括system.img、boot.img和recovery.img在内的镜像文件。

如果我们需要在Android手机上获取Magisk。提取内核(boot.img)就至关重要。当然其他镜像根据你的需要也有其他用处。

这时,如果你需要这些镜像文件,怎么做呢?

关注 "升级包>update.zip>payload.bin"。我们这篇的博客的目的就是从payload.bin中提取出镜像文件。

2. 环境准备的提取步骤

2.1 下载payload_dumper

打开 

  • GitHub - vm03/payload_dumper: Android OTA payload dumper

获取程序的压缩包解压放置合适的目录

2.2 安装库文件 

从压缩包里检查requirements.txt,里面有需要的python库的版本:

protobuf>=3.19.3, <=3.20.1
six>=1.16.0
bsdiff4>=1.1.5

安装指定版本的python库:

D:\zyy\payload_dumper-master\payload_dumper-master>pip install bsdiff4
Collecting bsdiff4
  Downloading bsdiff4-1.2.3-cp39-cp39-win_amd64.whl (18 kB)
Installing collected packages: bsdiff4
Successfully installed bsdiff4-1.2.3


D:\Users\zhangyy\AppData\Local\Programs\Python\Python39\Lib\site-packages\protobuf-python-3.20.1\protobuf-3.20.1>pip install protobuf==3.20.1
Collecting protobuf==3.20.1
  Downloading protobuf-3.20.1-cp39-cp39-win_amd64.whl (904 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 904.1/904.1 kB 202.8 kB/s eta 0:00:00
Installing collected packages: protobuf
Successfully installed protobuf-3.20.1

[notice] A new release of pip available: 22.3.1 -> 23.0.1
[notice] To update, run: python.exe -m pip install --upgrade pip

检查是否都安装成功:

D:\Users\zhangyy\AppData\Local\Programs\Python\Python39\Lib\site-packages\protobuf-python-3.20.1\protobuf-3.20.1>pip lis
t
Package      Version
------------ -------
asgiref      3.5.2
bcrypt       4.0.1
bsdiff4      1.2.3
cffi         1.15.1
cryptography 38.0.4
Django       4.1.3
paramiko     2.12.0
pip          22.3.1
protobuf     3.20.1
pycparser    2.21
PyNaCl       1.5.0
setuptools   56.0.0
six          1.16.0
sqlparse     0.4.3
tzdata       2022.6

OK,都安装成功而且版本合适。

2.3 执行镜像提取

将USB升级包的update.zip解压后拖到payload_dumper.py的同级目录执行


D:\zyy\payload_dumper-master\payload_dumper-master>python payload_dumper.py ota_package_update\payload.bin
Processing abl partition.Done
Processing bluetooth partition.Done
Processing boot partition................................Done
Processing cmnlib partition.Done
Processing cmnlib64 partition.Done
Processing devcfg partition.Done
Processing dsp partition................Done
Processing dtbo partition....Done
Processing hyp partition.Done
Processing imagefv partition.Done
Processing keymaster partition.Done
Processing modem partition....................................................Done
Processing product partition........................................................................................................................Done
Processing qupfw partition.Done
Processing recovery partition................................................Done
Processing rpm partition.Done
Processing system partition............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................Done
Processing tz partition.Done
Processing uefisecapp partition.Done
Processing vbmeta partition.Done
Processing vbmeta_system partition.Done
Processing vendor partition....................................................................................................................................................................................................................................................Done
Processing xbl partition..Done
Processing xbl_config partition.Done

执行完成后查看output目录

OK,这样就成功了,是不是很简单。

3. 利用脚本批量提取boot.img

将大量USB升级包放在 E:\store materials\all_firms_bak 目录下。

由于里面文件很多,经过分析,将“ "**" in nm and "ota" not in nm and len(nm) < 56” 作为筛选合适的USB升级包的判断条件。

payload_dumper-master脚本安装在 D:\zyy\payload_dumper-master\payload_dumper-master。

根据这些已知条件,编写python代码如下:


import os
import shutil
import zipfile
import time

count = 0


def extract_img():
    global count
    zip_dir = r"E:\store materials\all_firms_bak"
    for rt, dirs, fl in os.walk(zip_dir, topdown=True):
        for nm in fl:
            # if nm == "boot.img":
            if "**" in nm and "ota" not in nm and len(nm) < 56:
                file_path_name = str(rt) + "\\" + str(nm)
                print("文件:", file_path_name)
                unzip_and_extract_bootimg(file_path_name)

                count = count + 1
                print("bootimg count is:", count)

                # 获取当前时间
                current_time = int(time.time())
                print(current_time)  # 1631186249
                # 转换为localtime
                localtime = time.localtime(current_time)
                # 利用strftime()函数重新格式化时间
                dt = time.strftime('%Y:%m:%d %H:%M:%S', localtime)
                print(dt)  # 返回当前时间:2021:09:09 19:17:29

        # for _dir in dirs:
        # print("目录:", str(rt) + "\\" + str(_dir))


# 解压缩
def unzip_and_extract_bootimg(file_name):
    payload_dumper_path = r"D:\zyy\payload_dumper-master\payload_dumper-master"
    payload_dumper_ota_package_path = r"D:\zyy\payload_dumper-master\payload_dumper-master\ota_package_update/"
    payload_dumper_putput_path = r"D:\zyy\payload_dumper-master\payload_dumper-master\output"

    print("file_name is: ", file_name)
    zip_file = zipfile.ZipFile(file_name)
    if os.path.isdir(file_name + "_files"):
        print("dir already exits! do not need unzip")
    else:
        # 从升级压缩包提取出update.zip子压缩包
        os.mkdir(file_name + "_files")
        filepath_package = file_name + "_files/"
        print("destfilepath is: ", filepath_package)
        zip_file.extractall(path=filepath_package, members=['update.zip'])
        # 打印此时update.zip所在路径
        file_path_updatezip = filepath_package + r"update.zip"
        print("the path of update.zip is: ", file_path_updatezip)
        # 从update.zip里提取payload.bin(payload.bin通过脚本制作出boot.img)
        zip_file_bin = zipfile.ZipFile(file_path_updatezip)
        zip_file_bin.extractall(path=filepath_package + "update/", members=["payload.bin"])
        file_path_payloadbin = filepath_package + r"update/" + r"payload.bin"
        print("file path payloadbin is ", file_path_payloadbin)
        print("close zip_file")
        zip_file.close()
        mycopyfile(file_path_payloadbin, payload_dumper_ota_package_path)
        print("move payload.bin sucess!")
        os.chdir(payload_dumper_path)
        print(os.getcwd())
        ret = os.system(
            "python payload_dumper.py ota_package_update\payload.bin")
        store_bootimg_path = str(file_path_payloadbin).replace("all_firms_bak", "all_boot_test") + r"/"
        if os.path.exists(payload_dumper_putput_path + r"\boot.img"):
            mycopyfile(payload_dumper_putput_path + r"\boot.img", store_bootimg_path)
            os.remove(r"D:\zyy\payload_dumper-master\payload_dumper-master\ota_package_update\payload.bin")
            for f in os.listdir(r"D:\zyy\payload_dumper-master\payload_dumper-master\output"):
                os.remove(os.path.join(r"D:\zyy\payload_dumper-master\payload_dumper-master\output", f))
            time.sleep(3)
            print("extract bootimg completed!")
            return
        else:
            print("boot.img not exits!")


def mycopyfile(srcfile, dstpath):  # 复制函数
    if not os.path.isfile(srcfile):
        print("%s not exist!" % (srcfile))
    else:
        fpath, fname = os.path.split(srcfile)  # 分离文件名和路径
        if not os.path.exists(dstpath):
            os.makedirs(dstpath)  # 创建路径
        shutil.copy(srcfile, dstpath + fname)  # 复制文件
        print("copy %s -> %s" % (srcfile, dstpath + fname))


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    extract_img()

# See PyCharm help at https://www.jetbrains.com/help/pycharm/

执行结果:

只需要半天的时间,脚本成功帮助我们提取了数百个boot.img。

4.总结

        安卓系统USB升级包里其实是有镜像信息的,需要你做一个提取。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从安卓系统USB升级包里提取system.img、boot.img和recovery.img在内的镜像文件 的相关文章

随机推荐

  • 小工具4:Windows cports.exe

    以语雀 文档为准 文件 cports zip xff0c 文件来源于网络 xff0c 用于实时查看端口占用情况 xff0c 使用管理员权限运行时 xff0c 可杀端口 下载上述文件 xff0c 解压 xff0c 将 cports exe 放
  • 为何在 node 项目中使用固定版本号,而不使用 ~、^?

    以语雀 文档为准 使用 时吃过亏希望版本号掌握在自己手里 xff0c 作者自己升级 xff08 跟随官方进行升级 xff0c 就算麻烦作者 xff0c 也不想麻烦使用者 xff09 虽然 pnpm 很好用 xff0c 但是不希望在项目中用到
  • 导读 2、kubernetes(k8s)导读

    以语雀 文档为准 内容来自 Kubernetes 权威指南 第5版等 kubernetes 是什么 xff1f kubernetes是一个全新的基于容器技术的分布式架构领先方案 xff0c 是容器云的优秀平台选型方案 xff0c 已经成为新
  • 区块链——脱坑truffle

    使用truffle构建一个智能合约 实现输出 helloworld 的功能 网上有很多帖子 但也有很多坑 这里展示我的搭建过程 帮助大家绕过那些麻烦 一 安装web3 solc truffle npm g install solc npm
  • 使用fescar遇到can not register RM,err:can not connect to fescar-server.

    前提 如果你看到了这篇文章 xff0c 说明你已经成功跑起了阿里爸爸fescar官方提供的example和server xff0c 并且你的客户端和服务端之间心跳正常 xff0c 但是当客户端进行事务操作时却提示以下错误 com span
  • Arch常用软件

    常用软件 开发 gitandroid studiovim 图形界面 网络 pacman S networkmanager 启动其提供的服务 systemctl start NetworkManager service 让服务开机自启 sys
  • CentOS可以使用的yum仓库地址

    name 61 CentOS 6 6 Base baseurl 61 http mirrors aliyun com centos vault 6 6 os x86 64 gpgcheck 61 1 gpgkey 61 http mirro
  • pyqt错误:Unresolved reference 和 正确安装pycharm+python+pyqt5

    写如下代码 xff1a span class hljs keyword import span sys span class hljs keyword from span PyQt5 span class hljs keyword impo
  • 以下是adb工具包最新Google官方版下载地址:

    以下是adb工具包最新Google官方版下载地址 xff1a ADB和Fastboot for Windows https dl google com android repository platform tools latest win
  • java.lang.UnsupportedOperationException 及resultMap相关知识

    起因 今天在请求数据库数据时报错java lang UnsupportedOperationException xff0c 从字面上理解错误的含义就是不支持的操作异常 xff0c 后面定位到错误发生在数据库sql语句中 xff0c 具体原因
  • Spring Boot配置类处理

    ConfigurationClassPostProcessor处理所有配置类 xff0c 包括 64 Component 64 Bean 64 Import注解等 由于配置类可能会引入新的配置类 xff0c 新的配置类也需要被处理 xff0
  • 数据库范式1NF 2NF 3NF详细阐述

    范式 xff1a 关系数据库中的关系是要满足一定要求的 xff0c 满足不同程度要求的不同范式 满足最低要求的叫第一范式 xff0c 简称1NF xff0c 在第一范式中满足进一步要求的为第二范式 xff0c 其余以此类推 通俗来说是满足数
  • 记一次 Native Crash Abort message:‘FORTIPY :vsprintf:prevented 33-byte write into 32-byte buffer ’

    先贴上关键日志 第一眼看到日志 xff0c 以为是缺少了Arm64 的so文件 xff0c 查看后发现并没缺少 xff1b 无奈之下 xff0c 只有复现这个Crash xff0c 一点点缩小排查范围 xff1b 最终将问题的矛头指向了项目
  • spring Bean的完整生命周期

    spring bean的完整生命周期 1 1 容器启动时 BeanFactoryPostProcessor gt postProcessBeanFactory Spring IoC容器允许BeanFactoryPostProcessor在容
  • 1秒学会 Vim 插件管理

    Vim pathogen 通常情况下安装vim插件 xff0c 通常是将所有的插件和相关的doc文件都安装在中一文件夹中 xff0c 如将插件全部安装在 usr share vim vim73 plugin 目录下 xff0c 将帮助文档全
  • 【树莓派4B】Manjaro-ARM系统下配置VNC以及遇到的问题

    在两三个小时内经历了各种尝试之后 xff0c 终于成功 xff0c 现在记录一下过程 xff0c 以免下次忘记 系统 xff1a 我实在树莓派4B 8G版上安装了Manjaro 1 下载 wget https github com azal
  • 【硬件调试】串口乱码原因汇总

    一般有以下几种原因 xff0c 列举一下提醒自己 1 波特率出错或者其他串口设置出错 2 三线即可进行通信 xff0c 未接地或者接触不良 xff0c TTL 232 TX RX接反 xff0c 485 A B接反 3 如果接电脑可以通信
  • 真实面试题-高并发如何设置JVM参数

    阿里终面 xff1a 每天100w次登陆请求 xff0c 8G内存该如何设置JVM参数 设置内存大小 由于服务器只有8G内存 xff0c 需要合理分配内存给JVM xff0c 避免过度分配导致内存不足 xff0c 也避免分配不足导致频繁的垃
  • 项目切换分支后突然kotlin not configured

    从其他分支切换回来新功能开发分支后提示kotlin not configured 搜索网上提示是版本问题 要将jre8去掉 如 implementation 39 org jetbrains kotlin kotlin stdlib jre
  • 从安卓系统USB升级包里提取system.img、boot.img和recovery.img在内的镜像文件

    1 前言 如果你拿到一个USB升级包 xff0c 你会发现升级包的结构基本相似 但是里面并不是直接就有包括system img boot img和recovery img在内的镜像文件 如果我们需要在Android手机上获取Magisk 提