Skip to content

Commit

Permalink
squash *quite* a bit of bugs, add iphone9,1 & 9,3 13.0 bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
m1stadev committed Aug 25, 2020
1 parent fc725ad commit 6a597b4
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 26 deletions.
2 changes: 1 addition & 1 deletion custom_bundles.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
- Replace `<stock kernelcache im4p>` with the stock kernelcache `.im4p`.
- Use [Ralph0045's](https://twitter.com/Ralph0045) [Kernel64Patcher](https://github.com/Ralph0045/Kernel64Patcher) to patch the kernel:
- `Kernel64Patcher kernel.raw kernel.patched -a`.
- Use [this](https://raw.githubusercontent.com/dualbootfun/dualbootfun.github.io/master/source/compareFiles.py) Python 3 script (credits: [mcg29](https://twitter.com/mcg29_)) to create a diff file between the unpatched and patched kernels:
- Use [this](https://raw.githubusercontent.com/dualbootfun/dualbootfun.github.io/d947e2c9b6090a1e65a46ea6a58cd840986ff9d9/source/compareFiles.py) Python 3 script (credits: [mcg29](https://twitter.com/mcg29_)) to create a diff file between the unpatched and patched kernels:
- `python3 compareFiles.py kernel.raw kernel.patched`.
- Use img4lib to apply the patch onto the stock kernelcache im4p:
- `img4 -i <stock kernelcache image> -o kernelcache.release.*.patched -P kc.bpatch`.
Expand Down
12 changes: 9 additions & 3 deletions inferius.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
print('Checking if device is A9...')
is_a9 = ipsw.a9_check(firmware_bundle)
if is_a9:
if args.verbose:
print('Device is A9, fetching correct board config...')
board_configs = ipsw.fetch_a9_boardconfigs(firmware_bundle)
if len(board_configs) != 2:
sys.exit('Firmware Bundle for A9 is invalid.\nExiting...')
Expand All @@ -65,21 +67,25 @@
pass
else:
sys.exit('Invalid input given.\nExiting...')
else:
firm_bundle_number = 0
if args.verbose:
print('Device is not A9, continuing...')

if args.verbose:
ipsw_dir = ipsw.extract_ipsw(args.ipsw[0], 'yes')
else:
ipsw_dir = ipsw.extract_ipsw(args.ipsw[0])
print('IPSW extracted! Applying patches to bootchain...')
if args.verbose:
patch.patch_bootchain(firmware_bundle, ipsw_dir, 'yes')
patch.patch_bootchain(firmware_bundle, ipsw_dir, firm_bundle_number, 'yes')
else:
patch.patch_bootchain(firmware_bundle, ipsw_dir)
patch.patch_bootchain(firmware_bundle, ipsw_dir, firm_bundle_number)
print('Grabbing latest LLB and iBoot to put into custom IPSW...')
ipsw.grab_latest_llb_iboot(args.device[0], ipsw_dir, firmware_bundle, firm_bundle_number)
print('Packing everything into custom IPSW. This may take a while, please wait...')
if args.verbose:
ipsw_name = ipsw.make_ipsw(ipsw_dir, firmware_bundle, 'yes')
ipsw_name = ipsw.make_ipsw(ipsw_dir, firmware_bundle, 'yes')
else:
ipsw_name = ipsw.make_ipsw(ipsw_dir, firmware_bundle)
print(f'Done!\nCustom IPSW at: {ipsw_name}')
Expand Down
Binary file not shown.
24 changes: 24 additions & 0 deletions resources/FirmwareBundles/iPhone9,1_13.0_bundle/Info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "13.0",
"boardconfig": "d10",
"processor": "T8010",
"files": {
"ibss": {
"file": "Firmware/dfu/iBSS.d10.RELEASE.im4p",
"sha1": "9d1ad504b1c0452956951b060482e8ce98b0da4d",
"patch": "iBSS.d10.RELEASE.patch"},
"ibec": {
"file": "Firmware/dfu/iBEC.d10.RELEASE.im4p",
"sha1": "1a8f689a8cfd734ca0b9a90c7d975e3277198e99",
"patch": "iBEC.d10.RELEASE.patch"},
"ramdisk": {
"file": "048-96245-001.dmg",
"sha1": "bd9d65ddbcad1d6d0b73316e198ac46a2fd665ad",
"patch": "048-96245-001.asr.patch"},
"kernelcache": {
"file": "kernelcache.release.iphone9",
"sha1": "26ff142be2c9372cfa29d273b3778d39734e2e16",
"patch": "kernelcache.release.iphone9.patch"
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
24 changes: 24 additions & 0 deletions resources/FirmwareBundles/iPhone9,3_13.0_bundle/Info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "13.0",
"boardconfig": "d10",
"processor": "T8010",
"files": {
"ibss": {
"file": "Firmware/dfu/iBSS.d10.RELEASE.im4p",
"sha1": "9d1ad504b1c0452956951b060482e8ce98b0da4d",
"patch": "iBSS.d10.RELEASE.patch"},
"ibec": {
"file": "Firmware/dfu/iBEC.d10.RELEASE.im4p",
"sha1": "1a8f689a8cfd734ca0b9a90c7d975e3277198e99",
"patch": "iBEC.d10.RELEASE.patch"},
"ramdisk": {
"file": "048-96245-001.dmg",
"sha1": "bd9d65ddbcad1d6d0b73316e198ac46a2fd665ad",
"patch": "048-96245-001.asr.patch"},
"kernelcache": {
"file": "kernelcache.release.iphone9",
"sha1": "26ff142be2c9372cfa29d273b3778d39734e2e16",
"patch": "kernelcache.release.iphone9.patch"
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
15 changes: 10 additions & 5 deletions resources/ipsw.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ def find_bundle(device_identifier, version, verbose=None):
else:
sys.exit(f"Firmware bundle for {device_identifier}, {version} doesn't exist!\nIf you have provided your own firmware bundle,\nplease make sure it is in 'resources/FirmwareBundles'\nand named {device_identifier}_{version}_bundle")

def grab_latest_llb_iboot(device_identifier, ipsw_dir, firm_bundle, firm_bundle_number: int=None, verbose: str=None):
def grab_latest_llb_iboot(device_identifier, ipsw_dir, firm_bundle, firm_bundle_number):
l_device_identifier = device_identifier.lower()
with open(f'{firm_bundle}/Info.json') as f:
data = json.load(f)
if firm_bundle_number:
if firm_bundle_number != 0:
hardware_model = data['devices'][firm_bundle_number]['boardconfig']
elif device_identifier.startswith('iPhone6'):
elif l_device_identifier.startswith('iphone6'):
hardware_model = 'iphone6'
else:
hardware_model = data['boardconfig']
Expand All @@ -73,7 +74,7 @@ def grab_latest_llb_iboot(device_identifier, ipsw_dir, firm_bundle, firm_bundle_
shutil.copy(f'Firmware/all_flash/iBoot.{hardware_model}.RELEASE.im4p', f'{ipsw_dir}/Firmware/all_flash/')
shutil.rmtree('Firmware')

def extract_ibss_ibec(ipsw, firm_bundle, firm_bundle_number: int=None, verbose: str=None):
def extract_ibss_ibec(ipsw, firm_bundle, firm_bundle_number, verbose=None):
if os.path.isfile(ipsw):
pass
else:
Expand All @@ -86,7 +87,7 @@ def extract_ibss_ibec(ipsw, firm_bundle, firm_bundle_number: int=None, verbose:
sys.exit(f'IPSW {ipsw} is not a valid IPSW!\nExiting...')
with open(f'{firm_bundle}/Info.json') as f:
data = json.load(f)
if firm_bundle_number:
if firm_bundle_number == 0:
ibss_path = data['files']['ibss']['file']
ibec_path = data['files']['ibec']['file']
else:
Expand All @@ -102,6 +103,10 @@ def extract_ibss_ibec(ipsw, firm_bundle, firm_bundle_number: int=None, verbose:
ipsw.close()
return ibss_path, ibec_path

def fetch_processor(firm_bundle):
with open(f'{firm_bundle}/Info.json') as f:
data = json.load(f)
return data['processor']

def make_ipsw(ipsw_dir, firm_bundle, verbose=None):
if os.path.isfile(f'{firm_bundle[26:-7]}_custom.ipsw'):
Expand Down
4 changes: 2 additions & 2 deletions resources/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import subprocess
import time

def patch_bootchain(firm_bundle, ipsw_path, firm_bundle_number: int=None, verbose: str=None): # Applies patches from firmware bundle onto bootchain
def patch_bootchain(firm_bundle, ipsw_path, firm_bundle_number, 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)
if firm_bundle_number:
if firm_bundle_number != 0:
ibss = [data['devices'][firm_bundle_number]['files']['ibss']['file'], data['devices'][firm_bundle_number]['files']['ibss']['patch']]
ibec = [data['devices'][firm_bundle_number]['files']['ibec']['file'], data['devices'][firm_bundle_number]['files']['ibec']['patch']]
kernelcache = [data['files']['kernelcache']['file'], data['files']['kernelcache']['patch']]
Expand Down
10 changes: 9 additions & 1 deletion resources/restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@
import time
import sys

def send_ibss_ibec(verbose=None):
def send_ibss_ibec(processor, verbose=None):
with open('work/empty_file', 'w') as f:
f.close()
if processor.lower() == 's5l8960':
subprocess.Popen(f'./resources/bin/irecovery -f work/empty_file', stdout=subprocess.PIPE, shell=True)
time.sleep(5)
subprocess.Popen(f'./resources/bin/irecovery -f work/ipsw/ibss.img4', stdout=subprocess.PIPE, shell=True)
time.sleep(5)
subprocess.Popen(f'./resources/bin/irecovery -f work/ipsw/ibec.img4', stdout=subprocess.PIPE, shell=True)
time.sleep(5)
if processor.lower() == 't8010' or 't8015':
subprocess.Popen(f'./resources/bin/irecovery -c go', stdout=subprocess.PIPE, shell=True)
time.sleep(5)
if verbose:
print('[VERBOSE] Checking if device is in pwnrecovery...')
lsusb = subprocess.Popen('./resources/bin/lsusb', stdout=subprocess.PIPE, shell=True)
Expand Down
44 changes: 30 additions & 14 deletions restituere.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,10 @@
lsusb = subprocess.Popen('./resources/bin/lsusb', stdout=subprocess.PIPE, shell=True)
time.sleep(10)
lsusb_output = str(lsusb.stdout.read())
if 'Apple Mobile Device (DFU)' in lsusb_output:
if 'Apple Mobile Device (DFU Mode)' in lsusb_output:
pass
else:
sys.exit('Device not found!\nExiting...')
device_identifier = args.device[0]
device_identifier = device_identifier.lower()
if device_identifier.startswith('iphone8') or device_identifier == 'ipad6,11' or device_identifier == 'ipad6,12':
sys.exit('Error: A9 devices are currently not supported!\nExiting...') #TODO: Implement A9 support
else:
pass
sys.exit('DFU device not found!\nExiting...')
print('Fetching some required info...')
if args.verbose:
print('[VERBOSE] Fetching ECID...')
Expand Down Expand Up @@ -88,25 +82,47 @@
firmware_bundle = ipsw.find_bundle(args.device[0], args.version[0], 'yes')
else:
firmware_bundle = ipsw.find_bundle(args.device[0], args.version[0])
is_a9 = ipsw.a9_check(firmware_bundle)
if is_a9:
if args.verbose:
print('Device is A9, fetching correct board config...')
board_configs = ipsw.fetch_a9_boardconfigs(firmware_bundle)
if len(board_configs) != 2:
sys.exit('Firmware Bundle for A9 is invalid.\nExiting...')
firm_bundle_number = input(f'A9 device detected, please choose the correct board config for your device:\n[1] {board_configs[0]}\n[2] {board_configs[1]}\nChoice: ')
try:
int(firm_bundle_number)
except ValueError:
sys.exit('Input not a number!.\nExiting...')
firm_bundle_number = int(firm_bundle_number)
if 0 < firm_bundle_number < 3:
pass
else:
sys.exit('Invalid input given.\nExiting...')
else:
firm_bundle_number = 0
if args.verbose:
print('Device is not A9, continuing...')
if args.verbose:
print('Extracting iBSS and iBEC from custom IPSW...')
if args.verbose:
ibss_path, ibec_path = ipsw.extract_ibss_ibec(args.ipsw[0], firmware_bundle, 'yes')
ibss_path, ibec_path = ipsw.extract_ibss_ibec(args.ipsw[0], firmware_bundle, firm_bundle_number, 'yes')
else:
ibss_path, ibec_path = ipsw.extract_ibss_ibec(args.ipsw[0], firmware_bundle)
ibss_path, ibec_path = ipsw.extract_ibss_ibec(args.ipsw[0], firmware_bundle, firm_bundle_number)
print('Signing iBSS and iBEC with SHSH blob...')
if args.verbose:
patch.sign_ibss_ibec(ibss_path, ibec_path, 'yes')
else:
patch.sign_ibss_ibec(ibss_path, ibec_path)
processor = ipsw.fetch_processor(firmware_bundle)
print('Preparations done! Beginning restore...')
if args.verbose:
restore.send_ibss_ibec('yes')
restore.send_ibss_ibec(processor, 'yes')
else:
restore.send_ibss_ibec()
restore.send_ibss_ibec(processor)
if args.verbose:
restore.restore(args.ipsw[0], restore.is_cellular(device_identifier), 'yes')
restore.restore(args.ipsw[0], restore.is_cellular(args.device[0]), 'yes')
else:
restore.restore(args.ipsw[0], restore.is_cellular(device_identifier))
restore.restore(args.ipsw[0], restore.is_cellular(args.device[0]))
else:
exit(parser.print_help(sys.stderr))

0 comments on commit 6a597b4

Please sign in to comment.