mirror of
https://github.com/elseif/MikroTikPatch.git
synced 2025-01-23 13:35:09 +03:00
Update patch.py
Signed-off-by: elseif <elseif@live.cn>
This commit is contained in:
parent
f6fea00c16
commit
3ba9e027e3
15
patch.py
15
patch.py
@ -84,14 +84,23 @@ def patch_initrd_xz(initrd_xz:bytes,key_dict:dict,ljust=True):
|
|||||||
if old_public_key in new_initrd:
|
if old_public_key in new_initrd:
|
||||||
print(f'initrd public key patched {old_public_key[:16].hex().upper()}...')
|
print(f'initrd public key patched {old_public_key[:16].hex().upper()}...')
|
||||||
new_initrd = new_initrd.replace(old_public_key,new_public_key)
|
new_initrd = new_initrd.replace(old_public_key,new_public_key)
|
||||||
new_initrd_xz = lzma.compress(new_initrd,check=lzma.CHECK_CRC32,filters=[{"id": lzma.FILTER_LZMA2, "preset": 9,}] )
|
preset = 6
|
||||||
|
new_initrd_xz = lzma.compress(new_initrd,check=lzma.CHECK_CRC32,filters=[{"id": lzma.FILTER_LZMA2, "preset": preset }] )
|
||||||
|
while len(new_initrd_xz) > len(initrd_xz):
|
||||||
|
print(f'preset:{preset}')
|
||||||
|
print(f'new initrd xz size:{len(new_initrd_xz)}')
|
||||||
|
print(f'old initrd xz size:{len(initrd_xz)}')
|
||||||
|
preset += 1
|
||||||
|
new_initrd_xz = lzma.compress(new_initrd,check=lzma.CHECK_CRC32,filters=[{"id": lzma.FILTER_LZMA2, "preset": preset }] )
|
||||||
|
if len(new_initrd_xz) > len(initrd_xz):
|
||||||
|
new_initrd_xz = lzma.compress(new_initrd,check=lzma.CHECK_CRC32,filters=[{"id": lzma.FILTER_LZMA2, "preset": 9 ,"mf": lzma.MF_BT2}] )
|
||||||
if ljust:
|
if ljust:
|
||||||
assert len(new_initrd_xz) <= len(initrd_xz),'new initrd xz size is too big'
|
print(f'preset:{preset}')
|
||||||
print(f'new initrd xz size:{len(new_initrd_xz)}')
|
print(f'new initrd xz size:{len(new_initrd_xz)}')
|
||||||
print(f'old initrd xz size:{len(initrd_xz)}')
|
print(f'old initrd xz size:{len(initrd_xz)}')
|
||||||
print(f'ljust size:{len(initrd_xz)-len(new_initrd_xz)}')
|
print(f'ljust size:{len(initrd_xz)-len(new_initrd_xz)}')
|
||||||
|
assert len(new_initrd_xz) <= len(initrd_xz),'new initrd xz size is too big'
|
||||||
new_initrd_xz = new_initrd_xz.ljust(len(initrd_xz),b'\0')
|
new_initrd_xz = new_initrd_xz.ljust(len(initrd_xz),b'\0')
|
||||||
return new_initrd_xz
|
|
||||||
|
|
||||||
def find_7zXZ_data(data:bytes):
|
def find_7zXZ_data(data:bytes):
|
||||||
offset1 = 0
|
offset1 = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user