private void ParseIvfcHeader(FileStream fs, long offset) { this.MagicBytes = ParseFile.ReadUintBE(fs, offset); // verify magic bytes if (this.MagicBytes != 0x49564643) { throw new FormatException(String.Format("IVFC bytes not found.")); } this.VersionNumber = ParseFile.ReadUintLE(fs, offset + 0x04); this.MasterHashSize = ParseFile.ReadUintLE(fs, offset + 0x08); this.Level1Offset = ParseFile.ReadUlongLE(fs, offset + 0x0C); this.Level1HashDataSize = ParseFile.ReadUlongLE(fs, offset + 0x14); this.Level1BlockSize = ParseFile.ReadUintLE(fs, offset + 0x1C); this.Reserved01 = ParseFile.ReadUintLE(fs, offset + 0x20); this.Level2Offset = ParseFile.ReadUlongLE(fs, offset + 0x24); this.Level2HashDataSize = ParseFile.ReadUlongLE(fs, offset + 0x2C); this.Level2BlockSize = ParseFile.ReadUintLE(fs, offset + 0x34); this.Reserved02 = ParseFile.ReadUintLE(fs, offset + 0x38); this.Level3Offset = ParseFile.ReadUlongLE(fs, offset + 0x3C); this.Level3HashDataSize = ParseFile.ReadUlongLE(fs, offset + 0x44); this.Level3BlockSize = ParseFile.ReadUintLE(fs, offset + 0x4C); this.Reserved03 = ParseFile.ReadUintLE(fs, offset + 0x50); this.Reserved04 = ParseFile.ReadUintLE(fs, offset + 0x54); this.OptionalInfoSize = ParseFile.ReadUintLE(fs, offset + 0x58); }
private void BuildRomFsFile(FileStream isoStream, long ivfcOffset, long fileEntryOffset, long fileBlockOffset, long romFsDataOffset) { RomFsFileEntry file = new RomFsFileEntry(); // Nintendo3dsCtrFile tempFile; byte[] nameBytes; // load dir file.ParentDirOffset = ParseFile.ReadUintLE(isoStream, ivfcOffset + fileBlockOffset + fileEntryOffset); file.SiblingOffset = ParseFile.ReadInt32LE(isoStream, ivfcOffset + fileBlockOffset + fileEntryOffset + 4); file.DataOffset = ParseFile.ReadUlongLE(isoStream, ivfcOffset + fileBlockOffset + fileEntryOffset + 8); file.DataSize = ParseFile.ReadUlongLE(isoStream, ivfcOffset + fileBlockOffset + fileEntryOffset + 0x10); file.WeirdOffset = ParseFile.ReadUintLE(isoStream, ivfcOffset + fileBlockOffset + fileEntryOffset + 0x18); file.NameSize = ParseFile.ReadUintLE(isoStream, ivfcOffset + fileBlockOffset + fileEntryOffset + 0x1C); // build directory name if (file.NameSize > 0) { nameBytes = ParseFile.ParseSimpleOffset(isoStream, ivfcOffset + fileBlockOffset + fileEntryOffset + 0x20, (int)file.NameSize); file.Name = ByteConversion.GetUtf16LeText(nameBytes); } else // this is root { file.Name = "NO_NAME_FOUND"; // @TODO Make this a constant } this.FileName = file.Name; this.Offset = ivfcOffset + romFsDataOffset + (long)file.DataOffset; this.Size = (long)file.DataSize; // get sibling this.SiblingOffset = file.SiblingOffset; }
public void Initialize(FileStream isoStream, long offset, bool isRawDump) { this.VolumeBaseOffset = offset; this.IsRawDump = isRawDump; this.VolumeType = VolumeDataType.Data; this.DirectoryStructureArray = new ArrayList(); this.FormatDescription = MicrosoftExFatFileSystem.FORMAT_DESCRIPTION_STRING; this.JumpBoot = ParseFile.ReadUint24LE(isoStream, this.VolumeBaseOffset + 0); this.MagicBytes = ParseFile.ParseSimpleOffset(isoStream, this.VolumeBaseOffset + 3, 8); this.ZeroChunk = ParseFile.ParseSimpleOffset(isoStream, this.VolumeBaseOffset + 11, 53); this.PartitionOffset = ParseFile.ReadUlongLE(isoStream, this.VolumeBaseOffset + 64); this.VolumeLength = ParseFile.ReadUlongLE(isoStream, this.VolumeBaseOffset + 72); this.FatOffset = ParseFile.ReadUintLE(isoStream, this.VolumeBaseOffset + 80); this.FatLength = ParseFile.ReadUintLE(isoStream, this.VolumeBaseOffset + 84); this.ClusterHeapOffset = ParseFile.ReadUintLE(isoStream, this.VolumeBaseOffset + 88); this.ClusterCount = ParseFile.ReadUintLE(isoStream, this.VolumeBaseOffset + 92); this.RootDirectoryFirstCluster = ParseFile.ReadUintLE(isoStream, this.VolumeBaseOffset + 96); this.VolumeSerialNumber = ParseFile.ReadUintLE(isoStream, this.VolumeBaseOffset + 100); this.VolumeIdentifier = this.VolumeSerialNumber.ToString("X2"); this.FileSystemRevision = ParseFile.ReadUshortLE(isoStream, this.VolumeBaseOffset + 104); this.VolumeFlags = ParseFile.ReadUshortLE(isoStream, this.VolumeBaseOffset + 106); this.BytesPerSector = ParseFile.ReadByte(isoStream, this.VolumeBaseOffset + 108); this.SectorsPerCluster = ParseFile.ReadByte(isoStream, this.VolumeBaseOffset + 109); this.NumberOfFats = ParseFile.ReadByte(isoStream, this.VolumeBaseOffset + 110); // caclulate helper values this.SectorSizeInBytes = (uint)(1 << this.BytesPerSector); this.ClusterSizeInBytes = (uint)(1 << (this.SectorsPerCluster + this.BytesPerSector)); this.VolumeLengthInBytes = this.VolumeLength * this.SectorSizeInBytes; this.FatAbsoluteOffset = (ulong)this.VolumeBaseOffset + (this.FatOffset * this.SectorSizeInBytes); this.FatLengthInBytes = this.FatLength * this.SectorSizeInBytes; this.ClusterHeapAbsoluteOffset = (ulong)this.VolumeBaseOffset + (this.ClusterHeapOffset * this.SectorSizeInBytes); this.RootDirectoryAbsoluteOffset = MicrosoftExFatFileSystem.GetOffsetForClusterId(this.ClusterHeapAbsoluteOffset, this.ClusterSizeInBytes, this.RootDirectoryFirstCluster); // this.ClusterHeapAbsoluteOffset + ((this.RootDirectoryFirstCluster - MicrosoftExFatFileSystem.CLUSTER_CORRECTION_OFFSET) * this.ClusterSizeInBytes); if (this.FileSystemRevision == MicrosoftExFatFileSystem.EXFAT_VERSION_0100) { // initialize FAT this.InitializeAndValidateFat(isoStream); // process root directory entry this.GetVolumeLabel(isoStream); // load directories this.LoadDirectories(isoStream); } else { MessageBox.Show(String.Format("Unsupported exFAT version: {0}", this.FileSystemRevision.ToString("X8"))); } }
public MicrosoftExFatRootDirStreamExtensionEntry(byte[] streamExtensionEntry) { this.EntryType = streamExtensionEntry[0]; this.GeneralSecondaryFlags = streamExtensionEntry[1]; this.Reserved1 = streamExtensionEntry[2]; this.NameLength = streamExtensionEntry[3]; this.NameHash = ParseFile.ReadUshortLE(streamExtensionEntry, 4); this.Reserved2 = ParseFile.ReadUshortLE(streamExtensionEntry, 6); this.ValidDataLength = ParseFile.ReadUlongLE(streamExtensionEntry, 8); this.Reserved3 = ParseFile.ReadUintLE(streamExtensionEntry, 0x10); this.FirstCluster = ParseFile.ReadUintLE(streamExtensionEntry, 0x14); this.DataLength = ParseFile.ReadUlongLE(streamExtensionEntry, 0x18); }
private void ParseNcsdHeader(FileStream fs, long offset) { // parse NCSD header this.NcsdHash = ParseFile.ParseSimpleOffset(fs, offset, 0x100); this.MagicBytes = ParseFile.ReadUintBE(fs, offset + 0x100); this.ImageSize = ParseFile.ReadUintLE(fs, offset + 0x104); this.MediaId = ParseFile.ReadUlongLE(fs, offset + 0x108); this.PartitionsFsType = ParseFile.ReadUlongLE(fs, offset + 0x110); this.PartitionsEncryptionType = ParseFile.ReadUlongLE(fs, offset + 0x118); this.NcchOffsetInfo = new SimpleOffset[8]; for (int i = 0; i < 8; i++) { this.NcchOffsetInfo[i] = new SimpleOffset( ParseFile.ReadUintLE(fs, offset + 0x120 + (8 * i)), ParseFile.ReadUintLE(fs, offset + 0x120 + ((8 * i) + 4))); } // parse Exheader this.ExHeaderHash = ParseFile.ParseSimpleOffset(fs, offset + 0x160, 0x20); this.AdditionalHeaderSize = ParseFile.ReadUintLE(fs, offset + 0x180); this.SectorZeroOffset = ParseFile.ReadUintLE(fs, offset + 0x184); this.PartitionFlags = ParseFile.ReadUlongLE(fs, offset + 0x188); this.PartitionIds = new ulong[8]; for (int i = 0; i < 8; i++) { this.PartitionIds[i] = ParseFile.ReadUlongLE(fs, offset + 0x190 + (8 * i)); } this.Reserved01 = ParseFile.ParseSimpleOffset(fs, offset + 0x1D0, 0x20); this.Reserved02 = ParseFile.ParseSimpleOffset(fs, offset + 0x1F0, 0xE); this.Unknown01 = ParseFile.ReadByte(fs, 0x1FE); this.Unknown02 = ParseFile.ReadByte(fs, 0x1FF); // parse Card Info this.CardInfoWritableAddress = ParseFile.ReadInt32LE(fs, offset + 0x200); this.CardInfoBitmask = ParseFile.ReadUintLE(fs, offset + 0x204); this.CardInfoReserved01 = ParseFile.ParseSimpleOffset(fs, offset + 0x208, 0xDF8); this.CardInfoMediaId = ParseFile.ReadUlongLE(fs, offset + 0x1000); this.CardInfoReserved02 = ParseFile.ReadUlongLE(fs, offset + 0x1008); this.CardInfoInitialData = ParseFile.ParseSimpleOffset(fs, offset + 0x1010, 0x30); this.CardInfoReserved03 = ParseFile.ParseSimpleOffset(fs, offset + 0x1040, 0xC0); this.CardInfoNcchHeaderCopy = ParseFile.ParseSimpleOffset(fs, offset + 0x1011, 0x100); }
private void ParseNcchHeader(FileStream fs, long offset) { this.NcsdHash = ParseFile.ParseSimpleOffset(fs, offset, 0x100); this.MagicBytes = ParseFile.ReadUintBE(fs, offset + 0x100); this.ContentSize = ParseFile.ReadUintLE(fs, offset + 0x104); this.PartitionId = ParseFile.ReadUlongLE(fs, offset + 0x108); this.MakerCode = ParseFile.ReadUshortLE(fs, offset + 0x110); this.Version = ParseFile.ReadUshortLE(fs, offset + 0x112); this.Reserved01 = ParseFile.ReadUintLE(fs, offset + 0x114); this.ProgramId = ParseFile.ReadUlongLE(fs, offset + 0x118); this.Reserved02 = ParseFile.ParseSimpleOffset(fs, offset + 0x120, 0x10); this.LogoRegionHash = ParseFile.ParseSimpleOffset(fs, offset + 0x130, 0x20); this.ProductCode = ParseFile.ReadAsciiString(fs, offset + 0x150); this.ExtendedHeaderHash = ParseFile.ParseSimpleOffset(fs, offset + 0x160, 0x10); this.ExtendedHeaderSize = ParseFile.ReadUintLE(fs, offset + 0x180); this.Reserved03 = ParseFile.ReadUintLE(fs, offset + 0x184); this.Flags = ParseFile.ReadUlongLE(fs, offset + 0x188); this.PlainRegionOffset = ParseFile.ReadUintLE(fs, offset + 0x190); this.PlainRegionSize = ParseFile.ReadUintLE(fs, offset + 0x194); this.LogoRegionOffset = ParseFile.ReadUintLE(fs, offset + 0x198); this.LogoRegionSize = ParseFile.ReadUintLE(fs, offset + 0x19C); this.ExeFsOffset = ParseFile.ReadUintLE(fs, offset + 0x1A0); this.ExeFsSize = ParseFile.ReadUintLE(fs, offset + 0x1A4); this.ExeFsHashSize = ParseFile.ReadUintLE(fs, offset + 0x1A8); this.Reserved04 = ParseFile.ReadUintLE(fs, offset + 0x1AC); this.RomFsOffset = ParseFile.ReadUintLE(fs, offset + 0x1B0); this.RomFsSize = ParseFile.ReadUintLE(fs, offset + 0x1B4); this.RomFsHashSize = ParseFile.ReadUintLE(fs, offset + 0x1B8); this.Reserved05 = ParseFile.ReadUintLE(fs, offset + 0x1BC); this.ExeSuperblockHash = ParseFile.ParseSimpleOffset(fs, offset + 0x1C0, 0x20); this.RomFsSuperblockHash = ParseFile.ParseSimpleOffset(fs, offset + 0x1E0, 0x20); }