[Q] Unpack backup.ab created by "adb backup" command?

Search This thread

mbirth

Senior Member
Nov 22, 2006
270
112
Berlin
Is there any way to unpack the backup files created by the

Code:
adb backup -all

command? (Working since Android 4.0)

It seems this is a file-based backup and unpacking (and repacking) would allow tweaking some internal databases and files without needing to root.
 

bengali

New member
Dec 8, 2010
3
0
I believe the ".ab" format is in some kind of "tar" compressed archive.

Doesn't look like it. At least it's neither plain tar nor one of tarred gzip, bzip2 or compress. Also, it's not zip or rar.

So what's left?

- The android backup supports encryption. This does not necessarily mean that the archiver has to support that, too, since you could always first archive and then encrypt or vice versa.

- You can include .apk-files in backups. This suggests, that the archiver does not need to be über-effective, like bzip2, since that would cost time and cycles and .apk-files are already compressed, IIRC.

I don't know how to make any sense of this but maybe someone else does?
 

kapitan_petko

Member
Dec 8, 2009
7
19
If anyone is still interested, here's a small utility that does this:

Apparently I can't post links, so add 'http' in front to get the URLs:

github.com/nelenkov/android-backup-extractor

More details about the format and the tool here:

nelenkov.blogspot.jp/2012/06/unpacking-android-backups.html
 
Last edited:

aguaz

Senior Member
Jan 16, 2014
136
31
And the other way around:

1. create adb backup header
2. convert tar archive and append to header
Code:
echo -e "ANDROID BACKUP\n1\n1\nnone" > backup.ab
openssl zlib -in backup.tar >> backup.ab
 

gps3dx

Senior Member
Jan 24, 2010
792
401
HTC Desire
Samsung Galaxy Tab 10.1
any chance we can deflate .ab file on the phone itself ?
I know that one can deflate zlib by adding zlib header to the data then pass it through gzip:
printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" | cat - filename | gzip -d
source: printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" | cat - body.zlib | gzip -dc
I even tried ( and failed, cause i'm getting 'corrupt data' error
printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" | cat - /sdcard/backup.ab > /sdcard/backup2.ab
dd if=/sdcard/backup2.ab bs=24 skip=1 | busybox gzip -d > wa.tar

is the .ab ( without encryption ) is compress in some special way such that this technique isn't working ?

EDIT - SUCCESS !!!!
bu backup PACKAGE_NAME > /sdcard/backup.ab
dd if=/sdcard/backup.ab bs=24 skip=1 > /sdcard/backup2.ab
printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" | cat - /sdcard/backup2.ab | busybox gzip -d > /sdcard/backup.tar

although gzip throws an error of 'gzip: corrupted data' - the ".ab" file is deflated into .tar, so that running
Code:
tar xvf <TARFILE> <FULL_INTERNAL_FILE_PATH> -C <WHERE_TO_EXTRACT_FILE>
extract the file I want !!!

EUREKA !!!!

DON'T YOU GET IT !?!?!
NOW IT IS POSSIBLE TO MAKE BACKUP SCRIPTS FOR APPS ON THE DEVICE ITSELF FOR FREE!
 
Last edited:
  • Like
Reactions: scandiun

scandiun

Senior Member
Jul 12, 2010
1,903
983
any chance we can deflate .ab file on the phone itself ?
I know that one can deflate zlib by adding zlib header to the data then pass it through gzip:

source: printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" | cat - body.zlib | gzip -dc
I even tried ( and failed, cause i'm getting 'corrupt data' error


is the .ab ( without encryption ) is compress in some special way such that this technique isn't working ?

EDIT - SUCCESS !!!!


although gzip throws an error of 'gzip: corrupted data' - the ".ab" file is deflated into .tar, so that running
Code:
tar xvf <TARFILE> <FULL_INTERNAL_FILE_PATH> -C <WHERE_TO_EXTRACT_FILE>
extract the file I want !!!

EUREKA !!!!

DON'T YOU GET IT !?!?!
NOW IT IS POSSIBLE TO MAKE BACKUP SCRIPTS FOR APPS ON THE DEVICE ITSELF FOR FREE!
Is root required?

---------- Post added at 03:38 PM ---------- Previous post was at 03:24 PM ----------

any chance we can deflate .ab file on the phone itself ?
I know that one can deflate zlib by adding zlib header to the data then pass it through gzip:

source: printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" | cat - body.zlib | gzip -dc
I even tried ( and failed, cause i'm getting 'corrupt data' error


is the .ab ( without encryption ) is compress in some special way such that this technique isn't working ?

EDIT - SUCCESS !!!!


although gzip throws an error of 'gzip: corrupted data' - the ".ab" file is deflated into .tar, so that running
Code:
tar xvf <TARFILE> <FULL_INTERNAL_FILE_PATH> -C <WHERE_TO_EXTRACT_FILE>
extract the file I want !!!

EUREKA !!!!

DON'T YOU GET IT !?!?!
NOW IT IS POSSIBLE TO MAKE BACKUP SCRIPTS FOR APPS ON THE DEVICE ITSELF FOR FREE!
Ok thanks but it probably requires root. Testing it in my Samsung S7 official stock ROM it generates a 0 bytes file. Note that not all apps allow adb backup, you have to perform backup only in those that allow it.

If I do "bu" on android terminal I get:
sh: resetreason: can't execute: Permission denied. Killed.
 

gps3dx

Senior Member
Jan 24, 2010
792
401
HTC Desire
Samsung Galaxy Tab 10.1

bah... I think I gave my terminal emulator root perm, although I did not initiate any "su" command.
this gave some extra perm to the emulator...

so my answer is that root is required to run this command on the phone itself... but NO root is required is you run it through ADB from a PC.

so, yeah, no real special news here, but the fact that there is NO need to copy the backup to PC, because deflating zlib, tar extracting can be done on the phone itself.
which means in return, that NO special openSSL is needed to extract the WA key file.
 

scandiun

Senior Member
Jul 12, 2010
1,903
983
bah... I think I gave my terminal emulator root perm, although I did not initiate any "su" command.
this gave some extra perm to the emulator...

so my answer is that root is required to run this command on the phone itself... but NO root is required is you run it through ADB from a PC.

so, yeah, no real special news here, but the fact that there is NO need to copy the backup to PC, because deflating zlib, tar extracting can be done on the phone itself.
which means in return, that NO special openSSL is needed to extract the WA key file.

Having root I would prefer to use Titanium backup or similar. The problem with adb backup is that not all apps are allowed to be backed up. There's a flag in AndroidManifest.xml
 

gps3dx

Senior Member
Jan 24, 2010
792
401
HTC Desire
Samsung Galaxy Tab 10.1
Having root I would prefer to use Titanium backup or similar. The problem with adb backup is that not all apps are allowed to be backed up. There's a flag in AndroidManifest.xml

if you got root you don't need to use external backup, you have access directly to /data/data and can view/edit WA databases.

also, to backup WA's key, you MUST install old version of the app, then perform the "bu" backup.
( as OP's script does ).
 
  • Like
Reactions: scandiun

scandiun

Senior Member
Jul 12, 2010
1,903
983
Have a question, adb doesn't backup all kind of data, or doesn't backup all kind of apk?
I need some clarification please

It backups all apks provided that you use the -apk flag. For the data, it only backs up data for those applications that are allowed inside the manifest. with the app System Info for Android you can check the AndroidManifest of each app. Android does not tell you explicitly which apps will be backed up or not. iOS works much better, iTunes will backup all the data of your apps (the apps itself not, it have to be re-downloaded from the Apple Store, and if some app is removed from there you can't install it anymore).
 

lkjsoiuew

Senior Member
Nov 17, 2010
118
3
Please, don't use dd bs=24, instead use dd ibs=24, which is a bit faster, but really fast is only
Code:
tail -c +25 backup.ab |  zlib-flate -uncompress | tar -tf -
 
  • Like
Reactions: scandiun

Top Liked Posts

  • There are no posts matching your filters.
  • 15
    How to extract android adb ab backup

    You can do it that way, you need dd and openssl. You can do it from linux, mac or windows with cygwin:

    Code:
     dd if=mybackup.ab bs=24 skip=1 | openssl zlib -d > mybackup.tar
    10
    If anyone is still interested, here's a small utility that does this:

    Apparently I can't post links, so add 'http' in front to get the URLs:

    github.com/nelenkov/android-backup-extractor

    More details about the format and the tool here:

    nelenkov.blogspot.jp/2012/06/unpacking-android-backups.html
    3
    And the other way around:

    1. create adb backup header
    2. convert tar archive and append to header
    Code:
    echo -e "ANDROID BACKUP\n1\n1\nnone" > backup.ab
    openssl zlib -in backup.tar >> backup.ab
    2
    You can do it that way, you need dd and openssl. You can do it from linux, mac or windows with cygwin:

    Code:
     dd if=mybackup.ab bs=24 skip=1 | openssl zlib -d > mybackup.tar

    Note that this only works for unencrypted backups though.
    1
    any chance we can deflate .ab file on the phone itself ?
    I know that one can deflate zlib by adding zlib header to the data then pass it through gzip:
    printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" | cat - filename | gzip -d
    source: printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" | cat - body.zlib | gzip -dc
    I even tried ( and failed, cause i'm getting 'corrupt data' error
    printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" | cat - /sdcard/backup.ab > /sdcard/backup2.ab
    dd if=/sdcard/backup2.ab bs=24 skip=1 | busybox gzip -d > wa.tar

    is the .ab ( without encryption ) is compress in some special way such that this technique isn't working ?

    EDIT - SUCCESS !!!!
    bu backup PACKAGE_NAME > /sdcard/backup.ab
    dd if=/sdcard/backup.ab bs=24 skip=1 > /sdcard/backup2.ab
    printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" | cat - /sdcard/backup2.ab | busybox gzip -d > /sdcard/backup.tar

    although gzip throws an error of 'gzip: corrupted data' - the ".ab" file is deflated into .tar, so that running
    Code:
    tar xvf <TARFILE> <FULL_INTERNAL_FILE_PATH> -C <WHERE_TO_EXTRACT_FILE>
    extract the file I want !!!

    EUREKA !!!!

    DON'T YOU GET IT !?!?!
    NOW IT IS POSSIBLE TO MAKE BACKUP SCRIPTS FOR APPS ON THE DEVICE ITSELF FOR FREE!