debug_poll2.py
1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import sys, os, subprocess
sys.path.insert(0, '/data/data/com.termux/files/home/local-testkit')
import hermes_wechat_daemon as d
d.load_config()
d.setup_logging(d.config.get('logging', {}))
src = d.config.get('db_src_path')
work_dir = '/data/data/com.termux/files/home/hermes_work'
os.makedirs(work_dir, exist_ok=True)
copied = d.copy_db(src, work_dir)
print('copied=', copied)
enc = os.path.join(work_dir, 'EnMicroMsg.db')
plain = '/data/data/com.termux/files/home/EnMicroMsg.db.decrypted.db'
print('enc exists=', os.path.exists(enc))
print('enc size=', os.path.getsize(enc))
if os.path.exists(plain):
os.remove(plain)
key = d.config.get('sqlcipher_key')
print('key=', repr(key))
sql = f"""
PRAGMA key = "{key}";
PRAGMA cipher_compatibility = 1;
PRAGMA cipher_page_size = 1024;
ATTACH DATABASE '{plain}' AS plain KEY '';
SELECT sqlcipher_export('plain');
DETACH DATABASE plain;
.quit
"""
r = subprocess.run(
['/data/data/com.termux/files/usr/bin/sqlcipher', enc],
input=sql, capture_output=True, text=True, timeout=60
)
print('rc=', r.returncode)
print('stdout=', repr(r.stdout))
print('stderr=', repr(r.stderr))
print('plain exists=', os.path.exists(plain))
if os.path.exists(plain):
print('plain size=', os.path.getsize(plain))