Python 3 executes MIUI line brush in package flash_ gen_ crc_ list.py file

Zhitian 2020-11-13 11:20:49
python executes miui line brush


Some tips to share with you , About millet brush machine

  1. EDL Pattern , Qualcomm 9008 In mode , You can swipe in more content , May refer to : millet Note 3 Into the EDL (9008) Method pattern . Repairable sensors 、 The camera starts slowly
  2. After the thread brush package is decompressed , In the use of MiFlash Front brush , It can be used 「 The mushroom ROM assistant 」 Conduct IMG Mirror image edit : Download address
  3. The first 2 Point to the software , Suggest to modify cust.imguserdata.img,system.img There is a certain probability of package failure after modification , It is not recommended to modify him , Because even if it's modified , System OTA It will also be covered when updating
  4. edit partition.xml and rawprogram0.xml You can swipe in more partitions , For example, in 9008 By modifying these two files , Join in persist.img Can fix the sensor 、 Failure of gyroscope, etc
  5. After editing, you need to execute flash_gen_crc_list.py and flash_gen_md5_list.py Two files are used to generate the check value . and flash_gen_crc_list.py Need to manually edit and add additional image and correction code that needs to be flashed in

flash_gen_crc_list.py This file depends on flash_gen_resparsecount This procedure , So we can't be in Windows as well as Mac Run directly on .

If it is Windows 10 Of users can open Ubuntu Linux For Windows 10, Switch to bash Ubuntu On the command line , It can pass through normally python3 Running this program .

otherwise , Can only rely on virtual machine or physical installation Linux The system can run .

Here's the revised code :

#!/usr/bin/env python
from __future__ import print_function
import binascii
import os
import struct
# sparse_file_list And unsparse_file_list Adjust according to the brush package 
sparse_file_list = {

"cache": "cache.img",
"system": "system.img",
"cust": "cust.img",
"userdata": "userdata.img",
"persist": "persist.img"
}
unsparse_file_list = {

"xbl": "xbl.elf",
"xblbak": "xbl.elf",
"abl": "abl.elf",
"ablbak": "abl.elf",
"tz": "tz.mbn",
"tzbak": "tz.mbn",
"hyp": "hyp.mbn",
"hypbak": "hyp.mbn",
"rpm": "rpm.mbn",
"rpmbak": "rpm.mbn",
"pmic": "pmic.elf",
"pmicbak": "pmic.elf",
"devcfg": "devcfg.mbn",
"devcfgbak": "devcfg.mbn",
"storsec": "storsec.mbn",
"storsecbak": "storsec.mbn",
"bluetooth": "BTFM.bin",
"cmnlib": "cmnlib.mbn",
"cmnlibbak": "cmnlib.mbn",
"cmnlib64": "cmnlib64.mbn",
"cmnlib64bak": "cmnlib64.mbn",
"modem": "NON-HLOS.bin",
"dsp": "dspso.bin",
"keymaster": "keymaster.mbn",
"keymasterbak": "keymaster.mbn",
"logo": "logo.img",
"misc": "misc.img",
"recovery": "recovery.img",
"boot": "boot.img"
}
file_list = dict(unsparse_file_list, **sparse_file_list)
def gen_sparse_crc(path):
global crc
FH = open(path, 'rb')
header_bin = FH.read(28)
header = struct.unpack("<I4H4I", header_bin)
magic = header[0]
major_version = header[1]
minor_version = header[2]
file_hdr_sz = header[3]
chunk_hdr_sz = header[4]
blk_sz = header[5]
total_blks = header[6]
total_chunks = header[7]
image_checksum = header[8]
sparsecrc = 0
if magic != 0xED26FF3A:
print("%s: Magic should be 0xED26FF3A but is 0x%08X"
% (path, magic))
return 0
if major_version != 1 or minor_version != 0:
print("%s: I only know about version 1.0, but this is version %u.%u"
% (path, major_version, minor_version))
return 0
if file_hdr_sz != 28:
print("%s: The file header size was expected to be 28, but is %u."
% (path, file_hdr_sz))
return 0
if chunk_hdr_sz != 12:
print("%s: The chunk header size was expected to be 12, but is %u."
% (path, chunk_hdr_sz))
return 0
print("%s: Total of %u %u-byte output blocks in %u input chunks."
% (path, total_blks, blk_sz, total_chunks))
if image_checksum != 0:
print("checksum=0x%08X" % image_checksum)
offset = 0
for i in range(1, total_chunks + 1):
header_bin = FH.read(12)
header = struct.unpack("<2H2I", header_bin)
chunk_type = header[0]
reserved1 = header[1]
chunk_sz = header[2]
total_sz = header[3]
data_sz = total_sz - 12
if chunk_type == 0xCAC1:
if data_sz != (chunk_sz * blk_sz):
print("Raw chunk input size (%u) does not match output size (%u)"
% (data_sz, chunk_sz * blk_sz))
break
else:
sparsecrc = binascii.crc32(FH.read(data_sz), sparsecrc)
elif chunk_type == 0xCAC2:
if data_sz != 4:
print("Fill chunk should have 4 bytes of fill, but this has %u"
% (data_sz), end="")
break
else:
fill_bin = FH.read(4)
fill = struct.unpack("<I", fill_bin)
print("Fill with 0x%08X" % (fill))
fill_buf = [fill] * (blk_sz / data_sz)
# Python 3 No, xrange, use range Instead of 
for j in range(1, chunk_sz + 1):
sparsecrc = binascii.crc32(fill_buf, sparsecrc)
elif chunk_type == 0xCAC3:
if data_sz != 0:
print("Don't care chunk input size is non-zero (%u)" % (data_sz))
break
elif chunk_type == 0xCAC4:
if data_sz != 4:
print("CRC32 chunk should have 4 bytes of CRC, but this has %u"
% (data_sz), end="")
break
else:
crc_bin = FH.read(4)
crc = struct.unpack("<I", crc)
print("Unverified CRC32 0x%08X" % crc)
else:
print("Unknown chunk type 0x%04X" % chunk_type, end="")
break
offset += chunk_sz
return sparsecrc
def gen_crc(file_path):
f = open(file_path, "rb")
crc = binascii.crc32(f.read())
return crc
def get_sparse_count(cmd):
line = os.popen(cmd, 'r').readline()
if line[0] == 'I' or line[0] == 'i':
return -1
return int(line)
# ------------------------------------------------------------------------------
if __name__ == "__main__":
thispath = os.path.dirname(__file__)
path = os.path.join(thispath, 'images')
crclist = os.path.join(path, 'crclist.txt')
sparsecrclist = os.path.join(path, 'sparsecrclist.txt')
max_download_size = 512 * 1024 * 1024
crc = 0
try:
fs = open(sparsecrclist, 'w')
f = open(crclist, 'w')
fs.write("SPARSECRC-LIST\n")
f.write("CRC-LIST\n")
for ptn in file_list:
filepath = os.path.join(path, file_list[ptn])
print(filepath)
if not os.path.isfile(filepath):
print(filepath + ' doesn\'t exist, skip it')
continue
# has_key abandoned , use in Instead of 
if ptn in unsparse_file_list:
crc = gen_crc(filepath)
if crc:
f.write(ptn + ' ' + hex(crc & (2 ** 32 - 1)) + '\n')
else:
size = os.path.getsize(filepath)
if size < max_download_size:
crc = gen_crc(filepath)
if crc:
f.write(ptn + ' ' + hex(crc & (2 ** 32 - 1)) + '\n')
else:
# need get the sparsecount
cmdarg = './flash_gen_resparsecount' + ' -S ' + str(max_download_size) + ' ' + filepath
cmd = os.path.join(thispath, cmdarg)
count = get_sparse_count(cmd)
if count > 0:
countstr = str(count)
crc = gen_sparse_crc(filepath)
if crc:
fs.write(ptn + ' ' + hex(crc & (2 ** 32 - 1)) + ' ' + countstr + '\n')
# except Exception, e, Change the comma to as
except Exception as e:
os.remove(crclist)
os.remove(sparsecrclist)
raise
版权声明
本文为[Zhitian]所创,转载请带上原文链接,感谢

  1. 利用Python爬虫获取招聘网站职位信息
  2. Using Python crawler to obtain job information of recruitment website
  3. Several highly rated Python libraries arrow, jsonpath, psutil and tenacity are recommended
  4. Python装饰器
  5. Python实现LDAP认证
  6. Python decorator
  7. Implementing LDAP authentication with Python
  8. Vscode configures Python development environment!
  9. In Python, how dare you say you can't log module? ️
  10. 我收藏的有关Python的电子书和资料
  11. python 中 lambda的一些tips
  12. python中字典的一些tips
  13. python 用生成器生成斐波那契数列
  14. python脚本转pyc踩了个坑。。。
  15. My collection of e-books and materials about Python
  16. Some tips of lambda in Python
  17. Some tips of dictionary in Python
  18. Using Python generator to generate Fibonacci sequence
  19. The conversion of Python script to PyC stepped on a pit...
  20. Python游戏开发,pygame模块,Python实现扫雷小游戏
  21. Python game development, pyGame module, python implementation of minesweeping games
  22. Python实用工具,email模块,Python实现邮件远程控制自己电脑
  23. Python utility, email module, python realizes mail remote control of its own computer
  24. 毫无头绪的自学Python,你可能连门槛都摸不到!【最佳学习路线】
  25. Python读取二进制文件代码方法解析
  26. Python字典的实现原理
  27. Without a clue, you may not even touch the threshold【 Best learning route]
  28. Parsing method of Python reading binary file code
  29. Implementation principle of Python dictionary
  30. You must know the function of pandas to parse JSON data - JSON_ normalize()
  31. Python实用案例,私人定制,Python自动化生成爱豆专属2021日历
  32. Python practical case, private customization, python automatic generation of Adu exclusive 2021 calendar
  33. 《Python实例》震惊了,用Python这么简单实现了聊天系统的脏话,广告检测
  34. "Python instance" was shocked and realized the dirty words and advertisement detection of the chat system in Python
  35. Convolutional neural network processing sequence for Python deep learning
  36. Python data structure and algorithm (1) -- enum type enum
  37. 超全大厂算法岗百问百答(推荐系统/机器学习/深度学习/C++/Spark/python)
  38. 【Python进阶】你真的明白NumPy中的ndarray吗?
  39. All questions and answers for algorithm posts of super large factories (recommended system / machine learning / deep learning / C + + / spark / Python)
  40. [advanced Python] do you really understand ndarray in numpy?
  41. 【Python进阶】Python进阶专栏栏主自述:不忘初心,砥砺前行
  42. [advanced Python] Python advanced column main readme: never forget the original intention and forge ahead
  43. python垃圾回收和缓存管理
  44. java调用Python程序
  45. java调用Python程序
  46. Python常用函数有哪些?Python基础入门课程
  47. Python garbage collection and cache management
  48. Java calling Python program
  49. Java calling Python program
  50. What functions are commonly used in Python? Introduction to Python Basics
  51. Python basic knowledge
  52. Anaconda5.2 安装 Python 库(MySQLdb)的方法
  53. Python实现对脑电数据情绪分析
  54. Anaconda 5.2 method of installing Python Library (mysqldb)
  55. Python implements emotion analysis of EEG data
  56. Master some advanced usage of Python in 30 seconds, which makes others envy it
  57. python爬取百度图片并对图片做一系列处理
  58. Python crawls Baidu pictures and does a series of processing on them
  59. python链接mysql数据库
  60. Python link MySQL database