Skip to content

Commit

Permalink
Implement ipwnrecovery
Browse files Browse the repository at this point in the history
  • Loading branch information
axi0mX committed Jun 11, 2017
1 parent 0217600 commit 9f16469
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions ipwnrecovery
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/python
# ipwnrecovery: open-source jailbreaking tool for older iOS devices
# Author: axi0mX

import getopt, sys
import usb # pyusb: use 'pip install pyusb' to install this module
import recovery

def print_help():
print 'USAGE: ipwnrecovery [options]'
print 'Interact with an iOS device in Recovery Mode.\n'
print 'Basic options:'
print ' -c cmd\t\t\trun command on device'
print ' -f file\t\t\tsend file to device in Recovery Mode'
print 'Advanced options:'
print ' --exit-recovery-loop\t\tenable auto-boot and reboot device'

if __name__ == '__main__':
try:
advanced = ['exit-recovery-loop']
opts, args = getopt.getopt(sys.argv[1:], 'c:f:', advanced)
except getopt.GetoptError:
print 'ERROR: Invalid arguments provided.'
print_help()
sys.exit(2)

if len(opts) == 0:
print_help()
sys.exit(2)

for opt, arg in opts:
if opt == '-c':
device = recovery.acquire_device()
try:
recovery.send_command(device, arg)
except usb.core.USBError:
print 'WARNING: Caught USBError after running command.'
recovery.release_device(device)

if opt == '-f':
try:
with open(arg, 'rb') as f:
data = f.read()
except IOError:
print 'ERROR: Could not read file:', arg
sys.exit(1)

device = recovery.acquire_device()
recovery.send_data(device, data)
recovery.release_device(device)

if opt == '--exit-recovery-loop':
device = recovery.acquire_device()

# TODO: getenv auto-boot first and fail if it is already true.
recovery.send_command(device, 'setenv auto-boot true')
recovery.send_command(device, 'saveenv')
try:
recovery.send_command(device, 'reboot')
except usb.core.USBError:
# OK: this is expected when rebooting
pass

recovery.release_device(device)

0 comments on commit 9f16469

Please sign in to comment.