Exemplo n.º 1
0
 public bool Open(Stream fs)
 {
     try
     {
         var intBytes = new byte[4];
         fs.Read(intBytes, 0, 4);
         SignatureType = (SignatureType)BitConverter.ToInt32(intBytes, 0);
         // Read the TMD RSA Type
         if (SignatureType == SignatureType.RSA_2048_SHA256)
         {
             Hash = new byte[256];
         }
         else if (SignatureType == SignatureType.RSA_4096_SHA256)
         {
             Hash = new byte[512];
         }
         else
         {
             errorMessage = "This kind of TMD is unsupported.";
             return(false);
         }
         fs.Read(Hash, 0, Hash.Length);
         //Continue reading header
         Head = MarshalUtil.ReadStructBE <TMDHeader>(fs); //read header
         ContentInfoRecords = new TMDContentInfoRecord[64];
         for (var i = 0; i < ContentInfoRecords.Length; i++)
         {
             ContentInfoRecords[i] = MarshalUtil.ReadStructBE <TMDContentInfoRecord>(fs);
         }
         Chunks = new TMDContentChunkRecord[Head.ContentCount]; // new ArrayList();
         for (var i = 0; i < Head.ContentCount; i++)
         {
             Chunks[i] = MarshalUtil.ReadStructBE <TMDContentChunkRecord>(fs);
         }
         //Check if certificates are next
         fs.Read(intBytes, 0, 4);
         switch ((SignatureType)BitConverter.ToInt32(intBytes, 0))
         {
         case SignatureType.RSA_2048_SHA1:
         case SignatureType.RSA_2048_SHA256:
         case SignatureType.RSA_4096_SHA1:
         case SignatureType.RSA_4096_SHA256:
             fs.Seek(-4, SeekOrigin.Current);     //go back
             CertificatesContext = new CertificatesContext();
             if (!CertificatesContext.Open(fs))
             {
                 errorMessage = CertificatesContext.GetErrorMessage();
                 return(false);
             }
             break;
         }
         return(true);
     }
     catch
     {
         errorMessage = "Error opening the TMD file. may be corrupt.";
         return(false);
     }
 }
Exemplo n.º 2
0
        public bool Open(Stream fs)
        {
            var intBytes = new byte[4];
            Header = MarshalUtil.ReadStruct<CIAHeader>(fs); //read header

            CertificateChainOffset = Marshal.SizeOf(Header) + (long)Header.PaddingLength;
            TicketOffset = CertificateChainOffset + Header.CertificateChainLength;
            if (TicketOffset % 64 != 0)
                TicketOffset += (64 - TicketOffset % 64);
            TMDOffset = TicketOffset + Header.TicketLength;
            if (TMDOffset % 64 != 0)
                TMDOffset += (64 - TMDOffset % 64);
            ContentOffset = TMDOffset + Header.TMDLength; ;
            if (ContentOffset % 64 != 0)
                ContentOffset += (64 - ContentOffset % 64);
            MetaOffset = ContentOffset + (long)Header.ContentLength;
            if (MetaOffset % 64 != 0)
                MetaOffset += (64 - MetaOffset % 64);

            fs.Seek(TicketOffset, SeekOrigin.Begin);
            TicketContext = new TicketContext();
            if (!TicketContext.Open(fs))
            {
                errorMessage = TicketContext.GetErrorMessage();
                return false;
            }
            fs.Seek(CertificateChainOffset, SeekOrigin.Begin);
            CertificatesContext = new CertificatesContext();
            if (!CertificatesContext.Open(fs))
            {
                errorMessage = CertificatesContext.GetErrorMessage();
                return false;
            }
            fs.Seek(TMDOffset, SeekOrigin.Begin);
            TMDContext = new TMDContext();
            if (!TMDContext.Open(fs))
            {
                errorMessage = TMDContext.GetErrorMessage();
                return false;
            }

            if (Header.MetaLength > 0)
            {
                fs.Seek(MetaOffset, SeekOrigin.Begin);
                MetaHeaderEntries = new ArrayList();
                var metaHeaderEntry = MarshalUtil.ReadStruct<CIAMetaHeaderEntry>(fs);
                while (metaHeaderEntry.Type != 0)
                {
                    MetaHeaderEntries.Add(metaHeaderEntry);
                    metaHeaderEntry = MarshalUtil.ReadStruct<CIAMetaHeaderEntry>(fs);
                }
                fs.Seek(MetaOffset + 0x400, SeekOrigin.Begin); //Jump to the header
                ICN = new ICNContext();
                ICN.Open(fs);
            }
            return true;
        }
Exemplo n.º 3
0
        public bool Open(Stream fs)
        {
            var intBytes = new byte[4];

            Header = MarshalUtil.ReadStruct <CIAHeader>(fs); //read header

            CertificateChainOffset = Align(Marshal.SizeOf(Header), 64);
            TicketOffset           = Align(CertificateChainOffset + Header.CertificateChainLength, 64);
            TMDOffset     = Align(TicketOffset + Header.TicketLength, 64);
            ContentOffset = Align(TMDOffset + Header.TMDLength, 64);
            MetaOffset    = Align(ContentOffset + (long)Header.ContentLength, 64);


            fs.Seek(CertificateChainOffset, SeekOrigin.Begin);
            CertificatesContext = new CertificatesContext();
            if (!CertificatesContext.Open(fs))
            {
                errorMessage = CertificatesContext.GetErrorMessage();
                return(false);
            }

            fs.Seek(TicketOffset, SeekOrigin.Begin);
            TicketContext = new TicketContext();
            if (!TicketContext.Open(fs))
            {
                errorMessage = TicketContext.GetErrorMessage();
                return(false);
            }

            fs.Seek(TMDOffset, SeekOrigin.Begin);
            TMDContext = new TMDContext();
            if (!TMDContext.Open(fs))
            {
                errorMessage = TMDContext.GetErrorMessage();
                return(false);
            }

            if (Header.MetaLength > 0)
            {
                fs.Seek(MetaOffset, SeekOrigin.Begin);
                MetaHeaderEntries = new ArrayList();
                var metaHeaderEntry = MarshalUtil.ReadStruct <CIAMetaHeaderEntry>(fs);
                while (metaHeaderEntry.ID[6] == 4)
                {
                    MetaHeaderEntries.Add(metaHeaderEntry);
                    metaHeaderEntry = MarshalUtil.ReadStruct <CIAMetaHeaderEntry>(fs);
                }
                fs.Seek(MetaOffset + 0x400, SeekOrigin.Begin); //Jump to the header
                ICN = new ICNContext();
                ICN.Open(fs);
            }
            return(true);
        }
Exemplo n.º 4
0
 public bool Open(Stream fs)
 {
     try
     {
         var intBytes = new byte[4];
         fs.Read(intBytes, 0, 4);
         SignatureType = (SignatureType)BitConverter.ToInt32(intBytes, 0);
         // Read the TMD RSA Type 
         if (SignatureType == SignatureType.RSA_2048_SHA256)
             Hash = new byte[256];
         else if (SignatureType == SignatureType.RSA_4096_SHA256)
             Hash = new byte[512];
         else
         {
             errorMessage = "This kind of TMD is unsupported.";
             return false;
         }
         fs.Read(Hash, 0, Hash.Length);
         //Continue reading header
         Head = MarshalUtil.ReadStructBE<TMDHeader>(fs); //read header
         ContentInfoRecords = new TMDContentInfoRecord[64];
         for (var i = 0; i < ContentInfoRecords.Length; i++)
             ContentInfoRecords[i] = MarshalUtil.ReadStructBE<TMDContentInfoRecord>(fs);
         Chunks = new TMDContentChunkRecord[Head.ContentCount]; // new ArrayList();
         for (var i = 0; i < Head.ContentCount; i++)
             Chunks[i] = MarshalUtil.ReadStructBE<TMDContentChunkRecord>(fs);
         //Check if certificates are next
         fs.Read(intBytes, 0, 4);
         switch ((SignatureType)BitConverter.ToInt32(intBytes, 0))
         {
             case SignatureType.RSA_2048_SHA1:
             case SignatureType.RSA_2048_SHA256:
             case SignatureType.RSA_4096_SHA1:
             case SignatureType.RSA_4096_SHA256:
                 fs.Seek(-4, SeekOrigin.Current); //go back
                 CertificatesContext = new CertificatesContext();
                 if (!CertificatesContext.Open(fs))
                 {
                     errorMessage = CertificatesContext.GetErrorMessage();
                     return false;
                 }
                 break;
         }
         return true;
     }
     catch
     {
         errorMessage = "Error opening the TMD file. may be corrupt.";
         return false;
     }
 }