private void ReadCvmRootDirs() { mRootDirectories = new List <CvmDirectoryInfo>(); // find start of dir lists Console.WriteLine("Scanning for cvm directory lists in executable..."); int dirListStart = FindCvmRootDirsStart(); if (dirListStart == -1) { throw new InvalidDataException("No #DirLst# signature found in executable. Bad file."); } Console.WriteLine("Reading executable cvm directory lists..."); // Read header bytes mExecutableHeader = new byte[dirListStart]; mExecutableStream.Position = 0; mExecutableStream.Read(mExecutableHeader, 0, mExecutableHeader.Length); // Read dir entries mExecutableStream.Position = dirListStart; using (var reader = new BinaryReader(mExecutableStream, Encoding.Default, true)) { int rootDirectoryCount = 3; if (mGame == Game.Persona4) { rootDirectoryCount = 4; } for (int i = 0; i < rootDirectoryCount; i++) { var directory = new CvmDirectoryInfo(null); directory.Read(reader); mRootDirectories.Add(directory); } } // Read footer bytes mExecutableFooter = new byte[mExecutableStream.Length - mExecutableStream.Position]; mExecutableStream.Read(mExecutableFooter, 0, mExecutableFooter.Length); }
public void Read(BinaryReader reader) { #if DEBUG long start = reader.BaseStream.Position; #endif // 0x00 - 0x02 int entryCount = reader.ReadInt32(); // 0x04 - 0x08 int entryCountAux = reader.ReadInt32(); Debug.Assert(entryCount == entryCountAux, "entryCount != entryCountAux"); // 0x08 - 0x0C DirectoryLBA = reader.ReadInt32(); // 0x0C - 0x14 string tag = string.Empty; for (int i = 0; i < 8; ++i) { var b = reader.ReadByte(); if (b != 0) { tag += ( char )b; } } Debug.Assert(tag.Equals(TAG)); // 0x14 - 0x16 Debug.Assert(reader.ReadUInt16() == 0); #if DEBUG Debug.Assert((reader.BaseStream.Position - start) == 22); #endif // Read children Entries.Capacity = entryCount; for (int i = 0; i < entryCount; i++) { var entry = new CvmFileSystemEntry(this); entry.Read(reader); Entries.Add(entry); } reader.BaseStream.Position = (reader.BaseStream.Position + 15) & ~(15); for (int i = 1; i < entryCount; i++) { var entry = Entries[i]; if (entry.Flags.HasFlag(CvmFileSystemEntryFlags.DirectoryRecord)) { var directory = new CvmDirectoryInfo(entry); directory.Read(reader); entry.DirectoryInfo = directory; } } }
public CvmFileSystemEntry(CvmDirectoryInfo parent) { Parent = parent; }