4

I'm trying to come up with an effective way to create a gzipped archive of various system partitions on Android, piping everything out to stdout so as to be able to encrypt it as it comes across via gpg.

The workflow looks like this:

adb shell "/data/dobackup.sh" | gpg --output suchbackup.tar.gz.gpg --encrypt --sign --recipient me@myemail.com

The shell script needs to basically do this:

cat /dev/block/platform/msm_sdcc.1/by-name/recovery > recovery.img
cat /dev/block/platform/msm_sdcc.1/by-name/system > system.img
...

However, as seen, I'd like to do this whole thing over an adb shell execution so that everything is transferred over USB, into memory, and quickly is encrypted then written to disk, ie leaving no unencrypted trace.

The problem I'm having is that I'm not sure how to manufacture the internals of the script into a tar.gz file composed of multiple files/sources. Basically, I'm looking to output a tar.gz file from stdout from this script which includes the following files inside:

/recovery.img
/system.img
/userdata.img
/cache.img
/...

Is there any way I can do this? I haven't encountered a problem like this in my travels so far.

0

A thread you may wish to checkout on Hak5 forums will show the way to a project being worked on that makes use of mkfifo & other Bash magics... I've found that once set up it makes for easy encryption of nearly anything and there's tools for bulk decryption.

Prof is in the pudding so Travis-CI is currently used to show all working features including the recovery of test strings, file, and directory. This has been tested on Android with Busybox and chroot Linux, but you may only need busybox (if output rotation to email is disabled) because most of the source code is designed around limited systems.

Hint for tar specifically, check the build logs from the past few days and you'll find that it can be a hair-pulling experience if ya forget to put the trailing - or mess with v for testing.

1

Assuming you mean that you want to use tar to create an archive and send it to standard out, that's what happens by default if you don't use the f option to send the output to a file:

tar cz /{recovery,system,userdata,cache}.img | ...

If the problem is archiving "files" which don't actually exist on the filesystem, that's a bit trickier because of the format of tar files: each file is preceded by a header which includes the filesize. The filesize in the header must be correct because that's the only way that tar has to know where the next header entry starts.

So it's only feasible to do this if you can predict precisely the size of the generated file object. If you can do that,you should be able to construct a tar file using, for example, the standard python library tarfile module.

  • 1
    I know how to put a tar to stdout, it's just how to compose the contents of the tar, as they're basically dumps of filesystems that need to be generated from dd or cat and never saved to disk. – Naftuli Kay Jun 18 '14 at 2:48
  • @NaftuliTzviKay Ah. That's trickier because the tar header includes the size of the file, so you'd have to know how big the filesystem dump was before you generated it. If you know that, you can use something like the python tarfile module. – rici Jun 18 '14 at 3:37
  • Hmm, that's a bummer. I might just have to do them one at a time, encrypt them separately, and then pack them all in a tar, but then I'd lose compression, maybe I'll wrap them in gzip first... – Naftuli Kay Jun 18 '14 at 3:47
  • @NaftuliTzviKay: If the individual files are large enough, you might as well compress them first and then archive the compressed files. That lets you extract (or replace) an individual compressed file. Archiving and then compressing is a big win for an archive of lots of little files, but it doesn't save much for an archive of a few enormous files. – rici Jun 18 '14 at 4:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.