Browse Source

Seperated the methods into subclasses

seperation
Raphael Roberts 7 years ago
parent
commit
748054de69
  1. 72
      adb.py
  2. 2
      config.ini

72
adb.py

@ -13,6 +13,7 @@ debug = True
config = loaded.config config = loaded.config
keycodes = loaded.keycodes keycodes = loaded.keycodes
exe = config.defaults.exe exe = config.defaults.exe
exists = '''if [ -e "{file}" ]; then exists = '''if [ -e "{file}" ]; then
if [ -d "{file}" ]; then if [ -d "{file}" ]; then
echo "directory" echo "directory"
@ -63,8 +64,10 @@ def _adb(*args,output = "shell"):
elif output == "buffered": elif output == "buffered":
p = subprocess.Popen(args,stdout = subprocess.PIPE) p = subprocess.Popen(args,stdout = subprocess.PIPE)
return p.stdout return p.stdout
def kill_server(): def kill_server():
_adb('kill-server') _adb('kill-server')
def start_server(): def start_server():
_adb('start-server') _adb('start-server')
@ -82,8 +85,10 @@ def get_info():
device_dict.update(dict(category.split(":") for category in categories[2:])) device_dict.update(dict(category.split(":") for category in categories[2:]))
main[categories[0]] = device_dict main[categories[0]] = device_dict
return main return main
class Device:
class ADBWrapper:
root_mode = False root_mode = False
def connect(ip,port=5555): def connect(ip,port=5555):
if not re.match(r'(\d{1,3}\.){3}\d{1,3}',ip): if not re.match(r'(\d{1,3}\.){3}\d{1,3}',ip):
raise TypeError("Invalid ip") raise TypeError("Invalid ip")
@ -100,8 +105,10 @@ class Device:
def disconnect(self): def disconnect(self):
if self.tcip: if self.tcip:
_adb('disconnect',self.serial) _adb('disconnect',self.serial)
def db_connect(self,filepath): def db_connect(self,filepath):
return AndroidSQLConn(self,filepath) return AndroidSQLConn(self,filepath)
def prim_device(): def prim_device():
cont = True cont = True
while cont: while cont:
@ -134,14 +141,38 @@ class Device:
return self.shell(*args,output=output) return self.shell(*args,output=output)
else: else:
return self.shell('su','--','--',*args,output=output) return self.shell('su','--','--',*args,output=output)
@classmethod @classmethod
def root(cls): def root(cls):
cls.root_mode = True cls.root_mode = True
_adb('root') _adb('root')
@classmethod @classmethod
def unroot(cls): def unroot(cls):
cls.root_mode = False cls.root_mode = False
_adb('unroot') _adb('unroot')
def reboot(self,mode = None):
if mode:
if mode == "soft":
if self.mode != 'recovery':
pid = self.shell("pidof","zygote",output="out")
return self.sudo("kill",pid,output="shell")
else:
return self.reboot()
else:
self.adb("reboot",mode)
else:
self.adb("reboot")
while True:
infos = get_info()
if len(infos) > 0:
self.__dict__.update(infos[self.serial])
break
time.sleep(1)
class FSActionWrapper(ADBWrapper):
def type(self,file): def type(self,file):
e = exists.format(file = file) e = exists.format(file = file)
res = self.sudo(e,output="out") res = self.sudo(e,output="out")
@ -194,24 +225,7 @@ class Device:
def push(self,local,remote): def push(self,local,remote):
self.adb('push',local,remote) self.adb('push',local,remote)
def reboot(self,mode = None):
if mode:
if mode == "soft":
if self.mode != 'recovery':
pid = self.shell("pidof","zygote",output="out")
return self.sudo("kill",pid,output="shell")
else:
return self.reboot()
else:
self.adb("reboot",mode)
else:
self.adb("reboot")
while True:
infos = get_info()
if len(infos) > 0:
self.__dict__.update(infos[self.serial])
break
time.sleep(1)
class Input(ADBWrapper):
def send_keycode(self,code): def send_keycode(self,code):
try: try:
@ -221,13 +235,16 @@ class Device:
self.shell("input","keyevent",keycode) self.shell("input","keyevent",keycode)
def unlock_phone(self,password): def unlock_phone(self,password):
if self.mode != 'recovery':
if not decode_parcel(self.shell('service','call', 'power','12',output="out"),'int'):
self.send_keycode('power')
if decode_parcel(self.shell('service','call','trust','7',output="out"),'int'):
self.send_keycode('space')
self.shell("input","text",str(password))
self.send_keycode('enter')
if self.mode == 'recovery':
return
if not decode_parcel(self.shell('service','call', 'power','12',output="out"),'int'):
self.send_keycode('power')
if decode_parcel(self.shell('service','call','trust','7',output="out"),'int'):
self.send_keycode('space')
self.shell("input","text",str(password))
self.send_keycode('enter')
class TWRP(FSActionWrapper):
def backup(self,*partitions,name = None,backupdir = None): def backup(self,*partitions,name = None,backupdir = None):
if self.mode != 'recovery': if self.mode != 'recovery':
@ -274,5 +291,8 @@ class Device:
else: else:
update_path = '{}/{}'.format(config['remote']['updates'],name) update_path = '{}/{}'.format(config['remote']['updates'],name)
self.shell("twrp","install",update_path) self.shell("twrp","install",update_path)
class Device(TWRP,Input):
pass
if __name__ == "__main__" and debug: if __name__ == "__main__" and debug:
d = Device.prim_device() d = Device.prim_device()

2
config.ini

@ -1,6 +1,6 @@
[defaults] [defaults]
date_format = %Y-%m-%d_%H.%M.%S date_format = %Y-%m-%d_%H.%M.%S
exe = c:\Program Files (x86)\ADB\adb.exe
exe = C:\platform-tools\adb.exe
[remote] [remote]
messages = /data/user_de/0/com.android.providers.telephony/databases/mmssms.db messages = /data/user_de/0/com.android.providers.telephony/databases/mmssms.db
screenshots = /sdcard/Pictures/Screenshots screenshots = /sdcard/Pictures/Screenshots

Loading…
Cancel
Save