├── README.rst └── abtool /README.rst: -------------------------------------------------------------------------------- 1 | ==================================================== 2 | abtool - Unpack and repack unencrypted ADB backups 3 | ==================================================== 4 | 5 | This is a small tool that can be used to unpack (and repack) backups as used 6 | by the Android ``adb`` command line tool. The tool has a help mode which 7 | includes descriptions of all its features:: 8 | 9 | % ./abtool help 10 | Usage: ./abtool command [command arguments] 11 | 12 | Available commands: 13 | 14 | unpack Unpack an ADB backup to a directory. 15 | pack Pack a directory to an ADB backup. 16 | help Display usage information for commands. 17 | 18 | 19 | Backup format 20 | ------------- 21 | 22 | For information of the backup format used by ``adb``, read 23 | http://nelenkov.blogspot.fi/2012/06/unpacking-android-backups.html 24 | 25 | 26 | Dependencies 27 | ------------ 28 | 29 | * OpenSSL 30 | * tar 31 | * Bash 32 | 33 | .. vim: ft=rst spell spelllang=en 34 | 35 | -------------------------------------------------------------------------------- /abtool: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # 3 | # abtool 4 | # Copyright (C) 2013 Adrian Perez 5 | # 6 | # Distributed under terms of the MIT license. 7 | # 8 | set -e 9 | 10 | 11 | # 12 | # cmd_help topic 13 | # 14 | cmd_help () 15 | { 16 | case ${1:-commands} in 17 | commands) 18 | cat <<-EOF 19 | Usage: $0 command [command arguments] 20 | 21 | Available commands: 22 | 23 | unpack Unpack an ADB backup to a directory. 24 | pack Pack a directory to an ADB backup. 25 | list Lists contents of an ADB backup. 26 | help Display usage information for commands. 27 | 28 | EOF 29 | ;; 30 | unpack) 31 | cat <<-EOF 32 | Usage: $0 unpack file [path] 33 | 34 | Unpacks an ADB backup file to a directory tree. 35 | 36 | Arguments: 37 | 38 | file ADB backup file, obtained with 'adb backup' 39 | path Directory where to extract the backup contents. It will be 40 | automatically created if it does not exist. If not given, 41 | the current directory will be used for output. 42 | 43 | EOF 44 | ;; 45 | pack) 46 | cat <<-EOF 47 | Usage: $0 pack file [path] 48 | 49 | Packs a directory tree to an ADB backup file. 50 | 51 | Arguments: 52 | 53 | file ADB backup file resulting from the packing. 54 | path Directory containing the input files. If not given, the 55 | current directory will be used as input. 56 | 57 | EOF 58 | ;; 59 | list) 60 | cat <<-EOF 61 | Usage: $0 list file 62 | 63 | Lists the contents of an ADB backup file. 64 | 65 | Arguments: 66 | 67 | file ADB backup file resulting from the packing. 68 | 69 | EOF 70 | ;; 71 | help) 72 | cat <<-EOF 73 | Usage: $0 help [topic] 74 | 75 | Options: 76 | 77 | topic Command name or topic (use 'help topics' for a list) 78 | 79 | EOF 80 | ;; 81 | *) 82 | cat 1>&2 <<-EOF 83 | $0: help: No such topic '$1' 84 | EOF 85 | exit 1 86 | ;; 87 | esac 88 | } 89 | 90 | # 91 | # cmd_unpack backup.ab [dest_path] 92 | # 93 | cmd_unpack () 94 | { 95 | if [[ $# -lt 1 ]] ; then 96 | echo "$0: unpack: Invalid command line." 1>&2 97 | exit 1 98 | fi 99 | 100 | local tar_opts=( ) 101 | if [[ $# -gt 1 ]] ; then 102 | mkdir -p "$2" 103 | tar_opts=( -C "$2" ) 104 | fi 105 | tail -n +5 "$1" | openssl zlib -d | tar -xf - "${tar_opts[@]}" 106 | } 107 | 108 | # 109 | # cmd_list backup.ab 110 | # 111 | cmd_list () 112 | { 113 | if [[ $# -lt 1 ]] ; then 114 | echo "$0: list: Invalid command line." 1>&2 115 | exit 1 116 | fi 117 | tail -n +5 "$1" | openssl zlib -d | tar -tf - 118 | } 119 | 120 | 121 | declare -r HEADER=$'ANDROID BACKUP\n1\n1\nnone\n' 122 | 123 | # 124 | # cmd_pack 125 | # 126 | cmd_pack () 127 | { 128 | if [[ $# -lt 1 ]] ; then 129 | echo "$0: pack: Invalid command line." 1>&2 130 | exit 1 131 | fi 132 | 133 | local dir='.' 134 | if [[ $# -gt 1 ]] ; then 135 | if [[ ! -d $2 ]] ; then 136 | echo "$0: pack: Directory '$2' does not exist." 1>&2 137 | exit 1 138 | fi 139 | dir=$2 140 | fi 141 | ( cd "${dir}" 142 | echo "$HEADER" 143 | tar -cf - . | openssl zlib -e 144 | ) > "$1" 145 | } 146 | 147 | 148 | if [[ $# -eq 0 ]] ; then 149 | cmd=help 150 | else 151 | cmd=$1 152 | shift 153 | fi 154 | 155 | case ${cmd} in 156 | pack | unpack | list | help) 157 | cmd_${cmd} "$@" 158 | ;; 159 | *) 160 | cat 1>&2 <<-EOF 161 | $0: No such command '${cmd}' 162 | Use '$0 help' to get a list of available commands 163 | EOF 164 | exit 1 165 | ;; 166 | esac 167 | 168 | --------------------------------------------------------------------------------