-
Notifications
You must be signed in to change notification settings - Fork 4
/
opotoolkit.py
executable file
·1977 lines (1844 loc) · 95.7 KB
/
opotoolkit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
### HALF-ASSED ONE + ONE TOOLKIT
##### VERSION: 1.3.9 BETA
##### RELEASE DATE: AUG 24, 2015
##### AUTHOR: vvn [eudemonics on xda-developers]
##### DESCRIPTION: A spotaneously developed, very sporadically updated, but hopefully
##### helpful and comprehensive toolkit for Android, built originally for the OnePlus
##### One but can be used with most Android devices. again, please do not expect
##### frequent or timely updates. if you have a request, you may contact me directly
##### to submit your inquiry.
##### ***DO NOT FLASH ONEPLUS ONE SYSTEM FILES ON OTHER DEVICES!!!***
##### actually, don't flash ANY ROM images or system files unless they are built
##### specifically for the device you want to flash, as flashing an unsupported ROM, ##### firmware, or radio could HARD BRICK your device. only download factory images ##### from the official OEM website, and custom ROMs from trustworthy sites and
##### recognized developers.
#####
##### all system image downloads and other apps used in this program are hosted on
##### private servers to ensure
##### yet tested whether ALL the downloads work
##### REQUIREMENTS: Python 2.7, Android SDK, USB drivers, pyadb.py, opointro.py
#####
##### INSTALL INSTRUCTIONS USING GIT:
##### enter command into terminal:
##### git clone https://github.com/eudemonics/1plus1toolkit.git 1plus1toolkit
##### to run after using git clone (without $ sign):
##### $ cd 1plus1toolkit
##### $ chmod +x opotoolkit.py
##### $ python opotoolkit.py
#####
##### VIEW IN BROWSER:
##### https://github.com/eudemonics/1plus1toolkit
#####
##### UPDATE VIA GIT:
##### cd 1plus1toolkit
##### git pull https://github.com/eudemonics/1plus1toolkit.git
##################################################
##################################################
##### USER LICENSE AGREEMENT & DISCLAIMER
##### copyright (C) 2014-2015 vvn <lost [at] nobody.ninja>
#####
##### This program is FREE software: you can use it, redistribute it and/or modify
##### it as you wish. Copying and distribution of this file, with or without modification,
##### are permitted in any medium without royalty provided the copyright
##### notice and this notice are preserved. This program is offered AS-IS,
##### WITHOUT ANY WARRANTY; without even the implied warranty of
##### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
##### GNU General Public License for more details.
#####
##### For more information, please refer to the "LICENSE AND NOTICE" file that should
##### accompany all official download releases of this program.
##################################################
##################################################
##### don't ask about the arbitrary versioning. i am totally making this shit up.
##### getting credited for my work is nice. so are donations.
##### BTC: 1M511j1CHR8x7RYgakNdw1iF3ike2KehXh
#####
##### but to really show your appreciation, you should buy my EP instead!
##### you can stream and purchase it at: dreamcorp.bandcamp.com
##### (you might even enjoy listening to it)
##### questions, comments, feedback, bugs, complaints, death threats, marriage proposals?
##### contact me at:
##### lost (at) nobody (dot) ninja
##### latest version will always be available HERE:
##### https://github.com/eudemonics/1plus1toolkit
import subprocess, sys, re, os, os.path, hashlib, time, datetime, urllib
from opointro import *
from pyadb import *
global usecolor
if os.name == 'nt' or sys.platform == 'win32':
try:
import colorama
colorama.init()
s = opointro()
s.colorlogo()
startmenu = s.colormenu
usecolor = 'color'
except:
try:
import tendo.ansiterm
s = opointro()
s.colorlogo()
startmenu = s.colormenu
usecolor = 'color'
except:
s = opointro()
s.cleanlogo()
startmenu = s.cleanmenu
usecolor = 'clean'
pass
else:
s = opointro()
s.colorlogo()
startmenu = s.colormenu
usecolor = 'color'
def mainmenu():
print(startmenu)
def main():
os.system('cls' if os.name == 'nt' else 'clear')
mainmenu()
global option
option = raw_input('Select an option 0-18 --> ')
while not re.search(r'^[0-9]$', option) and not re.search(r'^1[0-8]$', option):
option = raw_input('Invalid selection. Please select an option 0-18 --> ')
if option:
obj = pyADB()
############################################################
############################################################
# OPTION 1 - REBOOT #
############################################################
############################################################
if option == '1': #reboot
rboption = raw_input("please enter 1 to reboot into android. enter 2 to reboot to bootloader. enter 3 to reboot to recovery. --> ")
while not re.search(r'^[123]$', rboption):
rboption = raw_input("invalid selection. please enter 1 to reboot into android, 2 for bootloader, and 3 for recovery. --> ")
rbtype = "android"
if rboption == '1':
rbtype = "android"
elif rboption == '2':
rbtype = "bootloader"
elif rboption == '3':
rbtype ="recovery"
checkdev = obj.get_state()
listdev = obj.attached_devices()
fastdev = obj.fastboot_devices()
if "device" in str(checkdev) and listdev is not None and "fastboot" not in str(fastdev):
print("rebooting via ADB..\n")
obj.reboot(rbtype)
time.sleep(0.9)
main()
elif "unknown" in str(checkdev) and "fastboot" in str(fastdev):
print("rebooting via fastboot..\n")
if rboption == '3':
rbtype = "bootloader"
obj.fastreboot(rbtype)
time.sleep(0.9)
main()
elif "unknown" in str(checkdev) and listdev is not None and "device" in str(fastdev):
print("rebooting via ADB..\n")
obj.reboot(rbtype)
time.sleep(0.9)
main()
elif "recovery" in [str(fastdev), str(listdev)] and checkdev is not None:
print("rebooting via ADB...\n")
obj.reboot(rbtype)
time.sleep(0.9)
main()
elif "unknown" in str(checkdev) and fastdev is not None and listdev is None:
print("rebooting via fastboot...\n")
if rboption == '3':
rbtype = "bootloader"
obj.fastreboot(rbtype)
time.sleep(0.9)
main()
elif "unknown" in str(checkdev) and "unauthorized" in str(listdev):
raw_input("verify that DEVICE IS UNLOCKED and COMPUTER IS AUTHORIZED FOR ADB ACCESS, then press ENTER.")
print("rebooting via ADB...\n")
obj.reboot(rbtype)
time.sleep(0.9)
main()
elif "unknown" in str(checkdev) and listdev is not None and fastdev is None:
raw_input("device appears to be in recovery mode. reboot from recovery menu, then press ENTER.")
checkstate = obj.get_state()
if "device" in str(checkstate):
obj.reboot(rbtype)
time.sleep(0.9)
main()
else:
print("rebooting via fastboot....\n")
if rboption == '3':
rbtype = "bootloader"
fastreboot = obj.fastreboot(rbtype)
if not fastreboot:
print("rebooting via ADB after fastboot... \n")
obj.reboot(rbtype)
if "error" in str(fastreboot):
print("rebooting via fastboot second time...\n")
obj.fastreboot(rbtype)
time.sleep(0.9)
main()
############################################################
############################################################
# OPTION 2 - WIPE OR FLASH PARTITIONS #
############################################################
############################################################
elif option == '2': #wipe
print("\033[35m***WIPING SOME PARTITIONS WILL ERASE YOUR DATA.***\n please make sure to back up any important data before proceeding!\n\n")
print('''\033[36mCHOOSE AN OPTION 1-8:\033[32m\n
[1]\033[37m perform a full system wipe [system, data, and cache partitions]\033[32m
[2]\033[37m wipe only the system partition\033[32m
[3]\033[37m wipe only the data partition\033[32m
[4]\033[37m wipe only the cache partition\033[32m
[5]\033[37m wipe only the boot partition\033[32m
[6]\033[37m wipe only the recovery partition\033[32m
[7]\033[37m flash device to factory images [flash system, boot, and recovery]\033[32m
[8]\033[37m return to main menu\n\n\033[0m''')
confirmwipe = raw_input("please enter an option 1-8 --> ")
while not re.search(r'^[1-8]$', confirmwipe):
confirmwipe = raw_input('not a valid option. please enter a selection between 1-8 from above choices -->')
if confirmwipe == '1':
obj.wipe('all')
raw_input("press ENTER to continue.")
time.sleep(0.9)
main()
elif confirmwipe == '2':
obj.wipe('system')
raw_input("press ENTER to continue.")
time.sleep(0.9)
main()
elif confirmwipe == '3':
obj.wipe('data')
raw_input("press ENTER to continue.")
time.sleep(0.9)
main()
elif confirmwipe == '4':
obj.wipe('cache')
raw_input("press ENTER to continue.")
time.sleep(0.9)
main()
elif confirmwipe == '5':
obj.wipe('boot')
raw_input("press ENTER to continue.")
time.sleep(0.9)
main()
elif confirmwipe == '6':
obj.wipe('recovery')
raw_input("press ENTER to continue.")
time.sleep(0.9)
main()
elif confirmwipe == '7':
obj.wipe('flashall')
raw_input("press ENTER to continue.")
time.sleep(0.9)
main()
elif confirmwipe == '8':
time.sleep(0.9)
main()
else:
print("there was a problem connecting to the device. returning to menu..\n")
time.sleep(0.9)
main()
############################################################
############################################################
# OPTION 3 - BOOT ONCE INTO CUSTOM RECOVERY #
############################################################
############################################################
elif option == '3': #boot custom recovery
recovery = raw_input("enter 1 for TWRP, 2 for ClockworkMod, or 3 for Philz recovery --> ")
while not re.search(r'^[1-3]$', recovery):
recovery = raw_input("invalid selection. please choose 1 for TWRP, 2 for CWM, or 3 for Philz --> ")
def dlrecov(recovfile):
dlfile = "http://notworth.it/opo/" + recovfile
dl = urllib.URLopener()
dl.retrieve(dlfile, recovfile)
site = urllib.urlopen(dlfile)
meta = site.info()
dlsize = meta.getheaders("Content-Length")[0]
fsize = os.path.getsize(recovfile)
print("file size: \033[33m")
print(dlsize)
print("\n\033[0mbytes downloaded: \033[33m")
print(fsize)
print("\033[0m\n")
obj.reboot("bootloader")
if recovery == '1':
recovfile = "twrp.img"
while not os.path.isfile(recovfile):
print("file \033[32mtwrp.img \033[0mnot found. attempting download...\n")
dlrecov(recovfile)
print("file \033[32mtwrp.img \033[0mfound!\n")
raw_input("press ENTER to continue booting into TWRP..")
obj.bootimg("twrp.img")
elif recovery == '2':
recovfile = "cwm.img"
while not os.path.isfile(recovfile):
print("file \033[32mcwm.img \033[0mnot found. attempting download...\n")
dlrecov(recovfile)
print("file \033[32mcwm.img \033[0mfound!\n")
raw_input("press ENTER to continue booting into ClockworkMod Recovery..")
obj.bootimg("cwm.img")
elif recovery == '3':
recovfile = "philz.img"
while not os.path.isfile(recovfile):
print("file \033[32mphilz.img \033[0mnot found. attempting download...\n")
dlrecov(recovfile)
print("file \033[32mphilz.img \033[0mfound!\n")
raw_input("press ENTER to continue booting into Philz Recovery..")
obj.bootimg("philz.img")
else:
print("unable to connect to device.\n")
raw_input("press ENTER to return to main menu..")
time.sleep(0.9)
main()
############################################################
############################################################
# OPTION 4 - INSTALL/UNINSTALL APK #
############################################################
############################################################
elif option == '4': #install or uninstall APK
whichinstall = raw_input("please enter 1 to install, 2 to uninstall, or 3 to return to main menu. --> ")
while not re.search(r'^[1-3]$', whichinstall):
whichinstall = raw_input("invalid selection. please enter 1 to install, 2 to uninstall, or 3 to return to main menu. --> ")
if not os.path.exists('apps'):
os.makedirs('apps')
if whichinstall == '1':
getapk = raw_input("place the APK file to install in the \"apps\" subdirectory, then type the filename --> ")
apkfile = os.path.join('apps', getapk)
while not os.path.isfile(apkfile):
print("\033[37mfile does not exist. please make sure the APK file is in the \"apps\" subdirectory.\033[0m\n")
getapk = raw_input("enter valid filename for the APK you want to install -->")
apkfile = os.path.join('apps', getapk)
print("installing \033[36m" + getapk + "\033[0m...")
obj.install(apkfile)
raw_input("press ENTER to continue...")
time.sleep(0.9)
main()
if whichinstall == '2':
getunapk = raw_input("please enter the complete path for the app you wish to uninstall --> ")
keepcheck = raw_input("would you like to keep your app data? Y or N --> ")
while not re.search(r'^[nyNY]$', keepcheck):
keepcheck = raw_input("invalid selection. please enter Y to keep app data or N to erase --> ")
keepargs = "erase"
uninstcmd = "pm uninstall " + getunapk
if re.match(r'(?i)Y', keepcheck):
keepargs = "keep"
uninstcmd = "pm uninstall -k " + getunapk
print("uninstalling \033[36m" + getunapk + "\033[0m...\n")
obj.uninstall(getunapk, keepargs)
obj.shell(uninstcmd)
raw_input("press ENTER to continue...")
time.sleep(0.9)
main()
if whichinstall == '3':
main()
else:
print("could not connect to device.\n")
time.sleep(0.9)
main()
############################################################
############################################################
# OPTION 5: COPY/SYNC FILES BETWEEN DEVICE & COMPUTER #
############################################################
############################################################
elif option == '5': #copy and/or sync between computer and device
copytype = raw_input("to push file from computer to device, enter T. to pull file from device to computer, enter F. to sync, enter S --> ")
matchT = re.search(r'(?i)T', copytype)
matchF = re.search(r'(?i)F', copytype)
matchS = re.search(r'(?i)S', copytype)
while not re.search(r'^[FfSsTt]$', copytype):
copytype = raw_input("invalid option. please enter T to push file, F to pull file, or S to sync --> ")
if matchT:
getpushfile = raw_input("please enter the file or directory you wish to copy as the RELATIVE path from the script location --> ")
while not os.path.exists(getpushfile):
getpushfile = raw_input("file does not exist. please enter valid path --> ")
getpushremote = raw_input("please enter destination path for copied file(s) on the device --> ")
obj.push(getpushfile, getpushremote)
raw_input("file transfer complete. press ENTER to continue...")
elif matchF:
getpullfile = raw_input("please enter path for the file or directory on your device to copy --> ")
getpulllocal = raw_input("please enter the copy destination folder as a RELATIVE path from the script location --> ")
if not os.path.exists(getpulllocal):
print("copy destination \033[35m" + getpulllocal + " \033[0mdoes not exist! creating new directory...")
os.makedirs(getpulllocal)
obj.pull(getpullfile, getpulllocal)
print("\033[32mtransferred file(s) in destination directory:\n")
for fn in next(os.walk(getpulllocal))[2]:
fullpath = os.path.join(getpulllocal, fn)
if os.path.getmtime(fullpath) >= os.path.getctime(getpulllocal):
print(fullpath)
print("\033[0m\n")
raw_input("file transfer complete. press ENTER to continue...")
elif matchS:
syncargs = raw_input("enter 1 to set sync directory, or 2 to sync the default system and data directories. --> ")
while not re.search(r'^[12]$', syncargs):
syncargs = raw_input("invalid selection. please enter 1 to set sync directory, or 2 to use default. --> ")
if syncargs == '1':
syncdir = raw_input("please enter sync directory --> ")
localargs = raw_input("enter 1 to set local sync directory, or 2 to use default ANDROID_PRODUCT_OUT --> ")
while not re.search(r'^[12]$',localargs):
localargs = raw_input("invalid selection. enter 1 to set local sync directory or 2 to use default ANDROID_PRODUCT_OUT --> ")
if localargs == '1':
localdir = raw_input("please enter relative path for local directory to sync device --> ")
while not os.path.exists(localdir):
print("the path you entered does not exist. would you like to create " + localdir + " as a new directory?\n")
crlocaldir = raw_input("enter 1 to create new directory or 2 to enter another location. --> ")
while not re.search(r'^[12]$', crlocaldir):
crlocaldir = raw_input("invalid selection. please enter 1 to create directory, or 2 to enter another location. --> ")
if crlocaldir == '1':
os.makedirs(localdir, 0755)
else:
localdir = raw_input("please enter relative path for local directory to sync device with --> ")
localsyncdir = os.path.join(localdir, syncdir)
while not os.path.exists(localsyncdir):
os.makedirs(localsyncdir, 0755)
print(localsyncdir + " created\n")
else:
localdir = "none"
obj.sync(localdir, syncdir)
if "none" not in localdir:
print("\033[32mfile(s) in sync directory:\n")
for fn in next(os.walk(localdir))[2]:
fullpath = os.path.join(localdir, fn)
if os.path.getmtime(fullpath) >= os.path.getctime(localdir):
print(fullpath)
print("\033[0m\n")
raw_input("press ENTER to continue...")
elif syncargs == '2':
# obj.sync()
localargs = raw_input("enter 1 to set local sync directory, or 2 to use default ANDROID_PRODUCT_OUT --> ")
while not re.search(r'^[12]$',localargs):
localargs = raw_input("invalid selection. enter 1 to set local sync directory or 2 to use default ANDROID_PRODUCT_OUT --> ")
if localargs == '1':
localdir = raw_input("please enter relative path for local directory to sync device --> ")
while not os.path.exists(localdir):
print("the path you entered does not exist. would you like to create " + localdir + " as a new directory?\n")
crlocaldir = raw_input("enter 1 to create new directory or 2 to enter another location. --> ")
while not re.search(r'^[12]$', crlocaldir):
crlocaldir = raw_input("invalid selection. please enter 1 to create directory, or 2 to enter another location. --> ")
if crlocaldir == '1':
os.makedirs(localdir, 0755)
else:
localdir = raw_input("please enter relative path for local directory to sync device with --> ")
else:
localdir = "none"
obj.sync(localdir, "none")
raw_input("press ENTER to continue...")
else:
print("could not connect to device.\n")
else:
print("could not connect to device.\n")
time.sleep(0.9)
main()
############################################################
############################################################
# OPTION 6 - BACKUP OR RESTORE #
############################################################
############################################################
elif option == '6': #backup
whichbackup = raw_input("to backup, enter 1. to restore, enter 2 --> ")
while not re.search(r'^[12]$', whichbackup):
whichbackup = raw_input("invalid selection. please enter 1 to backup or 2 to restore. --> ")
if whichbackup == '1':
fullbackup = raw_input("would you like to do a full backup, including system apps and sdcard contents? enter Y or N --> ")
while not re.search(r'^[yYnN]$', fullbackup):
fullbackup = raw_input("invalid selection. please enter Y for full backup or N for other options --> ")
if fullbackup.lower() == 'y':
backapk = "apk"
backobb = "obb"
backshared = "shared"
backall = "full"
backsys = "sys"
else:
checkapk = raw_input("enter 1 to include APK files, or 2 to exclude --> ")
while not re.search(r'^[12]$', checkapk):
checkapk = raw_input("invalid selection. enter 1 to include APK files, or 2 to exclude --> ")
if checkapk == '1':
backapk = "apk"
checkobb = raw_input("enter 1 to include APK expansion files, or 2 to exclude --> ")
while not re.search(r'^[12]$', checkobb):
checkobb = raw_input("invalid selection. enter 1 to include APK expansion files, or 2 to exclude --> ")
if checkobb == '1':
backobb = "obb"
else:
backobb = "no"
else:
backapk = "no"
checkshared = raw_input("enter 1 to backup sdcard [userdata] contents, or 2 to exclude --> ")
while not re.search(r'^[12]$', checkshared):
checkshared = raw_input("invalid selection. enter 1 to backup sdcard contents, or 2 to exclude --> ")
if checkshared == '1':
backshared = "shared"
checkall = raw_input("enter 1 to backup all installed applications, or 2 to exclude --> ")
while not re.search(r'^[12]$', checkall):
checkall = raw_input("invalid selection. enter 1 to backup all installed applications, or 2 to exclude --> ")
if checkall == '1':
backall = "all"
else:
backall = "no"
else:
backshared = "no"
backall = "all"
checksys = raw_input("enter 1 to backup system apps, or 2 to exclude --> ")
while not re.search(r'^[12]$',checksys):
checksys = raw_input("invalid selection. enter 1 to backup system apps, or 2 to exclude --> ")
if checksys == '1':
backsys = "sys"
else:
backsys = "no"
backupfile = 'backup-' + str(datetime.date.today()) + '.ab'
raw_input("to continue with backup, press ENTER. then check device and follow prompts to continue. the backup process may take awhile.")
obj.backup(backupfile, backapk, backobb, backshared, backall, backsys)
raw_input("backup complete! backup file saved as: \033[35m" + backupfile + "\033[0m. press ENTER to return to main menu.")
elif whichbackup == '2':
restorefile = raw_input("please enter path to backup file on your computer [ex. \'backup-yyyy-mm-dd.ab\'] --> ")
while not os.path.isfile(restorefile):
restorefile = raw_input("file does not exist. please enter valid path --> ")
obj.restore(restorefile)
raw_input("restore complete! press ENTER to reboot and continue..")
obj.reboot("android")
else:
print("unable to connect to device. returning to main menu..")
time.sleep(0.9)
main()
############################################################
############################################################
# OPTION 7 - ROOT DEVICE #
############################################################
############################################################
elif option == '7':
# FUNCTION TO CHECK MD5 SIGNATURE
def checkmd5(mfile, md5):
md5list = [('twrp.img','77ba4381b13a03cc6dcff90f95e59a24'),('philz.img', 'b2f8fb888e1377f00187ad0bd35a6584'),('CWM','b60bd10f3f7cc254a4354cdc9c69b3bd')]
md5_read = ''
integrity = 'none'
for dlfile, hashsig in zip(md5list):
if mfile in dlfile:
with open(dlfile, "r+b") as sf:
sfdata = sf.read()
md5_read = hashlib.md5(sfdata).hexdigest()
if hashsig == md5_read:
print("MD5 verified!")
integrity = 'passed'
else:
print("MD5 file integrity check failed!")
integrity = 'failed'
break
else:
continue
return integrity
# DOWNLOAD TWRP CUSTOM RECOVERY
def twrpdl():
TWRPurl = "http://notworth.it/opo/twrp.img"
TWRPmd5 = "77ba4381b13a03cc6dcff90f95e59a24"
dl = urllib.URLopener()
dl.retrieve(TWRPurl, "twrp.img")
site = urllib.urlopen(TWRPurl)
meta = site.info()
dlsize = meta.getheaders("Content-Length")[0]
fsize = os.path.getsize("twrp.img")
if usecolor == 'color':
print("file size: \033[33m")
print(dlsize)
print("\n\033[0mbytes downloaded: \033[33m")
print(fsize)
print("\033[0m\n")
print("\033[34mchecking md5 signature...\033[0m\n")
else:
print("file size: ")
print(dlsize)
print("bytes downloaded: ")
print(fsize)
print("checking md5 signature...")
md5_read = ''
integrity = ''
with open("twrp.img", "r+b") as sf:
sfdata = sf.read()
md5_read = hashlib.md5(sfdata).hexdigest()
if TWRPmd5 == md5_read:
print("MD5 verified!")
integrity = 'passed'
else:
print("MD5 file integrity check failed!")
integrity = 'failed'
if integrity == 'failed':
if dlsize != fsize:
with open("twrp.img", "r+b") as f:
# read contents of downloaded file
fdata = f.read()
f.write(site.read())
f.flush()
os.fsync(f.fileno())
f.close()
# DOWNLOAD IMAGE FROM SITE
def recovdl(recovimg):
recovurl = "http://notworth.it/opo/" + recovimg
if recovimg == 'philz.img':
recovmd5 = "b2f8fb888e1377f00187ad0bd35a6584"
elif recovimg == 'cwm.img':
recovmd5 = "b60bd10f3f7cc254a4354cdc9c69b3bd"
else: # twrp.img MD5
recovmd5 = "f69fa503419644851822d883c2388bb8"
#old recovmd5 = "77ba4381b13a03cc6dcff90f95e59a24"
dl = urllib.URLopener()
dl.retrieve(recovurl, recovimg)
site = urllib.urlopen(recovurl)
meta = site.info()
dlsize = meta.getheaders("Content-Length")[0]
fsize = os.path.getsize(recovimg)
if usecolor == 'color':
print("file size: \033[33m")
print(dlsize)
print("\n\033[0mbytes downloaded: \033[33m")
print(fsize)
print("\033[0m\n")
print("\033[34mchecking md5 signature...\033[0m\n")
else:
print("file size: ")
print(dlsize)
print("bytes downloaded: ")
print(fsize)
print("checking md5 signature...")
md5_read = ''
integrity = ''
with open(recovimg, "r+b") as sf:
sfdata = sf.read()
md5_read = hashlib.md5(sfdata).hexdigest()
if recovmd5 == md5_read:
print("MD5 verified!")
integrity = 'passed'
else:
print("MD5 file integrity check failed!")
integrity = 'failed'
if integrity == 'failed':
if dlsize != fsize:
with open(recovimg, "r+b") as f:
# read contents of downloaded recovery file
fdata = f.read()
f.write(site.read())
f.flush()
os.fsync(f.fileno())
f.close()
# CHOOSE WHICH CUSTOM RECOVERY TO BOOT INTO ONCE
def chooserec():
recovimg = "twrp.img"
pickrecov = raw_input("press 1 to flash superSU in TWRP Recovery, 2 to use Philz Recovery, or 3 to use CWM. --> ")
while not re.search(r'^[123]$', pickrecov):
pickrecov = raw_input("invalid selection. press 1 to flash superSU in TWRP Recovery, 2 for Philz, or 3 for CWM. --> ")
if pickrecov == '1': # SUPERSU TWRP
recovimg = "twrp.img"
elif pickrecov == '2': # SUPERSU PHILZ
recovimg = "philz.img"
elif pickrecov == '3': # SUPERSU CWM
recovimg = "cwm.img"
else:
print("unable to connect to device. returning to main menu..\n")
return recovimg
# DOWNLOAD SUPERSU ZIP
superSU = 'SuperSU-v2.49.zip'
def sudl():
URLsuperSU = "http://notworth.it/opo/" + superSU
MD5superSU = "6ad55644c8117c505d0da15b4f6bac8a"
dl = urllib.URLopener()
dl.retrieve(URLsuperSU, superSU)
site = urllib.urlopen(URLsuperSU)
meta = site.info()
dlsize = meta.getheaders("Content-Length")[0]
fsize = os.path.getsize(superSU)
if usecolor == "color":
print("file size: \033[33m")
print(dlsize)
print("\n\033[0mbytes downloaded: \033[33m")
print(fsize)
print("\033[0m\n")
print("\033[34mchecking md5 signature...\033[0m\n")
else:
print("file size: ")
print(dlsize)
print("bytes downloaded: ")
print(fsize)
print("checking md5 signature...")
md5_read = ''
integrity = ''
with open(superSU, "r+b") as sf:
sfdata = sf.read()
md5_read = hashlib.md5(sfdata).hexdigest()
if MD5superSU == md5_read:
print("MD5 verified!")
integrity = 'passed'
else:
print("MD5 file integrity check failed!")
integrity = 'failed'
if integrity == 'failed':
if dlsize != fsize:
with open(superSU, "r+b") as f:
# read contents of downloaded SuperSU file
fdata = f.read()
f.write(site.read())
f.flush()
os.fsync(f.fileno())
f.close()
# FUNCTION TO FLASH SUPERSU IN RECOVERY
def suroot(recovimg):
while not os.path.isfile(superSU):
if usecolor == 'color':
print("file \033[32m" + superSU + " \033[0mnot found.\n \033[40m\033[34;1mattempting download...\033[0m\n")
else:
print("file " + superSU + " not found. \n attempting download... \n")
sudl()
if usecolor == 'color':
print("file \033[32m" + superSU + " \033[0mfound!\n")
else:
print("file " + superSU + " found!\n")
while not os.path.isfile(recovimg):
if usecolor == 'color':
print("file \033[32m" + recovimg + " \033[0mnot found. attempting download...\n")
else:
print("file " + recovimg + " not found. attempting download...\n")
recovdl(recovimg)
if usecolor == 'color':
print("file \033[32m" + recovimg + " \033[0mfound!\n")
else:
print("file " + recovimg + " found!\n")
raw_input("press ENTER to copy file to device, then reboot into bootloader.")
remotesuperSU = '/sdcard/SuperSU-v2.49.zip'
obj.push(superSU, remotesuperSU)
obj.reboot("bootloader")
raw_input("press ENTER to boot into custom recovery.")
obj.bootimg(recovimg)
print("check that device is connected and booted into custom recovery. on device, choose the ADB SIDELOAD option [sometimes under ADVANCED].\n")
raw_input("press ENTER to continue with flashing superSU file via ADB sideload.")
obj.sideload(superSU)
sidefail = raw_input("if install failed, press 1 to attempt install from device. else, reboot into system from device recovery menu and press ENTER. --> ")
if sidefail == '1':
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")
raw_input("swipe to install - this may take a moment. if install is successful, select REBOOT from recovery menu. press ENTER to continue.")
obj.reboot("android")
# DOWNLOAD SUPERUSER ZIP
superusr = 'Superuser-3.1.3-arm-signed.zip'
def susrdl():
URLsuperusr = "http://notworth.it/opo/Superuser-3.1.3-arm-signed.zip"
MD5superusr = "b3c89f46f014c9df7d23b94d37386b8a"
dl = urllib.URLopener()
dl.retrieve(URLsuperusr, superusr)
site = urllib.urlopen(URLsuperusr)
meta = site.info()
dlsize = meta.getheaders("Content-Length")[0]
if usecolor == "color":
print("file size: \033[33m")
print(dlsize)
print("\n\033[0mbytes downloaded: \033[33m")
print(fsize)
print("\033[0m\n")
print("\033[34mchecking md5 signature...\033[0m\n")
else:
print("file size: ")
print(dlsize)
print("bytes downloaded: ")
print(fsize)
print("checking md5 signature...")
md5_read = ''
integrity = ''
with open(superusr, "r+b") as sf:
sfdata = sf.read()
md5_read = hashlib.md5(sfdata).hexdigest()
if MD5superusr == md5_read:
print("MD5 verified!")
integrity = 'passed'
else:
print("MD5 file integrity check failed!")
integrity = 'failed'
if integrity == 'failed':
if dlsize != fsize:
with open(superusr, "r+b") as f:
# read contents of downloaded Superuser file
fdata = f.read()
f.write(site.read())
f.flush()
os.fsync(f.fileno())
f.close()
# FLASH SUPERUSER ZIP IN CUSTOM RECOVERY
def susrroot(recovimg):
while not os.path.isfile(superusr):
if usecolor == 'color':
print("file \033[32m" + superusr + " \033[0mnot found. attempting download...\n")
else:
print("file " + superusr + " not found. attempting download... \n")
susrdl()
if usecolor == 'color':
print("file \033[32m" + superusr + " \033[0mfound!\n")
else:
print("file " + superusr + " found!\n")
while not os.path.isfile(recovimg):
if usecolor == 'color':
print("file \033[32m" + recovimg + " \033[0mnot found. attempting download...\n")
else:
print("file " + recovimg + " not found. attempting download...")
recovdl(recovimg)
if usecolor == 'color':
print("file \033[32m" + recovimg + " \033[0mfound!\n")
else:
print("file " + recovimg + " found!")
raw_input("press ENTER to copy file to device and reboot into bootloader.")
remotesuperusr = '/sdcard/Superuser-3.1.3-arm-signed.zip'
obj.push(superusr, remotesuperusr)
obj.reboot("bootloader")
raw_input("press ENTER to boot into custom recovery.")
obj.bootimg(recovimg)
if usecolor == 'color':
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")
else:
print("on device, choose INSTALL from recovery menu, then select file " + superusr + " in the /sdcard directory.\n")
raw_input("if install is successful, select REBOOT from recovery menu on device. press ENTER to continue.")
# DOWNLOAD TOWELROOT APK
trfile = 'apps/tr.apk'
def trdl():
dl = urllib.URLopener()
URLtr = "https://towelroot.com/tr.apk"
MD5tr = "e287e785d0e3e043fb0cfbfe69309d8e"
dl.retrieve(URLtr, trfile)
site = urllib.urlopen(URLtr)
meta = site.info()
dlsize = meta.getheaders("Content-Length")[0]
fsize = os.path.getsize(trfile)
if usecolor == "color":
print("file size: \033[33m")
print(dlsize)
print("\n\033[0mbytes downloaded: \033[33m")
print(fsize)
print("\033[0m\n")
print("\033[34mchecking md5 signature...\033[0m\n")
else:
print("file size: ")
print(dlsize)
print("bytes downloaded: ")
print(fsize)
print("checking md5 signature...")
md5_read = ''
integrity = ''
with open(trfile, "r+b") as sf:
sfdata = sf.read()
md5_read = hashlib.md5(sfdata).hexdigest()
if MD5tr == md5_read:
print("MD5 verified!")
integrity = 'passed'
else:
print("MD5 file integrity check failed!")
integrity = 'failed'
if integrity == 'failed':
if dlsize != fsize:
with open(trfile, "r+b") as f:
# read contents of downloaded TowelRoot file
fdata = f.read()
f.write(site.read())
f.flush()
os.fsync(f.fileno())
f.close()
# INSTALL TOWELROOT APK
def towroot():
if not os.path.exists('apps'):
os.makedirs('apps', 0755)
while not os.path.isfile(trfile):
print("file \033[32m" + trfile + " \033[0mnot found. attempting download...\n")
trdl()
print("file \033[32m" + trfile + " \033[0mfound!\n")
raw_input("press ENTER to install..")
obj.install(trfile)
obj.shell('am start -n com.geohot.towelroot/com.geohot.towelroot.TowelRoot')
print("if APK installed successfully, it should automatically launch on your device.")
raw_input("tap on MAKE IT RAIN. the results should appear shortly. follow instructions on device, then press ENTER to continue..")
pingpongfile = 'apps/pingpong5.1.apk'
# DOWNLOAD PINGPONGROOT APK
def ppdl():
dl = urllib.URLopener()
URLpp = "http://notworth.it/opo/apps/pingpong5.1.apk"
MD5pp = "93f08214e35eba4dacc29b1e04ef21d5"
dl.retrieve(URLpp, pingpongfile)
site = urllib.urlopen(URLpp)
meta = site.info()
dlsize = meta.getheaders("Content-Length")[0]
fsize = os.path.getsize(pingpongfile)
if usecolor == "color":
print("file size: \033[33m")
print(dlsize)
print("\n\033[0mbytes downloaded: \033[33m")
print(fsize)
print("\033[0m\n")
print("\033[34mchecking md5 signature...\033[0m\n")
else:
print("file size: ")
print(dlsize)
print("bytes downloaded: ")
print(fsize)
print("checking md5 signature...")
md5_read = ''
integrity = ''
with open(pingpongfile, "r+b") as sf:
sfdata = sf.read()
md5_read = hashlib.md5(sfdata).hexdigest()
if MD5tr == md5_read:
print("MD5 verified!")
integrity = 'passed'
else:
print("MD5 file integrity check failed!")
integrity = 'failed'
if integrity == 'failed':
if dlsize != fsize:
with open(pingpongfile, "r+b") as f:
# read contents of downloaded TowelRoot file
fdata = f.read()
f.write(site.read())
f.flush()
os.fsync(f.fileno())
f.close()
# INSTALL PINGPONGROOT APK
def pingpongroot():
if not os.path.exists('apps'):
os.makedirs('apps', 0755)
while not os.path.isfile(pingpongfile):
print("file \033[32m" + pingpongfile + " \033[0mnot found. attempting download...\n")
ppdl()
print("file \033[32m" + pingpongfile + " \033[0mfound!\n")
raw_input("press ENTER to install..")
obj.install(pingpongfile)
obj.shell('am start -n org.keenteam.pingpongroot/org.keenteam.pingpongroot.MainActivity')
print("if APK installed successfully, it should automatically launch on your device.")
raw_input("follow instructions on device, then press ENTER to continue..")
if usecolor == 'color':
rootwarning = '''\033[35mfor the ONEPLUS ONE, superSU is the safest and most widely confirmed root method. you may have to re-root after upgrading your ROM or flashing a custom ROM image. if flashing in recovery, remember to CLEAR CACHE AND DALVIK CACHE after zip installation!\033[0m\n
\033[33mif the build date for your device kernel is before \033[32mjune 4, 2014\033[33m, there is a chance the towelroot exploit may work.
\033[36mfor samsung s6 and s6 edge, and possibly other samsung devices, pingpongroot will work without tripping knox.
\033[31;1mROOTING YOUR DEVICE WILL VOID YOUR WARRANTY. YOU ALSO RUN THE RISK OF WIPING OR BRICKING YOUR DEVICE. BACKUP ANY IMPORTANT DATA AND CONTINUE AT YOUR OWN RISK!\033[0m\n'''
else:
rootwarning = '''for the ONEPLUS ONE, superSU is the safest and most widely confirmed root method. you may have to re-root after upgrading your ROM or flashing a custom ROM image. if flashing in recovery, remember to CLEAR CACHE AND DALVIK CACHE after zip installation!\n
if the build date for your device kernel is before june 4, 2014, there is a chance the towelroot exploit may work.
for samsung s6 and s6 edge, and possibly other samsung devices, pingpongroot will work without tripping knox.
ROOTING YOUR DEVICE WILL VOID YOUR WARRANTY. YOU ALSO RUN THE RISK OF WIPING OR BRICKING YOUR DEVICE. BACKUP ANY IMPORTANT DATA AND CONTINUE AT YOUR OWN RISK!'''
print(rootwarning)
rootcheck = raw_input("which root method would you like to try? enter 1 for SuperSU [recommended for oneplus one], 2 for towelroot, 3 for Superuser, 4 for pingpongroot, or 5 to install custom ZIP file. --> ")
while not re.search(r'^[1-5]$', rootcheck):
rootcheck = raw_input("invalid selection. enter 1 to install superSU package, 2 to install towelroot exploit, 3 to install Superuser, 4 to install pingpongroot, or 5 to install custom ZIP file. --> ")
# ROOT OPTION #1 - SUPERSU
if rootcheck == '1':
bootcustom = raw_input("press 1 to install superSU in a custom recovery, 2 to install in your current recovery, or 3 to install in fastboot [lower success rate]. --> ")
while not re.search(r'^[1-3]$', bootcustom):
bootcustom = raw_input("invalid choice. please enter 1 to load custom recovery, 2 to use installed recovery, or 3 for fastboot. --> ")
if bootcustom == '1': # SUPERSU TWRP
recovimg = chooserec()
suroot(recovimg) # SUPERSU CUSTOM RECOVERY
time.sleep(0.9)
main()
elif bootcustom == '2': # INSTALLED RECOVERY
while not os.path.isfile(superSU):
if usecolor == 'color':
print("file \033[32m" + superSU + " \033[0mnot found. attempting download...\n")
else:
print("file " + superSU + " not found. attempting download...")
sudl()
if usecolor == 'color':
print("file \033[32m" + superSU + " \033[0mfound!\n")
else:
print("file " + superSU + " found!\n")
raw_input("press ENTER to copy file to device, then reboot into recovery.")
remotesuperSU = '/sdcard/SuperSU-v2.49.zip'
obj.push(superSU, remotesuperSU)
raw_input("file copied to device. press ENTER to continue to recovery..")
obj.reboot("recovery")
raw_input("in recovery menu on device, please select APPLY UPDATE, then APPLY FROM ADB SIDELOAD. press ENTER when ready.")
obj.sideload("SuperSU-v2.49.zip")
if usecolor == 'color':
print("from device menu, find and select \033[34mCLEAR CACHE\033[0m and \033[34mCLEAR DALVIK CACHE\033[0m, then choose \033[35mREBOOT SYSTEM\033[0m. if zip installed successfully, press \033[32mENTER\033[0m.")
else:
print("from device menu, find and select CLEAR CACHE and CLEAR DALVIK CACHE, then choose REBOOT SYSTEM. if zip installed successfully, press ENTER.")