YuvrajRaghuvanshiS / WhatsApp-Key-Database-Extractor

The most advanced and complete solution for extracting WhatsApp key/DB from package directory (/data/data/com.whatsapp) without root access.
MIT License
447 stars 57 forks source link

bin\tar.exe: Unexpected EOF on archive file #24

Closed YuvrajRaghuvanshiS closed 3 years ago

YuvrajRaghuvanshiS commented 3 years ago

Describe the bug bin\tar.exe: Unexpected EOF on archive file.

To Reproduce Steps to reproduce the behavior:

  1. run 'python wa_kdbe.py --tcp-ip 192.168.43.130'
  2. Enter 'Run usually'

    . See error

Expected behavior Extract files.

Screenshots image

Terminal output

================================================================================
========                                                                ========
========  db   d8b   db  .d8b.         db   dD d8888b. d8888b. d88888b  ========
========  88   I8I   88 d8' `8b        88 ,8P' 88  `8D 88  `8D 88'      ========
========  88   I8I   88 88ooo88        88,8P   88   88 88oooY' 88ooooo  ========
========  Y8   I8I   88 88~~~88 C8888D 88`8b   88   88 88~~~b. 88~~~~~  ========
========  `8b d8'8b d8' 88   88        88 `88. 88  .8D 88   8D 88.      ========
========   `8b8' `8d8'  YP   YP        YP   YD Y8888D' Y8888P' Y88888P  ========
========                                                                ========
================================================================================

============ WhatsApp Key / Database Extrator for non-rooted Android ===========

================================================================================
===                                                                          ===
===  xxxxx  PLEASE TAKE WHATSAPP CHAT BACKUP BEFORE GETTING STARTED.  xxxxx  ===
===                                                                          ===
===    For that go to 'WhatsApp settings => Chat Settings => Chat Backup'    ===
===              here take a local backup. Prepare for Worst.                ===
===                                                                          ===
===     This script can extract your WhatsApp msgstore.db (non crypt12,      ===
===   unencrypted file) and your 'key' file from '\data\data\com.whatsapp'   ===
===  directory in Android 4.0+ device without root access. However you need  ===
===   to have JAVA installed on your system in order to 'view the extract'.  ===
===  If you don't have JAVA installed then you can 'view extract' later by   ===
===   running 'view_extract.py'. The idea is to install a 'Legacy WhatsApp'  ===
===       temporarily on your device in order to get the android backup      ===
===    permission. You should not lose any data and your current WhatsApp    ===
===   version will be installed after this process so don't panic and don't  ===
=== stop this script while it's working. However if something fails you can  ===
===    run 'restore_whatsapp.py' and reinstall current WhatsApp or simply    ===
===                    update that from Google Play Store.                   ===
===                                                                          ===
===                      Script by : Yuvraj Raghuvanshi                      ===
===                      Github.com/YuvrajRaghuvanshiS                       ===
================================================================================

[19:28:08.375181] Found Java installed on system.

[19:28:08.376183] Please read above instructions carefully ↑ . Continue? (default y) :
[19:28:09.735760] Connected to Redmi 5 Plus
[19:28:10.290134] WhatsApp V2.11.431 installed on device
[19:28:10.429188] Backing up WhatsApp 2.11.431 apk, the one installed on device to tmp/WhatsAppbackup.apk
426 KB/s (18329558 bytes in 42.011s)
[19:28:52.826569] Apk backup complete.
[19:28:52.826569] Uninstalling WhatsApp, skipping data.
Success
[19:28:53.595912] Uninstalled.
[19:28:53.595912] Rebooting device in TCP mode break the connection and won't work until explicitly turned on in device and/or in PC. Skipping...
[19:28:53.595912] Installing legacy WhatsApp V2.11.431, hold tight now.
243 KB/s (18329558 bytes in 73.382s)
Success
[19:30:14.235645] Installation Complete.
Starting: Intent { cmp=com.whatsapp/.Main }
[19:30:14.366871] Press any key after running Legacy WhatsApp for a while.
[19:30:28.186941] Backing up WhatsApp data as tmp/whatsapp.ab. May take time, don't panic.
Now unlock your device and confirm the backup operation.
[19:35:33.137229] Done backing up data. Size : 121174613 bytes.
[19:35:33.137229] Reinstallting original WhatsApp.
230 KB/s (18329558 bytes in 77.589s)
Success

[19:37:01.151420] Our work with device has finished, it is safe to remove it now.

[19:37:01.151420] Found whatsapp.ab in tmp folder. Continuing... Size : 121174613 bytes.
[19:37:01.151420] Enter a reference name for this user. : pppp
[19:37:06.818587] Enter same password which you entered on device when prompted earlier. : pppp
[19:37:13.420116] Successfully 'fluffed' tmp/whatsapp.ab tmp/whatsapp.tar. Size : 283204608 bytes.
[19:37:13.420116] Folder extracted/ already exists.
[19:37:13.420116] Taking out main files in tmp/ folder temporaily.
apps/com.whatsapp/f/key
bin\tar.exe: Unexpected EOF on archive file
bin\tar.exe: Error is not recoverable: exiting now
apps/com.whatsapp/db/msgstore.db
bin\tar.exe: Unexpected EOF on archive file
bin\tar.exe: Error exit delayed from previous errors
bin\tar.exe: Unexpected EOF on archive file
bin\tar.exe: Error is not recoverable: exiting now
[19:37:24.998517] [WinError 2] The system cannot find the file specified: 'tmp/apps/com.whatsapp/db/wa.db' -> 'extracted/pppp/wa.db'
[19:37:24.998517] Cleaning up tmp folder...

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

YuvrajRaghuvanshiS commented 3 years ago

This issue occurs only when backup is created using adb over tcp.

YuvrajRaghuvanshiS commented 3 years ago

image

YuvrajRaghuvanshiS commented 3 years ago

@nelenkov You're the only person I can think of who has enough experience with ADB backup, can you help me with what's going on here?

PS : whatsapp.ab header are correct. Here's how I'm doing it if you're curious.

.
.
.
if(os.path.isfile(tmp + 'whatsapp.ab')):
    CustomPrint('Found whatsapp.ab in tmp folder. Continuing... Size : ' +
                str(os.path.getsize(tmp + '/whatsapp.ab')) + ' bytes.')
    userName = CustomInput(
        'Enter a reference name for this user. : ') or 'user'
    abPass = CustomInput(
        'Enter same password which you entered on device when prompted earlier. : ')
    try:
        os.system('java -jar ' + bin + 'abe.jar unpack ' + tmp +
                  'whatsapp.ab ' + tmp + 'whatsapp.tar ' + str(abPass))
        CustomPrint('Successfully \'fluffed\' ' + tmp + 'whatsapp.ab to ' + tmp +
                    'whatsapp.tar. Size : ' + str(os.path.getsize(tmp + 'whatsapp.tar')) + ' bytes.')
        TakingOutMainFiles(userName, sdPath, ADBSerialId)

def TakingOutMainFiles(userName, sdPath, ADBSerialId):
    os.mkdir(extracted) if not (os.path.isdir(extracted)) else CustomPrint(
        'Folder ' + extracted + ' already exists.', 'yellow')
    os.mkdir(extracted + userName) if not (os.path.isdir(extracted + userName)
                                           ) else CustomPrint('Folder ' + extracted + userName + ' already exists.', 'yellow')
    CustomPrint('Taking out main files in ' + tmp + ' folder temporaily.')
    try:
        bin = '' if(isLinux) else 'bin\\'
        os.system(bin + tar + ' xvf ' + tmp + 'whatsapp.tar -C ' +
                  tmp + ' apps/com.whatsapp/f/key')
        os.replace('tmp/apps/com.whatsapp/f/key',
                   extracted + userName + '/key')
        os.system(bin + tar + ' xvf ' + tmp + 'whatsapp.tar -C ' +
                  tmp + ' apps/com.whatsapp/db/msgstore.db')
        os.replace('tmp/apps/com.whatsapp/db/msgstore.db',
                   extracted + userName + '/msgstore.db')
        os.system(bin + tar + ' xvf ' + tmp + 'whatsapp.tar -C ' +
                  tmp + ' apps/com.whatsapp/db/wa.db')
        os.replace('tmp/apps/com.whatsapp/db/wa.db',
                   extracted + userName + '/wa.db')
        os.system(bin + tar + ' xvf ' + tmp + 'whatsapp.tar -C ' +
                  tmp + ' apps/com.whatsapp/db/axolotl.db')
        os.replace('tmp/apps/com.whatsapp/db/axolotl.db',
                   extracted + userName + '/axolotl.db')
        os.system(bin + tar + ' xvf ' + tmp + 'whatsapp.tar -C ' +
                  tmp + ' apps/com.whatsapp/db/chatsettings.db')
        os.replace('tmp/apps/com.whatsapp/db/chatsettings.db',
                   extracted + userName + '/chatsettings.db')

        CleanTmp()

        CustomPrint(
            'You should not leave these extracted database and other files hanging in folder, it is very insecure.')
.
.
.
YuvrajRaghuvanshiS commented 3 years ago

Instead of using adb backup using adb shell "bu backup com.whatsapp ^> /sdcard/whatsapp.ab" seems to solve this.

echo -e "\nYou can backup using 'adb backup' command (option A)\n"
echo -e "or you can use 'bu' command and then 'adb pull' (option B) (need enough storage on sdcard)\n"
read -n1 -p "Please select an option? [A,B]" backup_option

            if [[ $input == "A" || $input == "a" ]]; then
                if [ $sdkver -ge 23 ]; then
                    adb backup -f tmp/whatsapp.ab com.whatsapp
                else
                    adb backup -f tmp/whatsapp.ab -noapk com.whatsapp
                fi
            elif [[ $input == "B" || $input == "b" ]]; then
                if [ $sdkver -ge 28 ]; then
                    echo -e "Android 9.0 or higher\n"
                    adb shell "bu backup com.whatsapp ^> /sdcard/whatsapp.ab"
                    adb pull /sdcard/whatsapp.ab tmp/whatsapp.ab
                elif [ $sdkver -ge 23 ]; then
                    echo -e "Android 6 to 8.1\n"
                    adb shell "bu 1 backup com.whatsapp ^> /sdcard/whatsapp.ab"
                    adb pull /sdcard/whatsapp.ab tmp/whatsapp.ab
                else
                    echo -e "Android before 6\n"
                    adb shell "bu 1 backup -noapk com.whatsapp ^> /sdcard/whatsapp.ab"
                    adb pull /sdcard/whatsapp.ab tmp/whatsapp.ab
                fi
            else
                echo -e "Sorry, unsupported option\n"
            fi
YuvrajRaghuvanshiS commented 3 years ago

adb v1.0.41 on TCP also avoids this issue.

nelenkov commented 3 years ago

Looks like a bug in adb then? Maybe depends on file size? In any case, glad it's resolved.

YuvrajRaghuvanshiS commented 3 years ago

Can't say if depends on file size, I believe creating backup and sharing it over TCP at the same time calls for it. Whatever the case is I'm also glad it is solved.