1.前言
如果你拿到一個USB升級包,你會發(fā)現(xiàn)升級包的結(jié)構(gòu)基本相似。
但是里面并不是直接就有包括system.img、boot.img和recovery.img在內(nèi)的鏡像文件。
如果我們需要在Android手機(jī)上獲取Magisk。提取內(nèi)核(boot.img)就至關(guān)重要。當(dāng)然其他鏡像根據(jù)你的需要也有其他用處。
這時,如果你需要這些鏡像文件,怎么做呢?
關(guān)注 "升級包>update.zip>payload.bin"。我們這篇的博客的目的就是從payload.bin中提取出鏡像文件。
2. 環(huán)境準(zhǔn)備的提取步驟
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 執(zhí)行鏡像提取
將USB升級包的update.zip解壓后拖到payload_dumper.py的同級目錄執(zhí)行
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
執(zhí)行完成后查看output目錄
OK,這樣就成功了,是不是很簡單。
3. 利用腳本批量提取boot.img
將大量USB升級包放在?E:\store materials\all_firms_bak 目錄下。
由于里面文件很多,經(jīng)過分析,將“?"**" in nm and "ota" not in nm and len(nm) < 56” 作為篩選合適的USB升級包的判斷條件。
payload_dumper-master腳本安裝在?D:\zyy\payload_dumper-master\payload_dumper-master。
根據(jù)這些已知條件,編寫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)
# 獲取當(dāng)前時間
current_time = int(time.time())
print(current_time) # 1631186249
# 轉(zhuǎn)換為localtime
localtime = time.localtime(current_time)
# 利用strftime()函數(shù)重新格式化時間
dt = time.strftime('%Y:%m:%d %H:%M:%S', localtime)
print(dt) # 返回當(dāng)前時間: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): # 復(fù)制函數(shù)
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) # 創(chuàng)建路徑
shutil.copy(srcfile, dstpath + fname) # 復(fù)制文件
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/
執(zhí)行結(jié)果:
只需要半天的時間,腳本成功幫助我們提取了數(shù)百個boot.img。文章來源:http://www.zghlxwxcb.cn/news/detail-780952.html
4.總結(jié)
????????安卓系統(tǒng)USB升級包里其實(shí)是有鏡像信息的,需要你做一個提取。文章來源地址http://www.zghlxwxcb.cn/news/detail-780952.html
到了這里,關(guān)于從安卓系統(tǒng)USB升級包里提取system.img、boot.img和recovery.img在內(nèi)的鏡像文件的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!