Example #1
0
        public static void DecryptXCI(Stream input, byte[] xci_header_key)
        {
            if (!input.CanWrite)
            {
                throw new Exception("File not writeable. Is it open somewhere?");
            }

            if (!SHA256.Create(xci_header_key).SequenceEqual(xci_sha256))
            {
                throw new InvalidDataException("The given XCI Header Key is wrong.");
            }

            using (var bw = new BinaryWriterX(input, true))
                using (var br = new BinaryReaderX(input, true))
                {
                    //Decrypt XCI Header
                    br.BaseStream.Position = 0x120;
                    var iv = br.ReadBytes(0x10).Reverse().ToArray();

                    br.BaseStream.Position = 0x190;
                    var encrypted_xci_header = br.ReadBytes(0x70);

                    bw.BaseStream.Position = 0x190;
                    bw.Write(Decryption.CBC128(encrypted_xci_header, xci_header_key, iv));

                    //Get HFS0 entries for NCA's
                    br.BaseStream.Position = 0x130;
                    var hfs0_offset      = br.ReadInt64();
                    var hfs0_header_size = br.ReadInt64();
                    var ncaEntries       = ParseHFS0List(br.BaseStream, hfs0_offset);

                    //Decrypt NCA's
                    foreach (var entry in ncaEntries)
                    {
                        if (entry.name.Contains(".nca"))
                        {
                            DecryptNCA(input, entry.entry.offset);
                        }
                    }
                }
        }
Example #2
0
        public static void DecryptXCI(Stream input)
        {
            if (!input.CanWrite)
            {
                throw new Exception("File not writeable. Is it open somewhere?");
            }

            var keyset = new Keyset();

            using (var bw = new BinaryWriterX(input, true))
                using (var br = new BinaryReaderX(input, true))
                {
                    //Decrypt XCI Header
                    br.BaseStream.Position = 0x120;
                    var iv = br.ReadBytes(0x10).Reverse().ToArray();

                    br.BaseStream.Position = 0x190;
                    var encrypted_xci_header = br.ReadBytes(0x70);

                    bw.BaseStream.Position = 0x190;
                    bw.Write(Decryption.CBC128(encrypted_xci_header, keyset["xci_header_key"], iv));

                    //Get HFS0 entries for NCA's
                    br.BaseStream.Position = 0x130;
                    var hfs0_offset      = br.ReadInt64();
                    var hfs0_header_size = br.ReadInt64();
                    var ncaEntries       = ParseHFS0List(br.BaseStream, hfs0_offset);

                    //Decrypt NCA's
                    foreach (var entry in ncaEntries)
                    {
                        if (entry.name.Contains(".nca"))
                        {
                            DecryptNCA(input, entry.entry.offset, keyset);
                        }
                    }
                }
        }