debug_name.py 1.49 KB
import os, sys
sys.path.insert(0, '/data/data/com.termux/files/home/local-testkit')
import hermes_wechat_daemon as d

d.load_config()
src = d.config.get('db_src_path')

# Test 1: hermes_work + EnMicroMsg.db.decrypted.db
work1 = '/data/data/com.termux/files/home/hermes_work'
os.makedirs(work1, exist_ok=True)
copied = d.copy_db(src, work1)
enc1 = os.path.join(work1, 'EnMicroMsg.db')
plain1 = '/data/data/com.termux/files/home/EnMicroMsg.db.decrypted.db'
if os.path.exists(plain1): os.remove(plain1)
ok1 = d.decrypt_db(enc1, plain1, d.config.get('sqlcipher_key'), 1024, 1)
print('test1 (hermes_work + EnMicroMsg.db.decrypted.db)=', ok1)

# Test 2: hermes_work2 + test1.db
work2 = '/data/data/com.termux/files/home/hermes_work2'
os.makedirs(work2, exist_ok=True)
copied = d.copy_db(src, work2)
enc2 = os.path.join(work2, 'EnMicroMsg.db')
plain2 = '/data/data/com.termux/files/home/test1.db'
if os.path.exists(plain2): os.remove(plain2)
ok2 = d.decrypt_db(enc2, plain2, d.config.get('sqlcipher_key'), 1024, 1)
print('test2 (hermes_work2 + test1.db)=', ok2)

# Test 3: hermes_work + EnMicroMsg.db.decrypted.db again (fresh copy)
if os.path.exists(plain1): os.remove(plain1)
# Remove and recopy
import shutil
shutil.copy(enc1, enc1 + '.bak')
if os.path.exists(enc1): os.remove(enc1)
shutil.copy(enc1 + '.bak', enc1)
if os.path.exists(enc1 + '.bak'): os.remove(enc1 + '.bak')
ok3 = d.decrypt_db(enc1, plain1, d.config.get('sqlcipher_key'), 1024, 1)
print('test3 (fresh copy to hermes_work + EnMicroMsg.db.decrypted.db)=', ok3)