commit
6100a3221f
3 changed files with 484 additions and 0 deletions
-
181adb.py
-
16defaults.json
-
287keycodes.json
@ -0,0 +1,181 @@ |
|||
import datetime |
|||
import json |
|||
import os |
|||
import re |
|||
import shutil |
|||
import subprocess |
|||
import time |
|||
|
|||
debug = True |
|||
with open('defaults.json') as d,open('keycodes.json') as k: |
|||
defaults = json.load(d) |
|||
keycodes = json.load(k) |
|||
exe = defaults['exe'] |
|||
for key,value in defaults['local'].items(): |
|||
defaults['local'][key] = os.path.expandvars(value) |
|||
|
|||
#I can't lmao |
|||
exists = '''if [ -e {} ] |
|||
then |
|||
echo "True" |
|||
else |
|||
echo "False" |
|||
fi''' |
|||
|
|||
def merge(src, dst,log = False): |
|||
if not os.path.exists(dst): |
|||
return False |
|||
ok = True |
|||
for path, dirs, files in os.walk(src): |
|||
relPath = os.path.relpath(path, src) |
|||
destPath = os.path.join(dst, relPath) |
|||
if not os.path.exists(destPath): |
|||
os.makedirs(destPath) |
|||
for file in files: |
|||
destFile = os.path.join(destPath, file) |
|||
if os.path.isfile(destFile): |
|||
if log: |
|||
print("Skipping existing file: " + os.path.join(relPath, file)) |
|||
ok = False |
|||
continue |
|||
srcFile = os.path.join(path, file) |
|||
shutil.move(srcFile, destFile) |
|||
for path, dirs, files in os.walk(src, False): |
|||
if len(files) == 0 and len(dirs) == 0: |
|||
os.rmdir(path) |
|||
return ok |
|||
|
|||
def _adb(*args,out = False): |
|||
args = [exe] + list(args) |
|||
if out: |
|||
return subprocess.check_output(args,shell = False).decode().rstrip('\r\n') |
|||
else: |
|||
subprocess.call(args,shell = False) |
|||
|
|||
def get_info(): |
|||
thing = _adb("devices","-l",out = True) |
|||
formed = list(filter(bool,thing.split("\r\n")))[1:] |
|||
main = {} |
|||
for device in formed: |
|||
categories = re.split(" +",device) |
|||
device_dict = { |
|||
"serial":categories[0], |
|||
"mode":categories[1] |
|||
} |
|||
|
|||
device_dict.update(dict(category.split(":") for category in categories[2:])) |
|||
main[categories[0]] = device_dict |
|||
return main |
|||
|
|||
class device: |
|||
|
|||
|
|||
def prim_device(): |
|||
while True: |
|||
prim_device_serial = get_info() |
|||
if len(prim_device_serial.keys()) > 0: |
|||
return device(list(prim_device_serial.keys())[0]) |
|||
|
|||
def __init__(self,serial=None): |
|||
if serial: |
|||
self.serial = serial |
|||
self.info = get_info()[serial] |
|||
else: |
|||
self.serial,self.info = get_info().items()[0] |
|||
|
|||
def adb(self,*args,out = False): |
|||
args = ['-s',self.serial]+ list(args) |
|||
return _adb(*args,out = out) |
|||
|
|||
def sudo(self,*args,out = False): |
|||
args = '"{}"'.format(" ".join(args)) |
|||
return self.adb("shell","su","-c",args,out = out) |
|||
|
|||
def exists(self,file): |
|||
e = exists.format(file) |
|||
res = self.sudo(e,out=True) |
|||
return res == "True" |
|||
|
|||
def reboot(self,mode = None): |
|||
if mode: |
|||
if mode == "soft": |
|||
pid = self.adb("shell","pidof","zygote",out = True) |
|||
return self.sudo("kill",pid,out=True) |
|||
|
|||
else: |
|||
self.adb("reboot",mode) |
|||
else: |
|||
self.adb("reboot") |
|||
|
|||
def delete(self,path): |
|||
self.sudo("rm","-rf",path) |
|||
|
|||
def copy(self,remote,local,del_duplicate = True): |
|||
if os.path.exists(computer): |
|||
last = os.path.split(computer)[-1] |
|||
real_dir = computer |
|||
computer = os.path.join(defaults['temp'],last) |
|||
flag = True |
|||
self.adb("pull","-a",phone,computer) |
|||
if flag: |
|||
shutil.merge(computer,real_dir) |
|||
if os.path.exists(computer) and delete_dups: |
|||
shutil.rmtree(computer) |
|||
|
|||
def send_keycode(self,code): |
|||
try: |
|||
keycode = keycodes[code] |
|||
except KeyError: |
|||
keycode = str(code) |
|||
self.adb("shell","input","keyevent",keycode) |
|||
|
|||
def move(self,remote,local,del_duplicate = True): |
|||
self.copy(remote,local,del_duplicate = del_duplicate) |
|||
self.delete(remote) |
|||
|
|||
def push(self,local,remote): |
|||
self.adb('push',local,remote) |
|||
|
|||
def backup(*partitions,name = None,backupdir): |
|||
|
|||
options_dict = { |
|||
"system": "S", |
|||
"data": "D", |
|||
"cache": "C", |
|||
"recovery": "R", |
|||
"spec_part_1": "1", |
|||
"spec_part_2": "2", |
|||
"spec_part_3": "3", |
|||
"boot": "B", |
|||
"as": "A" |
|||
} |
|||
options = "".join(options_dict[option] for option in partitions) |
|||
|
|||
if not name: |
|||
name = "backup_"+datetime.datetime.today().strftime(defaults['date_format']) |
|||
|
|||
filename = os.path.join(backupdir,name) |
|||
self.adb("shell","twrp","backup",options,name) |
|||
phone_dir = "/data/media/0/TWRP/BACKUPS/{serial}/{name}".format(serial = self.serial,name = name) |
|||
self.move(phone_dir,filename) |
|||
|
|||
def unlock_phone(self,pin): |
|||
self.send_keycode('power') |
|||
self.send_keycode('space') |
|||
self.adb("shell","input","text",str(pin)) |
|||
self.send_keycode('enter') |
|||
|
|||
def install(self,name): |
|||
if os.path.exists(name): |
|||
local_name = name |
|||
name = os.path.split(name)[-1] |
|||
update_path = '{}/{}'.format(defaults['remote']['updates'],name) |
|||
if not self.exists(update_path): |
|||
self.push(local_name,defaults['remote']['updates']) |
|||
|
|||
else: |
|||
update_path = '{}/{}'.format(defaults['remote']['updates'],name) |
|||
self.adb("shell","twrp","install",update_path) |
|||
|
|||
if __name__ == "__main__" and debug: |
|||
d = device.prim_device() |
|||
@ -0,0 +1,16 @@ |
|||
{ |
|||
"exe": "c:\\Program Files (x86)\\ADB\\adb.exe", |
|||
"date_format":"%Y-%m-%d_%H.%M.%S", |
|||
"local": { |
|||
"TWRP": "%userprofile%\\Android\\TWRP", |
|||
"TitaniumBackup": "%userprofile%\\Android\\TitaniumBackup", |
|||
"temp": "%userprofile%\\Android\\harbor", |
|||
"screenshots": "%userprofile%\\Pictures\\Screenshots", |
|||
"updates": "%userprofile%\\Downloads\\sort\\phone_updates" |
|||
}, |
|||
"remote": { |
|||
"screenshots": "/sdcard/Pictures/Screenshots", |
|||
"titanium_backup": "/sdcard/TitaniumBackup", |
|||
"updates": "/data/lineageos_updates" |
|||
} |
|||
} |
|||
@ -0,0 +1,287 @@ |
|||
{ |
|||
"unknown": "0", |
|||
"soft_left": "1", |
|||
"soft_right": "2", |
|||
"home": "3", |
|||
"back": "4", |
|||
"call": "5", |
|||
"endcall": "6", |
|||
"0": "7", |
|||
"1": "8", |
|||
"2": "9", |
|||
"3": "10", |
|||
"4": "11", |
|||
"5": "12", |
|||
"6": "13", |
|||
"7": "14", |
|||
"8": "15", |
|||
"9": "16", |
|||
"star": "17", |
|||
"pound": "18", |
|||
"dpad_up": "19", |
|||
"dpad_down": "20", |
|||
"dpad_left": "21", |
|||
"dpad_right": "22", |
|||
"dpad_center": "23", |
|||
"volume_up": "24", |
|||
"volume_down": "25", |
|||
"power": "26", |
|||
"camera": "27", |
|||
"clear": "28", |
|||
"a": "29", |
|||
"b": "30", |
|||
"c": "31", |
|||
"d": "32", |
|||
"e": "33", |
|||
"f": "34", |
|||
"g": "35", |
|||
"h": "36", |
|||
"i": "37", |
|||
"j": "38", |
|||
"k": "39", |
|||
"l": "40", |
|||
"m": "41", |
|||
"n": "42", |
|||
"o": "43", |
|||
"p": "44", |
|||
"q": "45", |
|||
"r": "46", |
|||
"s": "47", |
|||
"t": "48", |
|||
"u": "49", |
|||
"v": "50", |
|||
"w": "51", |
|||
"x": "52", |
|||
"y": "53", |
|||
"z": "54", |
|||
"comma": "55", |
|||
"period": "56", |
|||
"alt_left": "57", |
|||
"alt_right": "58", |
|||
"shift_left": "59", |
|||
"shift_right": "60", |
|||
"tab": "61", |
|||
"space": "62", |
|||
"sym": "63", |
|||
"explorer": "64", |
|||
"envelope": "65", |
|||
"enter": "66", |
|||
"del": "67", |
|||
"grave": "68", |
|||
"minus": "69", |
|||
"equals": "70", |
|||
"left_bracket": "71", |
|||
"right_bracket": "72", |
|||
"backslash": "73", |
|||
"semicolon": "74", |
|||
"apostrophe": "75", |
|||
"slash": "76", |
|||
"at": "77", |
|||
"num": "78", |
|||
"headsethook": "79", |
|||
"focus": "80", |
|||
"plus": "81", |
|||
"menu": "82", |
|||
"notification": "83", |
|||
"search": "84", |
|||
"media_play_pause": "85", |
|||
"media_stop": "86", |
|||
"media_next": "87", |
|||
"media_previous": "88", |
|||
"media_rewind": "89", |
|||
"media_fast_forward": "90", |
|||
"mute": "91", |
|||
"page_up": "92", |
|||
"page_down": "93", |
|||
"pictsymbols": "94", |
|||
"switch_charset": "95", |
|||
"button_a": "96", |
|||
"button_b": "97", |
|||
"button_c": "98", |
|||
"button_x": "99", |
|||
"button_y": "100", |
|||
"button_z": "101", |
|||
"button_l1": "102", |
|||
"button_r1": "103", |
|||
"button_l2": "104", |
|||
"button_r2": "105", |
|||
"button_thumbl": "106", |
|||
"button_thumbr": "107", |
|||
"button_start": "108", |
|||
"button_select": "109", |
|||
"button_mode": "110", |
|||
"escape": "111", |
|||
"forward_del": "112", |
|||
"ctrl_left": "113", |
|||
"ctrl_right": "114", |
|||
"caps_lock": "115", |
|||
"scroll_lock": "116", |
|||
"meta_left": "117", |
|||
"meta_right": "118", |
|||
"function": "119", |
|||
"sysrq": "120", |
|||
"break": "121", |
|||
"move_home": "122", |
|||
"move_end": "123", |
|||
"insert": "124", |
|||
"forward": "125", |
|||
"media_play": "126", |
|||
"media_pause": "127", |
|||
"media_close": "128", |
|||
"media_eject": "129", |
|||
"media_record": "130", |
|||
"f1": "131", |
|||
"f2": "132", |
|||
"f3": "133", |
|||
"f4": "134", |
|||
"f5": "135", |
|||
"f6": "136", |
|||
"f7": "137", |
|||
"f8": "138", |
|||
"f9": "139", |
|||
"f10": "140", |
|||
"f11": "141", |
|||
"f12": "142", |
|||
"num_lock": "143", |
|||
"numpad_0": "144", |
|||
"numpad_1": "145", |
|||
"numpad_2": "146", |
|||
"numpad_3": "147", |
|||
"numpad_4": "148", |
|||
"numpad_5": "149", |
|||
"numpad_6": "150", |
|||
"numpad_7": "151", |
|||
"numpad_8": "152", |
|||
"numpad_9": "153", |
|||
"numpad_divide": "154", |
|||
"numpad_multiply": "155", |
|||
"numpad_subtract": "156", |
|||
"numpad_add": "157", |
|||
"numpad_dot": "158", |
|||
"numpad_comma": "159", |
|||
"numpad_enter": "160", |
|||
"numpad_equals": "161", |
|||
"numpad_left_paren": "162", |
|||
"numpad_right_paren": "163", |
|||
"volume_mute": "164", |
|||
"info": "165", |
|||
"channel_up": "166", |
|||
"channel_down": "167", |
|||
"zoom_in": "168", |
|||
"zoom_out": "169", |
|||
"tv": "170", |
|||
"window": "171", |
|||
"guide": "172", |
|||
"dvr": "173", |
|||
"bookmark": "174", |
|||
"captions": "175", |
|||
"settings": "176", |
|||
"tv_power": "177", |
|||
"tv_input": "178", |
|||
"stb_power": "179", |
|||
"stb_input": "180", |
|||
"avr_power": "181", |
|||
"avr_input": "182", |
|||
"prog_red": "183", |
|||
"prog_green": "184", |
|||
"prog_yellow": "185", |
|||
"prog_blue": "186", |
|||
"app_switch": "187", |
|||
"button_1": "188", |
|||
"button_2": "189", |
|||
"button_3": "190", |
|||
"button_4": "191", |
|||
"button_5": "192", |
|||
"button_6": "193", |
|||
"button_7": "194", |
|||
"button_8": "195", |
|||
"button_9": "196", |
|||
"button_10": "197", |
|||
"button_11": "198", |
|||
"button_12": "199", |
|||
"button_13": "200", |
|||
"button_14": "201", |
|||
"button_15": "202", |
|||
"button_16": "203", |
|||
"language_switch": "204", |
|||
"manner_mode": "205", |
|||
"3d_mode": "206", |
|||
"contacts": "207", |
|||
"calendar": "208", |
|||
"music": "209", |
|||
"calculator": "210", |
|||
"zenkaku_hankaku": "211", |
|||
"eisu": "212", |
|||
"muhenkan": "213", |
|||
"henkan": "214", |
|||
"katakana_hiragana": "215", |
|||
"yen": "216", |
|||
"ro": "217", |
|||
"kana": "218", |
|||
"assist": "219", |
|||
"brightness_down": "220", |
|||
"brightness_up": "221", |
|||
"media_audio_track": "222", |
|||
"sleep": "223", |
|||
"wakeup": "224", |
|||
"pairing": "225", |
|||
"media_top_menu": "226", |
|||
"11": "227", |
|||
"12": "228", |
|||
"last_channel": "229", |
|||
"tv_data_service": "230", |
|||
"voice_assist": "231", |
|||
"tv_radio_service": "232", |
|||
"tv_teletext": "233", |
|||
"tv_number_entry": "234", |
|||
"tv_terrestrial_analog": "235", |
|||
"tv_terrestrial_digital": "236", |
|||
"tv_satellite": "237", |
|||
"tv_satellite_bs": "238", |
|||
"tv_satellite_cs": "239", |
|||
"tv_satellite_service": "240", |
|||
"tv_network": "241", |
|||
"tv_antenna_cable": "242", |
|||
"tv_input_hdmi_1": "243", |
|||
"tv_input_hdmi_2": "244", |
|||
"tv_input_hdmi_3": "245", |
|||
"tv_input_hdmi_4": "246", |
|||
"tv_input_composite_1": "247", |
|||
"tv_input_composite_2": "248", |
|||
"tv_input_component_1": "249", |
|||
"tv_input_component_2": "250", |
|||
"tv_input_vga_1": "251", |
|||
"tv_audio_description": "252", |
|||
"tv_audio_description_mix_up": "253", |
|||
"tv_audio_description_mix_down": "254", |
|||
"tv_zoom_mode": "255", |
|||
"tv_contents_menu": "256", |
|||
"tv_media_context_menu": "257", |
|||
"tv_timer_programming": "258", |
|||
"help": "259", |
|||
"navigate_previous": "260", |
|||
"navigate_next": "261", |
|||
"navigate_in": "262", |
|||
"navigate_out": "263", |
|||
"stem_primary": "264", |
|||
"stem_1": "265", |
|||
"stem_2": "266", |
|||
"stem_3": "267", |
|||
"dpad_up_left": "268", |
|||
"dpad_down_left": "269", |
|||
"dpad_up_right": "270", |
|||
"dpad_down_right": "271", |
|||
"media_skip_forward": "272", |
|||
"media_skip_backward": "273", |
|||
"media_step_forward": "274", |
|||
"media_step_backward": "275", |
|||
"soft_sleep": "276", |
|||
"cut": "277", |
|||
"copy": "278", |
|||
"paste": "279", |
|||
"system_navigation_up": "280", |
|||
"system_navigation_down": "281", |
|||
"system_navigation_left": "282", |
|||
"system_navigation_right": "283", |
|||
"all_apps": "284" |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue