• Stars
    star
    1,645
  • Rank 28,407 (Top 0.6 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created almost 10 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cracking encrypted wechat message history from android

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:

  • adb and rooted android phone connected to a Linux/Mac OSX/Win10+Bash. If the phone does not come with adb support, you can download an app such as https://play.google.com/store/apps/details?id=eu.chainfire.adbd
  • Python >= 3.6
  • sqlcipher >= 4.1
  • sox (command line tools)
  • Silk audio decoder (included; build it with ./third-party/compile_silk.sh)
  • Other python dependencies: pip install -r requirements.txt.

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.
  1. 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.

  1. 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.
  2. (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:

  • Parse and dump text messages of every chat (requires decrypted database):

    ./dump-msg.py decrypted.db output_dir
    
  • List all chats (required decrypted database):

    ./list-chats.py decrypted.db
    
  • Generate statistics report on text messages (requires output_dir from ./dump-msg.py):

    ./count-message.sh output_dir
    
  • Dump messages of one contact to html, containing voice messages, emojis, and images (requires decrypted database and resource):

    ./dump-html.py "<contact_display_name>"
    

    The output file is output.html.

    Check ./dump-html.py -h to use different paths.

Examples:

Screenshots of generated html:

byvoid

See here for an example html.

TODO List

  • Fix rare unhandled message types: > 10000 and < 0
  • Better user experiences... see grep 'TODO' wechat -R

Donate!

[paypal]

More Repositories

1

OpenPano

Automatic Panorama Stitching From Scratch
C++
1,844
star
2

speaker-recognition

A Speaker Recognition System
C++
675
star
3

Adversarial-Face-Attack

Black-Box Adversarial Attack on Public Face Recognition Systems
Python
401
star
4

dash-docset-tensorflow

dash/zeal docset for TensorFlow 1 & 2
CSS
197
star
5

SoPaper

Automatically Search and Download Papers
Python
194
star
6

RAM-multiprocess-dataloader

Demystify RAM Usage in Multi-Process Data Loaders
Python
169
star
7

moco.tensorflow

A TensorFlow re-implementation of Momentum Contrast (MoCo): https://arxiv.org/abs/1911.05722
Python
161
star
8

cocoapi

Contains the "pycocotools" package on PyPI. Changes made to the official cocoapi about packaging.
Jupyter Notebook
123
star
9

GroupNorm-reproduce

An official collection of code in different frameworks that reproduces experiments in "Group Normalization"
Python
117
star
10

Ray-Tracing-Engine

A Photorealistic 3D Rendering Engine
C++
104
star
11

dotfiles

my dotfiles..
Python
58
star
12

dotvim

Over 1200+ lines of vimrc
Vim Script
43
star
13

Stereo-Pose-Machines

Stereo Pose Machines - Real Time 3D Pose Estimation
Python
43
star
14

vim-PinyinSearch

help vim search Chinese by Pinyin
Vim Script
39
star
15

FRN-on-common-ImageNet-baseline

Filter Response Normalization tested on better ImageNet baselines.
Python
35
star
16

dash-docset-matlab

Generate Dash Docset for Matlab
22
star
17

haDNN

Proof-of-Concept CNN in Halide
C++
21
star
18

hexo-tag-vimhighlight

Highlight code using vim in hexo
CoffeeScript
20
star
19

duxiu-downloader

Download e-books from duxiu.com
JavaScript
14
star
20

math

notes on math
TeX
8
star
21

dash-docset-jax

Create nice dash/zeal docset for JAX+Flax
Python
7
star
22

N-Body

Parallel N-Body Simulation Program
C++
5
star
23

dash-docset-torch

Dash/zeal docset for torch
Shell
5
star
24

ImageResizer

An Image Resizer using Seam Carving alogrithm.
C++
5
star
25

sigmod14contest

Code for ACM SIGMOD 2014 programming contest
C++
5
star
26

tensorflow-wheels

A repo to store custom tensorflow wheels in releases
5
star
27

Mandelbrot-Set

draw Mandelbrot set based on Xwindow. Use mpi / openmp / pthread to speed up
C++
3
star
28

vim-SugarCpp

support SugarCpp in vim.
Vim Script
2
star
29

sudoku

A sudoku solver using dancing links and algorithm X
C++
1
star
30

googlecli

Command Line Google Search
Python
1
star