Пример #1
0
        public void VerifyCompressedFolder(string nspFile)
        {
            var nspFileNoExtension = Path.GetFileNameWithoutExtension(nspFile);

            Out.Event($"Task VerifyCompressedFolder \"{nspFileNoExtension}\" started\r\n");
            var keyset = ProcessKeyset.OpenKeyset();

            using (var inputFile = new FileStream(nspFile, FileMode.Open, FileAccess.Read))
                using (var inputFileStorage = inputFile.AsStorage())
                {
                    var pfs = new PartitionFileSystem(inputFileStorage);
                    ProcessNsp.GetTitlekey(pfs, keyset, Out);

                    var dirDecryptedReal      = new DirectoryInfo(decryptedDir);
                    var dirDecryptedRealCount = dirDecryptedReal.GetFiles().Length;
                    cleanFolder(decryptedDir);
                    var compressedFs = new LocalFileSystem(compressedDir);
                    var decryptedFs  = new LocalFileSystem(decryptedDir);
                    DecompressFs.ProcessFs(compressedFs, decryptedFs, Out);
                    UntrimDeltaNCA.Process(decryptedDir, pfs, keyset, Out);
                    EncryptNCA.Encrypt(decryptedFs, null, true, keyset, Out);
                }

            Out.Event($"Task VerifyCompressedFolder \"{nspFileNoExtension}\" completed!\r\n");
        }
Пример #2
0
        public void CompressXCI(string xciFile)
        {
            var xciFileNoExtension = Path.GetFileNameWithoutExtension(xciFile);

            Out.Event($"Task CompressXCI \"{xciFileNoExtension}\" started\r\n");
            var keyset = ProcessKeyset.OpenKeyset();

            ProcessXci.Decrypt(xciFile, decryptedDir, VerifyHashes, keyset, Out);
            CompressFolder.Compress(Out, decryptedDir, compressedDir, BlockSize, ZstdLevel, MaxDegreeOfParallelism);

            if (VerifyHashes)
            {
                var decryptedFs           = new LocalFileSystem(decryptedDir);
                var dirDecryptedRealCount = decryptedFs.GetEntryCount(OpenDirectoryMode.Files);
                cleanFolder(decryptedDir);
                var compressedFs = new LocalFileSystem(compressedDir);
                DecompressFs.ProcessFs(compressedFs, decryptedFs, Out);

                var dirDecryptedCount = decryptedFs.GetEntryCount(OpenDirectoryMode.Files);
                if (dirDecryptedRealCount != dirDecryptedCount)
                {
                    throw new FileNotFoundException();
                }

                EncryptNCA.Encrypt(decryptedFs, null, true, keyset, Out);
            }

            var compressedDirFs = new LocalFileSystem(compressedDir);
            var xciOutPath      = Path.Combine(OutputFolderPath, xciFileNoExtension);

            FolderTools.FolderToXCI(compressedDirFs, $"{xciOutPath}.xciz", keyset);
            Out.Event($"Task CompressXCI \"{xciFileNoExtension}\" completed!\r\n");
        }
Пример #3
0
        public void UntrimAndEncrypt(Keyset keyset)
        {
            FolderTools.ExtractTitlekeys(decryptedDir, keyset, Out);

            var decryptedFs = new LocalFileSystem(decryptedDir);
            var encryptedFs = new LocalFileSystem(encryptedDir);

            EncryptNCA.Encrypt(decryptedFs, encryptedFs, VerifyHashes, keyset, Out);

            var dirDecrypted = new DirectoryInfo(decryptedDir);

            foreach (var file in decryptedFs.EnumerateEntries()
                     .Where(item => item.Type == DirectoryEntryType.File && !item.Name.EndsWith(".tca")))
            {
                if (!file.Name.EndsWith(".nca"))
                {
                    using (var srcFile = decryptedFs.OpenFile(file.FullPath, OpenMode.Read))
                        using (var destFile = FolderTools.CreateAndOpen(file, encryptedFs, file.Name, file.Size))
                        {
                            srcFile.CopyTo(destFile);
                        }
                }

                decryptedFs.DeleteFile(file.FullPath);
            }

            UntrimDeltaNCA.Process(decryptedDir, encryptedFs, keyset, Out);
            EncryptNCA.Encrypt(decryptedFs, encryptedFs, VerifyHashes, keyset, Out);
        }
Пример #4
0
        public void CompressNSP(string nspFile)
        {
            var nspFileNoExtension = Path.GetFileNameWithoutExtension(nspFile);

            Out.Event($"Task CompressNSP \"{nspFileNoExtension}\" started\r\n");
            var keyset = ProcessKeyset.OpenKeyset();

            using (var inputFile = new FileStream(nspFile, FileMode.Open, FileAccess.Read))
                using (var inputFileStorage = inputFile.AsStorage())
                {
                    var pfs = new PartitionFileSystem(inputFileStorage);
                    ProcessNsp.Decrypt(pfs, decryptedDir, VerifyHashes, keyset, Out);
                    TrimDeltaNCA.Process(decryptedDir, keyset, Out);
                    CompressFolder.Compress(Out, decryptedDir, compressedDir, BlockSize, ZstdLevel, MaxDegreeOfParallelism);

                    if (VerifyHashes)
                    {
                        var dirDecryptedReal      = new DirectoryInfo(decryptedDir);
                        var dirDecryptedRealCount = dirDecryptedReal.GetFiles().Length;
                        cleanFolder(decryptedDir);
                        var compressedFs = new LocalFileSystem(compressedDir);
                        var decryptedFs  = new LocalFileSystem(decryptedDir);
                        DecompressFs.ProcessFs(compressedFs, decryptedFs, Out);
                        UntrimDeltaNCA.Process(decryptedDir, pfs, keyset, Out);

                        var dirDecrypted      = new DirectoryInfo(decryptedDir);
                        var dirDecryptedCount = dirDecrypted.GetFiles().Length;
                        if (dirDecryptedRealCount != dirDecryptedCount)
                        {
                            throw new FileNotFoundException();
                        }

                        EncryptNCA.Encrypt(compressedFs, null, true, keyset, Out);
                    }
                }

            var compressedDirFs    = new LocalFileSystem(compressedDir);
            var OutputFolderPathFs = new LocalFileSystem(OutputFolderPath);

            using (var outFile =
                       FolderTools.CreateOrOverwriteFileOpen(OutputFolderPathFs, $"{nspFileNoExtension}.nspz"))
            {
                FolderTools.FolderToNSP(compressedDirFs, outFile);
            }

            Out.Event($"Task CompressNSP \"{nspFileNoExtension}\" completed!\r\n");
        }