Browse Source
fixed su, added db interface
fixed su, added db interface
root/unroot method, ensures adb is running before gettting first devicemaster
5 changed files with 130 additions and 41 deletions
-
93adb.py
-
46android_db.py
-
1output
-
25sync_clip.py
-
6test.py
@ -0,0 +1,46 @@ |
|||||
|
import shlex |
||||
|
import re |
||||
|
import csv |
||||
|
import sys |
||||
|
csv.field_size_limit(2**31-1) |
||||
|
param_str = re.compile(r'(?<=\()[ ,\?]+(?=\))') |
||||
|
validator = re.compile(r'^\?(?: *\, *\?)*$') |
||||
|
param_sep = re.compile(r' *\, *') |
||||
|
class AndroidSQLConn: |
||||
|
def __init__(self,device,filepath,use_root=True): |
||||
|
self.device = device |
||||
|
self.filepath = filepath |
||||
|
self.root = use_root |
||||
|
|
||||
|
def _quote_param_(param): |
||||
|
if isinstance(param,str): |
||||
|
return "'{}'".format(param.replace("'","''")) |
||||
|
elif isinstance(param,bool): |
||||
|
return '1' if param else '0' |
||||
|
elif param is None: |
||||
|
return 'NULL' |
||||
|
else: |
||||
|
return str(param) |
||||
|
def _sub_params_(SQL,params): |
||||
|
p_string = param_str.search(SQL).group(0) |
||||
|
if not validator.match(p_string): |
||||
|
raise ValueError('Invalid substitution') |
||||
|
|
||||
|
n_params = len(param_sep.split(p_string)) |
||||
|
if len(params) < n_params: |
||||
|
raise ValueError('Not enough parameters supplied') |
||||
|
new_str = ','.join(map( |
||||
|
AndroidSQLConn._quote_param_,params[:n_params] |
||||
|
)) |
||||
|
return param_str.sub(new_str,SQL,1) |
||||
|
def execute(self,SQL,params = None): |
||||
|
if params: |
||||
|
SQL = AndroidSQLConn._sub_params_(SQL,params) |
||||
|
SQL = shlex.quote(SQL) |
||||
|
if self.root: |
||||
|
shell = self.device.sudo |
||||
|
else: |
||||
|
shell = self.device.shell |
||||
|
out = shell('sqlite3','-header','-csv',shlex.quote(self.filepath),SQL,output="out") |
||||
|
if out: |
||||
|
return csv.DictReader(out.splitlines()) |
||||
@ -0,0 +1 @@ |
|||||
|
'X:\\Users\\Ralphie\\Google Drive\\Python\\lib\\shlex.py' |
||||
@ -0,0 +1,25 @@ |
|||||
|
import pyperclip |
||||
|
import time |
||||
|
import re |
||||
|
def sync_clipboard(dev): |
||||
|
db_file = '/data/data/com.catchingnow.tinyclipboardmanager/databases/clippingnow.db' |
||||
|
try: |
||||
|
pid = dev.shell('pidof','com.catchingnow.tinyclipboardmanager',output="out") |
||||
|
dev.sudo('kill',pid,output='shell') |
||||
|
except: |
||||
|
pass |
||||
|
t = time.time() |
||||
|
text = pyperclip.paste() |
||||
|
conn = dev.db_connect(db_file) |
||||
|
# text = re.sub(r'([\{\}])',lambda match: match.group(1) * 2,text) |
||||
|
# sql = 'INSERT INTO cliphistory values ({},\'{}\',0)'.format(int(1000*t),text) |
||||
|
# sql = '"{}"'.format(sql) |
||||
|
# print(sql) |
||||
|
# dev.sudo('sqlite3','-csv',db_file,sql) |
||||
|
out = conn.execute("INSERT INTO cliphistory VALUES (?,?,?);",[int(1000*t),text,False]) |
||||
|
# print(list(out)) |
||||
|
dev.shell('am', 'start', '-n', 'com.catchingnow.tinyclipboardmanager/.activity.ActivityMain') |
||||
|
if __name__ == "__main__": |
||||
|
import adb |
||||
|
d = adb.Device.prim_device() |
||||
|
sync_clipboard(d) |
||||
@ -0,0 +1,6 @@ |
|||||
|
from adb import Device |
||||
|
d = Device.prim_device() |
||||
|
import time |
||||
|
d.root() |
||||
|
conn = d.db_connect('/data/data/com.catchingnow.tinyclipboardmanager/databases/clippingnow.db') |
||||
|
out = conn.execute('INSERT INTO cliphistory (date,history,star) values (?,?,?)',[int(time.time()*1000),"test_test",False]) |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue