解包的Andr​​oid备份

解包的Andr​​oid备份

本文介绍了的Python:解包的Andr​​oid备份?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Python来解压一个Android备份文件。

I'd like to unpack an Android backup file using python.

根据

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

tar xvf mybackup.tar

可这些都可以在Python做呢? Python有的zlib 的gzip tar文件,这似乎是如果他们应该是可用的。在任何情况下,如果他们可以做到,怎么样?

Can these can be done in python? Python has zlib, gzip and tarfile, which seem as if they should be usable. In any event, if they can be done, how to?

应该 tarfile.open('filename.tar','R:')第二步工作

我在Windows上,顺便说一句。

I'm on windows, btw.

推荐答案

如果文件不是太大的一切舒适地配合在内存中,从标准库所需的进口后:

If the file is not too big for everything to fit comfortably in memory, after the needed imports from the standard library:

with open('mybackup.ab', 'rb') as f:
    f.seek(24)  # skip 24 bytes
    data = f.read()  # read the rest

tarstream = zlib.decompress(data)
tf = tarfile.open(fileobj=io.BytesIO(tarstream))

现在在 TF 你有一个 tar文件实例作为的,所以你可以得到,例如其内容的清单,提取一个或多个成员,及放大器; C。

Now in tf you have a TarFile instance as documented in https://docs.python.org/2/library/tarfile.html#tarfile-objects , so you can e.g get a list of its contents, extract one or more members, &c.

如果备份太大所有这些位,以适应舒适内存,当然你也可以写任何或所有的中间结果到磁盘的;但如果它是足够小的保留在内存中一切都应该导致更快的执行速度。

If the backup is too big for all these bits to fit comfortably in memory, you can of course write any or all of the intermediate results to disk; but if it's small enough keeping everything in memory should result in faster execution.

这篇关于的Python:解包的Andr​​oid备份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 00:17