forked from m1stadev/Inferius
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatch.py
36 lines (34 loc) · 1.85 KB
/
patch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import json
import os
import bsdiff4
import subprocess
import time
def patch_bootchain(firm_bundle, ipsw_path, verbose=None): # Applies patches from firmware bundle onto bootchain
os.makedirs('work/patched_files', exist_ok = True)
with open(f'{firm_bundle}/Info.json') as f:
data = json.load(f)
ibss = [data['files']['ibss']['file'], data['files']['ibss']['patch']]
ibec = [data['files']['ibec']['file'], data['files']['ibec']['patch']]
kernelcache = [data['files']['kernelcache']['file'], data['files']['kernelcache']['patch']]
ramdisk = [data['files']['ramdisk']['file'], data['files']['ramdisk']['patch']]
bsdiff4.file_patch_inplace(f'work/ipsw/{ibss[0]}', f'{firm_bundle}/{ibss[1]}')
if verbose:
print(f'[VERBOSE] iBSS patched and put in work/ipsw/{ibss[0]}')
bsdiff4.file_patch_inplace(f'work/ipsw/{ibec[0]}', f'{firm_bundle}/{ibec[1]}')
if verbose:
print(f'[VERBOSE] iBEC patched and put in work/ipsw/{ibec[0]}')
bsdiff4.file_patch_inplace(f'work/ipsw/{kernelcache[0]}', f'{firm_bundle}/{kernelcache[1]}')
if verbose:
print(f'[VERBOSE] Kernelcache patched and put in work/ipsw/{kernelcache[0]}')
bsdiff4.file_patch_inplace(f'work/ipsw/{ramdisk[0]}', f'{firm_bundle}/{ramdisk[1]}')
if verbose:
print(f'[VERBOSE] Ramdisk patched and put in work/ipsw/{ramdisk[0]}')
def sign_ibss_ibec(ibss_path, ibec_path, shsh, verbose=None):
subprocess.Popen(f'./resources/bin/img4tool -c work/ipsw/ibss.img4 -p work/ipsw/{ibss_path} -s {shsh}', stdout=subprocess.PIPE, shell=True)
time.sleep(5)
if verbose:
print('[VERBOSE] iBSS packed into img4')
subprocess.Popen(f'./resources/bin/img4tool -c work/ipsw/ibec.img4 -p work/ipsw/{ibec_path} -s {shsh}', stdout=subprocess.PIPE, shell=True)
time.sleep(5)
if verbose:
print('[VERBOSE] iBEC packed into img4')