{"contents":"# -*- coding: utf-8 -*-#\nimport hmac\nimport hashlib\nfrom ._loger import wx_core_loger\n\n\ndef wx_core_error(func):\n def wrapper(*args, **kwargs):\n try:\n return func(*args, **kwargs)\n except Exception as e:\n wx_core_loger.error(f\"wx_core_error: {e}\", exc_info=True)\n return None\n return wrapper\n\n\ndef verify_raw_key(enc_key_hex: str, wx_db_path: str) -\u003e bool:\n \"\"\"\n 验证从进程内存提取的 raw key (已派生,无需 PBKDF2)。\n SQLCipher 4: AES-256-CBC, HMAC-SHA512, page=4096, reserve=80 (16 IV + 64 HMAC)\n \"\"\"\n KEY_SIZE = 32\n DEFAULT_PAGESIZE = 4096\n HMAC_SIZE = 64\n try:\n enc_key = bytes.fromhex(enc_key_hex)\n with open(wx_db_path, \"rb\") as file:\n blist = file.read(DEFAULT_PAGESIZE + 100)\n salt = blist[:16]\n first = blist[16:DEFAULT_PAGESIZE]\n mac_salt = bytes([(salt[i] ^ 58) for i in range(16)])\n mac_key = hashlib.pbkdf2_hmac(\"sha512\", enc_key, mac_salt, 2, KEY_SIZE)\n hash_mac = hmac.new(mac_key, first[:-HMAC_SIZE], hashlib.sha512)\n hash_mac.update(b'\\x01\\x00\\x00\\x00')\n return hash_mac.digest() == first[-HMAC_SIZE:]\n except Exception:\n return False\n","is_binary":false,"path":"wxdump_linux/wx_core/utils/common_utils.py","ref":""}