예제 #1
0
        private void decryptStreams(MemoryStream inputStream, BinaryWriter outputStream, long size, long offset, Content content)
        {
            NUSDecryption nusdecryption = new NUSDecryption(getTicket());
            short         contentIndex  = (short)content.index;

            long encryptedFileSize = content.encryptedFileSize;

            if (content.isEncrypted())
            {
                if (content.isHashed())
                {
                    NUSDataProvider dataProvider = NUSTitle.dataProvider;
                    byte[]          h3           = dataProvider.getContentH3Hash(content);
                    nusdecryption.decryptFileStreamHashed(inputStream, outputStream, size, offset, (short)contentIndex, h3);
                }
                else
                {
                    nusdecryption.decryptFileStream(inputStream, outputStream, size, (short)contentIndex, content.SHA2Hash, encryptedFileSize);
                }
            }
            else
            {
                StreamUtils.saveInputStreamToOutputStreamWithHash(inputStream, outputStream, size, content.SHA2Hash, encryptedFileSize);
            }

            inputStream.Close();
            outputStream.Close();
        }
예제 #2
0
        public void decryptContentToStream(Content content, BinaryWriter outputStream)
        {
            if (content == null)
            {
                return;
            }

            NUSDataProvider dataProvider = NUSTitle.dataProvider;
            MemoryStream    inputStream  = dataProvider.getInputStreamFromContent(content, 0);

            decryptContentFromStream(inputStream, outputStream, content);
        }
예제 #3
0
        public NUSTitle loadNusTitle(NUSTitleConfig config)
        {
            NUSTitle result = new NUSTitle();

            NUSDataProvider dataProvider = getDataProvider(result, config);

            result.dataProvider = (dataProvider);

            TMD tmd = TMD.parseTMD(dataProvider.getRawTMD());

            result.TMD = (tmd);

            if (tmd == null)
            {
                //MessageBox.Show("TMD not found.");
                throw new Exception();
            }

            Ticket ticket = config.ticket;

            if (ticket == null)
            {
                ticket = Ticket.parseTicket(dataProvider.getRawTicket());
            }
            result.ticket = ticket;
            // System.out.println(ticket);

            Content fstContent = tmd.getContentByIndex(0);

            MemoryStream fstContentEncryptedStream = dataProvider.getInputStreamFromContent(fstContent, 0);

            if (fstContentEncryptedStream == null)
            {
                return(null);
            }

            byte[] fstBytes = fstContentEncryptedStream.ToArray();// StreamUtils.getBytesFromStream(fstContentEncryptedStream, (int)fstContent.getEncryptedFileSize());

            if (fstContent.isEncrypted())
            {
                AESDecryption aesDecryption = new AESDecryption(ticket.decryptedKey, new byte[0x10]);
                fstBytes = aesDecryption.decrypt(fstBytes);
            }

            Dictionary <int, Content> contents = tmd.getAllContents();

            FST fst = FST.parseFST(fstBytes, contents);

            result.FST = (fst);

            return(result);
        }
예제 #4
0
        public void decryptFSTEntryToStream(FSTEntry entry, BinaryWriter outputStream)
        {
            if (entry.isNotInPackage || entry.content == null)
            {
                return;
            }

            Content c = entry.content;

            long fileSize        = entry.fileSize;
            long fileOffset      = entry.fileOffset;
            long fileOffsetBlock = entry.getFileOffsetBlock();

            NUSDataProvider dataProvider = NUSTitle.dataProvider;

            MemoryStream min = dataProvider.getInputStreamFromContent(c, fileOffsetBlock);

            try
            {
                decryptFSTEntryFromStreams(min, outputStream, fileSize, fileOffset, c);
            }
            catch (Exception)
            {
                //MessageBox.Show("Hash doesn't match");
                //if (entry.getFilename().endsWith(".xml")) {
                //    if (outputStream instanceof PipedOutputStream) {
                //        MessageBox.Show("Hash doesn't match. Please check the data for " + entry.getFullPath());
                //    } else {
                //        throw e;
                //    }
                //} else if (entry.getContent().isUNKNWNFlag1Set()) {
                //    MessageBox.Show("But file is optional. Don't worry.");
                //} else {
                //    StringBuilder sb = new StringBuilder();
                //    sb.append("Detailed info:").append(System.lineSeparator());
                //    sb.append(entry).append(System.lineSeparator());
                //    sb.append(entry.getContent()).append(System.lineSeparator());
                //    sb.append(String.format("%016x", this.NUSTitle.getTMD().getTitleID()));
                //    sb.append(e.getMessage() + " Calculated Hash: " + Utils.ByteArrayToString(e.getGivenHash()) + ", expected hash: "
                //            + Utils.ByteArrayToString(e.getExpectedHash()));
                //    MessageBox.Show(sb.toString());
                //    throw e;
                //}
            }
        }