Example #1
0
        private void PickNANDButtonClick(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog
            {
                FileName    = "rawnand.bin",
                DefaultExt  = ".bin",
                Filter      = "Raw NAND dump (.bin or .bin.*)|*.bin*",
                Multiselect = true
            };

            if (dlg.ShowDialog() == true)
            { // it's nullable so i HAVE to compare it to true
                string[] files = dlg.FileNames;
                if (files != null && files.Length > 0)
                {
                    IList <IStorage> streams = new List <IStorage>();
                    foreach (string file in files)
                    {
                        streams.Add(new FileInfo(file).OpenRead().AsStorage()); // Change to Open when write support is added
                    }
                    IStorage NANDSource = new ConcatenationStorage(streams, true);

                    if (!NANDService.InsertNAND(NANDSource, false))
                    {
                        MessageBox.Show("Invalid NAND dump!");
                    }
                }
            }
        }
Example #2
0
        private void PickNANDButtonClick(object sender, RoutedEventArgs e)
        {
            FileInfo[] files = Extensions.Extensions.RequestOpenFilesFromUser(".bin", "Raw NAND dump (.bin or .bin.*)|*.bin*", "Select raw NAND dump", "rawnand.bin");

            if (files != null)
            {
                IList <IStorage> streams = new List <IStorage>();
                foreach (FileInfo file in files)
                {
                    streams.Add(file.OpenRead().AsStorage()); // Change to Open when write support is added
                }
                IStorage NANDSource = new ConcatenationStorage(streams, true);

                if (!NANDService.InsertNAND(NANDSource, false))
                {
                    MessageBox.Show("Invalid NAND dump!");
                }
            }
        }
Example #3
0
        /// <summary>
        /// Opens a decrypted <see cref="IStorage"/> of the entire package.
        /// </summary>
        /// <param name="packageStorage">If the method returns successfully, contains a decrypted
        /// <see cref="IStorage"/> of the package.</param>
        /// <returns>The <see cref="Result"/> of the operation.</returns>
        public Result OpenDecryptedPackage(out IStorage packageStorage)
        {
            var storages = new List <IStorage>(4);

            // The signature and IV are unencrypted
            int unencryptedHeaderSize = Package2Header.SignatureSize + Unsafe.SizeOf <Buffer16>();
            int encryptedHeaderSize   = Unsafe.SizeOf <Package2Header>() - unencryptedHeaderSize;

            // Get signature and IV
            storages.Add(new SubStorage(_storage, 0, unencryptedHeaderSize));

            // Open decrypted meta
            var encMetaStorage = new SubStorage(_storage, unencryptedHeaderSize, encryptedHeaderSize);

            // The counter starts counting at the beginning of the meta struct, but the first block in
            // the struct isn't encrypted. Increase the counter by one to skip that block.
            byte[] iv = _header.Meta.HeaderIv.Bytes.ToArray();
            Utilities.IncrementByteArray(iv);

            storages.Add(new CachedStorage(new Aes128CtrStorage(encMetaStorage, _key.DataRo.ToArray(), iv, true), 0x100, 1, true));

            // Open all the payloads
            for (int i = 0; i < Package2Header.PayloadCount; i++)
            {
                if (_header.Meta.PayloadSizes[i] == 0)
                {
                    continue;
                }

                Result rc = OpenPayload(out IStorage payloadStorage, i);
                if (rc.IsFailure())
                {
                    UnsafeHelpers.SkipParamInit(out packageStorage);
                    return(rc);
                }

                storages.Add(payloadStorage);
            }

            packageStorage = new ConcatenationStorage(storages, true);
            return(Result.Success);
        }