Kittywhisker's Nibbles

Transferring WhatsApp chat logs from Android to iOS using only open-source tools

whatsapp android ios apple-configurator watoi wkde

Disclaimers

If you think you can skip this, this is specifically for you!

The hardware we need

  • An Android device with USB debugging enabled (this differs from platform to platform so there isn’t a catch-all method I can write about, some device manufacturers even change the tap-build-number-ten-times to access Developer Mode method to something else, so Google is your friend.)

    P.S.: Some devices reset the Enable USB Debugging setting on every reboot, please ensure before executing any commands that you’ve re-enabled it in case your phone pulls such shenanigans

  • An iPhone with Find My disabled (you can’t restore an unencrypted iTunes backup using AppleMobileBackup otherwise)

  • A computer that runs macOS (you can do this in a virtual machine if you need to but I’m afraid we can’t use Windows or Linux, if this changes, please let me know!)

  • The necessary cables (of decent quality, never cheap out on data cables) to attach said devices

The software we need

Retrieving our chats

We’re going to follow the instructions from the WhatsApp-Key-Database-Extractor’s repository. Once you’ve finished following the instructions in the README file, you’ll hopefully have:

  • Enabled USB debugging on your Android device
  • Created a “local backup” of your WhatsApp conversations, then switched off internet access (both Wifi & Cellular)
  • Added your computer as a trusted system (this will pop up when the first adb commands launch)
  • Installed all the dependencies WhatsApp-Key-Database-Extractor needs
  • Successfully run the first half script successfully the first time
  • Have your phone reboot, with a legacy version of WhatsApp installed after (psst, if something goes wrong, check your Developer Settings again)
  • Received a prompt asking for permission to backup your files, that you agreed to (I’d not bother setting a password but that’s up to you)
  • Find a .tar archive inside the extracted directory of WhatsApp-Key-Database-Extractor
  • Extract said archive, then go three directory layers deep (apps/com.whatsapp/db) and copy the path of msgstore.db and note it down somewhere

Okay, we don’t need our Android device anymore, we’re now going to the iPhone.

Backing up our iPhone

You could use iTunes or Finder (if you’re running more recent versions of macOS) but for some reason I was having constant freezes in Finder, so I needed to resort to using the command line. If iTunes and Finder work for you, then you can ignore these steps and do an unencrypted backup as usual, then skip forward. Go this route as a matter of last resort

  • Create an alias for AppleMobileBackup
alias amb="/System/Library/PrivateFrameworks/MobileDevice.framework/Versions/Current/AppleMobileDeviceHelper.app/Contents/Resources/AppleMobileBackup"
  • Fetch the UDID of our iPhone (after you’ve granted the computer permissions to access the contents of your iPhone)
system_profiler SPUSBDataType | sed -n -E -e '/(iPhone|iPad)/,/Serial/s/ *Serial Number: *(.+)/\1/p'

You’ll get a string akin to ffffffffffffffffffffffffffffffffffffffff in length, copy it down, you’ll need it.

  • Open the “Enable Unified Log Private Data” profile you’ve downloaded, then go to System Preferences > Profiles > Install (this is because AppleMobileBackup only throws errors in the Console application, not to stdout/stderr and they’re hidden behind <private> tags, this will reveal them, which will help us debug in case anything goes wrong.)

    Do remember to uninstall this profile after you’re done. See below for how your logs should look like after you uninstall the profile.

    A preview of logs containing sensitive data before installing the profile

  • Now backup your iPhone using AppleMobileBackup, monitor its behaviour using Console.app to make sure there aren’t any errors (but you can ignore the Info.plist warning)

amb --backup --source ffffffffffffffffffffffffffffffffffffffff # replace this with your UUID

Fetching a copy of WhatsApp from the App Store

watoi needs a copy of WhatsApp.ipa (basically, the package that contains WhatsApp for iOS) to perform its magic and while you could download it from a website claiming to mirror it from Apple’s servers, we’ll use Apple’s official utilities instead. Do update WhatsApp on your local device so that we have the same version that’s installed from the App Store onto your device and fetched from the App Store onto our Desktop.

These steps are screenshots courtesy of cormiertyshawn895’s Retroactive

Note to author: I wanted to display the instructions given without asking users to download and run another application, especially since it isn’t directly related to the guide (iTunes dropped support for what we’re looking for, hence the need for Configurator 2) and the Wiki page redirects me to the README of the repository, if these steps are documented in writing, I’ll be more than happy to link there instead of using screenshots. Also, your program is amazing :) Much love!

  • Open Apple Configurator 2 (you do have your iPhone plugged in, right?) and follow the steps below

Step 1

Step 2

Step 3

Step 4

Step 5

Step 6

Step 7

Step 8

  • Once you’ve copied WhatsApp to the Desktop, you’ll hopefully have something like this

    Note: You should probably rename this file, I noticed that this file has some weird characters prefixed to it when running ls, so renaming it will get rid of that

WhatsApp&rsquo;s IPA package on the Desktop

Modifying the WhatsApp database of our iPhone backup

It’s the same story as Retrieving our chats, we’re following the instructions provided on watoi's README, hopefully, you’ll have:

  • Cloned the repository and built watoi in the terminal
  • Verify that your unencrypted iPhone backup is stored to disk and is readable
  • Provide the path of the recently downloaded WhatsApp.ipa and extract its contents to the app directory within watoi
  • Backup your original WhatsApp chat database
  • Find the path where msgstore.db is located (you did note it down, right?) and execute the migration script with that path (hopefully successfully, if not, then you’ll probably need additional patches)
  • Modify your iTunes backup to contain your “updated” WhatsApp message history

Restoring the modified iPhone backup

This presumes you used AppleMobileBackup to perform your backup, I dunno what the steps are for iTunes/Finder cause I run Big Sur and Finder is buggy as all hell, hence my use of the terminal. Google is your friend ;)

  • Turn off Find My (iPhone), AppleMobileBackup does not play nice otherwise (see below)

    Restore failure, error 211: Find My iPhone must be disabled

  • Run the restore command

amb --restore # use `--restore --target ffffffffffffffffffffffffffffffffffffffff` if this doesn't work for some reason
  • Your iPhone should show you a white background, black logo and progress bar when restoring itself, then you’ll be greeted with a screen where you enter your iCloud credentials again, set up Siri, etc.

Hopefully we’re successful in restoring our WhatsApp conversation history. Like I said, it’s text conversations only so images will be replaced with <images> and deleted messages with <revoked>

P.S: You should probably go to ~/Library/Application Support/MobileSync/Backup/ and delete your unencrypted iPhone backups, just saying