Skip to content

Instantly share code, notes, and snippets.

@oconnor663
Created December 21, 2013 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oconnor663/8063575 to your computer and use it in GitHub Desktop.
Save oconnor663/8063575 to your computer and use it in GitHub Desktop.
How to restore Kingdom Rush game data from backup.ab
# This might, maybe, conceivably work as a script. But I suggest executing all
# the commands manually, because I doubt everything will Just Work,
# particularly the 'adb root' command. Setting the '-e' option makes the script
# exit on the first error, in case you do want to run it.
set -e
# First, make a copy of backup.ab, because if we accidentally delete it we're
# screwed.
OUR_TMPDIR=`mktemp -d`
cp backup.ab $OUR_TMPDIR
cd $OUR_TMPDIR
# Now, we need to convert backup.ab into a tar file. Assuming you didn't
# encrypt it, that means stripping the first 4 lines and un-DEFLATE-ing it.
tail -n +5 backup.ab | openssl zlib -d > backup.tar
# Confirm that what we got is a legit tar archive
file backup.tar
# Now we can extract and install the APK for Kingdom Rush from this tar
# archive. This is probably preferable to trying to install it by restoring the
# backup, because that backup might have a bunch of garbage data from a
# different version of Android, which will cause us problems. If you haven't
# already, you might want to do a factory reset of the device before this
# point.
APK_PATH=$(tar tf backup.tar | grep -E 'kingdomrush.humble.*apk')
echo $APK_PATH # Sanity check that this is one file, and that it's not garbage.
tar xOf backup.tar $APK_PATH > kingdomrush.apk
adb install kingdomrush.apk
# At this point, you should launch Kingdom Rush on the phone, to make sure it
# populates its initial data file, directories, etc. After that, kill Kingdom
# Rush in the task switcher. We are about to replace the data file, and we
# don't want it overwritten in the meantime.
# The file we want is called ".Defaults.plist". Extract it from the backup.
PATH_IN_ARCHIVE=$(tar tf backup.tar | grep -E 'kingdomrush.humble.*\.Defaults.plist')
echo $PATH_IN_ARCHIVE # Sanity check. Make especialy sure it's just one path.
tar xOf backup.tar $PATH_IN_ARCHIVE > gamedata.xml
# Take a look at the contents of gamedata.xml. It's neat. If you want to cheat,
# edit it ;)
# Find the path where .Defaults.plist is supposed to live on the device. (It's
# not the same as the path in the archive.) First we need to make sure the adb
# shell is operating as root. If you didn't enable this in developer settings
# on your phone, this first command will fail.
adb root
PATH_ON_PHONE=$(adb shell "find /data | grep -E 'kingdomrush.humble.*\\.Defaults.plist$'")
echo $PATH_ON_PHONE # sanity check
# Finally, copy the data file we got from the backup to the path where it lives
# on the phone.
adb push gamedata.xml $PATH_ON_PHONE
# FREEEEEEDOM!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment