Browse Source

added connect over tcp, decode parcel moved to seperate file,

capitalized device
master
Raphael Roberts 8 years ago
parent
commit
c2511d5cff
  1. 5
      .gitignore
  2. 70
      adb.py
  3. 10
      load_things.py

5
.gitignore

@ -1 +1,4 @@
__pycache__
__pycache__
decode_parcel.py
decoded.txt
parcel_ex.txt

70
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'(?<!0x)[a-f0-9]{8}')
res = ''
bytes_str = ''.join(match.group(0) for match in bytes_pat.finditer(s))
for p in range(0,len(bytes_str),2):
c= chr(int(bytes_str[p:p+2],16))
res += c
if '$' in res:
res = re.search(r'(?<=\$).+',res).group(0)
fres = ''
for c in range(0,len(res),4):
a = res[c:c+2]
b = res[c+2:c+4]
fres += b+a
return fres
else:
try:
return int(bytes_str,16)
except:
print(bytes_str,s)
# path = os.path.dirname(__file__)
defaults = loaded.defaults
keycodes = loaded.keycodes
exe = defaults.exe
def merge(src, dst,log = False):
if not os.path.exists(dst):
@ -85,20 +60,37 @@ def get_info():
main[categories[0]] = device_dict
return main
class device:
class Device:
def connect(ip,port=5555):
if not re.match(r'(\d{1,3}\.){3}\d{1,3}',ip):
raise TypeError("Invalid ip")
if not all(int(n) <= 255 and int(n) >= 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()

10
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)
Loading…
Cancel
Save