Example #1
0
 public NUSDataProviderWUD(NUSTitle title, WUDInfo wudinfo)
     : base(title)
 {
     //super(title);
     this.WUDInfo = wudinfo;
     this.tmd     = TMD.parseTMD(getRawTMD());
 }
Example #2
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);
        }
Example #3
0
        public static TMD parseTMD(byte[] input)
        {
            byte[] signature = new byte[SIGNATURE_LENGTH];
            byte[] issuer    = new byte[ISSUER_LENGTH];
            byte[] reserved  = new byte[RESERVED_LENGTH];
            byte[] SHA2      = new byte[SHA2_LENGTH];
            byte[] cert1     = new byte[CERT1_LENGTH];
            byte[] cert2     = new byte[CERT2_LENGTH];

            ContentInfo[] contentInfos = new ContentInfo[CONTENT_INFO_ARRAY_SIZE];

            ByteBuffer buffer = ByteBuffer.allocate(input.Length);

            buffer.put(input);

            // Get Signature
            buffer.position(0);
            int signatureType = buffer.getInt();

            buffer.position(POSITION_SIGNATURE);
            buffer.get(signature, 0, SIGNATURE_LENGTH);

            // Get Issuer
            buffer.position(POSITION_ISSUER);
            buffer.get(issuer, 0, ISSUER_LENGTH);

            // Get CACRLVersion and signerCRLVersion
            buffer.position(0x180);
            byte version          = buffer.get();
            byte CACRLVersion     = buffer.get();
            byte signerCRLVersion = buffer.get();

            // Get title information
            buffer.position(0x184);
            long  systemVersion = buffer.getLong();
            long  titleID       = buffer.getLong();
            int   titleType     = buffer.getInt();
            short groupID       = buffer.getShort();

            // Get other information
            buffer.position(POSITION_RESERVED);
            buffer.get(reserved, 0, RESERVED_LENGTH);

            // Get accessRights,titleVersion,contentCount,bootIndex
            buffer.position(0x1D8);
            int   accessRights = buffer.getInt();
            short titleVersion = buffer.getShort();
            short contentCount = buffer.getShort();
            short bootIndex    = buffer.getShort();

            // Get hash
            buffer.position(POSITION_SHA2);
            buffer.get(SHA2, 0, SHA2_LENGTH);

            // Get contentInfos
            buffer.position(CONTENT_INFO_OFFSET);
            for (int i = 0; i < CONTENT_INFO_ARRAY_SIZE; i++)
            {
                byte[] contentInfo = new byte[ContentInfo.CONTENT_INFO_SIZE];
                buffer.get(contentInfo, 0, ContentInfo.CONTENT_INFO_SIZE);
                contentInfos[i] = ContentInfo.parseContentInfo(contentInfo);
            }

            List <Content> contentList = new List <Content>();

            // Get Contents
            for (int i = 0; i < contentCount; i++)
            {
                buffer.position(CONTENT_OFFSET + (Content.CONTENT_SIZE * i));
                byte[] content = new byte[Content.CONTENT_SIZE];
                buffer.get(content, 0, Content.CONTENT_SIZE);
                Content c = Content.parseContent(content);
                contentList.Add(c);
            }

            try
            {
                buffer.get(cert2, 0, CERT2_LENGTH);
            }
            catch (Exception)
            {
            }

            try
            {
                buffer.get(cert1, 0, CERT1_LENGTH);
            }
            catch (Exception)
            {
            }

            TMDParam param = new TMDParam();

            param.signatureType    = (signatureType);
            param.signature        = (signature);
            param.version          = (version);
            param.CACRLVersion     = (CACRLVersion);
            param.signerCRLVersion = (signerCRLVersion);
            param.systemVersion    = (systemVersion);
            param.titleID          = (titleID);
            param.titleType        = (titleType);
            param.groupID          = (groupID);
            param.accessRights     = (accessRights);
            param.titleVersion     = (titleVersion);
            param.contentCount     = (contentCount);
            param.bootIndex        = (bootIndex);
            param.SHA2             = (SHA2);
            param.contentInfos     = (contentInfos);
            param.cert1            = (cert1);
            param.cert2            = (cert2);

            TMD result = new TMD(param);

            foreach (Content c in contentList)
            {
                result.setContentToIndex(c.index, c);
                result.setContentToID(c.ID, c);
            }

            return(result);
        }