0

When I try to recover my Whatsapp messages on my new phone after I have copied the Whatsapp folder from my old phone to the SDcard, it suddenly crashes after 10 seconds: "Whatsapp has stopped working"

I looked into the System Log to find some clues about this crash. It looks like it has something to do with SQLite and the msgstore.db (or msgstore.db.crypt) file, because there's msgstore.db file is corrupt error. Here are some lines from the System log:

 "E/DefaultDatabaseErrorHandler (3784): Corruption reported by sqlite
    on database: /data/data/com.whatsapp/databasesmsgstore.db"
 "E/AndroidRuntime (3784): java.lang.AssertionError: android.database.sqlite.SQLiteDatabaseCorruptExcep tion: Database disk image is malformed (code 11), SQLiteConnection.java,-2"
 "E/SQLiteLog (3784): (14) cannot open file at line 30191 of [00bb9c9ce4]"
 "E/SQLiteDatabase (3784): Failed to open database '/data/data/com.whatsapp/databases/msgstore.db' "
 "E/SQLiteDatabaseException: unknown error (code 14): Could not open database"
 "I/sqlite_db_corrupt (3784): /data/data.com.whatsapp/databases/msgstore.db"

Can somebody help me to unravel this mistery? I really want to copy my old messages to my new phone and continue using the app on my new phone.

How can I fix the corrupt msgstore file? Or see what part of the file is corrupt (the exact cause)

Some screenshots of the System Log file:

Screenshot 1 Screenshot 2 Screenshot 3 Screenshot 4

3

Usually if you place your msgstore.db or msgstore.db.crypt7 file in the following directory on your SD card and reinstall WhatsApp it will see it and ask if you would like to restore your old messages during installation.

/sdcard/WhatsApp/Databases/

However if your database (msgstore.db or msgstore.db.crypt7) is corrupt you may still be able to regenerate the databases using sqlite3.

The WhatsApp Database is an sqlite3 database and is stored unencrypted at this path on the Android device:

/data/data/com.whatsapp/databases/msgstore.db

Backups of the database are also stored encrypted on the SD card typically at the following location:

/sdcard/WhatsApp/Databases/msgstore.db.crypt7

The unique key for the encrypted backup databases is stored here:

/data/data/com.whatsapp/files/key

Access to the /data/data directory requires root access. Alternatively ADB (Android Debug Bridge) can be used to extract the above files after booting into recovery on the device.

If you are dealing msgstore.db.crypt7 files then you must Decrypt them first as follows:

(commands below are run from a linux enviroment)

  • Extract Key File: /data/data/com.whatsapp/files/key
  • Extract crypt7 file: /sdcard/WhatsApp/Databases/msgstore.db.crypt7
  • Extract Decryption Keys from "key" file extracted in step 1:

    • 256-bit AES key:

      hexdump -e '2/1 "%02x"' key | cut -b 253-316 > aes.txt

    • IV (initialisation vector):

      hexdump -e '2/1 "%02x"' key | cut -b 221-252 > iv.txt

  • Strip Header in crypt7 File:

    dd if=msgstore.db.crypt7 of=msgstore.db.crypt7.nohdr ibs=67 skip=1

    Note: Size of header stripped file in bytes must be divisible by 16

  • Decrypt crypt7 File:

    openssl enc -aes-256-cbc -d -nosalt -nopad -bufsize 16384 -in msgstore.db.crypt7.nohdr -K $(cat aes.txt) -iv $(cat iv.txt) > msgstore.db

Once you have you msgstore.db file either by first decrypting the msgstore.db.crypt7 or by extracting it from the /data/data/com.whatsapp/databases/ directory you can now try to regenerate it using the following commands:

echo .dump | sqlite3.exe msgstore.db > Temp.sql

echo .quit | sqlite3.exe -init Temp.sql msgstore_new.db

Now Try to Restore your database Again

  • If you followed the procedure above correctly you should now have a msgstore_new.db file.
  • Rename this file to msgstore.db and place it file in /sdcard/WhatsApp/Databases/ and reinstall WhatsApp. Choose to restore your old database/messages when asked during installation.

Reference:

  1. http://forum.xda-developers.com/showpost.php?p=24566937&postcount=3
  2. http://forum.xda-developers.com/showthread.php?t=1583021
| improve this answer | |