获取来自 Whatsapp 的所有消息
我正在尝试实现一个应用程序,它将在文本视图中显示从 Whatsapp 收到的所有消息。有什么办法可以做到吗?是否可以提取 Whatsapp 中的所有消息?
I'm trying to implement an app that will show in a textview all the messages received from Whatsapp. Is there any way to do it? Is it possible to extract all the messages from Whatsapp?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
Whatsapp 将所有消息存储在加密数据库 (pyCrypt) 中,使用 Python 很容易破译该数据库。
您可以在 Android、iPhone、Blackberry 上轻松获取此数据库并将其转储到 html 文件中。以下是完整说明:在 Android、iPhone、Blackberry 上读取、提取 WhatsApp 消息备份
免责声明:我研究并撰写了这份内容广泛的指南。
Whatsapp store all messages in an encrypted database (pyCrypt) which is very easy to decipher using Python.
You can fetch this database easily on Android, iPhone, Blackberry and dump it into html file. Here are complete instructions: Read, Extract WhatsApp Messages backup on Android, iPhone, Blackberry
Disclaimer: I researched and wrote this extensive guide.
工作 Android 代码:(无需 root)
一旦您有权访问 dbcrypt5 文件,以下是解密它的 Android 代码:
Working Android Code: (No root required)
Once you have access to the dbcrypt5 file , here is the android code to decrypt it:
编辑
随着 WhatsApp 努力改进其加密系统,获取数据不再那么容易。对于较新版本的 WhatsApp,无法再使用
adb backup
。应用程序可以拒绝备份,WhatsApp 客户端就是这样做的。如果您碰巧拥有已 root 的手机,则可以使用 root shell 来获取未加密的数据库文件。如果您没有 root,如果您有旧的 WhatsApp APK,您仍然可以解密数据。找到仍然允许备份的版本。然后,您可以备份应用程序的数据文件夹,其中将包含一个名为
key
的加密密钥。现在您需要加密的数据库。使用您选择的文件浏览器,或者,如果您更喜欢命令行,请使用 adb:
使用这两个文件,您现在可以使用 https://gitlab.com/digitalinternals/whatsapp-crypt12 获取纯文本数据库。不再可能使用像
openssl
这样的 Linux 板工具,因为 WhatsApp 似乎使用 Spongy Castle API 用于 openssl 无法理解的密码学。原始答案(仅适用于旧的crypt7)
由于whatsapp现在使用crypt7格式,因此获取和解密数据库不再那么容易。有一种使用 ADB 和 USB 调试的工作方法。
您可以通过 ADB 获取加密密钥并解密存储在 /sdcard 上的消息数据库,或者您只需通过 ADB 备份获取数据库的纯版本,这似乎是更简单的选择。
要获取数据库,请执行以下操作:
将 Android 手机连接到计算机。现在运行
以备份 WhatsApp 在其私人文件夹中创建的所有文件。
您将获得一个使用 tar 格式和一些 ADB 标头的 zlib 压缩文件。我们需要首先删除这些标头,因为它们会混淆解压缩命令:
现在可以解压缩文件:
此命令运行 Python 并使用 zlib 将文件解压缩为 Whatsapp_backup.tar
现在我们可以解压该文件:
存档现已提取到您当前的工作目录,您可以在 apps/com.whatsapp/db/ 中找到数据库(msgstore.db 和 wa.db)
Edit
As WhatsApp put some effort into improving their encryption system, getting the data is not that easy anymore. With newer versions of WhatsApp it is no longer possible to use
adb backup
. Apps can deny backups and the WhatsApp client does that. If you happen to have a rooted phone, you can use a root shell to get the unencrypted database file.If you do not have root, you can still decrypt the data if you have an old WhatsApp APK. Find a version that still allows backups. Then you can make a backup of the app's data folder, which will contain an encryption key named, well,
key
.Now you'll need the encrypted database. Use a file explorer of your choice or, if you like the command line more, use adb:
Using the two files, you could now use https://gitlab.com/digitalinternals/whatsapp-crypt12 to get the plain text database. It is no longer possible to use Linux board tools like
openssl
because WhatsApp seems to use a modified version of the Spongy Castle API for cryptography that openssl does not understand.Original Answer (only for the old crypt7)
As whatsapp is now using the crypt7 format, it is not that easy to get and decrypt the database anymore. There is a working approach using ADB and USB debugging.
You can either get the encryption keys via ADB and decrypt the message database stored on /sdcard, or you just get the plain version of the database via ADB backup, what seems to be the easier option.
To get the database, do the following:
Connect your Android phone to your computer. Now run
to backup all files WhatsApp has created in its private folder.
You will get a zlib compressed file using tar format with some ADB headers. We need to get rid of those headers first as they confuse the decompression command:
The file can now be decompressed:
This command runs Python and decompresses the file using zlib to whatsapp_backup.tar
Now we can unTAR the file:
The archive is now extracted to your current working directory and you can find the databases (msgstore.db and wa.db) in apps/com.whatsapp/db/
我认为您只能以 root 用户身份访问位于 SD 卡上的 WhatsApp 数据库。如果你打开“\data\data\com.whatsapp”,你会看到“databases”链接到“\firstboot\sqlite\com.whatsapp\”
You can get access to the WhatsApp data base located on the SD card only as a root user I think. if you open "\data\data\com.whatsapp" you will see that "databases" is linked to "\firstboot\sqlite\com.whatsapp\"
如果您确实想要简单的东西并且知道如何编写/运行 Python,请查看脚本 Bas Bosschert: 来源
完整运行:
Pritam Baral 提到了一种更简单的方法:
If you really want something simple and know how to write/run Python, take a look at the script Bas Bosschert: sources
Full run:
Pritam Baral has mentioned an even simpler way:
对于 root 用户:whats app 将所有消息和联系人以纯文本形式存储在 msgstore.db 和 wa.db 文件中。这些文件位于 /data/data/com.whatsapp/databases/ 中。您可以使用任何 SQLite 浏览器(例如 SQLite 数据库浏览器)打开这些文件。
For rooted users :whats app store all message and contacts in msgstore.db and wa.db files in plain text.These files are available in /data/data/com.whatsapp/databases/. you can open these files using any sqlite browser like SQLite Database Browser.
如果我们从字面上理解这个问题:
那么简单的答案是,您可以从 WhatsApp 导出聊天记录(请参阅 常见问题解答)。
现在您可以构建一个应用程序,侦听 WhatsApp Share 事件并显示所有消息。对于一个简单的 PWA,可能如下所示:
If we take the question literally:
Then the simple answer is that you can export chats from WhatsApp (see FAQ).
Now you can build an App, that listens to WhatsApp Share event and display all the messages. For a simple PWA this could look like this: