48

How can I run this command in OSX?

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

When I run this I get the following errors

$ dd if=mybackup.ab bs=24 skip=1|openssl zlib -d > mybackup.tar
dd: mybackup.ab: No such file or directory
openssl:Error: 'zlib' is an invalid command.

Standard commands
asn1parse      ca             ciphers        crl            crl2pkcs7      
dgst           dh             dhparam        dsa            dsaparam       
ec             ecparam        enc            engine         errstr         
gendh          gendsa         genrsa         nseq           ocsp           
passwd         pkcs12         pkcs7          pkcs8          prime          
rand           req            rsa            rsautl         s_client       
s_server       s_time         sess_id        smime          speed          
spkac          verify         version        x509           

Message Digest commands (see the `dgst' command for more details)
md2            md4            md5            mdc2           rmd160         
sha            sha1           

Cipher commands (see the `enc' command for more details)
aes-128-cbc    aes-128-ecb    aes-192-cbc    aes-192-ecb    aes-256-cbc    
aes-256-ecb    base64         bf             bf-cbc         bf-cfb         
bf-ecb         bf-ofb         cast           cast-cbc       cast5-cbc      
cast5-cfb      cast5-ecb      cast5-ofb      des            des-cbc        
des-cfb        des-ecb        des-ede        des-ede-cbc    des-ede-cfb    
des-ede-ofb    des-ede3       des-ede3-cbc   des-ede3-cfb   des-ede3-ofb   
des-ofb        des3           desx           rc2            rc2-40-cbc     
rc2-64-cbc     rc2-cbc        rc2-cfb        rc2-ecb        rc2-ofb        
rc4            rc4-40         rc5            rc5-cbc        rc5-cfb        
rc5-ecb        rc5-ofb        seed           seed-cbc       seed-cfb       
seed-ecb       seed-ofb     
jww
  • 97,681
  • 90
  • 411
  • 885
Jack Shultz
  • 2,031
  • 2
  • 30
  • 53
  • 1
    Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Apple Stack Exchange](http://apple.stackexchange.com/) would be a better place to ask. – jww Apr 23 '15 at 21:51

2 Answers2

71

Openssl on mac is compiled without zlib support. Alternative method described in this article works on my Yosemite:

dd if=backup.ab bs=1 skip=24 | python3 -c "import zlib,sys;sys.stdout.buffer.write(zlib.decompress(sys.stdin.buffer.read()))" | tar -xvf -

Optionaly, if you just want to convert it into tar archive:

dd if=backup.ab bs=1 skip=24 | python3 -c "import zlib,sys;sys.stdout.buffer.write(zlib.decompress(sys.stdin.buffer.read()))" > backup.tar

It skips first 24 bytes of Android header and then uncompresses zlib data.

flaviut
  • 2,007
  • 3
  • 23
  • 32
baf
  • 4,531
  • 1
  • 21
  • 24
  • 2
    It is apparently not so easy, the order of files in tar archive is important for example, read http://nelenkov.blogspot.com/2012/06/unpacking-android-backups.html – baf Apr 24 '15 at 04:48
  • 1
    got it "..make sure you specify the files to include in the proper order by creating a backup file list and passing to tar with the -T option." – Jack Shultz Apr 24 '15 at 12:57
  • Note that this works with Python 2, but not with Python 3. If you get an error like `UnicodeDecodeError: 'utf-8' codec can't decode byte 0xda in position 1: invalid continuation byte` then run `python --version` to see what version you're running. – Olaf Aug 08 '18 at 09:52
  • 8
    Version that worked for me in python 3: `dd if=backup.ab bs=24 skip=1| python -c "import zlib,sys;sys.stdout.buffer.write(zlib.decompress(sys.stdin.buffer.read()))" > backup.tar` – Louis M Dec 22 '19 at 21:28
15

Just fix it

Get latest version from OpenSSL Official Repo.

$ wget https://www.openssl.org/source/openssl-1.1.0e.tar.gz
$ tar -zxvf openssl-1.1.0e.tar.gz
$ cd openssl-1.1.0e

Configure OpenSSL with zlib support

$ ./config zlib
$ make 
$ sudo make install

Happy days

$ which openssl
/usr/local/bin/openssl
Mick
  • 30,759
  • 16
  • 111
  • 130
  • 1
    If `wget` isn't available, you can do `curl https://www.openssl.org/source/openssl-1.1.0e.tar.gz -o openssl-1.1.0e.tar.gz`. – Ben Aug 24 '18 at 13:19
  • 1
    Following the above instructions for https://www.openssl.org/source/openssl-1.0.2q.tar.gz, `which openssl` still points to `/usr/bin/openssl`. However, I did find version 1.0.2q in `/usr/local/ssl/bin/openssl`. Without making further changes, the OP's command can then be run as `dd if=mybackup.ab bs=24 skip=1|/usr/local/ssl/bin/openssl zlib -d > mybackup.tar` – mark Jan 01 '19 at 23:51