()
| 131 | } |
| 132 | |
| 133 | public void StfsInit() |
| 134 | { |
| 135 | if (Position == 0) |
| 136 | Position = Stream.Position; |
| 137 | |
| 138 | // Read in XContent/PEC header if the volume descriptor isn't already set: |
| 139 | if (StfsVolumeDescriptor.DescriptorLength != 0x24) |
| 140 | { |
| 141 | Stream.Position = Position; |
| 142 | PecHeader = Stream.ReadStruct<PEC_HEADER>(); |
| 143 | PecHeader.EndianSwap(); |
| 144 | if (PecHeader.ConsoleSignature.IsStructureValid) |
| 145 | { |
| 146 | IsXContent = false; |
| 147 | IsConsoleSigned = true; |
| 148 | ConsoleSignature = PecHeader.ConsoleSignature; |
| 149 | StfsVolumeDescriptor = PecHeader.StfsVolumeDescriptor; |
| 150 | } |
| 151 | else |
| 152 | { |
| 153 | IsXContent = true; |
| 154 | Stream.Seek(0, SeekOrigin.Begin); |
| 155 | |
| 156 | Header = Stream.ReadStruct<XCONTENT_HEADER>(); |
| 157 | Header.EndianSwap(); |
| 158 | |
| 159 | if (Header.SignatureType != XCONTENT_HEADER.kSignatureTypeConBE && |
| 160 | Header.SignatureType != XCONTENT_HEADER.kSignatureTypeLiveBE && |
| 161 | Header.SignatureType != XCONTENT_HEADER.kSignatureTypePirsBE) |
| 162 | throw new FileSystemParseException("File has invalid header magic"); |
| 163 | |
| 164 | if (Header.SizeOfHeaders == 0) |
| 165 | throw new FileSystemParseException("Package doesn't contain STFS filesystem"); |
| 166 | |
| 167 | if (Header.SignatureType == XCONTENT_HEADER.kSignatureTypeConBE) |
| 168 | { |
| 169 | IsConsoleSigned = true; |
| 170 | ConsoleSignature = Header.ConsoleSignature; |
| 171 | } |
| 172 | |
| 173 | byte[] headerRaw = new byte[0x118]; |
| 174 | Stream.Position = 0x22C; |
| 175 | Stream.Read(headerRaw, 0, 0x118); |
| 176 | headerSha1 = Sha1.ComputeHash(headerRaw); |
| 177 | |
| 178 | var metadataEnd = (int)(Utility.RoundToPages(Header.SizeOfHeaders, kSectorSize) * kSectorSize); |
| 179 | |
| 180 | byte[] metadataRaw = new byte[metadataEnd - 0x344]; |
| 181 | Stream.Position = 0x344; |
| 182 | Stream.Read(metadataRaw, 0, metadataEnd - 0x344); |
| 183 | |
| 184 | contentIdValid = Sha1.ComputeHash(metadataRaw).BytesMatch(Header.ContentId); |
| 185 | |
| 186 | Stream.Position = 0x344; |
| 187 | Metadata = Stream.ReadStruct<XCONTENT_METADATA>(); |
| 188 | Metadata.EndianSwap(); |
| 189 | |
| 190 | if (Header.SizeOfHeaders > 0x971A) |
no test coverage detected