예제 #1
0
def main(backup, write_to_disk, password, dump_all, dump_raw):
    """Reads device information out from an sqlite3 DB.
     If the given file is an Android backup (.ab), the database
     will be extracted automatically.
     If the given file is an iOS backup, the tokens will be
     extracted (and decrypted if needed) automatically.
    """
    def read_miio_database(tar):
        DBFILE = "apps/com.xiaomi.smarthome/db/miio2.db"
        try:
            db = tar.extractfile(DBFILE)
        except KeyError as ex:
            click.echo("Unable to find miio database file %s: %s" %
                       (DBFILE, ex))
            return []
        if write_to_disk:
            file = write_to_disk
        else:
            file = tempfile.NamedTemporaryFile()
        with file as fp:
            click.echo("Saving database to %s" % fp.name)
            fp.write(db.read())

            return list(reader.read_tokens(fp.name))

    def read_yeelight_database(tar):
        DBFILE = "apps/com.yeelight.cherry/sp/miot.xml"
        _LOGGER.info("Trying to read %s", DBFILE)
        try:
            db = tar.extractfile(DBFILE)
        except KeyError as ex:
            click.echo("Unable to find yeelight database file %s: %s" %
                       (DBFILE, ex))
            return []

        return list(read_android_yeelight(db))

    devices = []
    reader = BackupDatabaseReader(dump_raw)
    if backup.endswith(".ab"):

        with AndroidBackup(backup, stream=False) as f:
            tar = f.read_data(password)

            devices.extend(read_miio_database(tar))

            devices.extend(read_yeelight_database(tar))
    else:
        devices = list(reader.read_tokens(backup))

    for dev in devices:
        if dev.ip or dump_all:
            click.echo("%s\n"
                       "\tModel: %s\n"
                       "\tIP address: %s\n"
                       "\tToken: %s\n"
                       "\tMAC: %s" %
                       (dev.name, dev.model, dev.ip, dev.token, dev.mac))
            if dump_raw:
                click.echo(dev)
예제 #2
0
    def test_compressed_nonstream(self):
        with AndroidBackup(io.BytesIO(TEST_DATA_NONENC), stream=False) as ab:
            self.assertEqual(ab.version, 3)
            self.assertEqual(ab.encryption, EncryptionType.NONE)
            self.assertEqual(ab.compression, CompressionType.ZLIB)

            names = list(map(lambda f: f.name, ab.get_files()))
            self.assertListEqual(names, TEST_MEMBERS_NAMES)

            tar = ab.read_data()
            tar.extractfile(
                'apps/eu.bluec0re.android-backup/r/settings.cfg').read()
예제 #3
0
    def test_compressed_stream(self):
        with AndroidBackup(io.BytesIO(TEST_DATA_NONENC)) as ab:
            self.assertEqual(ab.version, 3)
            self.assertEqual(ab.encryption, EncryptionType.NONE)
            self.assertEqual(ab.compression, CompressionType.ZLIB)

            names = list(map(lambda f: f.name, ab.get_files()))
            self.assertListEqual(names, TEST_MEMBERS_NAMES)

            tar = ab.read_data()
            with self.assertRaisesRegex(tarfile.StreamError,
                                        'seeking backwards is not allowed'):
                tar.extractfile(
                    'apps/eu.bluec0re.android-backup/r/settings.cfg').read()