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
keycodes = loaded.keycodes
exe = config.defaults.exe
exists = '''if [ -e "{file}" ]; then
if [ -d "{file}" ]; then
echo "directory"
@ -63,8 +64,10 @@ def _adb(*args,output = "shell"):
elif output == "buffered":
p = subprocess.Popen(args,stdout = subprocess.PIPE)
return p.stdout
def kill_server():
_adb('kill-server')
def start_server():
_adb('start-server')
@ -82,8 +85,10 @@ def get_info():
device_dict.update(dict(category.split(":") for category in categories[2:]))
main[categories[0]] = device_dict
return main
class Device:
class ADBWrapper:
root_mode = False
def connect(ip,port=5555):
if not re.match(r'(\d{1,3}\.){3}\d{1,3}',ip):
raise TypeError("Invalid ip")
@ -100,8 +105,10 @@ class Device:
def disconnect(self):
if self.tcip:
_adb('disconnect',self.serial)
def db_connect(self,filepath):
return AndroidSQLConn(self,filepath)
def prim_device():
cont = True
while cont:
@ -134,14 +141,38 @@ class Device:
return self.shell(*args,output=output)
else:
return self.shell('su','--','--',*args,output=output)
@classmethod
def root(cls):
cls.root_mode = True
_adb('root')
@classmethod
def unroot(cls):
cls.root_mode = False
_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):
e = exists.format(file = file)
res = self.sudo(e,output="out")
@ -194,24 +225,7 @@ class Device:
def push(self,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):
try:
@ -221,13 +235,16 @@ class Device:
self.shell("input","keyevent",keycode)
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):
if self.mode != 'recovery':
@ -274,5 +291,8 @@ class Device:
else:
update_path = '{}/{}'.format(config['remote']['updates'],name)
self.shell("twrp","install",update_path)
class Device(TWRP,Input):
pass
if __name__ == "__main__" and debug:
d = Device.prim_device()

2
config.ini

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

Loading…
Cancel
Save