コード例 #1
0
        private void decryptTitleKey()
        {
            byte[] ckey;
            if (dsitik)
            {
                ckey = CommonKey.GetDSiKey();
            }
            else
            {
                ckey = (commonKeyIndex == 0x01) ? CommonKey.GetKoreanKey() : CommonKey.GetStandardKey();
            }
            byte[] iv = BitConverter.GetBytes(Shared.Swap(titleId));
            Array.Resize(ref iv, 16);

            RijndaelManaged rm = new RijndaelManaged();

            rm.Mode      = CipherMode.CBC;
            rm.Padding   = PaddingMode.None;
            rm.KeySize   = 128;
            rm.BlockSize = 128;
            rm.Key       = ckey;
            rm.IV        = iv;

            ICryptoTransform decryptor = rm.CreateDecryptor();

            MemoryStream ms = new MemoryStream(encryptedTitleKey);
            CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read);

            cs.Read(decryptedTitleKey, 0, decryptedTitleKey.Length);

            cs.Dispose();
            ms.Dispose();
            decryptor.Dispose();
            rm.Clear();
        }
コード例 #2
0
ファイル: Headers.cs プロジェクト: spycrab/NUSDownloader
        /// <summary>
        /// Checks the byte array for Headers.
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public static HeaderType DetectHeader(byte[] file)
        {
            if (file.Length > 68)
            {
                if (Shared.Swap(BitConverter.ToUInt32(file, 64)) == imetMagic)
                {
                    return(HeaderType.ShortIMET);
                }
            }
            if (file.Length > 132)
            {
                if (Shared.Swap(BitConverter.ToUInt32(file, 128)) == imetMagic)
                {
                    return(HeaderType.IMET);
                }
            }
            if (file.Length > 4)
            {
                if (Shared.Swap(BitConverter.ToUInt32(file, 0)) == imd5Magic)
                {
                    return(HeaderType.IMD5);
                }
            }

            return(HeaderType.None);
        }
コード例 #3
0
        public void Read(BinaryReader reader)
        {
            if (Shared.Swap(reader.ReadUInt32()) != smplId)
            {
                throw new Exception("Wrong chunk ID!");
            }

            smplSize      = reader.ReadUInt32();
            manufacturer  = reader.ReadUInt32();
            product       = reader.ReadUInt32();
            samplePeriod  = reader.ReadUInt32();
            unityNote     = reader.ReadUInt32();
            pitchFraction = reader.ReadUInt32();
            smpteFormat   = reader.ReadUInt32();
            smpteOffset   = reader.ReadUInt32();
            numLoops      = reader.ReadUInt32();
            samplerData   = reader.ReadUInt32();

            for (int i = 0; i < numLoops; i++)
            {
                WaveSmplLoop tempLoop = new WaveSmplLoop();
                tempLoop.Read(reader);

                smplLoops.Add(tempLoop);
            }
        }
コード例 #4
0
ファイル: Headers.cs プロジェクト: TheShadowEevee/libWiiSharp
 /// <summary>
 /// Checks the stream for Headers.
 /// </summary>
 /// <param name="file"></param>
 /// <returns></returns>
 public static Headers.HeaderType DetectHeader(Stream file)
 {
     byte[] buffer = new byte[4];
     if (file.Length > 68L)
     {
         file.Seek(64L, SeekOrigin.Begin);
         file.Read(buffer, 0, buffer.Length);
         if ((int)Shared.Swap(BitConverter.ToUInt32(buffer, 0)) == (int)imetMagic)
         {
             return(HeaderType.ShortIMET);
         }
     }
     if (file.Length > 132L)
     {
         file.Seek(128L, SeekOrigin.Begin);
         file.Read(buffer, 0, buffer.Length);
         if ((int)Shared.Swap(BitConverter.ToUInt32(buffer, 0)) == (int)imetMagic)
         {
             return(HeaderType.IMET);
         }
     }
     if (file.Length > 4L)
     {
         file.Seek(0L, SeekOrigin.Begin);
         file.Read(buffer, 0, buffer.Length);
         if ((int)Shared.Swap(BitConverter.ToUInt32(buffer, 0)) == (int)imd5Magic)
         {
             return(HeaderType.IMD5);
         }
     }
     return(HeaderType.None);
 }
コード例 #5
0
        private void encryptTitleKey()
        {
            commonKeyIndex = newKeyIndex;
            byte[] ckey = CommonKey.GetStandardKey();
            byte[] iv   = BitConverter.GetBytes(Shared.Swap(titleId));
            Array.Resize(ref iv, 16);

            RijndaelManaged rm = new RijndaelManaged();

            rm.Mode      = CipherMode.CBC;
            rm.Padding   = PaddingMode.None;
            rm.KeySize   = 128;
            rm.BlockSize = 128;
            rm.Key       = ckey;
            rm.IV        = iv;

            ICryptoTransform encryptor = rm.CreateEncryptor();

            MemoryStream ms = new MemoryStream(decryptedTitleKey);
            CryptoStream cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Read);

            cs.Read(encryptedTitleKey, 0, encryptedTitleKey.Length);

            cs.Dispose();
            ms.Dispose();
            encryptor.Dispose();
            rm.Clear();
        }
コード例 #6
0
ファイル: U8.cs プロジェクト: volt72/NEW-NUSGrabberGUI
 public void Write(Stream writeStream)
 {
     writeStream.Write(BitConverter.GetBytes(Shared.Swap(type)), 0, 2);
     writeStream.Write(BitConverter.GetBytes(Shared.Swap(offsetToName)), 0, 2);
     writeStream.Write(BitConverter.GetBytes(Shared.Swap(offsetToData)), 0, 4);
     writeStream.Write(BitConverter.GetBytes(Shared.Swap(sizeOfData)), 0, 4);
 }
コード例 #7
0
        /// <summary>
        /// Returns the length of the BNS audio file in seconds
        /// </summary>
        /// <param name="bnsFile"></param>
        /// <returns></returns>
        public static int GetBnsLength(byte[] bnsFile)
        {
            uint sampleRate  = Shared.Swap(BitConverter.ToUInt16(bnsFile, 44));
            uint sampleCount = Shared.Swap(BitConverter.ToUInt32(bnsFile, 52));

            return((int)(sampleCount / sampleRate));
        }
コード例 #8
0
ファイル: Headers.cs プロジェクト: spycrab/NUSDownloader
        /// <summary>
        /// Checks the stream for Headers.
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public static HeaderType DetectHeader(Stream file)
        {
            byte[] tmp = new byte[4];

            if (file.Length > 68)
            {
                file.Seek(64, SeekOrigin.Begin);
                file.Read(tmp, 0, tmp.Length);
                if (Shared.Swap(BitConverter.ToUInt32(tmp, 0)) == imetMagic)
                {
                    return(HeaderType.ShortIMET);
                }
            }
            if (file.Length > 132)
            {
                file.Seek(128, SeekOrigin.Begin);
                file.Read(tmp, 0, tmp.Length);
                if (Shared.Swap(BitConverter.ToUInt32(tmp, 0)) == imetMagic)
                {
                    return(HeaderType.IMET);
                }
            }
            if (file.Length > 4)
            {
                file.Seek(0, SeekOrigin.Begin);
                file.Read(tmp, 0, tmp.Length);
                if (Shared.Swap(BitConverter.ToUInt32(tmp, 0)) == imd5Magic)
                {
                    return(HeaderType.IMD5);
                }
            }

            return(HeaderType.None);
        }
コード例 #9
0
        public void Write(Stream outStream)
        {
            byte[] temp = BitConverter.GetBytes(Shared.Swap(size));

            outStream.Write(magic, 0, magic.Length);
            outStream.Write(temp, 0, temp.Length);
            outStream.Write(data, 0, data.Length);
        }
コード例 #10
0
ファイル: U8.cs プロジェクト: volt72/NEW-NUSGrabberGUI
 public void Write(Stream writeStream)
 {
     writeStream.Write(BitConverter.GetBytes(Shared.Swap(u8Magic)), 0, 4);
     writeStream.Write(BitConverter.GetBytes(Shared.Swap(offsetToRootNode)), 0, 4);
     writeStream.Write(BitConverter.GetBytes(Shared.Swap(headerSize)), 0, 4);
     writeStream.Write(BitConverter.GetBytes(Shared.Swap(offsetToData)), 0, 4);
     writeStream.Write(padding, 0, 16);
 }
コード例 #11
0
ファイル: Headers.cs プロジェクト: spycrab/NUSDownloader
 private void writeToStream(Stream writeStream)
 {
     writeStream.Seek(0, SeekOrigin.Begin);
     writeStream.Write(BitConverter.GetBytes(Shared.Swap(imd5Magic)), 0, 4);
     writeStream.Write(BitConverter.GetBytes(Shared.Swap(fileSize)), 0, 4);
     writeStream.Write(padding, 0, padding.Length);
     writeStream.Write(hash, 0, hash.Length);
 }
コード例 #12
0
 /// <summary>
 /// Checks whether a file is Lz77 compressed or not.
 /// </summary>
 /// <param name="file"></param>
 /// <returns></returns>
 public static bool IsLz77Compressed(Stream file)
 {
     Headers.HeaderType h    = Headers.DetectHeader(file);
     byte[]             temp = new byte[4];
     file.Seek((long)h, SeekOrigin.Begin);
     file.Read(temp, 0, temp.Length);
     return(Shared.Swap(BitConverter.ToUInt32(temp, 0)) == lz77Magic);
 }
コード例 #13
0
ファイル: Lz77.cs プロジェクト: TheShadowEevee/libWiiSharp
 /// <summary>
 /// Checks whether a file is Lz77 compressed or not.
 /// </summary>
 /// <param name="file"></param>
 /// <returns></returns>
 public static bool IsLz77Compressed(Stream file)
 {
     Headers.HeaderType headerType = Headers.DetectHeader(file);
     byte[]             buffer     = new byte[4];
     file.Seek((long)headerType, SeekOrigin.Begin);
     file.Read(buffer, 0, buffer.Length);
     return((int)Shared.Swap(BitConverter.ToUInt32(buffer, 0)) == (int)lz77Magic);
 }
コード例 #14
0
        private void GrabFromTmd(Stream tmd)
        {
            FireDebug("Scanning TMD for Certificates...");
            byte[] buffer = new byte[2];
            tmd.Seek(478L, SeekOrigin.Begin);
            tmd.Read(buffer, 0, 2);
            int num = 484 + Shared.Swap(BitConverter.ToUInt16(buffer, 0)) * 36;

            for (int index = 0; index < 3; ++index)
            {
                FireDebug("   Scanning at Offset 0x{0}:", (object)num.ToString("x8"));
                try
                {
                    tmd.Seek(num, SeekOrigin.Begin);
                    byte[] array = new byte[1024];
                    tmd.Read(array, 0, array.Length);
                    FireDebug("   Checking for Certificate CA...");
                    if (IsCertCa(array) && !certsComplete[1])
                    {
                        FireDebug("   Certificate CA detected...");
                        certCa           = array;
                        certsComplete[1] = true;
                        num += 1024;
                        continue;
                    }
                    FireDebug("   Checking for Certificate CP...");
                    if (IsCertCp(array) && !certsComplete[2])
                    {
                        FireDebug("   Certificate CP detected...");
                        Array.Resize <byte>(ref array, 768);
                        certCp           = array;
                        certsComplete[2] = true;
                        num += 768;
                        continue;
                    }
                    FireDebug("   Checking for Certificate XS...");
                    if (IsCertXs(array))
                    {
                        if (!certsComplete[0])
                        {
                            FireDebug("   Certificate XS detected...");
                            Array.Resize <byte>(ref array, 768);
                            certXs           = array;
                            certsComplete[0] = true;
                            num += 768;
                            continue;
                        }
                    }
                }
                catch
                {
                }
                num += 768;
            }
            FireDebug("Scanning TMD for Certificates Finished...");
        }
コード例 #15
0
        public void Read(BinaryReader reader)
        {
            if (Shared.Swap(reader.ReadUInt32()) != dataId)
            {
                throw new Exception("Wrong chunk ID!");
            }

            dataSize = reader.ReadUInt32();
            data     = reader.ReadBytes((int)dataSize);
        }
コード例 #16
0
        public void Read(Stream input)
        {
            BinaryReader reader = new BinaryReader(input);

            if (!Shared.CompareByteArrays(magic, reader.ReadBytes(4)))
            {
                throw new Exception("This is not a valid BNS audfo file!");
            }

            size = Shared.Swap(reader.ReadUInt32());
            data = reader.ReadBytes((int)size - 8);
        }
コード例 #17
0
        public void Write(BinaryWriter writer)
        {
            byteRate   = sampleRate * numChannels * bitsPerSample / 8;
            blockAlign = (ushort)(numChannels * bitsPerSample / 8);

            writer.Write(Shared.Swap(fmtId));
            writer.Write(fmtSize);
            writer.Write(audioFormat);
            writer.Write(numChannels);
            writer.Write(sampleRate);
            writer.Write(byteRate);
            writer.Write(blockAlign);
            writer.Write(bitsPerSample);
        }
コード例 #18
0
        public void Read(BinaryReader reader)
        {
            if (Shared.Swap(reader.ReadUInt32()) != headerId)
            {
                throw new Exception("Not a valid RIFF Wave file!");
            }

            fileSize = reader.ReadUInt32();

            if (Shared.Swap(reader.ReadUInt32()) != format)
            {
                throw new Exception("Not a valid RIFF Wave file!");
            }
        }
コード例 #19
0
ファイル: Headers.cs プロジェクト: TheShadowEevee/libWiiSharp
        /// <summary>
        /// Checks the byte array for Headers.
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public static Headers.HeaderType DetectHeader(byte[] file)
        {
            if (file.Length > 68 && (int)Shared.Swap(BitConverter.ToUInt32(file, 64)) == (int)imetMagic)
            {
                return(HeaderType.ShortIMET);
            }

            if (file.Length > 132 && (int)Shared.Swap(BitConverter.ToUInt32(file, 128)) == (int)imetMagic)
            {
                return(HeaderType.IMET);
            }

            return(file.Length > 4 && (int)Shared.Swap(BitConverter.ToUInt32(file, 0)) == (int)imd5Magic ? HeaderType.IMD5 : HeaderType.None);
        }
コード例 #20
0
        public void Read(BinaryReader reader)
        {
            if (Shared.Swap(reader.ReadUInt32()) != fmtId)
            {
                throw new Exception("Wrong chunk ID!");
            }

            fmtSize       = reader.ReadUInt32();
            audioFormat   = reader.ReadUInt16();
            numChannels   = reader.ReadUInt16();
            sampleRate    = reader.ReadUInt32();
            byteRate      = reader.ReadUInt32();
            blockAlign    = reader.ReadUInt16();
            bitsPerSample = reader.ReadUInt16();
        }
コード例 #21
0
        private void grabFromTmd(Stream tmd)
        {
            fireDebug("Scanning TMD for Certificates...");

            byte[] temp = new byte[2];
            tmd.Seek(478, SeekOrigin.Begin);
            tmd.Read(temp, 0, 2);

            int numContents = Shared.Swap(BitConverter.ToUInt16(temp, 0));
            int off         = 484 + numContents * 36;

            for (int i = 0; i < 3; i++)
            {
                fireDebug("   Scanning at Offset 0x{0}:", off.ToString("x8"));

                try
                {
                    tmd.Seek(off, SeekOrigin.Begin);
                    temp = new byte[0x400];

                    tmd.Read(temp, 0, temp.Length);

                    fireDebug("   Checking for Certificate CA...");
                    if (isCertCa(temp) && !certsComplete[1])
                    {
                        fireDebug("   Certificate CA detected..."); certCa = temp; certsComplete[1] = true; off += 0x400; continue;
                    }

                    fireDebug("   Checking for Certificate CP...");
                    if (isCertCp(temp) && !certsComplete[2])
                    {
                        fireDebug("   Certificate CP detected..."); Array.Resize(ref temp, 0x300); certCp = temp; certsComplete[2] = true; off += 0x300; continue;
                    }

                    fireDebug("   Checking for Certificate XS...");
                    if (isCertXs(temp) && !certsComplete[0])
                    {
                        fireDebug("   Certificate XS detected..."); Array.Resize(ref temp, 0x300); certXs = temp; certsComplete[0] = true; off += 0x300; continue;
                    }
                }
                catch { }

                off += 0x300;
            }

            fireDebug("Scanning TMD for Certificates Finished...");
        }
コード例 #22
0
ファイル: Headers.cs プロジェクト: spycrab/NUSDownloader
            private void parseHeader(Stream headerStream)
            {
                headerStream.Seek(0, SeekOrigin.Begin);
                byte[] tmp = new byte[4];

                headerStream.Read(tmp, 0, 4);
                if (Shared.Swap(BitConverter.ToUInt32(tmp, 0)) != imd5Magic)
                {
                    throw new Exception("Invalid Magic!");
                }

                headerStream.Read(tmp, 0, 4);
                fileSize = Shared.Swap(BitConverter.ToUInt32(tmp, 0));

                headerStream.Read(padding, 0, padding.Length);
                headerStream.Read(hash, 0, hash.Length);
            }
コード例 #23
0
ファイル: Headers.cs プロジェクト: spycrab/NUSDownloader
            private void writeToStream(Stream writeStream)
            {
                writeStream.Seek(0, SeekOrigin.Begin);

                if (!isShortImet)
                {
                    writeStream.Write(additionalPadding, 0, additionalPadding.Length);
                }

                writeStream.Write(padding, 0, padding.Length);
                writeStream.Write(BitConverter.GetBytes(Shared.Swap(imetMagic)), 0, 4);
                writeStream.Write(BitConverter.GetBytes(Shared.Swap(sizeOfHeader)), 0, 4);
                writeStream.Write(BitConverter.GetBytes(Shared.Swap(unknown)), 0, 4);
                writeStream.Write(BitConverter.GetBytes(Shared.Swap(iconSize)), 0, 4);
                writeStream.Write(BitConverter.GetBytes(Shared.Swap(bannerSize)), 0, 4);
                writeStream.Write(BitConverter.GetBytes(Shared.Swap(soundSize)), 0, 4);
                writeStream.Write(BitConverter.GetBytes(Shared.Swap(flags)), 0, 4);

                writeStream.Write(japaneseTitle, 0, japaneseTitle.Length);
                writeStream.Write(englishTitle, 0, englishTitle.Length);
                writeStream.Write(germanTitle, 0, germanTitle.Length);
                writeStream.Write(frenchTitle, 0, frenchTitle.Length);
                writeStream.Write(spanishTitle, 0, spanishTitle.Length);
                writeStream.Write(italianTitle, 0, italianTitle.Length);
                writeStream.Write(dutchTitle, 0, dutchTitle.Length);
                writeStream.Write(unknownTitle1, 0, unknownTitle1.Length);
                writeStream.Write(unknownTitle2, 0, unknownTitle2.Length);
                writeStream.Write(koreanTitle, 0, koreanTitle.Length);
                writeStream.Write(padding2, 0, padding2.Length);

                int hashPos = (int)writeStream.Position;

                hash = new byte[16];
                writeStream.Write(hash, 0, hash.Length);

                byte[] toHash = new byte[writeStream.Position];
                writeStream.Seek(0, SeekOrigin.Begin);
                writeStream.Read(toHash, 0, toHash.Length);

                computeHash(toHash, isShortImet ? 0 : 0x40);

                writeStream.Seek(hashPos, SeekOrigin.Begin);
                writeStream.Write(hash, 0, hash.Length);
            }
コード例 #24
0
        public void Write(BinaryWriter writer)
        {
            writer.Write(Shared.Swap(smplId));
            writer.Write(smplSize);
            writer.Write(manufacturer);
            writer.Write(product);
            writer.Write(samplePeriod);
            writer.Write(unityNote);
            writer.Write(pitchFraction);
            writer.Write(smpteFormat);
            writer.Write(smpteOffset);
            writer.Write(numLoops);
            writer.Write(samplerData);

            for (int i = 0; i < numLoops; i++)
            {
                smplLoops[i].Write(writer);
            }
        }
コード例 #25
0
ファイル: U8.cs プロジェクト: volt72/NEW-NUSGrabberGUI
        /// <summary>
        /// Checks whether a file is a U8 file or not.
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public static bool IsU8(byte[] file)
        {
            if (Lz77.IsLz77Compressed(file))
            {
                byte[] partOfFile = new byte[(file.Length > 2000) ? 2000 : file.Length];

                for (int i = 0; i < partOfFile.Length; i++)
                {
                    partOfFile[i] = file[i];
                }

                Lz77 l = new Lz77();
                partOfFile = l.Decompress(partOfFile);

                return(IsU8(partOfFile));
            }
            else
            {
                Headers.HeaderType h = Headers.DetectHeader(file);
                return(Shared.Swap(BitConverter.ToUInt32(file, (int)h)) == 0x55AA382D);
            }
        }
コード例 #26
0
        public void Read(Stream input)
        {
            BinaryReader reader = new BinaryReader(input);

            if (!Shared.CompareByteArrays(magic, reader.ReadBytes(4)))
            {
                reader.BaseStream.Seek(28, SeekOrigin.Current);
                if (!Shared.CompareByteArrays(magic, reader.ReadBytes(4)))
                {
                    throw new Exception("This is not a valid BNS audfo file!");
                }
            }

            flags      = Shared.Swap(reader.ReadUInt32());
            fileSize   = Shared.Swap(reader.ReadUInt32());
            size       = Shared.Swap(reader.ReadUInt16());
            chunkCount = Shared.Swap(reader.ReadUInt16());
            infoOffset = Shared.Swap(reader.ReadUInt32());
            infoLength = Shared.Swap(reader.ReadUInt32());
            dataOffset = Shared.Swap(reader.ReadUInt32());
            dataLength = Shared.Swap(reader.ReadUInt32());
        }
コード例 #27
0
        private void parseWave(BinaryReader reader)
        {
            bool[] hasChunk = new bool[] { false, false, false };

            while (reader.BaseStream.Position < reader.BaseStream.Length - 4)
            {
                uint curChunk       = Shared.Swap(reader.ReadUInt32());
                uint curChunkLength = reader.ReadUInt32();
                long nextChunkPos   = reader.BaseStream.Position + curChunkLength;

                switch (curChunk)
                {
                case 0x52494646:     //RIFF
                    try
                    {
                        reader.BaseStream.Seek(-8, SeekOrigin.Current);
                        header.Read(reader);
                        hasChunk[0] = true;
                    }
                    catch { reader.BaseStream.Seek(nextChunkPos, SeekOrigin.Begin); }
                    break;

                case 0x666d7420:     //fmt
                    try
                    {
                        reader.BaseStream.Seek(-8, SeekOrigin.Current);
                        fmt.Read(reader);
                        hasChunk[1] = true;
                    }
                    catch { reader.BaseStream.Seek(nextChunkPos, SeekOrigin.Begin); }
                    break;

                case 0x64617461:     //data
                    try
                    {
                        reader.BaseStream.Seek(-8, SeekOrigin.Current);
                        data.Read(reader);
                        hasChunk[2] = true;
                    }
                    catch { reader.BaseStream.Seek(nextChunkPos, SeekOrigin.Begin); }
                    break;

                case 0x736d706c:     //smpl
                    try
                    {
                        reader.BaseStream.Seek(-8, SeekOrigin.Current);
                        smpl.Read(reader);
                        hasSmpl = true;
                    }
                    catch { reader.BaseStream.Seek(nextChunkPos, SeekOrigin.Begin); }
                    break;

                default:
                    reader.BaseStream.Seek(curChunkLength, SeekOrigin.Current);
                    break;
                }

                if (hasChunk[0] && hasChunk[1] && hasChunk[2] && hasSmpl)
                {
                    break;
                }
            }

            if (!(hasChunk[0] && hasChunk[1] && hasChunk[2]))
            {
                throw new Exception("Couldn't parse Wave file...");
            }
        }
コード例 #28
0
 public void Write(BinaryWriter writer)
 {
     writer.Write(Shared.Swap(headerId));
     writer.Write(fileSize);
     writer.Write(Shared.Swap(format));
 }
コード例 #29
0
        private void parseTmd(Stream tmdFile)
        {
            fireDebug("Pasing TMD...");

            tmdFile.Seek(0, SeekOrigin.Begin);
            byte[] temp = new byte[8];

            fireDebug("   Reading Signature Exponent... (Offset: 0x{0})", tmdFile.Position.ToString("x8").ToUpper());
            tmdFile.Read(temp, 0, 4);
            signatureExponent = Shared.Swap(BitConverter.ToUInt32(temp, 0));

            fireDebug("   Reading Signature... (Offset: 0x{0})", tmdFile.Position.ToString("x8").ToUpper());
            tmdFile.Read(signature, 0, signature.Length);

            fireDebug("   Reading Padding... (Offset: 0x{0})", tmdFile.Position.ToString("x8").ToUpper());
            tmdFile.Read(padding, 0, padding.Length);

            fireDebug("   Reading Issuer... (Offset: 0x{0})", tmdFile.Position.ToString("x8").ToUpper());
            tmdFile.Read(issuer, 0, issuer.Length);

            fireDebug("   Reading Version... (Offset: 0x{0})", tmdFile.Position.ToString("x8").ToUpper());
            fireDebug("   Reading CA Crl Version... (Offset: 0x{0})", tmdFile.Position.ToString("x8").ToUpper());
            fireDebug("   Reading Signer Crl Version... (Offset: 0x{0})", tmdFile.Position.ToString("x8").ToUpper());
            fireDebug("   Reading Padding Byte... (Offset: 0x{0})", tmdFile.Position.ToString("x8").ToUpper());
            tmdFile.Read(temp, 0, 4);
            version          = temp[0];
            caCrlVersion     = temp[1];
            signerCrlVersion = temp[2];
            paddingByte      = temp[3];

            fireDebug("   Reading Startup IOS... (Offset: 0x{0})", tmdFile.Position.ToString("x8").ToUpper());
            tmdFile.Read(temp, 0, 8);
            startupIos = Shared.Swap(BitConverter.ToUInt64(temp, 0));

            fireDebug("   Reading Title ID... (Offset: 0x{0})", tmdFile.Position.ToString("x8").ToUpper());
            tmdFile.Read(temp, 0, 8);
            titleId = Shared.Swap(BitConverter.ToUInt64(temp, 0));

            fireDebug("   Reading Title Type... (Offset: 0x{0})", tmdFile.Position.ToString("x8").ToUpper());
            tmdFile.Read(temp, 0, 4);
            titleType = Shared.Swap(BitConverter.ToUInt32(temp, 0));

            fireDebug("   Reading Group ID... (Offset: 0x{0})", tmdFile.Position.ToString("x8").ToUpper());
            tmdFile.Read(temp, 0, 2);
            groupId = Shared.Swap(BitConverter.ToUInt16(temp, 0));

            fireDebug("   Reading Padding2... (Offset: 0x{0})", tmdFile.Position.ToString("x8").ToUpper());
            tmdFile.Read(temp, 0, 2);
            padding2 = Shared.Swap(BitConverter.ToUInt16(temp, 0));

            fireDebug("   Reading Region... (Offset: 0x{0})", tmdFile.Position.ToString("x8").ToUpper());
            tmdFile.Read(temp, 0, 2);
            region = Shared.Swap(BitConverter.ToUInt16(temp, 0));

            fireDebug("   Reading Reserved... (Offset: 0x{0})", tmdFile.Position.ToString("x8").ToUpper());
            tmdFile.Read(reserved, 0, reserved.Length);

            fireDebug("   Reading Access Rights... (Offset: 0x{0})", tmdFile.Position.ToString("x8").ToUpper());
            tmdFile.Read(temp, 0, 4);
            accessRights = Shared.Swap(BitConverter.ToUInt32(temp, 0));

            fireDebug("   Reading Title Version... (Offset: 0x{0})", tmdFile.Position.ToString("x8").ToUpper());
            fireDebug("   Reading NumOfContents... (Offset: 0x{0})", tmdFile.Position.ToString("x8").ToUpper());
            fireDebug("   Reading Boot Index... (Offset: 0x{0})", tmdFile.Position.ToString("x8").ToUpper());
            fireDebug("   Reading Padding3... (Offset: 0x{0})", tmdFile.Position.ToString("x8").ToUpper());
            tmdFile.Read(temp, 0, 8);
            titleVersion  = Shared.Swap(BitConverter.ToUInt16(temp, 0));
            numOfContents = Shared.Swap(BitConverter.ToUInt16(temp, 2));
            bootIndex     = Shared.Swap(BitConverter.ToUInt16(temp, 4));
            padding3      = Shared.Swap(BitConverter.ToUInt16(temp, 6));

            contents = new List <TMD_Content>();

            //Read Contents
            for (int i = 0; i < numOfContents; i++)
            {
                fireDebug("   Reading Content #{0} of {1}... (Offset: 0x{2})", i + 1, numOfContents, tmdFile.Position.ToString("x8").ToUpper().ToUpper());

                TMD_Content tempContent = new TMD_Content();
                tempContent.Hash = new byte[20];

                tmdFile.Read(temp, 0, 8);
                tempContent.ContentID = Shared.Swap(BitConverter.ToUInt32(temp, 0));
                tempContent.Index     = Shared.Swap(BitConverter.ToUInt16(temp, 4));
                tempContent.Type      = (ContentType)Shared.Swap(BitConverter.ToUInt16(temp, 6));

                tmdFile.Read(temp, 0, 8);
                tempContent.Size = Shared.Swap(BitConverter.ToUInt64(temp, 0));

                tmdFile.Read(tempContent.Hash, 0, tempContent.Hash.Length);

                contents.Add(tempContent);
            }

            fireDebug("Pasing TMD Finished...");
        }
コード例 #30
0
 public void Write(BinaryWriter writer)
 {
     writer.Write(Shared.Swap(dataId));
     writer.Write(dataSize);
     writer.Write(data, 0, data.Length);
 }