Ejemplo n.º 1
0
        public byte[] GetAsData()
        {
            BigEndianMemoryStream buffer = new BigEndianMemoryStream(GetDataSize());

            buffer.WriteBigEndian(signatureType);
            buffer.Write(signature);
            buffer.Seek(60, SeekOrigin.Current);
            buffer.Write(issuer);

            buffer.WriteByte(version);
            buffer.WriteByte(CACRLVersion);
            buffer.WriteByte(signerCRLVersion);
            buffer.Seek(1, SeekOrigin.Current);

            buffer.WriteBigEndian(systemVersion);
            buffer.WriteBigEndian(ticket.titleID);
            buffer.WriteBigEndian(titleType);
            buffer.WriteBigEndian(groupID);
            buffer.WriteBigEndian(appType);
            buffer.Seek(58, SeekOrigin.Current);
            buffer.WriteBigEndian(accessRights);
            buffer.WriteBigEndian(titleVersion);
            buffer.WriteBigEndian(contentCount);
            buffer.WriteBigEndian(bootIndex);
            buffer.Seek(2, SeekOrigin.Current);

            buffer.Write(SHA2);

            buffer.Write(contentInfo.GetAsData());
            buffer.Write(contents.GetAsData());

            return(buffer.GetBuffer());
        }
Ejemplo n.º 2
0
        public byte[] GetAsData()
        {
            BigEndianMemoryStream buffer = new BigEndianMemoryStream(2304);

            buffer.WriteBigEndian(indexOffset);
            buffer.WriteBigEndian(contentCount);

            buffer.Write(SHA2Hash);

            return(buffer.GetBuffer());
        }
Ejemplo n.º 3
0
        public byte[] GetAsData()
        {
            BigEndianMemoryStream buffer = new BigEndianMemoryStream(staticDataSize);

            buffer.WriteBigEndian(ID);
            buffer.WriteBigEndian(index);
            buffer.WriteBigEndian(type);
            buffer.WriteBigEndian(encryptedFileSize);

            buffer.Write(SHA1);

            return(buffer.GetBuffer());
        }
Ejemplo n.º 4
0
        public byte[] GetAsData()
        {
            BigEndianMemoryStream buffer = new BigEndianMemoryStream(GetDataSize());

            buffer.Write(magicbytes);
            buffer.WriteBigEndian(unknown);
            buffer.WriteBigEndian(contentCount);
            buffer.Seek(20, SeekOrigin.Current);
            buffer.Write(contents.GetFSTContentHeaderAsData());
            buffer.Write(fileEntries.GetAsData());
            buffer.Write(strings.ToArray());

            return(buffer.GetBuffer());
        }
Ejemplo n.º 5
0
        public byte[] GetAsData()
        {
            Random rdm = new Random();
            BigEndianMemoryStream buffer = new BigEndianMemoryStream(0x350);

            buffer.Write(Utils.HexStringToByteArray("00010004"));
            byte[] randomData = new byte[0x100];
            rdm.NextBytes(randomData);
            buffer.Write(randomData);
            buffer.Seek(0x3C, SeekOrigin.Current);
            buffer.Write(Utils.HexStringToByteArray("526F6F742D434130303030303030332D58533030303030303063000000000000"));
            buffer.Seek(0x5C, SeekOrigin.Current);
            buffer.Write(Utils.HexStringToByteArray("010000"));
            buffer.Write(GetEncryptedKey().key);
            buffer.Write(Utils.HexStringToByteArray("000005"));
            randomData = new byte[0x06];
            rdm.NextBytes(randomData);
            buffer.Write(randomData);
            buffer.Seek(0x04, SeekOrigin.Current);
            buffer.WriteBigEndian(titleID);
            buffer.Write(Utils.HexStringToByteArray("00000011000000000000000000000005"));
            buffer.Seek(0xB0, SeekOrigin.Current);
            buffer.Write(Utils.HexStringToByteArray("00010014000000AC000000140001001400000000000000280000000100000084000000840003000000000000FFFFFF01"));
            buffer.Seek(0x7C, SeekOrigin.Current);

            return(buffer.GetBuffer());
        }
Ejemplo n.º 6
0
        public Encryption GetEncryption()
        {
            BigEndianMemoryStream ivStream = new BigEndianMemoryStream(0x10);

            ivStream.WriteBigEndian(ticket.titleID);

            return(new Encryption(ticket.decryptedKey, new IV(ivStream.GetBuffer())));
        }
Ejemplo n.º 7
0
        public KeyValuePair <long, byte[]> GetFSTContentHeaderAsData(long oldContentOffset)
        {
            BigEndianMemoryStream buffer = new BigEndianMemoryStream(staticFSTContentHeaderDataSize);

            byte unknown;
            long content_offset           = oldContentOffset;
            long fst_content_size         = encryptedFileSize / CONTENT_FILE_PADDING;
            long fst_content_size_written = fst_content_size;

            if (IsHashed)
            {
                unknown = 2;
                fst_content_size_written -= ((fst_content_size / 64) + 1) * 2;
                if (fst_content_size_written < 0)
                {
                    fst_content_size_written = 0;
                }
            }
            else
            {
                unknown = 1;
            }

            if (isFSTContent)
            {
                unknown = 0;
                if (fst_content_size == 1)
                {
                    fst_content_size = 0;
                }

                content_offset += fst_content_size + 2;
            }
            else
            {
                content_offset += fst_content_size;
            }

            buffer.WriteBigEndian((int)oldContentOffset);
            buffer.WriteBigEndian((int)fst_content_size_written);
            buffer.WriteBigEndian(parentTitleID);
            buffer.WriteBigEndian(groupID);
            buffer.WriteByte(unknown);

            return(new KeyValuePair <long, byte[]>(content_offset, buffer.GetBuffer()));
        }
Ejemplo n.º 8
0
        public void EncryptFileWithPadding(FileStream input, int contentID, FileStream output, int blockSize)
        {
            BigEndianMemoryStream ivStream = new BigEndianMemoryStream(0x10);

            ivStream.WriteBigEndian((short)contentID);
            IV iv = new IV(ivStream.GetBuffer());

            EncryptSingleFile(input, output, input.Length, iv, blockSize);
        }
Ejemplo n.º 9
0
        public Key GetEncryptedKey()
        {
            BigEndianMemoryStream ivStream = new BigEndianMemoryStream(0x10);

            ivStream.WriteBigEndian(titleID);
            Encryption encrypt = new Encryption(encryptWith, new IV(ivStream.GetBuffer()));

            return(new Key(encrypt.Encrypt(decryptedKey.key)));
        }
Ejemplo n.º 10
0
        public void EncryptFileWithPadding(FST fst, string outputFilename, short contentID, int blockSize)
        {
            using FileStream output = new FileStream(outputFilename, FileMode.Create);

            MemoryStream          input    = new MemoryStream(fst.GetAsData());
            BigEndianMemoryStream ivStream = new BigEndianMemoryStream(0x10);

            ivStream.WriteBigEndian(contentID);
            IV iv = new IV(ivStream.GetBuffer());

            EncryptSingleFile(input, output, fst.GetDataSize(), iv, blockSize);
        }
Ejemplo n.º 11
0
        private byte[] EncryptChunkHashed(byte[] buffer, int block, ContentHashes hashes, int contentID)
        {
            BigEndianMemoryStream ivStream = new BigEndianMemoryStream(16);

            ivStream.WriteBigEndian((short)contentID);
            aes.IV = ivStream.GetBuffer();
            byte[] decryptedHashes = hashes.GetHashForBlock(block);
            decryptedHashes[1] ^= (byte)contentID;

            byte[] encryptedhashes = Encrypt(decryptedHashes);
            decryptedHashes[1] ^= (byte)contentID;
            int iv_start = (block % 16) * 20;

            aes.IV = Utils.CopyOfRange(decryptedHashes, iv_start, iv_start + 16);

            byte[]       encryptedContent = Encrypt(buffer);
            MemoryStream outputStream     = new MemoryStream(0x10000);

            outputStream.Write(encryptedhashes);
            outputStream.Write(encryptedContent);

            return(outputStream.GetBuffer());
        }
Ejemplo n.º 12
0
        public byte[] GetAsData()
        {
            BigEndianMemoryStream buffer = new BigEndianMemoryStream(GetDataSize());

            if (isRoot)
            {
                buffer.WriteByte(1);
                buffer.Seek(7, SeekOrigin.Current);
                buffer.WriteBigEndian(rootEntryCount);
                buffer.Seek(4, SeekOrigin.Current);
            }
            else
            {
                buffer.WriteByte(GetTypeAsByte());
                buffer.WriteByte((byte)(nameOffset >> 16)); // We need to write a 24bit int (big endian)
                buffer.WriteByte((byte)(nameOffset >> 8));
                buffer.WriteByte((byte)nameOffset);

                if (isDir)
                {
                    buffer.WriteBigEndian(parentOffset);
                    buffer.WriteBigEndian(nextOffset);
                }
                else
                {
                    buffer.WriteBigEndian((int)(fileOffset >> 5));
                    buffer.WriteBigEndian((int)fileSize);
                }

                buffer.WriteBigEndian(flags);
                buffer.WriteBigEndian((short)content.ID);
            }

            foreach (FSTEntry entry in children)
            {
                buffer.Write(entry.GetAsData());
            }

            return(buffer.GetBuffer());
        }