Ejemplo n.º 1
0
        public static void Decrypt(PartitionFileSystem pfs, string outDirPath, bool verifyBeforeDecrypting, Keyset keyset, Output Out)
        {
            Out.Log(pfs.Print());
            ProcessNsp.GetTitlekey(pfs, keyset, Out);
            var         OutDirFs   = new LocalFileSystem(outDirPath);
            IDirectory  sourceRoot = pfs.OpenDirectory("/", OpenDirectoryMode.All);
            IDirectory  destRoot   = OutDirFs.OpenDirectory("/", OpenDirectoryMode.All);
            IFileSystem sourceFs   = sourceRoot.ParentFileSystem;
            IFileSystem destFs     = destRoot.ParentFileSystem;

            foreach (var entry in FileIterator(sourceRoot))
            {
                destFs.CreateFile(entry.Name, entry.Size, CreateFileOptions.None);
                using (IFile srcFile = sourceFs.OpenFile(entry.Name, OpenMode.Read))
                    using (IFile dstFile = destFs.OpenFile(entry.Name, OpenMode.Write))
                    {
                        if (entry.Name.EndsWith(".nca"))
                        {
                            ProcessNca.Process(srcFile, dstFile, verifyBeforeDecrypting, keyset, Out);
                        }
                        else
                        {
                            srcFile.CopyTo(dstFile);
                        }
                    }
            }
        }
Ejemplo n.º 2
0
 public static void Extract(string inFile, string outDirPath, Output Out)
 {
     using (var file = new FileStream(inFile, FileMode.Open, FileAccess.Read))
     {
         var pfs = new PartitionFileSystem(file.AsStorage());
         Out.Log(pfs.Print());
         pfs.Extract(outDirPath);
     }
 }
Ejemplo n.º 3
0
        public static void ExtractRomFS(string inFile, string outDirPath, Keyset keyset, Output Out)
        {
            using (var file = new FileStream(inFile, FileMode.Open, FileAccess.Read))
            {
                var         pfs        = new PartitionFileSystem(file.AsStorage());
                var         OutDirFs   = new LocalFileSystem(outDirPath);
                IDirectory  sourceRoot = pfs.OpenDirectory("/", OpenDirectoryMode.All);
                IFileSystem sourceFs   = sourceRoot.ParentFileSystem;
                Out.Log(pfs.Print());

                foreach (var entry in FileIterator(sourceRoot))
                {
                    if (entry.Name.EndsWith(".nca"))
                    {
                        var fullOutDirPath = $"{outDirPath}/{entry.Name}";
                        Out.Log($"Extracting {entry.Name}...\r\n");
                        using (IFile srcFile = sourceFs.OpenFile(entry.Name, OpenMode.Read))
                        {
                            ProcessNca.Extract(srcFile.AsStream(), fullOutDirPath, true, keyset, Out);
                        }
                    }
                    else if (entry.Name.EndsWith(".nca.nsz"))
                    {
                        var fullOutDirPath = $"{outDirPath}/{entry.Name}";
                        Out.Log($"Extracting {entry.Name}...\r\n");
                        using (IFile srcFile = sourceFs.OpenFile(entry.Name, OpenMode.Read))
                            using (var decompressedFile = new DecompressionStorage(srcFile))
                            {
                                ProcessNca.Extract(decompressedFile.AsStream(), fullOutDirPath, true, keyset, Out, true);

                                // Header can't be patched for now due to OpenSection
                                // and ValidateMasterHash needs to know if AesCtrEx
                                // so Nca.cs was patched and now accepts isDecryptedNca
                                // as constructor argument which disables decryption

                                /*
                                 * var DecryptedHeader = new byte[0xC00];
                                 * decompressedFile.AsStream().Read(DecryptedHeader, 0, 0xC00);
                                 * DecryptedHeader[1028] = (int)NcaEncryptionType.None;
                                 * DecryptedHeader[1540] = (int)NcaEncryptionType.None;
                                 * DecryptedHeader[2052] = (int)NcaEncryptionType.None;
                                 * DecryptedHeader[2564] = (int)NcaEncryptionType.None;
                                 * var HeaderKey1 = new byte[16];
                                 * var HeaderKey2 = new byte[16];
                                 * Buffer.BlockCopy(keyset.HeaderKey, 0, HeaderKey1, 0, 16);
                                 * Buffer.BlockCopy(keyset.HeaderKey, 16, HeaderKey2, 0, 16);
                                 * var headerEncrypted = CryptoInitialisers.AES_XTS(HeaderKey1, HeaderKey2, 0x200, DecryptedHeader, 0);
                                 * var ncaStorageList = new List<IStorage>() { new MemoryStorage(headerEncrypted), decompressedFile.Slice(0xC00) };
                                 * var cleanDecryptedNca = new ConcatenationStorage(ncaStorageList, true);
                                 * ProcessNca.Extract(cleanDecryptedNca.AsStream(), fullOutDirPath, true, keyset, Out);
                                 */
                            }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public static void Decompress(string inFile, string outDirPath, Output Out)
 {
     using (var file = new FileStream(inFile, FileMode.Open, FileAccess.Read))
         using (var fileStorage = file.AsStorage())
         {
             var pfs = new PartitionFileSystem(fileStorage);
             Out.Log(pfs.Print());
             var decompressedFs = new LocalFileSystem(outDirPath);
             DecompressFs.ProcessFs(pfs, decompressedFs, Out);
         }
 }
Ejemplo n.º 5
0
        public static void Process(Context ctx)
        {
            using (var file = new LocalStorage(ctx.Options.InFile, FileAccess.Read))
            {
                var pfs = new PartitionFileSystem(file);
                ctx.Logger.LogMessage(pfs.Print());

                if (ctx.Options.OutDir != null)
                {
                    pfs.Extract(ctx.Options.OutDir, ctx.Logger);
                }
            }
        }