Esempio n. 1
0
        public Package1(Keyset keyset, Stream stream)
        {
            StreamSource = new SharedStreamSource(stream);
            var reader = new BinaryReader(stream);

            BuildHash = reader.ReadBytes(0x10);
            BuildDate = reader.ReadAscii(0xE);
            Field1E   = reader.ReadUInt16();

            reader.BaseStream.Position = 0x3FE0;
            Pk11Size = reader.ReadInt32();

            reader.BaseStream.Position += 0xC;
            Counter = reader.ReadBytes(0x10);

            // Try decrypting the PK11 blob with all known package1 keys
            Stream encStream = StreamSource.CreateStream(0x4000, Pk11Size);
            var    decBuffer = new byte[0x10];

            for (int i = 0; i < 0x20; i++)
            {
                var dec = new Aes128CtrStream(encStream, keyset.Package1Keys[i], Counter);
                dec.Read(decBuffer, 0, 0x10);

                if (BitConverter.ToUInt32(decBuffer, 0) == Pk11Magic)
                {
                    KeyRevision = i;

                    dec.Position = 0;
                    Pk11         = new Pk11(new RandomAccessSectorStream(dec));

                    return;
                }
            }

            throw new InvalidDataException("Failed to decrypt PK11! Is the correct key present?");
        }
Esempio n. 2
0
        public Package1(KeySet keySet, IStorage storage)
        {
            Storage = storage;
            var reader = new BinaryReader(storage.AsStream());

            BuildHash = reader.ReadBytes(0x10);
            BuildDate = reader.ReadAscii(0xE);
            Field1E   = reader.ReadUInt16();

            reader.BaseStream.Position = 0x3FE0;
            Pk11Size = reader.ReadInt32();

            reader.BaseStream.Position += 0xC;
            Counter = reader.ReadBytes(0x10);

            // Try decrypting the PK11 blob with all known package1 keys
            IStorage encStorage = Storage.Slice(0x4000, Pk11Size);

            byte[] decBuffer = new byte[0x10];

            for (int i = 0; i < 0x20; i++)
            {
                var dec = new Aes128CtrStorage(encStorage, keySet.Package1Keys[i].DataRo.ToArray(), Counter, true);
                dec.Read(0, decBuffer).ThrowIfFailure();

                if (BitConverter.ToUInt32(decBuffer, 0) == Pk11Magic)
                {
                    KeyRevision = i;

                    Pk11 = new Pk11(new CachedStorage(dec, 4, true));

                    return;
                }
            }

            throw new InvalidDataException("Failed to decrypt PK11! Is the correct key present?");
        }
Esempio n. 3
0
        public IStorage OpenDecryptedPackage()
        {
            IStorage[] storages = { OpenPackage1Ldr(), Pk11.OpenDecryptedPk11() };

            return(new ConcatenationStorage(storages, true));
        }