Update patch.py

Signed-off-by: elseif <elseif@live.cn>
This commit is contained in:
elseif 2025-02-07 03:39:14 +08:00 committed by GitHub
parent c657f2e736
commit 39af3326bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,10 +10,10 @@ def replace_key(old,new,data,name=''):
pattern_bytes = b''.join(pattern_parts) pattern_bytes = b''.join(pattern_parts)
pattern = re.compile(pattern_bytes, flags=re.DOTALL) pattern = re.compile(pattern_bytes, flags=re.DOTALL)
def replace_match(match): def replace_match(match):
print(f'{name} found public key at {match.start()} {match.group().hex().upper()}') # print(f'{name} found public key at {match.start()} {match.group().hex().upper()}')
replaced = b''.join([new_chunks[i] + match.group(i+1) for i in range(len(new_chunks) - 1)]) replaced = b''.join([new_chunks[i] + match.group(i+1) for i in range(len(new_chunks) - 1)])
replaced += new_chunks[-1] replaced += new_chunks[-1]
print(f'{name} replace public key {replaced.hex().upper()}') # print(f'{name} replace public key {replaced.hex().upper()}')
print(f'{name} public key patched {old[:16].hex().upper()}...') print(f'{name} public key patched {old[:16].hex().upper()}...')
return replaced return replaced
return re.sub(pattern, replace_match, data) return re.sub(pattern, replace_match, data)
@ -269,9 +269,6 @@ def patch_squashfs(path,key_dict):
for file in files: for file in files:
file = os.path.join(root,file) file = os.path.join(root,file)
if os.path.isfile(file): if os.path.isfile(file):
if 'sys2' in file:
os.remove(file)
continue
data = open(file,'rb').read() data = open(file,'rb').read()
for old_public_key,new_public_key in key_dict.items(): for old_public_key,new_public_key in key_dict.items():
_data = replace_key(old_public_key,new_public_key,data,file) _data = replace_key(old_public_key,new_public_key,data,file)