Skip to content

Instantly share code, notes, and snippets.

@xnumad
Created October 22, 2019 22:45
Show Gist options
  • Save xnumad/96a4b15d63a3dad5cce2b2663f5fcd08 to your computer and use it in GitHub Desktop.
Save xnumad/96a4b15d63a3dad5cce2b2663f5fcd08 to your computer and use it in GitHub Desktop.
WhatsApp message backup and restore process

If you activate WhatsApp (verifying your phone number) while having a /sdcard/WhatsApp/Databases/msgstore.db.crypt12 file present AND have a WhatsApp backup on Google Drive, WhatsApp will claim to restore your Google Drive backup (with your consent), but it only restores the media files from Google Drive but at no occassion the msgstore.db.crypt12. It won't merge your local backup and the cloud backup databases!

With local WhatsApp media files it will only offer to restore the local backup at activation but not the one from Google Drive, hence the need for an empty /sdcard/WhatsApp/Media/ folder. But with a local chat backup, the Google Drive backup restore process just imports media only anyways.

Ways to get to the key file to decrypt the *.crypt12 DBs:

  • either access /data/data/com.whatsapp/files/key with root permissions
  • OR adb backup com.whatsapp and extract the key from the .ab file

I have extracted the key and found out that it's the same for all my devices (I always tested with the same phone number). For the decryption and restoring of the locally saved msgstore.db.crypt12 (like described above), it is also automatically saved on WhatsApp servers.

@xnumad
Copy link
Author

xnumad commented May 20, 2020

@luciferRK
According to https://android.stackexchange.com/q/28481 the easiest solution with graphical interface is https://github.com/camalot/droidexplorer/releases
This should help out. I only wrote about the backup method to access the file because I know an Android backup backs up these files, so in case you can't access the file directly because of no root, you can use that method as a circumvention. Never tried myself though because of having root.

If you don't have a .ab file you can grab https://github.com/B16f00t/whapa

@palladidrago
Copy link

palladidrago commented Nov 13, 2020

According to what i found out whatsapp doesn't allow backups in its manifest, so you would need to decompile and recompile the app.

@YuvrajRaghuvanshiS
Copy link

According to what i found out whatsapp doesn't allow backups in its manifest, so you would need to decompile and recompile the app.

It doesn't now, you can use https://github.com/yuvrajraghuvanshis/whatsApp-Key-Database-Extractor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment