当前位置: 首页>>代码示例>>Python>>正文


Python Keybag.unlockBackupKeybagWithPasscode方法代码示例

本文整理汇总了Python中keystore.keybag.Keybag.unlockBackupKeybagWithPasscode方法的典型用法代码示例。如果您正苦于以下问题:Python Keybag.unlockBackupKeybagWithPasscode方法的具体用法?Python Keybag.unlockBackupKeybagWithPasscode怎么用?Python Keybag.unlockBackupKeybagWithPasscode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在keystore.keybag.Keybag的用法示例。


在下文中一共展示了Keybag.unlockBackupKeybagWithPasscode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getBackupKeyBag

# 需要导入模块: from keystore.keybag import Keybag [as 别名]
# 或者: from keystore.keybag.Keybag import unlockBackupKeybagWithPasscode [as 别名]
def getBackupKeyBag(backupfolder, passphrase):
    manifest = readPlist(backupfolder + "/Manifest.plist")

    kb = Keybag(manifest["BackupKeyBag"].data)

    if kb.unlockBackupKeybagWithPasscode(passphrase):
        print "BackupKeyBag unlock OK"
        return kb
    else:
        return None
开发者ID:yzx65,项目名称:AppParser,代码行数:12,代码来源:demo_backup_keychain.py

示例2: MobileBackupClient

# 需要导入模块: from keystore.keybag import Keybag [as 别名]
# 或者: from keystore.keybag.Keybag import unlockBackupKeybagWithPasscode [as 别名]

#.........这里部分代码省略.........
    def computeIV(self, lba):
        iv = ""
        lba &= 0xffffffff
        for _ in xrange(4):
            if (lba & 1):
                lba = 0x80000061 ^ (lba >> 1)
            else:
                lba = lba >> 1

            iv += struct.pack("<L", lba)

        return iv

    def download(self, backupUDID, item_types):
        mbsbackup = self.get_backup(backupUDID)
        self.output_folder = os.path.join(self.output_folder, backupUDID.encode("hex"))

        print "Downloading backup {} to {}".format(backupUDID.encode("hex"), self.output_folder)

        try:
            mkdir_p(self.output_folder)
        except OSError:
            print "Directory \"{}\" already exists.".format(self.output_folder)
            return

        keys = self.get_keys(backupUDID)
        if not keys or not len(keys.Key):
            print "get_keys FAILED!"
            return

        print "Got OTA Keybag"

        self.kb = Keybag(keys.Key[1].KeyData)
        if not self.kb.unlockBackupKeybagWithPasscode(keys.Key[0].KeyData):
            print "Unable to unlock OTA keybag !"
            return

        print "Available Snapshots: %d" % (mbsbackup.Snapshot.SnapshotID)
        if self.chosen_snapshot_id == None:
            snapshot_list = [1, mbsbackup.Snapshot.SnapshotID - 1, mbsbackup.Snapshot.SnapshotID]
        elif self.chosen_snapshot_id < 0:
            snapshot_list = [mbsbackup.Snapshot.SnapshotID + self.chosen_snapshot_id + 1] # Remember chosen_snapshot_id is negative
        else:
            snapshot_list = [self.chosen_snapshot_id]

        for snapshot in snapshot_list:
            print "Listing snapshot %d..." % (snapshot)
            files = self.list_files(backupUDID, snapshot)
            print "Files in snapshot %d" % (len(files))

            def matches_allowed_domain(a_file):
                return self.domain_filter in a_file.Domain

            def matches_allowed_item_types(a_file):
                return any(ITEM_TYPES_TO_FILE_NAMES[item_type] in a_file.RelativePath.lower() \
                        for item_type in item_types)

            if self.domain_filter:
                files = filter(matches_allowed_domain, files)

            if len(item_types) > 0:
                files = filter(matches_allowed_item_types, files)

            print "Downloading %d files due to filter" % (len(files))

            if len(files):
开发者ID:lionheart,项目名称:iloot,代码行数:70,代码来源:iloot.py

示例3: MobileBackupClient

# 需要导入模块: from keystore.keybag import Keybag [as 别名]
# 或者: from keystore.keybag.Keybag import unlockBackupKeybagWithPasscode [as 别名]

#.........这里部分代码省略.........
        makedirs(os.path.dirname(path))
        ff = open(path, "wb")
        h = hashlib.sha1()
        for i in xrange(len(decrypted_chunks)):
            d = decrypted_chunks[i]
            h.update(d)
            ff.write(d)
        ff.close()

        if f.Attributes.EncryptionKey:
            EncryptionKey = f.Attributes.EncryptionKey
            #ProtectionClass = f.Attributes.ProtectionClass
            hexdump(EncryptionKey)
            ProtectionClass = struct.unpack(">L", EncryptionKey[0x18:0x1C])[0]
            assert ProtectionClass == f.Attributes.ProtectionClass
            #EncryptionKeyVersion=2 => starts with keybag uuid
            if f.Attributes.EncryptionKeyVersion and f.Attributes.EncryptionKeyVersion == 2:
                assert self.kb.uuid == EncryptionKey[:0x10]
                keyLength = struct.unpack(">L", EncryptionKey[0x20:0x24])[0]
                assert keyLength == 0x48
                wrapped_key = EncryptionKey[0x24:]
            else:#XXX old format ios 5 backup
                wrapped_key = EncryptionKey[0x1C:]
            print "ProtectionClass= %d" % ProtectionClass
            filekey = self.kb.unwrapCurve25519(ProtectionClass, wrapped_key)
            if not filekey:
                print "Failed to unwrap file key for file %s !!!" % f.RelativePath
            else:
                print "filekey",filekey.encode("hex")
                self.decryptProtectedFile(path, filekey, f.Attributes.DecryptedSize)

    def decryptProtectedFile(self, path, filekey, DecryptedSize=0):
        ivkey = hashlib.sha1(filekey).digest()[:16]
        h = hashlib.sha1()
        sz = os.path.getsize(path)
        #iOS 5 trailer = uint64 sz + sha1 of encrypted file
        #assert (sz % 0x1000) == 0x1C
        oldpath = path + ".encrypted"
        try:
            os.rename(path, oldpath)
        except:
            pass
        f1 = open(oldpath, "rb")
        f2 = open(path, "wb")
        n = (sz / 0x1000)
        if DecryptedSize:
            n += 1
        for block in xrange(n):
            iv = AESencryptCBC(self.computeIV(block * 0x1000), ivkey)
            data = f1.read(0x1000)
            h.update(data)
            f2.write(AESdecryptCBC(data, filekey, iv))
        if DecryptedSize == 0: #old iOS 5 format
            trailer = f1.read(0x1C)
            DecryptedSize = struct.unpack(">Q", trailer[:8])[0]
            assert h.digest() == trailer[8:]
        f1.close()
        f2.truncate(DecryptedSize)
        f2.close()

    def computeIV(self, lba):
        iv = ""
        lba &= 0xffffffff
        for _ in xrange(4):
            if (lba & 1):
                lba = 0x80000061 ^ (lba >> 1);
            else:
                lba = lba >> 1;
            iv += struct.pack("<L", lba)
        return iv

    def download(self, backupUDID):
        mbsbackup = self.getBackup(backupUDID)
        print "Downloading backup %s" % backupUDID.encode("hex")
        self.outputFolder = os.path.join(self.outputFolder, backupUDID.encode("hex"))
        makedirs(self.outputFolder)
        print backup_summary(mbsbackup)
        #print mbsbackup.Snapshot.Attributes.KeybagUUID.encode("hex")
        keys = self.getKeys(backupUDID)
        if not keys or not len(keys.Key):
            print "getKeys FAILED!"
            return
        
        print "Got OTA Keybag"
        self.kb = Keybag(keys.Key[1].KeyData)
        if not self.kb.unlockBackupKeybagWithPasscode(keys.Key[0].KeyData):
            print "Unable to unlock OTA keybag !"
            return

        for snapshot in xrange(1, mbsbackup.Snapshot.SnapshotID+1):
            files = self.listFiles(backupUDID, snapshot)
            print "%d files" % len(files)
            files2 = []
            for f in files:
                if f.Attributes.EncryptionKey:
                    files2.append(f)
                    print f
            if len(files2):
                authTokens = self.getFiles(backupUDID, snapshot, files)
                self.authorizeGet(authTokens)
开发者ID:yzx65,项目名称:AppParser,代码行数:104,代码来源:backup.py

示例4: MobileBackupClient

# 需要导入模块: from keystore.keybag import Keybag [as 别名]
# 或者: from keystore.keybag.Keybag import unlockBackupKeybagWithPasscode [as 别名]

#.........这里部分代码省略.........
    def computeIV(self, lba):
        iv = ""
        lba &= 0xffffffff
        for _ in xrange(4):
            if (lba & 1):
                lba = 0x80000061 ^ (lba >> 1);
            else:
                lba = lba >> 1;

            iv += struct.pack("<L", lba)

        return iv

    def download(self, backupUDID, item_types):
        mbsbackup = self.get_backup(backupUDID)
        self.output_folder = os.path.join(self.output_folder, backupUDID.encode("hex"))

        print "Downloading backup {} to {}".format(backupUDID.encode("hex"), self.output_folder)

        try:
            mkdir_p(self.output_folder)
        except OSError:
            print "Directory \"{}\" already exists.".format(self.output_folder)
            return

        keys = self.get_keys(backupUDID)
        if not keys or not len(keys.Key):
            print "get_keys FAILED!"
            return

        print "Got OTA Keybag"

        self.kb = Keybag(keys.Key[1].KeyData)
        if not self.kb.unlockBackupKeybagWithPasscode(keys.Key[0].KeyData):
            print "Unable to unlock OTA keybag !"
            return

        print "Available Snapshots: ", mbsbackup.Snapshot.SnapshotID
        #for snapshot in xrange(1, mbsbackup.Snapshot.SnapshotID+1):
        for snapshot in [1, mbsbackup.Snapshot.SnapshotID - 1, mbsbackup.Snapshot.SnapshotID]:
            print "Listing snapshot..."
            files = self.list_files(backupUDID, snapshot)
            print "Files in snapshot %s : %s" % (snapshot, len(files))

            def matches_allowed_item_types(file):
                return any(ITEM_TYPES_TO_FILE_NAMES[item_type] in file.RelativePath \
                        for item_type in item_types)

            if len(item_types) > 0:
                files = filter(matches_allowed_item_types, files)

            if len(files):
                authTokens = self.get_files(backupUDID, snapshot, files)
                self.authorize_get(authTokens, snapshot)

            if self.itunes_style:
                self.write_info_plist(mbsbackup, snapshot)

    # Writes a plist file in the output_directory simular to that created by iTunes during backup
    def write_info_plist(self, mbsbackup, snapshot):
        if self.combined:
            directory = self.output_folder
        else:
            directory = os.path.join(self.output_folder, "snapshot_"+str(snapshot))

        plist_file = open(directory+"/Info.plist", "w")
开发者ID:hweining,项目名称:iloot,代码行数:70,代码来源:iloot.py


注:本文中的keystore.keybag.Keybag.unlockBackupKeybagWithPasscode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。