diff --git a/.gitignore b/.gitignore index ed8ebf5..6ccfa62 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -__pycache__ \ No newline at end of file +__pycache__ +decode_parcel.py +decoded.txt +parcel_ex.txt diff --git a/adb.py b/adb.py index ae53ce3..a9f45e1 100644 --- a/adb.py +++ b/adb.py @@ -5,38 +5,13 @@ import re import shutil import subprocess import time - +from load_things import loaded +from decode_parcel import decode_parcel debug = True -path = os.path.dirname(__file__) -with open(os.path.join(path,'defaults.json')) as d,open(os.path.join(path,'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) - -def decode_parcel(s): - bytes_pat = re.compile(r'(?= 0 for n in ip.split('.')): + raise TypeError("Invalid ip") + if not (port >= 0 and port <= 2**16-1): + raise TyperError("Port must be in the range 0-65536") + id = '{}:{}'.format(ip,port) + _adb('connect','{}:{}'.format(ip,port)) + dev = Device(id) + dev.tcip = True + return dev + def disconnect(self): + if self.tcip: + _adb('disconnect',self.serial) + #init operations def prim_device(): cont = True while cont: try: - d = device() + d = Device() cont = False except IndexError: time.sleep(1) return d - #todo connect over tcip + def __init__(self,serial=None): + self.tcip = False if serial: self.serial = serial info = get_info()[serial] @@ -212,13 +204,13 @@ fi''' keycode = str(code) self.shell("input","keyevent",keycode) - def unlock_phone(self,pin): + def unlock_phone(self,pass): if self.mode != 'recovery': - if not decode_parcel(self.shell('service','call', 'power','12',out=True)): + if not decode_parcel(self.shell('service','call', 'power','12',out=True),'int'): self.send_keycode('power') - if decode_parcel(self.shell('service','call','trust','7',out=True)): + if decode_parcel(self.shell('service','call','trust','7',out=True),'int'): self.send_keycode('space') - self.shell("input","text",str(pin)) + self.shell("input","text",str(pass)) self.send_keycode('enter') #end of convenience @@ -269,4 +261,4 @@ fi''' #end of twrp if __name__ == "__main__" and debug: - d = device.prim_device() + d = Device.prim_device() diff --git a/load_things.py b/load_things.py new file mode 100644 index 0000000..e37ec0a --- /dev/null +++ b/load_things.py @@ -0,0 +1,10 @@ +import json +import munch +import os +path = os.path.dirname(__file__) +with open(os.path.join(path,'defaults.json')) as d,open(os.path.join(path,'keycodes.json')) as k: + defaults = munch.munchify(json.load(d)) + keycodes = munch.munchify(json.load(k)) +for key,value in defaults['local'].items(): + defaults['local'][key] = os.path.expandvars(value) +loaded = munch.Munch(defaults = defaults,keycodes = keycodes) \ No newline at end of file