From 32ef5f3aeb12636274bd8c9157d3309c2568da85 Mon Sep 17 00:00:00 2001 From: elseif Date: Sat, 18 Jan 2025 10:53:36 +0800 Subject: [PATCH] Update patch.py Signed-off-by: elseif --- patch.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/patch.py b/patch.py index fad35b3..4ba6510 100644 --- a/patch.py +++ b/patch.py @@ -86,14 +86,14 @@ def patch_initrd_xz(initrd_xz:bytes,key_dict:dict,ljust=True): new_initrd = new_initrd.replace(old_public_key,new_public_key) 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): + while len(new_initrd_xz) > len(initrd_xz) and preset < 10: 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}] ) + new_initrd_xz = lzma.compress(new_initrd,check=lzma.CHECK_CRC32,filters=[{"id": lzma.FILTER_LZMA2, "preset": 9 | lzma.PRESET_EXTREME,'dict_size': 32*1024*1024,"lc": 4,"lp": 0, "pb": 0,}] ) if ljust: print(f'preset:{preset}') print(f'new initrd xz size:{len(new_initrd_xz)}') @@ -101,6 +101,7 @@ def patch_initrd_xz(initrd_xz:bytes,key_dict:dict,ljust=True): 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') + return new_initrd_xz def find_7zXZ_data(data:bytes): offset1 = 0