ppwwyyxx / wechat-dump

Cracking encrypted wechat message history from android
GNU General Public License v3.0
1.65k stars 309 forks source link
android wechat

Dump WeChat Messages from Android

导出安卓微信消息记录

WeChat, as the most popular mobile IM app in China, doesn't provide any methods to export structured message history.

We reverse-engineered the storage protocol of WeChat messages, and provide this tool to decrypt and parse WeChat messages on a rooted android phone. It can also render the messages into self-contained html files including voice messages, images, emojis, videos, etc.

If the tool works for you, please take a moment to add your phone/OS to the wiki.

How to use:

Dependencies:

Get Necessary Data:

  1. Pull database file and (for older wechat versions) avatar index:

    • Automatic: ./android-interact.sh db. It may use an incorrect userid.
    • Manual:
    • Figure out your ${userid} by inspecting the contents of /data/data/com.tencent.mm/MicroMsg on the root filesystem of the device. It should be a 32-character-long name consisting of hexadecimal digits.
    • Get /data/data/com.tencent.mm/MicroMsg/${userid}/EnMicroMsg.db from the device.
  2. Decrypt database file:

    • Automatic: ./decrypt-db.py decrypt --input EnMicroMsg.db
    • Manual:
    • Get WeChat uin (an integer), possible ways are:
      • ./decrypt-db.py uin, which looks for uin in /data/data/com.tencent.mm/shared_prefs/
      • Login to web wechat, get wxuin=1234567 from document.cookie
    • Get your device id (a positive integer), possible ways are:
      • ./decrypt-db.py imei implements some ways to find device id.
      • Call *#06# on your phone
      • Find IMEI in system settings
    • Decrypt database with combination of uin and device id:

      ./decrypt-db.py decrypt --input EnMicroMsg.db --imei <device id> --uin <uin>

      NOTE: you may need to try different ways to get device id and find one that can decrypt the database. Some phones may have multiple IMEIs, you may need to try them all. See #33. The command will dump decrypted database at EnMicroMsg.db.decrypted.

    If the above decryption doesn't work, you can also try the password cracker to brute-force the key. The encryption key is not very strong.

  3. Copy the WeChat user resource directory /mnt/sdcard/tencent/MicroMsg/${userid}/{avatar,emoji,image2,sfs,video,voice2} from the phone to the resource directory:

    • ./android-interact.sh res
    • Change RES_DIR in the script if the location of these directories is different on your phone.
    • This can take a while. Can be faster to first archive it with tar with or without compression, and then copy the archive, busybox tar is recommended as the Android system's tar may choke on long paths.
    • In the end, we need a resource directory with the following subdir: avatar,emoji,image2,sfs,video,voice2.
  4. (Optional) Download the emoji cache from here and decompress it under wechat-dump. This will avoid downloading too many emojis during rendering.

    wget -c https://github.com/ppwwyyxx/wechat-dump/releases/download/0.1/emoji.cache.tar.bz2
    tar xf emoji.cache.tar.bz2

Run:

Examples:

Screenshots of generated html:

byvoid

See here for an example html.

TODO List

Donate!

[paypal]