示例#1
0
        private void Init()
        {
            if (_unlocked)
            {
                return;
            }

            FileInfo     file     = new FileInfo(ManifestFile);
            NSDictionary rootDict = (NSDictionary)PropertyListParser.Parse(file);

            NSData backupKeyBag = (NSData)rootDict.ObjectForKey("BackupKeyBag");

            _keybag = new KeyBag(backupKeyBag);

            NSData manifestKeyObject = (NSData)rootDict.ObjectForKey("ManifestKey");

            if (manifestKeyObject == null)
            {
                throw new Exception("Could not find ManifestKey. Is this an encrypted backup?");
            }

            var manifestKey   = manifestKeyObject.Bytes.Skip(4).ToArray();
            var manifestClass = (int)StructConverter.Unpack("<l", manifestKeyObject.Bytes.Take(4).ToArray())[0];

            _keybag.UnlockWithPassphrase(_passPhrase);


            var key = _keybag.UnwrapKeyForClass(manifestClass, manifestKey);


            var encryptedDb = File.ReadAllBytes(ManifestDb);

            var decryptedData = EncryptionHelper.DecryptAES(encryptedDb, key, CipherMode.CBC);

            File.WriteAllBytes($"{_tempFilePath}\\Manifest.db", decryptedData);


            if (!_repository.OpenTempDb())
            {
                throw new Exception("Manifest.db file does not seem to be the right format!");
            }

            _unlocked = true;
        }
示例#2
0
 private ulong Unpack64Bit(byte[] bytes)
 {
     return((ulong)StructConverter.Unpack(">Q", bytes.Reverse().ToArray())[0]);
 }
示例#3
0
 private static int GetInt(byte[] bytes)
 {
     return((int)(uint)StructConverter.Unpack(">L", bytes.Reverse().ToArray())[0]);
 }
示例#4
0
 private byte[] Pack64Bit(ulong l)
 {
     return(StructConverter.Pack(new object[] { l }));
 }