Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android 12: Export: wa.db - Contacts are not exported. #63

Open
sietsevdschoot opened this issue Sep 28, 2023 · 13 comments
Open

Android 12: Export: wa.db - Contacts are not exported. #63

sietsevdschoot opened this issue Sep 28, 2023 · 13 comments
Labels
android Android exclusive issue bug Something isn't working

Comments

@sietsevdschoot
Copy link

sietsevdschoot commented Sep 28, 2023

I have a OnePlus Android 12 Phone.

Using WhatsApp-Key-DB-Extractor I can successfully extract the whatsapp databases. My whatsapp backups are not password protected.

However, after explorer the wa.db with DB Browser for SqlLite i see that the wa_contacts table remains empty.
Other tables like wa_vnames,wa_contact_storage_usage,wa_biz_profiles in this sqlite are populated

Also in Whatsapp on the device all contacts in the Whatsapp conversation have their correct names.

FWIW:
When i have to confirm the permission for the backup and press Enter afterwards, i can give the permissions, but i can't open the app because of the Your phone data is inaccurate. Adjust your clock and try again error, - even though the system time is correct - that is caused by the older version of WhatsApp.

Whatsapp Chat Exporter:

wtsexporter -a

Processing contacts...(0)
Processing messages...(22625/22625)
Processing media...(4410/4410)
Processing vCards...(56/56)
Processing calls...(74)
Generating chats...(376/376)
WhatsApp directory already exists in output directory. Skipping...

Everything is done!

Extracted files:

Name                Length LastWriteTime
----                ------ -------------
.placeholder             2 20:34:43
axolotl.db          299008 22:00:55
chatsettings.db      24576 21:29:43
msgstore.db       18329600 20:34:52
wa.db               417792 20:37:41
wa.db-shm            32768 20:42:08
wa.db-wal                0 20:42:08
whatsapp.cryptkey      158 21:29:41

WhatsAppKeyDBExtract output:

Please connect your Android device with USB Debugging enabled:

* daemon not running. starting it now on port 5037 *
* daemon started successfully *

WhatsApp 2.23.18.79 installed

Found legacy WhatsApp 2.11.431 in local folder

Backing up WhatsApp 2.23.18.79
6745 KB/s (52214668 bytes in 7.558s)
Backup complete

Removing WhatsApp 2.23.18.79 skipping data
Success
Removal complete

Installing legacy WhatsApp 2.11.431
3912 KB/s (18329558 bytes in 4.575s)
Success
Install complete


Paused. Open Whatsapp. Ok the Permissions Request. Press Enter to continue:

Now unlock your device and confirm the backup operation.

Please enter your backup password (leave blank for none) and press Enter:


apps/com.whatsapp/f/key
C:\Temp\WhatsApp\WhatsApp-Key-DB-Extractor\bin\tar.exe: apps/com.whatsapp/f/encrypted_backup.key: Not found in archive
C:\Temp\WhatsApp\WhatsApp-Key-DB-Extractor\bin\tar.exe: Error exit delayed from previous errors
apps/com.whatsapp/db/msgstore.db
apps/com.whatsapp/db/wa.db
apps/com.whatsapp/db/axolotl.db
apps/com.whatsapp/db/chatsettings.db
C:\Temp\WhatsApp\WhatsApp-Key-DB-Extractor\bin\tar.exe: apps/com.whatsapp/Avatars: Not found in archive
C:\Temp\WhatsApp\WhatsApp-Key-DB-Extractor\bin\tar.exe: Error exit delayed from previous errors

Extracting whatsapp.cryptkey ...
Extracting msgstore.db ...
Extracting wa.db ...
Extracting axolotl.db ...
Extracting chatsettings.db ...

Pushing cipher key to: /sdcard/WhatsApp/Databases/.nomedia
5 KB/s (158 bytes in 0.027s)

Cleaning up temporary files ...
Done

Restoring WhatsApp 2.23.18.79
4923 KB/s (52214668 bytes in 10.355s)
Success
Restore complete

Removing WhatsApp 2.23.18.79 temporary apk


Operation complete

@KnugiHK
Copy link
Owner

KnugiHK commented Sep 29, 2023

Hi. Would you be able to find where the contact names came from?

@KnugiHK
Copy link
Owner

KnugiHK commented Oct 1, 2023

When i have to confirm the permission for the backup and press Enter afterwards, i can give the permissions, but i can't open the app because of the Your phone data is inaccurate. Adjust your clock and try again error, - even though the system time is correct - that is caused by the older version of WhatsApp.

This is normal.

However, after explorer the wa.db with DB Browser for SqlLite i see that the wa_contacts table remains empty.
Other tables like wa_vnames,wa_contact_storage_usage,wa_biz_profiles in this sqlite are populated

Also in Whatsapp on the device all contacts in the Whatsapp conversation have their correct names.

I can reproduce the problem. But further investigations are needed.

@KnugiHK KnugiHK added the bug Something isn't working label Oct 1, 2023
@sietsevdschoot
Copy link
Author

sietsevdschoot commented Oct 1, 2023

Hi. Would you be able to find where the contact names came from?

The wa.db contains a table system_contacts_version_table with a id and version column. In my database this table contains about 2000 rows. It might have something to do with it.

The contacts app on my Android, synced with Gmail contacts, contains all contacts used in the WhatsApp conversations.

@sietsevdschoot
Copy link
Author

sietsevdschoot commented Oct 1, 2023

When i have to confirm the permission for the backup and press Enter afterwards, i can give the permissions, but i can't open the app because of the Your phone data is inaccurate. Adjust your clock and try again error, - even though the system time is correct - that is caused by the older version of WhatsApp.

This is normal.

However, after explorer the wa.db with DB Browser for SqlLite i see that the wa_contacts table remains empty.
Other tables like wa_vnames,wa_contact_storage_usage,wa_biz_profiles in this sqlite are populated
Also in Whatsapp on the device all contacts in the Whatsapp conversation have their correct names.

I can reproduce the problem. But further investigations are needed.

I've tried several ways of trying to force whatsapp to refresh the contact list. But none of those options caused the contacts table to get populated.

So i took another approach. I downloaded all contacts from Gmail in .vcf format.
I've found a nice Powershell script to convert .vcf on Github ConvertFrom-Vcf. I had to tweak it a little bit to work for the Gmail format.

After that I wrote a Powershell script to sanitize the phonenumbers and replace all occurences with the actual contactname in the generated .html files, and to rename the file to the contactname.

@KnugiHK
Copy link
Owner

KnugiHK commented Oct 2, 2023

No sure if WhatsApp changed the database structure again. Any more people encounter this issue?

@sietsevdschoot
Copy link
Author

In the meantime I have a script (Github gist) to fix the problem using exported Gmail .vcf contacts to replace contactnames after running the Whatsapp Chat Exporter.

@KnugiHK
Copy link
Owner

KnugiHK commented Dec 3, 2023

Weird. I just did a new export from WhatsApp 2.23.25.3. The wa_contacts table was populated.

@msloco
Copy link

msloco commented Feb 27, 2024

I can confirm same behavior reported by the op happens here with a decrypted wa.db.crypt15 : only populated tables seems to be wa_trusted_contacts and wa_trusted_contacts_send.
whatsapp reports version 2.24.3.81.

@guilherme-puida
Copy link

The issue also happens here with an export from version 2.24.6.10.

@iher1
Copy link

iher1 commented Apr 23, 2024

Hi, I also see the issue on WhatsApp 2.24.8.85 on Android: the wa.db is not populated with any contact data.

@qosch
Copy link

qosch commented May 10, 2024

Using a WhatsApp database I exported a few years ago (mid 2021), I am experiencing the same issue. Looking at the wa.db file, I can't find any table indicating actual contact names. wa_contact_storage_usage does contain a plausible number of lines, though (but no names).

@code-consensus
Copy link

Hi there, I think I have figured out what is going on.

I tested this on a number of WhatsApp versions dating from 2022 to the latest version of 2024 (v2.22.xx, 2.23.xx, 2.24.xx).

The issue is that WhatsApp itself does not fully backup wa.db. That is, the "original" unencrypted wa.db found in the WhatsApp data folder (/data/data/com.whatsapp/databases/ if one has root access) is not the file that gets encrypted to /sdcard/Android/media/com.whatsapp/WhatsApp/Backup/wa.db.crypt15 (or wa.db.crypt14).

Whereas the original unencrypted wa.db file will have the wa_contacts table populated, the backup wa.db.crypt15 will not. The same goes for several other tables too, e.g. wa_address_book, wa_vnames, wa_group_admin_settings, etc. -- they are all populated in /data/data/com.whatsapp/databases/wa.db, but upon backup they are all blank within wa.db.crypt15.

Perhaps WhatsApp doesn't backup the contact address book so that a new installation of WhatsApp will sync with the new phone's address book rather than potentially create conflicts.

In any case, the end result is that there is sadly nothing that @KnugiHK can do about this issue, as the underlying information is not backed up by WhatsApp itself, so the information is inherently missing in the wa.db.crypt15 file.

A workaround to this would be to export your contact details to a CSV file from your own contacts program (e.g. Outlook). Then with the decrypted wa.db.crypt15 backup file, you can import that data into the wa_contacts table using a program like DB Browser for SQLite). The issue is that you'll need to convert your contact data into the format that the wa_contacts table would expect (e.g. the phone number (555) 555-6666 would be transformed to [email protected]).

@KnugiHK
Copy link
Owner

KnugiHK commented Aug 27, 2024

Hi there, I think I have figured out what is going on.

I tested this on a number of WhatsApp versions dating from 2022 to the latest version of 2024 (v2.22.xx, 2.23.xx, 2.24.xx).

The issue is that WhatsApp itself does not fully backup wa.db. That is, the "original" unencrypted wa.db found in the WhatsApp data folder (/data/data/com.whatsapp/databases/ if one has root access) is not the file that gets encrypted to /sdcard/Android/media/com.whatsapp/WhatsApp/Backup/wa.db.crypt15 (or wa.db.crypt14).

Whereas the original unencrypted wa.db file will have the wa_contacts table populated, the backup wa.db.crypt15 will not. The same goes for several other tables too, e.g. wa_address_book, wa_vnames, wa_group_admin_settings, etc. -- they are all populated in /data/data/com.whatsapp/databases/wa.db, but upon backup they are all blank within wa.db.crypt15.

Perhaps WhatsApp doesn't backup the contact address book so that a new installation of WhatsApp will sync with the new phone's address book rather than potentially create conflicts.

In any case, the end result is that there is sadly nothing that @KnugiHK can do about this issue, as the underlying information is not backed up by WhatsApp itself, so the information is inherently missing in the wa.db.crypt15 file.

A workaround to this would be to export your contact details to a CSV file from your own contacts program (e.g. Outlook). Then with the decrypted wa.db.crypt15 backup file, you can import that data into the wa_contacts table using a program like DB Browser for SQLite). The issue is that you'll need to convert your contact data into the format that the wa_contacts table would expect (e.g. the phone number (555) 555-6666 would be transformed to [email protected]).

Hey! Thanks for your research! Another option could be importing contacts from Google Contacts, which was implemented in #106 and will be available in the next release.

Unfortunately, I don't have access to a rooted Android phone at the moment, so I can't investigate the issue further. However, based on your research, it seems that if the database is extracted directly with root permissions, this issue doesn't occur.

@KnugiHK KnugiHK added the android Android exclusive issue label Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Android exclusive issue bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants