debug_poll2.py 1.23 KB
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))