This repository has been archived by the owner on Feb 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adbPassInput.py
executable file
·66 lines (54 loc) · 2.52 KB
/
adbPassInput.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
import os, getpass, sys, argparse
def main():
# Creating instruction page
parser = argparse.ArgumentParser(usage="python3 %(prog)s [options]")
parser.add_argument('--version', action='version', version='%(prog)s 1.20')
args = parser.parse_args()
# If script called with arguments exists with error message
if len(sys.argv) != 1:
parser.error("Script called with arguments")
print("{}".format(args))
# Else it continues processing
else:
# Ask for Password
adbInput = getpass.getpass("ADB Input: ")
if '\t' in adbInput:
# If it finds a tab sequence in the string it separats it on the tab sequence
adbInput = adbInput.split('\t')
print("Username: {}".format(adbInput[0]))
print("Password: ********")
# It then sends the username through the escaper function and sends a tab event after returning
escaper(adbInput[0])
inputer("keyevent", "61")
# Finally it sends the password through the escaper function and ends up with sending the "enter" key event
escaper(adbInput[1])
inputer("keyevent", "66")
else:
# Escapes the password only and sends the enter key event
escaper(adbInput)
#inputer("keyevent", "66")
def escaper(escaping):
# For each special character replace with an escaped sequence
for ch in ['\\', '`', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '=', '+', ',', '<', '.', '>', '|', '[', '{', ']', '}', ';', ':', "'", '"', '/', '?', '"<']:
if ch == '"':
# '"' requires escaping and clisong of in "'" for adb to process it as part of the string to send...
escaping = escaping.replace('"', '''"'\\"'"''')
else:
# Everything else gets escaped with a single '\'
escaping = escaping.replace(ch, "\\{}".format(ch))
# Calls inputer with the text event and the string to be inputed
inputer("text", escaping)
def inputer(eventType, adbEscapedInput):
# executes the adb input command type with the escaped string
os.system('adb shell input {} "{}"'.format(eventType, adbEscapedInput))
if __name__== "__main__":
# Tries to call main
try:
main()
# Handles keyboard interuption exceptions
except KeyboardInterrupt:
print ('\rExecution interrupted...Exiting!')
try:
sys.exit(0)
except SystemExit as Err:
print("Error exiting: {}".format(Err))