View difference between Paste ID: y511TjV1 and ciAj8NJy
SHOW: | | - or go back to the newest paste.
1
#!/usr/bin/python
2-
### HALF ASSED ONE PLUS ONE TOOLKIT v1.0 OFFICIAL RELEASE!
2+
### HALF-ASSED ONE + ONE TOOLKIT v1.3b BETA BLOCKERS
3
##### AUTHOR: vvn
4-
##### RELEASE DATE: august 18, 2014
4+
##### RELEASE DATE: AUGUST 26, 2014
5-
##### this is a very half-assed project and i cannot guarantee fast or frequent updates.
5+
##### REQUIREMENTS: Python 2.7, Android SDK (or at minimum, adb and fastboot), pyadb.py library
6-
##### USE AT YOUR OWN RISK. i am not responsible for any damage to your device.
6+
##### also required, obviously, is a computer that runs an OS that supports python 2.7.
7-
##### IMPORTANT!!! ***requires pyadb.py (also on my pastebin)***
7+
##### HOLY SHIT I HAVE A README FILE!
8-
##### GET PYADB (pyadb.py) HERE: http://pastebin.com/g2Z08JN1
8+
##### http://notworth.it/opo/README
9-
##### for #8 custom recovery flash, download files (filehost + filename) and put in script directory:
9+
##### PYTHON SCRIPTS AVAILABLE FOR DOWNLOAD ON MY SITE:
10-
##### filehost: notworth (dot) it / opo / opotoolkit / 
10+
##### notworth (dot) it /opo/opotoolkit.py -AND- notworth (dot) it /opo/pyadb.py
11-
##### filenames: twrp.img, philz.img, cwm.img
11+
##### until the github repo cooperates, check for latest updates on my pastebin:
12-
##### download ZIP file containing scripts, superSU, custom recoveries, and adb/fastboot binaries for OSX/windows:
12+
##### http://pastebin.com/u/eudemonics
13-
##### filehost: notworth (dot) it / opo /
13+
### DOWNLOAD LINKS (piece 'em together if you're not a robot):
14-
##### filename: 1plus1-halfassedtoolkit_v1.zip
14+
## PYTHON SCRIPTS AND ADB/FASTBOOT BINARIES: notworth (dot) it /opo/1plus1-halfassedtoolkit.zip
15-
##### for #8 flash options, download + unzip (filehost + filename):
15+
## SHA1(1plus1-halfassedtoolkit.zip)= c86bfba7da78a5a435adf01dd4e69c479f7d8d21
16-
##### filehost: notworth (dot) it / opo / 
16+
17-
##### filenames: XNPH25R.zip, XNPH30O.zip
17+
import subprocess, sys, re, os, os.path, time, datetime, urllib, urllib2
18-
##### unzip files as subdirectories inside script location: /scripthome/XNPH25R  /scripthome/XNPH30O
18+
19-
##### to report bugs or suggestions, email me: vvn (at) eudemonics (dot) org
19+
20-
##### feel free to share, modify, or whatever.
20+
def intro():
21-
##### you can use this with any android device, not just the oneplus one. just change out the files.
21+
22-
##### some credit would be nice since i worked pretty hard on this.
22+
   print ("\033[41m\033[37;1m#################################################################\033[0m")
23-
##### but what would be even better is if you bought my EP!
23+
   time.sleep(0.1)
24-
##### stream and buy it here: dreamcorp.bandcamp.com or any major online digital retailer
24+
   print ("\033[41m\033[37;1m#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#\033[0m")
25-
##### to run, save this file as opotoolkit.py and save pyadb.py (link above) in same directory
25+
   time.sleep(0.1)
26-
##### make sure you have the android SDK installed.
26+
   print ("\033[41m\033[37;1m#~~~~~~~~~~~~~~~~~~~~~~ \033[40m\033[33;1mTHE HALF-ASSED\033[41m\033[37;1m ~~~~~~~~~~~~~~~~~~~~~~~~~#\033[0m")
27-
##### download android SDK here: https://developer.android.com/sdk/
27+
   time.sleep(0.1)
28-
##### you can either put the scripts in the same directory as your android SDK,
28+
   print ("\033[41m\033[37;1m#~~~~~~~~~~~~~~~~~~~~ \033[40m\033[33mONEPLUS ONE TOOLKIT\033[41m\033[37m ~~~~~~~~I\033[41m\033[37;1m   7~~~~~~~~~#\033[0m")
29-
##### or create an environmental path variable for your android SDK directory
29+
   time.sleep(0.1)
30-
##### python 2.7 is also required. download python here: https://www.python.org/downloads/
30+
   print ("\033[41m\033[37;1m#~~~~~~~~~~~~~~~~~~~~~~~~~ \033[41m\033[40;1mv1.3 BETA\033[41m\033[37;1m ~~~~~~~~~~~~~I   7~~~~~~~~~#\033[0m")
31
   time.sleep(0.1)
32-
import subprocess, sys, re, os, os.path, time, datetime
32+
   print ("\033[41m\033[37;1m#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~I   7~~~~~~~~~#\033[0m")
33
   time.sleep(0.1)
34
   print ("\033[41m\033[37;1m#~~~~~~~~I                           77~~~~~I               7~~~#\033[0m")
35
   time.sleep(0.1)
36
   print ("\033[41m\033[37;1m#~~~~~~~~I   7~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~I   7~~~~~~~~~#\033[0m")
37
   time.sleep(0.1)
38
   print ("\033[41m\033[37;1m#~~~~~~~~I   7~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~I   7~~~~~~~~~#\033[0m")
39
   time.sleep(0.1)
40-
   print ('''\033[34m
40+
   print ("\033[41m\033[37;1m#~~~~~~~~I   7~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~I   7~~~~~~~~~#\033[0m")
41-
*************************************************
41+
   time.sleep(0.1)
42-
*** \033[36mHALF-ASSED ONE PLUS ONE TOOLKIT v1.0 BETA \033[34m***
42+
   print ("\033[41m\033[37;1m#~~~~~~~~I   7~~~~~~~~~~I         7~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#\033[0m")
43-
******************** \033[35mby vvn \033[34m*********************
43+
   time.sleep(0.2)
44-
************* \033[32mUSE AT YOUR OWN RISK! \033[34m*************
44+
   print ("\033[41m\033[37;1m#~~~~~~~~I   7~~~~~~~~~~~~~~~~I   7~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#\033[0m")
45-
********** \033[37msupport my work: buy my EP! \033[34m**********
45+
   time.sleep(0.2)
46-
********* \033[37mhttp://dreamcorp.bandcamp.com \033[34m*********
46+
   print ("\033[41m\033[37;1m#~~~~~~~~I   7~~~~~~~~~~~~~~~~I   7~~~~~~~~~~~~~~~I   7~~~~~~~~~#\033[0m")
47-
*************************************************\033[0m\n''')
47+
   time.sleep(0.2)
48
   print ("\033[41m\033[37;1m#~~~~~~~~I   7~~~~~~~~~~~~~~~~I   7~~~~~~~~~~~~~~~I   7~~~~~~~~~#\033[0m")
49
   time.sleep(0.2)
50
   print ("\033[41m\033[37;1m#~~~~~~~~I   7~~~~~~~~~~~~~~~~I   7~~~~~~~~~~~~~~~I   7~~~~~~~~~#\033[0m")
51
   time.sleep(0.1)
52
   print ("\033[41m\033[37;1m#~~~~~~~~I   7~~~~~~~~~~~~~~~~I   7~~~~~~~~~~~~~~~I   7~~~~~~~~~#\033[0m")
53-
-\033[31m[2]\033[37m wipe device\033[0m
53+
   time.sleep(0.1)
54
   print ("\033[41m\033[37;1m#~~~~~~~~I   7~~~~~~~~~~~~~~~~I   7~~~~~~~~~~~~~~~I   7~~~~~~~~~#\033[0m")
55
   time.sleep(0.1)
56
   print ("\033[41m\033[37;1m#~~~~~~~~I   7~~~~~~~~~~~~~~~~I   7~~~~~~~~~~~~~~~I   7~~~~~~~~~#\033[0m")
57
   time.sleep(0.1)
58
   print ("\033[41m\033[37;1m#~~~~~~~~I   7~~~~~~~~~~I               7~~~~~~~~~I   7~~~~~~~~~#\033[0m")
59
   time.sleep(0.1)
60
   print ("\033[41m\033[37;1m#~~~~~~~~I   7~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~I   7~~~~~~~~~#\033[0m")
61
   time.sleep(0.1)
62
   print ("\033[41m\033[37;1m#~~~~~~~~I   7~~~~ SUPPORT MY WORK! BUY MY EP! ~~~I   7~~~~~~~~~#\033[0m")
63
   time.sleep(0.1)
64
   print ("\033[41m\033[37;1m#~~~~~~~~I   7~~ http://dreamcorp.bandcamp.com ~~~I   7~~~~~~~~~#\033[0m")
65
   time.sleep(0.1)
66
   print ("\033[41m\033[37;1m#~~~~~~~~I   7~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~I   7~~~~~~~~~#\033[0m")
67
   time.sleep(0.1)
68
   print ("\033[41m\033[37;1m#~~~~~~~~I                                            7~~~~~~~~~#\033[0m")
69
   time.sleep(0.1)
70
   print ("\033[41m\033[37;1m#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#\033[0m")
71
   time.sleep(0.1)
72
   print ("\033[41m\033[37;1m#~~~~~~~~~~~~~~~~~~~~~~~~~ \033[40m\033[35;1mAUTHOR: VVN \033[41m\033[37;1m~~~~~~~~~~~~~~~~~~~~~~~~~#\033[0m")
73
   time.sleep(0.1)
74
   print ("\033[41m\033[37;1m#~~~~~~~~~~~~~~~~ \033[40m\033[36;1mRELEASE DATE: AUGUST 26, 2014 \033[41m\033[37;1m~~~~~~~~~~~~~~~~#\033[0m")
75
   time.sleep(0.1)
76
   print ("\033[41m\033[37;1m#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#\033[0m")
77
   time.sleep(0.1)
78
   print ("\033[41m\033[37;1m#################################################################\033[0m")
79
   time.sleep(4.5)
80
   print("\n\n")
81
82
def main():
83
   """menu output user input"""
84
   quotes = [
85
   '\nvvn@notworth.it\n'
86
      ]
87-
         if checkdev is not None:
87+
   print ('''
88-
            print("adb get-status: " + str(checkdev) + "\n")
88+
\033[40m\033[34m***********************************************************\033[0m 
89
\033[40m\033[34m************ \033[36mTHE HALF-ASSED ONEPLUS ONE TOOLKIT \033[34m***********\033[0m
90
\033[40m\033[34m*************** \033[37mVERSION: 1.3b BETA \033[34m* \033[35mby vvn \033[34m***************\033[0m
91
\033[40m\033[34m***********************************************************\033[0m
92
\033[40m\033[34m*** \033[33mthis is a FREE program, released AS-IS: NO WARRANTY \033[34m***\033[0m
93-
         elif listdev >= 0:
93+
\033[40m\033[34m****************** \033[32mUSE AT YOUR OWN RISK! \033[34m******************\033[0m
94-
            print("adb devices: " + str(listdev) + "\n")
94+
\033[40m\033[34m***********************************************************\033[0m 
95
\033[40m\033[34m*************** \033[37msupport my work: buy my EP! \033[34m***************\033[0m
96
\033[40m\033[34m************** \033[37mhttp://dreamcorp.bandcamp.com \033[34m**************\033[0m
97
\033[40m\033[34m***********************************************************\033[0m \n''')
98
99-
         elif listdev == 0 and fastdev is not None:
99+
100-
            print("adb devices: " + str(listdev) + "\n")
100+
101
   print ('''\033[32mMAIN MENU:\033[0m
102
-\033[31m[1]\033[37m reboot into android, bootloader, or recovery\033[0m
103
-\033[31m[2]\033[37m wipe device or flash partitions\033[0m
104
-\033[31m[3]\033[37m boot once into custom recovery without flashing\033[0m
105
-\033[31m[4]\033[37m install or uninstall APK\033[0m
106
-\033[31m[5]\033[37m copy files between computer and device, or sync\033[0m
107-
         elif [[ len(str(fastdev)) > 5 | fastdev > 0 ]] and fastdev is not None:
107+
108-
            print("fastboot devices: " + str(fastdev) + "\n")
108+
109
-\033[31m[8]\033[37m unlock bootloader and/or flash custom image\033[0m
110
-\033[31m[9]\033[37m run shell command on device\033[0m
111
-\033[31m[0]\033[37m quit \033[0m\n''')
112
113
   global option
114
   option = raw_input('Select an option 0-9 --> ')
115
   
116
   while not re.search(r'^[0-9]$', option):
117
      option = raw_input('Invalid selection. Please select an option 0-9 --> ')
118
 
119
   if option:
120
121
      obj = pyADB()
122-
               obj.reboot(rtype)
122+
123
      if option == '1': #reboot      
124
         rboption = raw_input("please enter 1 to reboot into android. enter 2 to reboot to bootloader. enter 3 to reboot to recovery. --> ")
125
         while not re.search(r'^[123]$', rboption):
126
            rboption = raw_input("invalid selection. please enter 1 to reboot into android, 2 for bootloader, and 3 for recovery. --> ")
127
         rbtype = "android"
128
         if rboption == '1':
129
            rbtype = "android"
130
         elif rboption == '2':
131
            rbtype = "bootloader"
132
         elif rboption == '3':
133
            rbtype ="recovery"
134
         checkdev = obj.get_state()
135
         listdev = obj.attached_devices()
136
         fastdev = obj.fastboot_devices()
137
         if "device" in str(checkdev) and listdev is not None and "fastboot" not in str(fastdev):
138
            print("rebooting via ADB..\n")
139
            obj.reboot(rbtype)
140
            time.sleep(0.9)
141
            main()
142
         elif "unknown" in str(checkdev) and "fastboot" in str(fastdev):
143
            print("rebooting via fastboot..\n")
144
            if rboption == '3':
145
               rbtype = "bootloader"
146
            obj.fastreboot(rbtype)
147
            time.sleep(0.9)
148
            main()
149
         elif "unknown" in str(checkdev) and listdev is not None and "device" in str(fastdev):
150
            print("rebooting via ADB..\n")
151
            obj.reboot(rbtype)
152
            time.sleep(0.9)
153
            main()
154
         elif "recovery" in [str(fastdev), str(listdev)] and checkdev is not None:
155
            print("rebooting via ADB...\n")
156
            obj.reboot(rbtype)
157
            time.sleep(0.9)
158
            main()
159
         elif "unknown" in str(checkdev) and fastdev is not None and listdev is None:
160
            print("rebooting via fastboot...\n")
161
            if rboption == '3':
162
               rbtype = "bootloader"
163
            obj.fastreboot(rbtype)
164
            time.sleep(0.9)
165
            main()
166
         elif "unknown" in str(checkdev) and "unauthorized" in str(listdev):
167
            raw_input("verify that DEVICE IS UNLOCKED and COMPUTER IS AUTHORIZED FOR ADB ACCESS, then press ENTER.")
168
            print("rebooting via ADB...\n")
169
            obj.reboot(rbtype)
170
            time.sleep(0.9)
171
            main()
172
         elif "unknown" in str(checkdev) and listdev is not None and fastdev is None:
173
            raw_input("device appears to be in recovery mode. reboot from recovery menu, then press ENTER.")
174
            checkstate = obj.get_state()
175
            if "device" in str(checkstate):
176
               obj.reboot(rbtype)
177
            time.sleep(0.9)
178
            main()
179
         else:
180
            print("rebooting via fastboot....\n")
181
            if rboption == '3':
182
               rbtype = "bootloader"
183
            fastreboot = obj.fastreboot(rbtype)
184
            if not fastreboot:
185
               print("rebooting via ADB after fastboot... \n")
186
               obj.reboot(rbtype)
187
               if "error" in str(fastreboot):
188
                  print("rebooting via fastboot second time...\n")
189
                  obj.fastreboot(rbtype)
190
            time.sleep(0.9)
191
            main()
192
193
      elif option == '2': #wipe
194
         print("\033[35m***WIPING SOME PARTITIONS WILL ERASE YOUR DATA.***\n please make sure to back up any important data before proceeding!\n\n")
195
         print('''\033[36mCHOOSE AN OPTION 1-8:\033[32m\n
196
   [1]\033[37m perform a full system wipe [system, data, and cache partitions]\033[32m
197
   [2]\033[37m wipe only the system partition\033[32m
198
   [3]\033[37m wipe only the data partition\033[32m
199
   [4]\033[37m wipe only the cache partition\033[32m
200
   [5]\033[37m wipe only the boot partition\033[32m
201
   [6]\033[37m wipe only the recovery partition\033[32m
202
   [7]\033[37m flash device to factory images [flash system, boot, and recovery]\033[32m
203
   [8]\033[37m return to main menu\n\n\033[0m''')
204
         confirmwipe = raw_input("please enter an option 1-8 --> ")
205
         while not re.search(r'^[1-8]$', confirmwipe):
206
            confirmwipe = raw_input('not a valid option. please enter a selection between 1-8 from above choices -->')         
207
         if confirmwipe == '1':
208
            obj.wipe('all')
209-
            os.mkdirs('apps')
209+
210
            time.sleep(0.9)
211
            main()
212
         elif confirmwipe == '2':
213
            obj.wipe('system')
214
            raw_input("press ENTER to continue.")
215
            time.sleep(0.9)
216
            main()
217
         elif confirmwipe == '3':
218
            obj.wipe('data')
219
            raw_input("press ENTER to continue.")
220
            time.sleep(0.9)
221
            main()
222
         elif confirmwipe == '4':
223
            obj.wipe('cache')
224-
            getunapk = raw_input("place the APK file you wish to uninstall in the \"apps\" subdirectory, then enter filename --> ")
224+
225-
            unapkfile = os.path.join('apps', getunapk)
225+
226-
            while not os.path.isfile(unapkfile):
226+
227
         elif confirmwipe == '5':
228-
               getunapk = raw_input("enter valid filename for the APK you want to uninstall -->")
228+
229-
               unapkfile = os.path.join('apps', getunapk)
229+
230
            time.sleep(0.9)
231
            main()
232
         elif confirmwipe == '6':
233-
            keepargs = "no"
233+
234
            raw_input("press ENTER to continue.")
235
            time.sleep(0.9)
236-
            print("uninstalling \033[36m" + getunapk + "\033[0m...")
236+
237-
            obj.uninstall(unapkfile, keepargs)
237+
238-
            uninstcmd = "pm uninstall -k " + unapkfile
238+
239
            raw_input("press ENTER to continue.")
240
            time.sleep(0.9)
241
            main()
242
         elif confirmwipe == '8':
243
            time.sleep(0.9)
244
            main()
245
         else:
246
            print("there was a problem connecting to the device. returning to menu..\n")
247
            time.sleep(0.9)
248
            main()
249
            
250
                          
251
      elif option == '3': #boot custom recovery
252-
      elif option == '5': #copy
252+
253
         while not re.search(r'^[1-3]$', recovery):
254
            recovery = raw_input("invalid selection. please choose 1 for TWRP, 2 for CWM, or 3 for Philz --> ")
255
         def dlrecov(recovfile):
256
            dlfile = "http://notworth.it/opo/" + recovfile
257-
         while not re.search(r'^[(?i)T|(?i)F|(?i)S]$', copytype):
257+
            dl = urllib.URLopener()
258
            dl.retrieve(dlfile, recovfile)
259
            site = urllib.urlopen(dlfile)
260
            meta = site.info()
261-
            getpushfile = raw_input("please enter relative path for the file or directory on your computer to copy --> ")
261+
            dlsize = meta.getheaders("Content-Length")[0]
262
            fsize = os.path.getsize(recovfile)
263
            print("file size: \033[33m")
264
            print(dlsize)
265
            print("\n\033[0mbytes downloaded: \033[33m")
266
            print(fsize)
267
            print("\033[0m\n")
268
         obj.reboot("bootloader")
269
         if recovery == '1':
270-
            getpulllocal = raw_input("please enter destination path for copied file(s) on your computer --> ")
270+
            recovfile = "twrp.img"
271
            while not os.path.isfile(recovfile):
272-
               os.mkdirs(getpulllocal)
272+
               print("file \033[32mtwrp.img \033[0mnot found. attempting download...\n")
273-
            obj.pull(getpullfile, getpulllocal)
273+
               dlrecov(recovfile)
274
            print("file \033[32mtwrp.img \033[0mfound!\n")
275
            raw_input("press ENTER to continue booting into TWRP..")
276
            obj.bootimg("twrp.img")
277
         elif recovery == '2':
278
            recovfile = "cwm.img"
279
            while not os.path.isfile(recovfile):
280
               print("file \033[32mcwm.img \033[0mnot found. attempting download...\n")
281-
               syncdir = raw_input("please enter path to the local directory you wish to sync --> ")
281+
               dlrecov(recovfile)
282
            print("file \033[32mcwm.img \033[0mfound!\n")
283-
                  syncdir = raw_input("the directory you entered does not exist. please enter valid path --> ")
283+
            raw_input("press ENTER to continue booting into ClockworkMod Recovery..")
284
            obj.bootimg("cwm.img")
285
         elif recovery == '3':
286
            recovfile = "philz.img"
287
            while not os.path.isfile(recovfile):
288
               print("file \033[32mphilz.img \033[0mnot found. attempting download...\n")
289
               dlrecov(recovfile)
290
            print("file \033[32mphilz.img \033[0mfound!\n")
291
            raw_input("press ENTER to continue booting into Philz Recovery..")
292
            obj.bootimg("philz.img")
293
         else:
294
            print("unable to connect to device.\n")    
295
            
296
         raw_input("press ENTER to return to main menu..")
297
         time.sleep(0.9)
298
         main()
299
300
      elif option == '4': #install or uninstall APK
301
         whichinstall = raw_input("please enter 1 to install, 2 to uninstall, or 3 to return to main menu. --> ")
302
         while not re.search(r'^[1-3]$', whichinstall):
303
            whichinstall = raw_input("invalid selection. please enter 1 to install, 2 to uninstall, or 3 to return to main menu. --> ")
304
         if not os.path.exists('apps'):
305
            os.makedirs('apps')
306-
            restorefile = raw_input("please enter path to backup file on your computer --> ")
306+
307
            getapk = raw_input("place the APK file to install in the \"apps\" subdirectory, then type the filename --> ")
308
            apkfile = os.path.join('apps', getapk)
309
            while not os.path.isfile(apkfile):
310
               print("\033[37mfile does not exist. please make sure the APK file is in the \"apps\" subdirectory.\033[0m\n")
311
               getapk = raw_input("enter valid filename for the APK you want to install -->")
312
               apkfile = os.path.join('apps', getapk)
313
            print("installing \033[36m" + getapk + "\033[0m...")
314
            obj.install(apkfile)
315-
         def suroot():
315+
316-
            superSU = 'UPDATE-SuperSU-v2.01.zip'
316+
317-
            remotesuperSU = '/sdcard/UPDATE-SuperSU-v2.01.zip'
317+
318
            
319
         if whichinstall == '2':
320
            getunapk = raw_input("please enter the complete path for the app you wish to uninstall --> ")
321
            keepcheck = raw_input("would you like to keep your app data? Y or N --> ")
322-
            print("on device, choose INSTALL from TWRP menu, then select file \033[36m" + superSU + "\033[0m in the \033[36m/sdcard\033[0m directory.\n")
322+
323-
            raw_input("if install is successful, select REBOOT from TWRP menu on device. press ENTER to continue.")
323+
324
            keepargs = "erase"
325-
         def towroot():
325+
            uninstcmd = "pm uninstall " + getunapk
326-
            obj.install("apps/tr.apk")
326+
327
               keepargs = "keep"
328
               uninstcmd = "pm uninstall -k " + getunapk
329
            print("uninstalling \033[36m" + getunapk + "\033[0m...\n")
330
            obj.uninstall(getunapk, keepargs)
331-
         print("\033[32mhowever, superSU is a much safer and more widely confirmed root method for the oneplus one. ATTEMPT AT YOUR OWN RISK!\033[0m\n\n")
331+
332-
         rootcheck = raw_input("which root method would you like to try? enter 1 for towelroot or 2 for superSU [recommended for oneplus one]. --> ")
332+
333-
         while not re.search(r'^[12]$', rootcheck):
333+
334-
            rootcheck = raw_input("invalid selection. enter 1 to install towelroot exploit, or 2 to install superSU package. --> ")
334+
335-
         if rootcheck == '1':
335+
336
         if whichinstall == '3':
337
            main()
338-
            if trysuroot == '1':
338+
339-
               suroot()
339+
340
            print("could not connect to device.\n")
341
            time.sleep(0.9)
342
            main()
343
344
      elif option == '5': #copy and/or sync between computer and device
345-
         elif rootcheck == '2':
345+
346-
            bootcustom = raw_input("press 1 to install superSU in TWRP recovery, or 2 to install in fastboot [lower success rate]. --> ")
346+
347
         matchF = re.search(r'(?i)F', copytype)
348-
               bootcustom = raw_input("invalid choice. please enter 1 to load TWRP or 2 for fastboot. --> ")
348+
349
         while not re.search(r'^[FfSsTt]$', copytype):
350-
               suroot()
350+
351
            
352
         if matchT:
353
            getpushfile = raw_input("please enter the file or directory you wish to copy as the RELATIVE path from the script location --> ")
354
            while not os.path.exists(getpushfile):
355
               getpushfile = raw_input("file does not exist. please enter valid path --> ")
356
            getpushremote = raw_input("please enter destination path for copied file(s) on the device --> ")
357
            obj.push(getpushfile, getpushremote)
358
            raw_input("file copy complete. press ENTER to continue...")
359
            
360-
                     raw_input("\033[32mmake sure your computer is authorized to access your device over ADB, then press ENTER.\033[0m")
360+
361
            getpullfile = raw_input("please enter path for the file or directory on your device to copy --> ")
362
            getpulllocal = raw_input("please enter the copy destination folder as a RELATIVE path from the script location --> ")
363-
                     obj.sideload("UPDATE-SuperSU-v2.01.zip")
363+
364-
                     superfail = raw_input("if update successful, choose REBOOT SYSTEM from device menu then press ENTER key. else, press 1 to install superSU from TWRP -->" )
364+
               print("copy destination \033[35m" + getpulllocal + " \033[0mdoes not exist! creating new directory...")
365
               os.makedirs(getpulllocal)
366-
                        suroot()
366+
            # obj.pull(getpullfile, getpulllocal)
367
            def getprogress(n):
368
               tenths = n/10
369
               for i in range(n):
370
                  obj.pull(getpullfile, getpulllocal)
371
                  if i%tenths == 0:
372
                     print(str(i) + "% ")
373
                     sys.stdout.flush()
374
               print("\n\033[0m ..TRANSFER COMPLETE!")
375
            print("transferring files... \033[37m"),
376
            sys.stdout.flush()
377
            getprogress(100)
378
            print("\033[32mfile\(s\) in destination directory:\n\033[0m")
379
            for fn in next(os.walk(getpulllocal))[2]:
380
               fullpath = os.path.join(getpulllocal, fn)
381
               print(fullpath)
382
            raw_input("file copy complete. press ENTER to continue...")
383
            
384
         elif matchS:
385
            syncargs = raw_input("enter 1 to set sync directory, or 2 to sync the default system and data directories. --> ")
386
            while not re.search(r'^[12]$', syncargs):
387
               syncargs = raw_input("invalid selection. please enter 1 to set sync directory, or 2 to use default. --> ")
388
            if syncargs == '1':
389
               syncdir = raw_input("please enter relative path for local directory to sync device with --> ")
390
               while not os.path.exists(syncdir):
391-
            print ('''\n\033[35mSTOCK IMAGES AVAILABLE TO FLASH - THIS WILL REPLACE YOUR CURRENT PARTITION!\n
391+
                  print("the path you entered does not exist. would you like to create " + syncdir + " as a new directory?\n")
392-
\033[36m***IF POSSIBLE, FLASH IN SEQUENTIAL ORDER - BOOT.IMG SHOULD GO FIRST***\n
392+
                  crsyncdir = raw_input("enter 1 to create new directory or 2 to enter another location. --> ")
393-
\033[33mLATEST UPDATE XNPH30O SELECTIONS IN YELLOW\n\033[0m
393+
                  while not re.search(r'^[12]$', crsyncdir):
394-
-\033[31m[1]\033[37m XNPH25R stock BOOT.IMG \033[0m
394+
                     crsyncdir = raw_input("invalid selection. please enter 1 to create directory, or 2 to enter another location. --> ")
395
                  if crsyncdir == '1':
396
                     os.makedirs(syncdir, 0755)
397
                  else:
398
                     syncdir = raw_input("please enter relative path for local directory to sync device with --> ")
399
               obj.sync(syncdir)
400-
-\033[31m[7]\033[33m XNPH30O stock radio, modem, sbl1, aboot \033[34m[flash-extras.sh]\033[0m
400+
401-
-\033[31m[8]\033[33m XNPH30O stock OTA UPDATE #1 \033[0m
401+
402-
-\033[31m[9]\033[33m XNPH30O stock OTA UPDATE #2 - FLASH UPDATE #1 FIRST! \033[0m
402+
403-
-\033[31m[0]\033[37m quit\033[0m\n''')
403+
404
            else:
405-
            flashsel = raw_input("\033[32mselect a choice between 0 through 9 from menu \033[0m--> ")
405+
406
         
407
         else:
408-
            print("\n\033[34mrebooting into bootloader...\033[0m\n")
408+
409
            
410
         time.sleep(0.9)
411
         main()
412-
               obj.flashf("boot", "XNPH25R/boot.img")
412+
413
      elif option == '6': #backup
414
         whichbackup = raw_input("to backup, enter 1. to restore, enter 2 --> ")
415
         while not re.search(r'^[12]$', whichbackup):
416
            whichbackup = raw_input("invalid selection. please enter 1 to backup or 2 to restore. --> ")
417
         if whichbackup == '1':
418
            backupfile = 'backup-' + str(datetime.date.today()) + '.ab'
419
            obj.backup(backupfile)
420
         elif whichbackup == '2':
421
            restorefile = raw_input("please enter path to backup file on your computer [ex. \'backup-yyyy-mm-dd.ab\'] --> ")
422
            while not os.path.isfile(restorefile):
423
               restorefile = raw_input("file does not exist. please enter valid path --> ")
424
            obj.restore(restorefile)
425
         time.sleep(0.9)
426
         main()
427
428
      elif option == '7': #root
429
      
430
         def twrpdl(): # DOWNLOAD TWRP CUSTOM RECOVERY
431
            TWRPurl = "http://notworth.it/opo/twrp.img"
432
            dl = urllib.URLopener()
433
            dl.retrieve(TWRPurl, "twrp.img")
434
            site = urllib.urlopen(TWRPurl)
435
            meta = site.info()
436
            dlsize = meta.getheaders("Content-Length")[0]
437
            fsize = os.path.getsize("twrp.img")
438
            print("file size: \033[33m")
439
            print(dlsize)
440
            print("\n\033[0mbytes downloaded: \033[33m")
441
            print(fsize)
442
            print("\033[0m\n")
443-
               subprocess.check_call(["./flash-radio.sh"], cwd="/XNPH25R")
443+
444
         def recovdl(recovimg): # DOWNLOAD IMAGE FROM SITE
445
            recovurl = "http://notworth.it/opo/" + recovimg
446
            dl = urllib.URLopener()
447-
               subprocess.check_call(["./flash-extras.sh"], cwd="/XNPH30O")
447+
            dl.retrieve(recovurl, recovimg)
448
            site = urllib.urlopen(recovurl)
449
            meta = site.info()
450
            dlsize = meta.getheaders("Content-Length")[0]
451-
               obj.update("XNPH30O/XNPH30O-update1-signed.zip")
451+
            fsize = os.path.getsize(recovimg)
452-
               failupd = raw_input("if update failed, press 1 to try sideload option. otherwise, press ENTER key to continue...")
452+
            print("file size: \033[33m")
453-
               if failupd == '1':
453+
            print(dlsize)
454
            print("\n\033[0mbytes downloaded: \033[33m")
455-
                  raw_input("make sure your device is unlocked and your PC is authenticated for ADB access. press ENTER to continue.")
455+
            print(fsize)
456-
                  print("\033[32mpushing first XNPH30O OTA update file to device..\033[0m\n")
456+
            print("\033[0m\n")
457-
                  obj.push("XNPH30O/XNPH30O-update1-signed.zip", "/sdcard/XNPH30O-update1-signed.zip")
457+
458
         def chooserec(): # CHOOSE WHICH CUSTOM RECOVERY TO BOOT INTO ONCE
459
            recovimg = "twrp.img"
460-
                  print("choose APPLY UPDATE from recovery menu and select APPLY FROM ADB.\n\n")
460+
            pickrecov = raw_input("press 1 to flash superSU in TWRP Recovery, 2 to use Philz Recovery, or 3 to use CWM. --> ")
461-
                  raw_input("press ENTER to install the *first* XNPH30O OTA update now.")
461+
            while not re.search(r'^[123]$', pickrecov):
462-
                  obj.sideload("XNPH30O/XNPH30O-update1-signed.zip")
462+
               pickrecov = raw_input("invalid selection. press 1 to flash superSU in TWRP Recovery, 2 for Philz, or 3 for CWM. --> ")
463-
                  failside = raw_input("if update did not succeed, press 1 to install from device. otherwise, press ENTER to continue..")
463+
            if pickrecov == '1': # SUPERSU TWRP
464
               recovimg = "twrp.img"
465
            elif pickrecov == '2': # SUPERSU PHILZ
466-
                     print("select XNPH30O-update1-signed.zip from root of SDCARD directory and install file.\n\n")
466+
               recovimg = "philz.img"
467
            elif pickrecov == '3': # SUPERSU CWM
468-
                     menusel = raw_input("press 1 if update was successful, or 2 to return to main menu.")
468+
               recovimg = "cwm.img"
469
            else:
470-
                        menusel = raw_input("invalid selection. press 1 for flash menu, or 2 to return to main menu.")
470+
               print("unable to connect to device. returning to main menu..\n")
471
            return recovimg
472-
                        obj.shell("rm -rf /sdcard/XNPH30O-update1-signed.zip")
472+
473
         superSU = 'UPDATE-SuperSU-v2.02.zip'
474
         def sudl(): # DOWNLOAD SUPERSU ZIP
475
            URLsuperSU = "http://download.chainfire.eu/452/SuperSU/UPDATE-SuperSU-v2.02.zip?retrieve_file=1"
476
            
477
            dl = urllib.URLopener()
478
            dl.retrieve(URLsuperSU, superSU)
479
           
480
            site = urllib.urlopen(URLsuperSU)
481
            meta = site.info()
482
            dlsize = meta.getheaders("Content-Length")[0]
483-
                     obj.shell("rm -rf /sdcard/XNPH30O-update1-signed.zip")
483+
            fsize = os.path.getsize(superSU)
484
            print("file size: \033[33m")
485
            print(dlsize)
486
            print("\n\033[0mbytes downloaded: \033[33m")
487
            print(fsize)
488
            print("\033[0m\n")
489
            if dlsize != fsize:
490
               with open(superSU, "r+b") as f:
491
                  f.write(site.read())
492-
               obj.update("XNPH30O/XNPH30O-update2-signed.zip")
492+
                  f.flush()
493-
               failupd = raw_input("if update failed, press 1. otherwise, press ENTER key to continue. --> ")
493+
                  os.fsync(f.fileno())
494-
               if failupd == '1':
494+
                  f.close()
495
            
496-
                  obj.push("XNPH30O/XNPH30O-update2-signed.zip", "/sdcard/XNPH30O-update2-signed.zip")
496+
         def suroot(recovimg):
497-
                  time.sleep(2.5)
497+
            while not os.path.isfile(superSU):
498-
                  print("\033[34mrebooting into recovery...\n\033[0m")
498+
               print("file \033[32m" + superSU + " \033[0mnot found. attempting download...\n")
499
               sudl()
500-
                  print("choose APPLY UPDATE from recovery menu and select APPLY FROM ADB.\n\n")
500+
            print("file \033[32m" + superSU + " \033[0mfound!\n")
501-
                  raw_input("press ENTER to install the *second* XNPH30O OTA update now.")
501+
            while not os.path.isfile(recovimg):
502-
                  obj.sideload("XNPH30O/XNPH30O-update2-signed.zip")
502+
               print("file \033[32m" + recovimg + " \033[0mnot found. attempting download...\n")
503-
                  failside = raw_input("if update failed, press 1 to update from device storage. otherwise, press ENTER to continue. --> ")
503+
               recovdl(recovimg)
504
            print("file \033[32m" + recovimg + " \033[0mfound!\n")
505
            raw_input("press ENTER to copy file to device, then reboot into bootloader.")
506-
                     print("select XNPH30O-update2-signed.zip from root of SDCARD directory and install file.\n\n")
506+
            remotesuperSU = '/sdcard/UPDATE-SuperSU-v2.02.zip'
507-
                     print("\033[35mif update fails again, return to main menu and reboot into custom recovery.\033[0m\n\n")
507+
508-
                     menusel = raw_input("press 1 to return to flash menu, or 2 to return to main menu. --> ")
508+
509
            raw_input("press ENTER to boot into custom recovery.")
510-
                        menusel = raw_input("invalid selection. press 1 for flash menu, or 2 to return to main menu. --> ")
510+
            obj.bootimg(recovimg)
511
            print("check that device is connected and booted into custom recovery. on device, choose the ADB SIDELOAD option [sometimes under ADVANCED].\n")
512
            raw_input("press ENTER to continue with flashing superSU file via ADB sideload.")
513
            obj.sideload(superSU)
514
            sidefail = raw_input("if install failed, press 1 to attempt install from device. else, reboot into system from device recovery menu and press ENTER. --> ")
515
            if sidefail == '1':
516
               print("on device recovery menu, choose INSTALL, then select file \033[36m" + superSU + "\033[0m from the \033[36m/SDCARD\033[0m root directory.\n")
517
               raw_input("swipe to install - this may take a moment. if install is successful, select REBOOT from recovery menu. press ENTER to continue.")
518
            obj.reboot("android")
519
         
520
         superusr = 'Superuser-3.1.3-arm-signed.zip'
521
         def susrdl():  # DOWNLOAD SUPERUSER ZIP
522-
                     obj.shell("rm -rf /sdcard/XNPH30O-update2-signed.zip")
522+
            URLsuperusr = "http://notworth.it/opo/Superuser-3.1.3-arm-signed.zip"
523
            dl = urllib.URLopener()
524
            dl.retrieve(URLsuperusr, superusr)
525
            site = urllib.urlopen(URLsupusr)
526
            meta = site.info()
527
            dlsize = meta.getheaders("Content-Length")[0]
528
            fsize = os.path.getsize(superusr)
529
            print("file size: \033[33m")
530
            print(dlsize)
531
            print("\n\033[0mbytes downloaded: \033[33m")
532
            print(fsize)
533
            print("\033[0m\n")
534
            
535
         def susrroot(recovimg): # FLASH SUPERUSER ZIP IN CUSTOM RECOVERY
536
            while not os.path.isfile(superusr):
537
               print("file \033[32m" + superusr + " \033[0mnot found. attempting download...\n")
538-
            flashcont = raw_input("select 1 to continue flashing recovery. select 2 to flash a stock partition image. select 3 to return to flash menu. --> ")
538+
               susrdl()
539
            print("file \033[32m" + superusr + " \033[0mfound!\n")
540
            while not os.path.isfile(recovimg):
541
               print("file \033[32m" + recovimg + " \033[0mnot found. attempting download...\n")
542
               recovdl(recovimg)
543
            print("file \033[32m" + recovimg + " \033[0mfound!\n")
544
            raw_input("press ENTER to copy file to device and reboot into bootloader.")
545
            remotesuperusr = '/sdcard/Superuser-3.1.3-arm-signed.zip'
546
            obj.push(superusr, remotesuperusr)
547
            obj.reboot("bootloader")
548
            raw_input("press ENTER to boot into custom recovery.")
549
            obj.bootimg(recovimg)
550
            print("on device, choose INSTALL from recovery menu, then select file \033[36m" + superusr + "\033[0m in the \033[36m/sdcard\033[0m directory.\n")
551
            raw_input("if install is successful, select REBOOT from recovery menu on device. press ENTER to continue.")
552
         
553
         trfile = 'apps/tr.apk'
554
         def trdl(): # DOWNLOAD TOWELROOT APK
555
            dl = urllib.URLopener()
556
            dl.retrieve("https://towelroot.com/tr.apk", trfile)
557
            site = urllib.urlopen("https://towelroot.com/tr.apk")
558
            meta = site.info()
559
            dlsize = meta.getheaders("Content-Length")[0]
560
            fsize = os.path.getsize(trfile)
561
            print("file size: \033[33m")
562
            print(dlsize)
563
            print("\033[0m\nbytes downloaded: \033[33m")
564
            print(fsize)
565
            print("\033[0m\n")
566
            
567
         def towroot(): # INSTALL TOWELROOT APK
568
            if not os.path.exists('apps'):
569-
         print("\033[35mIF YOUR DEVICE HOLDS IMPORTANT DATA, BACK UP DEVICE BEFORE YOU CONTINUE!\033[0m\n")
569+
               os.makedirs('apps', 0755)
570
            while not os.path.isfile(trfile):
571-
         print("\033[32mif you are running XNPH30O or newer, YOUR RE-UNLOCK ATTEMPTS WILL FAIL. you must return to the previous menu and flash the XNPH25R images to your device.\033[0m\n")
571+
               print("file \033[32m" + trfile + " \033[0mnot found. attempting download...\n")
572-
         bunlock = raw_input("enter 1 to continue unlocking bootloader. enter 2 to skip to flashing custom recovery or images.\n enter 3 to re-lock bootloader. or enter 4 to return to menu. --> ")
572+
               trdl()
573
            print("file \033[32m" + trfile + " \033[0mfound!\n")
574-
            bunlock = raw_input("invalid selection. enter 1 to unlock bootloader and wipe device. enter 2 to skip to flashing custom recovery or images.\n enter 3 to re-lock bootloader. or enter 4 to return to menu. --> ")
574+
            raw_input("press ENTER to install..")
575
            obj.install(trfile)
576
            print("\033[36m\nif APK installed successfully, locate TR [towelroot] in app drawer on device and run.\n\033[0m")
577
            raw_input("tap on MAKE IT RAIN. the results should appear shortly. follow instructions on device, then press ENTER to continue..")
578
            
579
         print("\033[36mif the firmware release date for your device is before june 2014, there is a chance the towelroot exploit may work.\n")
580
         print("\033[35mhowever, superSU is a safer and more widely confirmed root method for the ONEPLUS ONE. ATTEMPT AT YOUR OWN RISK!\033[0m\n\n")
581
         rootcheck = raw_input("which root method would you like to try? enter 1 for towelroot or 2 for superSU [recommended for oneplus one], or 3 for Superuser. --> ")
582
         while not re.search(r'^[123]$', rootcheck):
583
            rootcheck = raw_input("invalid selection. enter 1 to install towelroot exploit, 2 to install superSU package, or 3 to install Superuser package. --> ")
584
         
585
         if rootcheck == '1': # TOWELROOT
586
            towroot()
587
            trysuroot = raw_input("if towelroot failed, press 1 to launch superSU method. otherwise, press ENTER to return to main menu. --> ")
588
            if trysuroot == '1': # SUPERSU
589
               recovimg = chooserec()
590
               suroot(recovimg) # SUPERSU CUSTOM RECOVERY
591
               time.sleep(0.9)
592
               main()
593
            else:
594
               time.sleep(0.9)
595
               main()
596
               
597
         elif rootcheck == '2': # SUPERSU
598
            bootcustom = raw_input("press 1 to install superSU in custom recovery, or 2 to install in fastboot [lower success rate]. --> ")
599
            while not re.search(r'^[12]$', bootcustom):
600
               bootcustom = raw_input("invalid choice. please enter 1 to load custom recovery or 2 for fastboot. --> ")
601
            if bootcustom == '1': # SUPERSU TWRP
602
               recovimg = chooserec()
603
               suroot(recovimg) # SUPERSU CUSTOM RECOVERY
604
               time.sleep(0.9)
605
               main()
606
            elif bootcustom == '2': # SUPERSU FASTBOOT
607
               updatewhich = raw_input("to try installing superSU in fastboot, press 1. else, enter name of ZIP file to install --> ")
608
               if updatewhich == '1': # SUPERSU FASTBOOT
609
                  while not os.path.isfile(superSU):
610
                     print("file \033[32m" + superSU + " \033[0mnot found. attempting download...\n\n")
611
                     sudl()
612
                  raw_input("press ENTER to reboot into bootloader.")
613
                  obj.reboot("bootloader")
614
                  print("\033[35mattempting to install superSU via fastboot...\n\033[0m")
615
                  obj.update(superSU)
616
                  failsu = raw_input("if installation failed, press 1 to try sideload method. otherwise, press ENTER to continue...")
617
                  if failsu == '1': # SUPERSU SIDELOAD
618
                     obj.fastreboot("android")
619
                     time.sleep(0.9)
620
                     print("\033[32mmake sure your computer is authorized to access your device over ADB.\033[0m\n")
621
                     raw_input("press ENTER to continue..")
622
                     obj.reboot("recovery")
623
                     raw_input("in recovery menu on device, please select APPLY UPDATE, then APPLY FROM ADB. press ENTER when ready.")
624
                     obj.sideload("UPDATE-SuperSU-v2.02.zip")
625
                     superfail = raw_input("choose REBOOT SYSTEM from device menu. if update successful, press ENTER. else, press 1 to install superSU from TWRP, or 2 to install superSU from Philz --> " )
626
                     ogj.reboot("android")
627
                     if superfail == '1': # SUPERSU TWRP
628
                        suroot("twrp.img")
629
                     elif superfail == '2': # SUPERSU PHILZ
630
                        suroot("philz.img")
631
                     else:
632
                        obj.get_state()
633
                  time.sleep(0.9)
634
                  main()
635
               else:
636
                  print("attempting to install " + updatewhich + "...\n\n")
637
                  while not os.path.isfile(updatewhich):
638
                     updatewhich = raw_input("invalid file path. please enter correct path of ZIP file to install --> ")
639
                  obj.update(updatewhich) # CUSTOM FASTBOOT UPDATE
640
                  failupd = raw_input("if installation failed, press 1 to try sideload method. otherwise, press ENTER to continue...")
641
                  if failupd == '1':
642
                     obj.fastreboot("android")
643
                     time.sleep(0.9)
644
                     print("\033[32mmake sure your computer is authorized to access your device over ADB.\033[0m\n")
645
                     raw_input("press ENTER to continue..")
646
                     obj.reboot("recovery")
647
                     raw_input("in recovery menu on device, please select APPLY UPDATE, then APPLY FROM ADB. press ENTER when ready.")
648
                     obj.sideload(updatewhich) # CUSTOM SIDELOAD
649
                     raw_input("please follow reboot prompts on device recovery menu, then press ENTER to continue...")
650
                  else:
651
                     obj.fastreboot("android")
652
                  time.sleep(0.9)
653
                  main()
654
            else:
655
               print("failed to connect to device. returning to main menu.. \n\n")
656
         
657
         elif rootcheck == '3': # SUPERUSER or CUSTOM ZIP FILE
658
            bootcustom = raw_input("press 1 to install Superuser in TWRP recovery, 2 to install in Philz recovery, or 3 to install in fastboot [lowest success rate]. --> ")
659
            while not re.search(r'^[123]$', bootcustom):
660
               bootcustom = raw_input("invalid choice. please enter 1 to load TWRP, 2 for Philz, or 3 for fastboot. --> ")
661
            if bootcustom == '1':
662
               susrroot("twrp.img")
663
            elif bootcustom == '2':
664
               susrroot("philz.img")
665
            elif bootcustom == '3':
666
               updatewhich = raw_input("to try installing Superuser in fastboot, press 1. else, enter name of ZIP file to install --> ")
667
               if updatewhich == '1':
668
                  while not os.path.isfile(superusr):
669
                     print("file \033[32m" + superusr + " \033[0mnot found. attempting download...\n\n")
670
                     sudl()
671
                  raw_input("press ENTER to reboot into bootloader.")
672
                  obj.reboot("bootloader")
673
                  print("\033[35mattempting to install Superuser via fastboot...\n\033[0m")
674
                  obj.update(superusr)
675
                  failsu = raw_input("if installation failed, press 1 to try sideload method. otherwise, press ENTER to continue...")
676
                  if failsu == '1':
677
                     obj.fastreboot("android")
678
                     time.sleep(0.9)
679
                     print("\033[32mmake sure your computer is authorized to access your device over ADB.\033[0m\n")
680
                     raw_input("press ENTER to continue..")
681
                     obj.reboot("recovery")
682
                     raw_input("in recovery menu on device, please select APPLY UPDATE, then APPLY FROM ADB. press ENTER when ready.")
683
                     obj.sideload(superusr)
684
                     superfail = raw_input("choose REBOOT SYSTEM from device menu. if update successful, press ENTER. else, press 1 to install Superuser via TWRP or 2 to install Superuser via Philz. --> " )
685
                     if superfail == '1':
686
                        susrroot("twrp.img")
687
                     elif superfail == '2':
688
                        susrroot("philz.img")
689
                     else:
690
                        obj.get_state()
691
                  time.sleep(0.9)
692
                  main()
693
                  
694
               else:
695
                  print("attempting to install " + updatewhich + "...\n\n")
696
                  while not os.path.isfile(updatewhich):
697
                     updatewhich = raw_input("invalid file path. please enter correct path of ZIP file to install --> ")
698
                  obj.update(updatewhich)
699
                  raw_input("please press ENTER to continue...")
700
            
701
            else:
702
               print("failed to connect to device. returning to main menu.. \n\n")
703
               
704
         else:
705
            print("failed to connect to device. returning to main menu.. \n\n")
706
                  
707
         time.sleep(0.9)
708
         main()
709
         
710
      elif option == '8': #flash stock images/partitions
711
      
712
         def flashmenu():
713
            print ('''\n\033[36mSTOCK IMAGES AVAILABLE TO FLASH - THIS WILL REPLACE YOUR CURRENT PARTITION!
714
\033[37mFLASH IN SEQUENTIAL ORDER IF POSSIBLE - BOOT.IMG SHOULD GO FIRST
715
\033[33;1m***LATEST UPDATE FILES IN YELLOW***\n\033[0m
716
-\033[31m[1]\033[37m XNPH25R stock BOOT.IMG \033[0m -or- \033[33m XNPH30O stock BOOT.IMG \033[0m
717
-\033[31m[2]\033[37m XNPH25R stock USERDATA(_64).IMG \033[35m[WIPES USER DATA!]\033[0m
718
-\033[31m[3]\033[37m XNPH25R stock SYSTEM.IMG \033[0m
719
-\033[31m[4]\033[37m XNPH25R stock RECOVERY.IMG \033[0m
720
-\033[31m[5]\033[37m XNPH25R stock CACHE.IMG \033[0m
721
-\033[31m[6]\033[37m XNPH25R stock radio, modem, aboot, & more \033[34m[flash-radio.sh]\033[0m
722
-\033[31m[7]\033[37m XNPH30O stock radio, modem, sbl1, aboot \033[34m[flash-extras.sh]\033[0m
723
-\033[31m[8]\033[33m XNPH30O stock OTA UPDATES #1 and #2 \033[0m-or- \033[33;1mXNPH33R stock OTA UPDATE\033[0m
724
-\033[31m[9]\033[37m FLASH ENTIRE STOCK OR CUSTOM ROM IMAGE \033[0m
725
-\033[31m[0]\033[37m return to main menu\033[0m\n
726
\033[35mCHECK THAT DEVICE IS UNLOCKED AND COMPUTER IS AUTHORIZED FOR ADB ACCESS.\n\033[0m''')
727
728
            flashsel = raw_input("\033[32mselect an option between 0 through 9 from menu \033[0m--> ")
729
            while not re.search(r'^[0-9]$', flashsel):
730
			   flashsel = raw_input("invalid selection. please choose an option between 0 through 9 --> ")
731
            
732
            def dlimg(imgfile):
733
               dlfile = "http://notworth.it/opo/" + imgfile
734
               dl = urllib.URLopener()
735
               dl.retrieve(dlfile, imgfile)
736
               site = urllib.urlopen(dlfile)
737
               meta = site.info()
738
               dlsize = meta.getheaders("Content-Length")[0]
739
               fsize = os.path.getsize(imgfile)
740
               print("file size: \033[33m")
741
               print(dlsize)
742
               print("\n\033[0mbytes downloaded: \033[33m")
743
               print(fsize)
744
               print("\033[0m\n")
745
            
746
            if re.search(r'^[1-7]$', flashsel):
747
               print("\n\033[34mrebooting into bootloader...\033[0m\n")
748
               obj.reboot("bootloader")
749
            
750
            if flashsel == '1':
751
               whichboot = raw_input("enter 1 to flash boot.img from XNPH25R. enter 2 for boot.img from XNPH30O. --> ")
752
               while not re.search(r'^[12]$', whichboot):
753
                  whichboot = raw_input("invalid selection. enter 1 for XNPH25R boot.img, or 2 for XNPH30O boot.img --> ")
754
               if whichboot == '1':
755
                  imgfile = "XNPH25R/boot.img"
756
                  while not os.path.isfile(imgfile):
757
                     if not os.path.exists('XNPH25R'):
758
                        os.makedirs('XNPH25R', 0755)
759
                     print("downloading XNPH25R/boot.img...\n")
760
                     dlimg(imgfile)
761
                  obj.flashf("boot", imgfile)
762
               elif whichboot == '2':
763
                  imgfile = "XNPH30O/boot.img"
764
                  while not os.path.isfile(imgfile):
765
                     if not os.path.exists('XNPH30O'):
766
                        os.makedirs('XNPH30O', 0755)
767
                     print("downloading XNPH30O/boot.img..\n")
768
                     dlimg(imgfile)
769
                  obj.flashf("boot", imgfile)
770
               else:
771
                  print("an error has occurred. returning to flash menu..\n")
772
                  flashmenu()
773
               raw_input("press ENTER key to continue...")
774
               flashmenu()
775
               
776
            elif flashsel == '2':
777
               whichsize = raw_input("IMPORTANT!! choose correct storage capacity: enter 1 for 16gb device, or 2 for 64gb device. --> ")
778
               while not re.search(r'^[12]$', whichsize):
779
                  whichsize = raw_input("invalid selection. enter 1 for 16gb device, or 2 for 64gb device. --> ")
780
               if whichsize == '1':
781
                  imgfile = "XNPH25R/userdata.img"
782
                  while not os.path.isfile(imgfile):
783
                     if not os.path.exists('XNPH25R'):
784
                        os.makedirs('XNPH25R', 0755)
785
                     print("downloading XNPH25R/userdata.img..\n")
786
                     dlimg(imgfile)
787
                  obj.flashf("userdata", "XNPH25R/userdata.img")
788
               elif whichsize == '2':
789
                  imgfile = "XNPH25R/userdata_64G.img"
790
                  while not os.path.isfile(imgfile):
791
                     if not os.path.exists('XNPH25R'):
792
                        os.makedirs('XNPH25R', 0755)
793
                     print("downloading XNPH25R/userdata_64G.img..\n")
794
                     dlimg(imgfile)
795
                  obj.flashf("userdata", "XNPH25R/userdata_64G.img")
796
               else:
797
                  print("ERROR: unable to connect to device.\n")   
798
               raw_input("press ENTER key to return to flash menu...")
799
               flashmenu()
800
               
801
            elif flashsel == '3':
802
               imgfile = "XNPH25R/system.img"
803
               while not os.path.isfile(imgfile):
804
                  if not os.path.exists('XNPH25R'):
805
                     os.makedirs('XNPH25R', 0755)
806
                  print("downloading XNPH25R/system.img..\n")
807
                  dlimg(imgfile)
808
               obj.flashf("system", "XNPH25R/system.img")
809
               raw_input("press ENTER key to continue...")
810
               flashmenu()
811
               
812
            elif flashsel == '4':
813
               imgfile = "XNPH25R/recovery.img"
814
               while not os.path.isfile(imgfile):
815
                  if not os.path.exists('XNPH25R'):
816
                     os.makedirs('XNPH25R', 0755)
817
                  print("downloading XNPH25R/recovery.img..\n")
818
                  dlimg(imgfile)
819
               obj.flashf("recovery", "XNPH25R/recovery.img")
820
               raw_input("press ENTER key to continue...")
821
               flashmenu()
822
               
823
            elif flashsel == '5':
824
               imgfile = "XNPH25R/cache.img"
825
               while not os.path.isfile(imgfile):
826
                  if not os.path.exists('XNPH25R'):
827
                     os.makedirs('XNPH25R', 0755)
828
                  print("downloading XNPH25R/cache.img..\n")
829
                  dlimg(imgfile)
830
               obj.flashf("cache", "XNPH25R/cache.img")
831
               raw_input("press ENTER key to continue...")
832
               flashmenu()
833
               
834
            elif flashsel == '6':
835
               if not os.path.exists('XNPH25R'):
836
                  os.makedirs('XNPH25R', 0755)
837
               imgfile = "XNPH25R/flash-radio.sh"
838
               while not os.path.isfile("XNPH25R/flash-radio.sh"):
839
                  print("downloading XNPH25R/flash-radio.sh..\n")
840
                  dlimg("XNPH25R/flash-radio.sh")
841
                  os.chmod("XNPH25R/flash-radio.sh", 0755)
842
               while not os.path.isfile("XNPH25R/boot.img"):
843
                  print("downloading XNPH25R/boot.img..\n")
844
                  dlimg("XNPH25R/boot.img")
845
               while not os.path.isfile("XNPH25R/emmc_appsboot.mbn"):
846
                  print("downloading XNPH25R/emmc_appsboot.mbn..\n")
847
                  dlimg("XNPH25R/emmc_appsboot.mbn")
848
               while not os.path.isfile("XNPH25R/NON-HLOS.bin"):
849
                  print("downloading XNPH25R/NON-HLOS.bin..\n")
850
                  dlimg("XNPH25R/NON-HLOS.bin")
851
               while not os.path.isfile("XNPH25R/rpm.mbn"):
852
                  print("downloading XNPH25R/rpm.mbn..\n")
853
                  dlimg("XNPH25R/rpm.mbn")
854
               while not os.path.isfile("XNPH25R/sbl1.mbn"):
855
                  print("downloading XNPH25R/sbl1.mbn..\n")
856
                  dlimg("XNPH25R/sbl1.mbn")
857
               while not os.path.isfile("XNPH25R/sdi.mbn"):
858
                  print("downloading XNPH25R/sdi.mbn..\n")
859
                  dlimg("XNPH25R/sdi.mbn")
860
               while not os.path.isfile("XNPH25R/tz.mbn"):
861
                  print("downloading XNPH25R/tz.mbn..\n")
862
                  dlimg("XNPH25R/tz.mbn")
863
               while not os.path.isfile("XNPH25R/logo.bin"):
864
                  print("downloading XNPH25R/logo.bin..\n")
865
                  dlimg("XNPH25R/logo.bin")
866
               subprocess.call(['./flash-radio.sh'], cwd='XNPH25R', shell=True)
867
               raw_input("press ENTER key to continue...")
868
               flashmenu()
869
               
870
            elif flashsel == '7':
871
               if not os.path.exists('XNPH30O'):
872
                  os.makedirs('XNPH30O', 0755)
873
               while not os.path.isfile("XNPH30O/boot.img"):
874
                  print("downloading XNPH30O/boot.img..\n")
875
                  dlimg("XNPH30O/boot.img")
876
               while not os.path.isfile("XNPH30O/emmc_appsboot.mbn"):
877
                  print("downloading XNPH30O/emmc_appsboot.mbn..\n")
878
                  dlimg("XNPH30O/emmc_appsboot.mbn")
879
               while not os.path.isfile("XNPH30O/NON-HLOS.bin"):
880
                  print("downloading XNPH30O/NON-HLOS.bin..\n")
881
                  dlimg("XNPH30O/NON-HLOS.bin")
882
               while not os.path.isfile("XNPH30O/rpm.mbn"):
883
                  print("downloading XNPH30O/rpm.mbn..\n")
884
                  dlimg("XNPH30O/rpm.mbn")
885
               while not os.path.isfile("XNPH30O/sbl1.mbn"):
886
                  print("downloading XNPH30O/sbl1.mbn..\n")
887
                  dlimg("XNPH30O/sbl1.mbn")
888
               while not os.path.isfile("XNPH30O/flash-extras.sh"):
889
                  print("downloading XNPH30O/flash-extras.sh..\n")
890
                  dlimg("XNPH30O/flash-extras.sh")
891
                  os.chmod("XNPH30O/flash-extras.sh", 0755)
892
               subprocess.call(['./flash-extras.sh'], cwd='XNPH30O', shell=True)
893
               raw_input("press ENTER key to continue...")
894
               obj.fastreboot("android")
895
               flashmenu()
896
               
897
            elif flashsel == '8':
898
               whichupdate = raw_input("enter 1 for XNPH30O update #1, 2 for XNPH30O update #2, 3 for XNPH33R update, or 4 to return to flash menu --> ")
899
               while not re.search(r'^[1-4]$', whichupdate):
900
                  whichupdate = raw_input("invalid selection. enter 1 for XNPH30O update #1, 2 for XNPH30O update #2, 3 for XNPH33R update, or 4 to return to flash menu --> ")
901
               
902
               imgfile = "XNPH33R-update1-signed.zip"
903
               
904
               if whichupdate == '1': # XNPH30O update 1
905
                  imgfile = "XNPH30O-update1-signed.zip"
906
                  while not os.path.isfile(imgfile):
907
                     print("\033[35mdownloading XNPH30O-update1-signed.zip...\033[0m\n")
908
                     dlimg(imgfile)
909
                  print("file \033[32m" + imgfile + " \033[0mfound!\n")
910
                  
911
               elif whichupdate == '2': # XNPH30O update 2
912
                  imgfile = "XNPH30O-update2-signed.zip"
913
                  while not os.path.isfile(imgfile):
914
                     print("\033[35mdownloading XNPH30O-update2-signed.zip...\033[0m\n")
915
                     dlimg(imgfile)
916
                  print("file \033[32m" + imgfile + " \033[0mfound!\n")
917
                  
918
               elif whichupdate == '3': # XNPH33R update 1
919
                  imgfile = "XNPH33R-update1-signed.zip"
920
                  while not os.path.isfile(imgfile):
921
                     print("\033[35mdownloading XNPH33R-update1-signed.zip...\033[0m\n")
922
                     dlimg(imgfile)
923
                  print("file \033[32m" + imgfile + " \033[0mfound!\n")
924
                  
925
               elif whichupdate == '4': # return to flash menu
926
                  time.sleep(0.9)
927
                  flashmenu()
928
                  
929
               else: # error, return to flash menu
930
                  print("unable to connect to device. returning to flash menu..\n")
931
                  time.sleep(0.9)
932
                  flashmenu()
933
               
934
               # choose which recovery [installed or custom] to flash update "imgfile"
935
               recflupd = raw_input("enter 1 to flash update in installed recovery [may lose root], or 2 to flash in custom recovery [keep root prompt]. --> ")
936
               while not re.search(r'^[12]$', recflupd):
937
                  recflupd = raw_input("invalid selection. enter 1 to flash in installed recovery, or 2 to flash in custom recovery. --> ")
938
               
939
               # copy update to device
940
               raw_input("make sure device is unlocked and PC is authenticated for ADB access. press ENTER to copy update to device.")
941
               rimgfile = "/sdcard/" + imgfile
942
               print("\033[32mpushing update file to device..\033[0m\n")
943
               obj.push(imgfile, rimgfile)
944
               
945
               # flash update in installed recovery
946
               if recflupd == '1':
947
                  raw_input("press ENTER to reboot into recovery.")
948
                  obj.reboot("recovery")
949
                  print("choose APPLY UPDATE from recovery menu and select APPLY FROM ADB.\n")
950
                  raw_input("press ENTER to install update now.")
951
                  obj.sideload(imgfile)
952
                  failside = raw_input("if update did not succeed, press 1 to install from device. else, push POWER button on device to reboot, then press ENTER to continue..")
953
                  if failside == '1':
954
                     print("choose APPLY UPDATE from recovery menu, then select CHOOSE FROM INTERNAL STORAGE.\n")
955
                     print("select \033[32m" + imgfile + " \033[0mfrom root of SDCARD directory and install file.\n")
956
                     print("\033[35mif update failed, return to main menu and select option 3 to boot into custom recovery.\033[0m\n\n")
957
                     menusel = raw_input("enter 1 to return to flash menu, or 2 to return to main menu.")
958
                     while not re.search(r'^[12]$',menusel):
959
                        menusel = raw_input("invalid selection. enter 1 for flash menu, or 2 to return to main menu.")
960
                     if menusel == '1':
961
                        time.sleep(0.9)
962
                        flashmenu()
963
                     elif menusel == '2':
964
                        time.sleep(0.9)
965
                        main()
966
                     else:
967
                        print("error connecting to device. returning to main menu...\n")
968
                        time.sleep(0.9)
969
                        main()
970
                  else:
971
                     print("\033[32mreturning to flash menu..\033[0m\n\n")
972
               
973
               # flash update in custom recovery
974
               elif recflupd == '2':
975
                  whichcustrec = raw_input("\033[36;1mselect custom recovery:\033[36m 1 for TWRP, 2 for Philz, 3 for CWM \033[0m--> ")
976
                  while not re.search(r'^[12]$', whichcustrec):
977
                     whichcustrec = raw_input("invalid selection. enter 1 for TWRP, 2 for Philz, 3 for CWM --> ")
978
                  v
979
                  # TWRP
980
                  if whichcustrec == '1':      
981
                     custimgfile = "twrp.img"
982
                     
983
                  # PHILZ
984
                  elif whichcustrec == '2':
985
                     custimgfile = "philz.img"
986
                     
987
                  # CWM
988
                  else:                        
989
                     custimgfile = "cwm.img"
990
                     
991
                  while not os.path.isfile(custimgfile):
992
                     print("file \033[32m" + custimgfile + " \033[0mnot found. attempting download...\n")
993
                     dlimg(custimgfile)
994
                  print("file \033[32m" + custimgfile + " \033[0mfound!\n")
995
                  
996
                  raw_input("press ENTER to reboot to bootloader.")
997
                  obj.reboot("bootloader")
998
                  
999
                  raw_input("press ENTER to continue booting into custom recovery..")
1000
                  obj.bootimg(custimgfile)
1001
                  
1002
                  print("choose INSTALL UPDATE from recovery menu and select APPLY FROM ADB SIDELOAD.\n")
1003
                  raw_input("press ENTER to install update now.")
1004
                  obj.sideload(imgfile)
1005
                  
1006
                  failside = raw_input("if update did not succeed, press 1 to install from device. else, select REBOOT into SYSTEM from TWRP menu on device, then press ENTER..")
1007
                  if failside == '1':
1008
                     print("on device, choose INSTALL from recovery menu, then select \033[32m" + imgfile + " \033[0mfrom SDCARD root and swipe to install file.\n")
1009
                     print("\033[35mwhen finished, select REBOOT into SYSTEM from recovery options on device.\033[0m\n\n")
1010
                     menusel = raw_input("enter 1 to return to flash menu, or 2 to return to main menu.")
1011
                     while not re.search(r'^[12]$',menusel):
1012
                        menusel = raw_input("invalid selection. enter 1 for flash menu, or 2 to return to main menu.")
1013
                     if menusel == '1':
1014
                        time.sleep(0.9)
1015
                        flashmenu()
1016
                     elif menusel == '2':
1017
                        time.sleep(0.9)
1018
                        main()
1019
                     else:
1020
                        print("error connecting to device. returning to main menu...\n")
1021
                        time.sleep(0.9)
1022
                        main()
1023
                  else:
1024
                     print("\033[32mreturning to flash menu..\033[0m\n\n")
1025
               else:
1026
                  print("\033[32mreturning to flash menu..\033[0m\n\n")
1027
               
1028
               time.sleep(0.9)
1029
               flashmenu()
1030
               
1031
            elif flashsel == '9':
1032
               romsel = raw_input("enter 1 to flash XNPH30O stock ROM, 2 to flash XNPH25R stock ROM, or 3 to flash custom ROM. --> ")
1033
               while not re.search(r'^[1-3]$', romsel):
1034
                  romsel = raw_input("invalid selection. enter 1 to flash XNPH30O stock ROM, 2 to flash XNPH25R stock ROM, or 3 to flash custom ROM. --> ")
1035
               if romsel != '3':
1036
                  if romsel == '1':
1037
                     imgfile = "XNPH30O/cm-11.0-XNPH30O-bacon-signed-fastboot.zip"
1038
                     if not os.path.exists('XNPH30O'):
1039
                        os.makedirs('XNPH30O', 0755)
1040
                  if romsel == '2':
1041
                     imgfile = "XNPH25R/cm-11.0-XNPH25R-bacon-signed-fastboot.zip"
1042
                     if not os.path.exists('XNPH25R'):
1043
                        os.makedirs('XNPH25R', 0755)
1044
                  while not os.path.isfile(imgfile):
1045
                     print("file \033[32m" + imgfile + " \033[0mnot found. attempting download...\n")
1046
                     dlimg(imgfile)
1047
                  print("file \033[32m" + imgfile + " \033[0mfound!\n")
1048
                  raw_input("press ENTER to reboot into bootloader..")
1049
                  obj.reboot("bootloader")
1050
                  obj.update(imgfile)
1051
                  failupd = raw_input("if update failed, press 1. otherwise, press ENTER key to continue. --> ")
1052
                  if failupd == '1':
1053
                     obj.fastreboot("android")
1054
                     raw_input("check that device is unlocked and computer is authorized for ADB access. press ENTER to continue..")
1055
                     imgfileonly = imgfile[8:]
1056
                     rimgfile = "/sdcard/" + imgfileonly
1057
                     obj.push(imgfile, rimgfile)
1058
                     raw_input("press ENTER to reboot into recovery.")
1059
                     obj.reboot("recovery")
1060
                     print("choose APPLY UPDATE from recovery menu and select APPLY FROM ADB.\n")
1061
                     raw_input("press ENTER to install from stock image now.")
1062
                     obj.sideload(imgfile)
1063
                     failside = raw_input("if update failed, press 1 to update from device storage. else, push POWER button on device to reboot, then press ENTER to continue. --> ")
1064
                     if failside == '1':
1065
                        print("choose APPLY UPDATE from recovery menu, then select CHOOSE FROM INTERNAL STORAGE.\n")
1066
                        print("select file \033[32m" + imgfileonly + " \033[0mfrom root of SDCARD directory and install.\n")
1067
                        print("\033[35mif update fails again, return to main menu and choose option 3 to reboot into custom recovery.\033[0m\n\n")
1068
                        menusel = raw_input("enter 1 to return to flash menu, or 2 to return to main menu. --> ")
1069
                        while not re.search(r'^[12]$',menusel):
1070
                           menusel = raw_input("invalid selection. press 1 for flash menu, or 2 to return to main menu. --> ")
1071
                        if menusel == '1':
1072
                           time.sleep(0.9)
1073
                           flashmenu()
1074
                        elif menusel == '2':
1075
                           time.sleep(0.9)
1076
                           main()
1077
                        else:
1078
                           print("error connecting to device. returning to main menu...\n")
1079
                           time.sleep(0.9)
1080
                           main()
1081
                     else:
1082
                        print("\033[32mreturning to flash menu..\033[0m\n\n")
1083
                        time.sleep(0.9)
1084
                        flashmenu()
1085
                  else:
1086
                     print("\033[32mreturning to flash menu..\033[0m\n\n")
1087
                     time.sleep(0.9)
1088
                     flashmenu()
1089
               else:
1090
                  print("\033[31mmake sure device is unlocked and PC is authenticated for ADB access.\033[0m\n")
1091
                  romname = raw_input("place ROM file into same directory as the script home, then enter filename --> ")
1092
                  while not os.path.isfile(romname):
1093
                     romname = raw_input("invalid filename. make sure ROM ZIP file to flash is in correct location, then enter filename --> ")
1094
                  rimgfile = "/sdcard/" + romname
1095
                  print("\033[32mpushing update file to device..\033[0m\n")
1096
                  obj.push(romname, rimgfile)
1097
                  raw_input("press ENTER to reboot to bootloader.")
1098
                  obj.reboot("bootloader")
1099
                  while not os.path.isfile("twrp.img"):
1100
                     print("file \033[32mtwrp.img \033[0mnot found. attempting download...\n")
1101
                     dlimg("twrp.img")
1102
                  print("file \033[32mtwrp.img \033[0mfound!\n")
1103
                  raw_input("press ENTER to continue booting into TWRP recovery.")
1104
                  obj.bootimg("twrp.img")
1105
                  print("on device, choose ADVANCED from TWRP menu, then select INSTALL ZIP and to APPLY VIA ADB SIDELOAD.\n")
1106
                  raw_input("press ENTER to install the zip file you specified.")
1107
                  obj.sideload(imgfile)
1108
                  failside = raw_input("if update failed, enter 1 to try installing from device storage. otherwise, push select REBOOT from device recovery menu, reboot into system, and press ENTER to continue. --> ")
1109
                  if failside == '1':
1110
                     print("select INSTALL on device TWRP menu, then find your file \033[32m" + romname + " \033[0min device SDCARD root and swipe to install file.\n")
1111
                     menusel = raw_input("when flash complete, select REBOOT into SYSTEM from recovery options on device. then enter 1 to return to flash menu, or 2 for main menu.")
1112
                     while not re.search(r'^[12]$',menusel):
1113
                        menusel = raw_input("invalid selection. enter 1 for flash menu, or 2 to return to main menu.")
1114
                     if menusel == '1':
1115
                        time.sleep(0.9)
1116
                        flashmenu()
1117
                     elif menusel == '2':
1118
                        time.sleep(0.9)
1119
                        main()
1120
                     else:
1121
                        print("error connecting to device. returning to main menu...\n")
1122
                        time.sleep(0.9)
1123
                        main()
1124
                  
1125
            elif flashsel == '0':
1126
               checkreboot = raw_input("press 1 to reboot device into system, or ENTER to continue.. --> ")
1127
               if checkreboot == '1':
1128
                  obj.fastreboot("android")
1129
               main()
1130
            else:
1131
               print("unable to connect to device.\n")
1132
              
1133
         def recovflash():
1134
            print("\n")
1135
            flashcont = raw_input("select 1 to continue flashing recovery. select 2 to flash a stock or custom image. select 3 to return to flash menu. --> ")
1136
            while not re.search(r'^[123]$', flashcont):
1137
               flashcont = raw_input("invalid selection. select 1 to continue flashing recovery. select 2 to flash a stock partition image. select 3 to return to flash menu. --> ")
1138
            if flashcont == '1':
1139
               recovchoice = raw_input("enter 1 for TWRP, 2 for ClockworkMod, or 3 for Philz recovery --> ")
1140
               while not re.search(r'^[1-3]$', recovchoice):
1141
                  recovchoice = raw_input("invalid selection. please choose 1 for TWRP, 2 for CWM, or 3 for Philz --> ")
1142
               obj.reboot("bootloader")
1143
               if recovchoice == '1':
1144
                  recovfile = "twrp.img"
1145
                  while not os.path.isfile(recovfile):
1146
                     print("file \033[32mtwrp.img \033[0mnot found. attempting download...\n")
1147
                     dlrecov(recovfile)
1148
                  print("file \033[32mtwrp.img \033[0mfound!\n")
1149
                  raw_input("press ENTER to flash twrp.img over current recovery.")
1150
                  obj.flashf("recovery","twrp.img")
1151
               elif recovchoice == '2':
1152
                  recovfile = "cwm.img"
1153
                  while not os.path.isfile(recovfile):
1154
                     print("file \033[32mcwm.img \033[0mnot found. attempting download...\n")
1155
                     dlrecov(recovfile)
1156
                  print("file \033[32mcwm.img \033[0mfound!\n")
1157
                  raw_input("press ENTER to flash cwm.img over current recovery.")
1158
                  obj.flashf("recovery","cwm.img")
1159
               elif recovchoice == '3':
1160
                  recovfile = "philz.img"
1161
                  while not os.path.isfile(recovfile):
1162
                     print("file \033[32mphilz.img \033[0mnot found. attempting download...\n")
1163
                     dlrecov(recovfile)
1164
                  print("file \033[32mphilz.img \033[0mfound!\n")
1165
                  raw_input("press ENTER to flash philz.img over current recovery.")
1166
                  obj.flashf("recovery","philz.img")
1167
               else:
1168
                  print("unable to connect to device.\n")
1169
                  
1170
            elif flashcont == '2':
1171
               flashmenu()   
1172
                                
1173
            elif flashcont == '3':
1174
               main()
1175
               
1176
            else:
1177
               print("unable to connect to device.\n")
1178
            
1179
            time.sleep(0.9)
1180
            flashmenu()
1181
               
1182
         print("\n\033[36mFlashing a CUSTOM RECOVERY requires an UNLOCKED BOOTLOADER.\033[0m\n")
1183
         print("\033[33m***UNLOCKING YOUR BOOTLOADER WILL WIPE YOUR DEVICE!!!***\033[0m\n")
1184
         print("\033[37mIF YOUR DEVICE HOLDS IMPORTANT DATA, BACK UP DEVICE BEFORE YOU CONTINUE!\033[0m\n")
1185
         print("\033[35mIMPORTANT: if you have already unlocked your device and are re-unlocking, you MUST be running the XNPH25R stock firmware or older.\n")
1186
         print("\033[32mRE-UNLOCK ATTEMPTS WILL FAIL on XNPH30O or newer. you must return to the previous menu and flash the XNPH25R images to your device.\033[0m\n")
1187
         bunlock = raw_input("enter 1 to continue unlocking bootloader. enter 2 to skip to flashing custom recovery or images. enter 3 to re-lock bootloader. or enter 4 to return to menu. --> ")
1188
         while not re.search(r'^[123]$', bunlock):
1189
            bunlock = raw_input("invalid selection. enter 1 to unlock bootloader and wipe device. enter 2 to skip to flashing custom recovery or images. enter 3 to re-lock bootloader. or enter 4 to return to menu. --> ")
1190
         
1191
         if bunlock == '1':
1192
            obj.reboot("bootloader")
1193
            obj.unlockboot()
1194
            print("your device should reboot after successfully unlocking the bootloader.\n")
1195
            raw_input("press ENTER to continue...")
1196
            recovflash()
1197
            
1198
         elif bunlock == '2':
1199
            recovflash()
1200
                    
1201
         elif bunlock == '3':
1202
            print("\033[33mREMINDER: to unlock your device again, you MUST downgrade to firmware release XNPH25R or earlier!\033[0m\n")
1203
            btlockconfirm = raw_input("press ENTER to continue, or 1 to exit to the previous menu --> ")
1204
            if btlockconfirm == '1':
1205
               flashmenu()
1206
            else:
1207
               obj.reboot("bootloader")
1208
               obj.lockboot()
1209
               raw_input("press ENTER to reboot your device")
1210
               obj.fastreboot("android")
1211
               
1212
         else:
1213
            flashmenu()
1214
               
1215
         time.sleep(0.9)
1216
         main()
1217
1218
      elif option == '9': #run shell command
1219
         shellcmd = raw_input("enter shell command --> ")
1220
         while shellcmd:
1221
            obj.shell(shellcmd)
1222
            shellcmd = raw_input("enter another shell command, or press ENTER to continue --> ")
1223
         time.sleep(0.9)
1224
         main()
1225
         
1226
      elif option == '0': #quit
1227
         sys.exit()
1228
                  
1229
      else:
1230
         print '\n\033[32man unhandled exception occurred. returning to main menu..\033[0m\n'
1231
         time.sleep(0.9)
1232
         main()    
1233
1234
intro()
1235
os.system('cls' if os.name == 'nt' else 'clear')
1236
main()
1237
sys.exit()