wcdb-key-tool recovers your own WeChat database key after the 4.1 change
Extract WeChat (WCDB/SQLCipher4) database encryption keys on Linux. Auto-adapts to new versions via ELF static analysis — no manual reverse engineering needed per update. Linux 微信数据库密钥提取工具。通过 ELF静态分析自动适配新版本,无需每次更新手动逆向。
At a glance
- What is it?
- wcdb-key-tool is a single file Python script that derives the SQLite key for your own WeChat WCDB database by reading a passphrase out of the running client, then decrypting each database file. It suits someone restoring their own chat history on their own machine, and the derived passphrase is a credential worth protecting.
- Who is it for?
- Adopt wcdb-key-tool if you need to read your own WeChat chat history from your own machine and you are comfortable attaching a debugger to a running process. Skip it if the data is not yours, and think twice before installing it on a machine with a compromised WeChat install, because the passphrase it caches is equivalent to your chat database key.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 80 days ago.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on October 23, 2026, and from our analysis. They are not legal advice.
Editorial analysis
The tool is scoped to your own account, and the README says so explicitly
The project is explicit about its purpose and its limits, and that framing matters for a tool that touches encryption keys. The repository states that it does one thing: publish the approach and the code for legitimately extracting the database key of your own account from WeChat's own process, with no collection, no batch operation and no contact with any server communication. The security notes list three points. The tool is only for extracting the database key of your own account on your own device. The debugger attaches only at the moment of key computation, reads the register or memory value once and detaches immediately, and does not modify WeChat's behaviour or touch network protocols. The FAQ adds that it will not trigger an account ban, because the whole process is short and does not alter program behaviour or communicate with WeChat servers. The project is MIT licensed and the credits name the original GDB breakpoint idea and the ELF static analysis method it builds on. The last recorded commit was on 2026-08-04, so the code base is compact enough to read end to end, which matters for a tool that runs with elevated privileges.
WeChat 4.1 removed the raw key from memory, which broke the old scanning tools
The background section explains why this tool exists at all. WeChat 4.1 and later no longer cache the raw database encryption key in process memory, only a passphrase remains, from which the real key must be derived. That change broke every existing tool that relied on x'<hex>' memory pattern scanning, because the pattern those tools searched for is no longer in memory. The consequence for the cryptography is that the key bytes you can observe are weaker than the key you need. The tool handles this in four steps. First it obtains the key material, then it derives the real key for each database with PBKDF2, then it verifies the result with HMAC, and finally it decrypts page by page with AES-256-CBC to recover a standard SQLite file. The three platform scripts are wcdb_key_tool.py for Linux, wcdb_key_tool_macos.py for macOS and wcdb_key_tool_windows.py for Windows, and the compatibility table records that the new path is verified on real hardware for all three.
Each platform gets the passphrase a different way
The three routes differ only in how the raw material is obtained, the rest of the logic is identical. For older WeChat versions, the client itself assembles the raw key and salt into a hexadecimal string that sits in clear text in process memory, so a memory scan finds it directly. For 4.1 and later, the passphrase is computed only once, at login, and then stays in memory without being recomputed, so catching it means interrupting the computation itself, which requires a debugger breakpoint on the function that handles the key and a user who logs out and back in to trigger a fresh calculation. On Linux the WeChat binary exposes no usable system symbols, so the tool does ELF static analysis, finds WCDB characteristic strings in the .rodata section, follows the cross references to the key handling function entry and sets a GDB breakpoint there, using elf_analyzer.py and gdb_capture.py. On macOS WeChat calls the system's own CommonCrypto library, which is a public system symbol, so there is no need to reverse engineer WeChat's own binary and LLDB can simply break on CCKeyDerivationPBKDF, and that path is recorded as verified 18 out of 18. On Windows the main path is a read-only runtime scan for the com.Tencent.WCDB.Config.Cipher object, decoding candidate x'<64hex key><32hex salt>' fragments and checking them with HMAC, with the older memory scan used as a fallback.
PBKDF2 and the HMAC check are what make a hit trustworthy
The last two steps are where the tool earns trust in its output, and they are worth understanding before you rely on the result. Once the passphrase is obtained, each database file has its own 16 byte salt, and the tool runs PBKDF2-HMAC-SHA512 with 256,000 iterations to derive that database's own 32 byte AES-256 key. The derived key is then not taken on faith. The tool computes HMAC-SHA512 over the first page of the database and compares it with the HMAC the database stores for itself, and only a match means the key is correct. The documentation is direct that this is the safety net against grabbing the wrong thing and the only criterion for whether a runtime scan or a fallback route actually succeeded, because a hit does not mean what you read is right. The final step is AES-256-CBC decryption page by page to restore a standard SQLite file. A related safety feature is encryption-aware extraction, which identifies protected entries and extracts plaintext metadata without producing corrupt output.
Running it needs a debugger, and on Linux and macOS that means root
There are no third-party Python dependencies to install, because all three platforms call the system cryptography library directly, with OpenSSL on Linux, CommonCrypto on macOS and CNG on Windows. What you do need is a debugger. On Linux that is gdb, on macOS it is the lldb that comes with the Xcode command line tools, and on Windows neither the old memory scan nor the new runtime scan needs anything extra, with cdb.exe needed only if you want to test the experimental route:
# Linux
sudo apt install gdbThe FAQ explains the sudo requirement. GDB and LLDB need ptrace permission, which on macOS is task_for_pid, to attach to another process's memory space. On Linux you can also relax the restriction temporarily with echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope, which reverts after a reboot, instead of running sudo every time. The macOS path has an extra step, because the WeChat app has to be re-signed to drop the Hardened Runtime before task_for_pid will work, and the re-signing may have to be redone after a WeChat upgrade.
The first extraction needs a logout and login, and afterwards the passphrase is cached
The usage is a single extract command per platform, and the first run has a manual step built into it. On Linux it is the tool run with sudo, and the same shape applies on macOS and Windows:
# Linux
sudo python3 wcdb_key_tool.py extract --decryptThe Windows invocation does not need root, and the experimental route remains available as a separate command that is not the main path:
python3 wcdb_key_tool_windows.py capture-experimentalEvery first extraction requires logging out of WeChat and logging back in once, so that the key computation happens again and the breakpoint has a chance to hit. The passphrase that is caught is then cached, so the step is not repeated. The FAQ says where it goes: the file ~/.wcdb-key-tool/wechat-passphrase.json, with mode 600, readable only by the current user, and the same path is used on all three platforms. The decrypt flag means the run goes on to produce the decrypted databases, not just the key.
Staying working after a WeChat update is a question of where you break
The FAQ answers the question that decides whether this is worth adopting: will it still work after WeChat updates. On Linux the answer is probably yes, because the ELF static analysis locates the function through string cross references, so as long as WeChat keeps using the com.Tencent.WCDB.Config.Cipher string the tool adapts automatically. On macOS the breakpoint is on an Apple system function, so it is independent of WeChat's own version and theoretically more stable, though a WeChat upgrade may require re-signing the app again, because the system restores the Hardened Runtime and task_for_pid then fails. That is the honest summary of the trade-off between the two approaches, and it is the reason the Linux route needs the static analysis while the macOS route does not. The repository has no GitHub releases, the last push was on 2026-08-04, and the tree is deliberately minimal, holding the three platform scripts, a LICENSE, a README and a .gitignore, with the analysis helpers living inside the scripts rather than as separate modules.
Where wcdb-key-tool is the wrong choice
Three situations argue against it, and the first is not a technical one. If the chat data is not yours, the tool has no legitimate use, and the same applies to a device that belongs to someone else or to a corporate machine where reading another user's account would be a violation of policy. The second is a security concern about your own machine. The tool runs with root on Linux and macOS, attaches a debugger to a running process, and then leaves a file on disk whose contents are equivalent to your chat database key. If the machine has any other compromise, that file is the prize. The third is a need the tool does not meet. It recovers the database key and decrypts the files, but it is not a chat export tool, it is not a backup, and it produces SQLite files rather than a readable conversation archive, so you still need something else to turn those files into something you can read. The honest alternative for the same goal is a tool built for export, of which the credits name one, which handles the same decryption and then produces the messages directly. If you only need the messages, that is the shorter path, and the key tool is the component you would reach for when the export route is blocked.
Editorial conclusion
Adopt wcdb-key-tool if you need to read your own WeChat chat history from your own machine and you are comfortable attaching a debugger to a running process. Skip it if the data is not yours, and think twice before installing it on a machine with a compromised WeChat install, because the passphrase it caches is equivalent to your chat database key. Verify first that the passphrase file at ~/.wcdb-key-tool/wechat-passphrase.json is not readable by other users, and re-run the extraction after a WeChat upgrade in case the ELF layout moved.
Frequently asked questions
What does wcdb-key-tool do?
It extracts the WeChat WCDB database encryption key for your own account on your own device, covering Linux, macOS and Windows. It reads a passphrase from the running client, derives each database key with PBKDF2, verifies it with HMAC and decrypts the files into standard SQLite databases.
Why does WeChat 4.1 break the older key extraction tools?
Because 4.1 and later no longer cache the raw database encryption key in process memory, only a passphrase remains from which the real key must be derived. Every tool relying on x'<hex>' memory pattern scanning stops working as a result.
How do I run wcdb-key-tool on Linux?
Install gdb with sudo apt install gdb, then run sudo python3 wcdb_key_tool.py extract --decrypt. The first extraction needs you to log out of WeChat and log back in so the key computation runs again, and the caught passphrase is cached for later runs.
Where is the extracted passphrase stored?
In ~/.wcdb-key-tool/wechat-passphrase.json, with mode 600 so only the current user can read it. The same path is used on all three platforms.
Will wcdb-key-tool still work after a WeChat update?
On Linux it probably will, because the ELF static analysis finds the function through string cross references and adapts as long as WeChat keeps using the com.Tencent.WCDB.Config.Cipher string. On macOS the breakpoint is on an Apple system function so it is independent of WeChat's version, but the app may need re-signing after an upgrade because the system restores the Hardened Runtime.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/tangandxue-wcdb-key-tool)Was this useful?