public Header(IStorage storage, KeySet keySet) { MainStorage = storage; MainHeader = MainStorage.Slice(0x100, 0x200); DuplexHeader = MainStorage.Slice(0x300, 0x44); DataIvfcHeader = MainStorage.Slice(0x344, 0xC0); JournalHeader = MainStorage.Slice(0x408, 0x200); SaveHeader = MainStorage.Slice(0x608, 0x48); MainRemapHeader = MainStorage.Slice(0x650, 0x40); MetaDataRemapHeader = MainStorage.Slice(0x690, 0x40); ExtraDataStorage = MainStorage.Slice(0x6D8, 0x400); FatIvfcHeader = MainStorage.Slice(0xAD8, 0xC0); Layout = new FsLayout(MainHeader); DuplexMasterBitmapA = MainStorage.Slice(Layout.DuplexMasterOffsetA, Layout.DuplexMasterSize); DuplexMasterBitmapB = MainStorage.Slice(Layout.DuplexMasterOffsetB, Layout.DuplexMasterSize); DataIvfcMaster = MainStorage.Slice(Layout.IvfcMasterHashOffsetA, Layout.IvfcMasterHashSize); FatIvfcMaster = MainStorage.Slice(Layout.FatIvfcMasterHashA, Layout.IvfcMasterHashSize); var reader = new BinaryReader(storage.AsStream()); reader.BaseStream.Position = 0; Data = reader.ReadBytes(0x4000); reader.BaseStream.Position = 0; Cmac = reader.ReadBytes(0x10); reader.BaseStream.Position = 0x100; reader.BaseStream.Position = 0x300; Duplex = new DuplexHeader(reader); reader.BaseStream.Position = 0x6D8; ExtraData = new ExtraData(reader); Ivfc = new IvfcHeader(DataIvfcHeader) { NumLevels = 5 }; if (Layout.Version >= 0x50000) { FatIvfc = new IvfcHeader(FatIvfcHeader) { NumLevels = 4 }; } MasterHash = storage.Slice(Layout.IvfcMasterHashOffsetA, Layout.IvfcMasterHashSize); Span <byte> actualHeaderHash = stackalloc byte[Sha256.DigestSize]; Sha256.GenerateSha256Hash(Data.AsSpan(0x300, 0x3d00), actualHeaderHash); HeaderHashValidity = Utilities.SpansEqual(Layout.Hash, actualHeaderHash) ? Validity.Valid : Validity.Invalid; SignatureValidity = ValidateSignature(keySet); }
public Header(IStorage storage, Keyset keyset) { MainStorage = storage; MainHeader = MainStorage.Slice(0x100, 0x200); DuplexHeader = MainStorage.Slice(0x300, 0x44); DataIvfcHeader = MainStorage.Slice(0x344, 0xC0); JournalHeader = MainStorage.Slice(0x408, 0x200); SaveHeader = MainStorage.Slice(0x608, 0x48); MainRemapHeader = MainStorage.Slice(0x650, 0x40); MetaDataRemapHeader = MainStorage.Slice(0x690, 0x40); ExtraDataStorage = MainStorage.Slice(0x6D8, 0x400); FatIvfcHeader = MainStorage.Slice(0xAD8, 0xC0); Layout = new FsLayout(MainHeader); DuplexMasterBitmapA = MainStorage.Slice(Layout.DuplexMasterOffsetA, Layout.DuplexMasterSize); DuplexMasterBitmapB = MainStorage.Slice(Layout.DuplexMasterOffsetB, Layout.DuplexMasterSize); DataIvfcMaster = MainStorage.Slice(Layout.IvfcMasterHashOffsetA, Layout.IvfcMasterHashSize); FatIvfcMaster = MainStorage.Slice(Layout.FatIvfcMasterHashA, Layout.IvfcMasterHashSize); var reader = new BinaryReader(storage.AsStream()); reader.BaseStream.Position = 0; Data = reader.ReadBytes(0x4000); reader.BaseStream.Position = 0; Cmac = reader.ReadBytes(0x10); reader.BaseStream.Position = 0x100; reader.BaseStream.Position = 0x300; Duplex = new DuplexHeader(reader); reader.BaseStream.Position = 0x6D8; ExtraData = new ExtraData(reader); Ivfc = new IvfcHeader(DataIvfcHeader) { NumLevels = 5 }; if (Layout.Version >= 0x50000) { FatIvfc = new IvfcHeader(FatIvfcHeader) { NumLevels = 4 }; } MasterHash = storage.Slice(Layout.IvfcMasterHashOffsetA, Layout.IvfcMasterHashSize); HeaderHashValidity = Crypto.CheckMemoryHashTable(Data, Layout.Hash, 0x300, 0x3d00); SignatureValidity = ValidateSignature(keyset); }