-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMethods.py
233 lines (174 loc) · 5.2 KB
/
Methods.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
# coding:utf-8
'''
Target: Python AndroidToolBox ADB Plugin Methods Module
Author: LZR@BUAA
Date: 08/26/2020
'''
import io
import os
import re
import subprocess
import sys
import tarfile
import time
import datetime
import threading
from tkinter import Tk, filedialog, messagebox
tk = Tk()
tk.withdraw()
'''
Check Connections:
'''
def getFastbootConnection():
cmd("fastboot devices")
def USBConnected():
echo = cmd("adb devices").split("\n")
return echo[1] != ''
def BLConnected():
echo = cmd("fastboot devices").find("fastboot")
return echo != -1
def WLANConnected():
if powerStatus():
IP = getIPaddress()
r = cmd("adb devices")
if r.find(IP) == -1:
return False
else:
return True
'''
Reboot:
'''
def rebootList():
os.system("cls")
print("+--------------重启菜单--------------+")
print("[1]重启到系统\n[2]重启到Recovery\n[3]重启到BootLoader\n[4]退出程序")
print("请选择-> ", end='')
op = InputJudge(4)
if op == 1:
rebootUI()
elif op == 2:
rebootRec()
elif op == 3:
rebootBL()
elif op == 4:
exitProgram(1)
exitProgram(0)
def rebootUI():
if BLConnected():
cmd("fastboot reboot")
if(USBConnected):
cmd("adb reboot")
def rebootBL():
cmd("adb reboot bootloader")
def rebootRec():
cmd("adb reboot recovery")
'''
Get Info:
'''
def getInfo():
MobileInfo = {}
model = cmd("adb shell getprop ro.product.model").replace(
'\n', '').replace('\r', '')
manufacturer = cmd("adb shell getprop ro.product.brand").replace(
'\n', '').replace('\r', '')
APIver = cmd("adb shell getprop ro.build.version.sdk").replace(
'\n', '').replace('\r', '')
wlandevice = cmd("adb shell getprop wifi.interface").replace(
'\n', '').replace('\r', '')
Serial = cmd("adb shell getprop ro.boot.serialno").replace(
'\n', '').replace('\r', '')
version = cmd("adb shell getprop ro.build.version.release").replace(
'\n', '').replace('\r', '')
battery = cmd("adb shell dumpsys battery | findstr \"level\"").split(": ")[-1].replace(
'\n', '').replace('\r', '')
MobileInfo.update({'model': model, 'API': APIver, 'android': version,
'brand': manufacturer, 'Wlan': wlandevice, 'serial': Serial, 'battery': battery})
return MobileInfo
def getIPaddress():
netstatus = cmd("adb shell ip addr | findstr \"wlan0\"")
IP = re.findall(r"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b", netstatus)
return IP[0]
def powerStatus():
PowerStat = cmd("adb shell getprop sys.boot_completed")
if PowerStat == "\n":
return False
else:
return True
'''
File Operations:
'''
def pushFile(sourcedir, rmpath):
print(cmd("adb push " + sourcedir + " " + rmpath))
def pullFile(rmpath, destdir):
r = cmd("adb pull " + rmpath + " " + destdir)
print(r)
return r
def touchPoint(x, y):
cmd("adb shell input tap "+x+" "+y)
def slidePoint(x1, y1, x2, y2):
cmd("adb shell input swipe "+x1+" "+y1+" "+x2+" "+y2)
def cmd(command):
r = os.popen(command).read()
return r
def unziptar(filename, dirs):
t = tarfile.open(filename)
t.extractall(path=dirs)
t.close()
def InputJudge(num):
if num == 2:
while True:
command = input()
if command not in ['Y', 'y', 'N', 'n']:
print("输入有误,请检查输入!")
else:
if command in ['y', 'Y']:
return True
else:
return False
else:
while True:
command = input()
if command.isdigit():
intput = int(command)
if intput not in range(1, num+1):
print("输入有误,请检查输入!")
else:
return intput
else:
print("输入有误,请检查输入!")
def exitProgram(num):
if num == 0:
print("\n操作已成功完成,程序退出中……")
time.sleep(1)
elif num == 1:
print("\n用户终止操作,程序退出中……")
time.sleep(1)
elif num == 3:
print("\n出现异常,程序退出中……")
time.sleep(1)
def directFlash(mode, file):
print(cmd("fastboot flash "+mode+" "+file))
'''
def fastbootReboot():
cmd("fastboot reboot")
def NewProgram(pyFileName):
os.system('cls')
# print("Press Enter to Continue……")
print(cmd("python "+pyFileName))
def dragtoWindowGetName():
filedir = input("请将文件拖动到窗口,并点击窗口后按下Enter")
return filedir
def dragtoPush(rmpath):
dir = dragtoWindowGetName()
pushFile(dir, rmpath)
def lockStatus():
rebootBL()
while True:
if BLConnected():
break
r = cmd("fastboot oem device-info | findstr unlocked")
if r.split(":")[-1].replace(" ", "") == "true":
return True
else:
return False
'''