Exemplo n.º 1
0
        public virtual void LoadDirectories(FileStream isoStream)
        {
            // change name of top level folder
            this.DirectoryRecordForRootDirectory.FileIdentifierString = String.Empty;

            // get first path record
            byte[] rootDirPathBytes = CdRom.GetSectorByLba(isoStream, this.VolumeBaseOffset, this.LocationOfOccurrenceOfTypeMPathTable, this.IsRawDump, this.LogicalBlockSize);
            rootDirPathBytes = CdRom.GetDataChunkFromSector(rootDirPathBytes, this.IsRawDump);

            // grab the directory record
            uint rootDirectoryOffset = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(rootDirPathBytes, 2, 4));

            byte[] rootDirDirectorySector = CdRom.GetSectorByLba(isoStream, this.VolumeBaseOffset, rootDirectoryOffset, this.IsRawDump, this.LogicalBlockSize);
            rootDirDirectorySector = CdRom.GetDataChunkFromSector(rootDirDirectorySector, this.IsRawDump);

            byte rootDirectoryRecordSize = rootDirDirectorySector[0];

            byte[] rootDirectoryRecord = ParseFile.ParseSimpleOffset(rootDirDirectorySector, 0, rootDirectoryRecordSize);
            this.DirectoryRecordForRootDirectory = new GreenBookCdiDirectoryRecord(rootDirectoryRecord);

            // populate this volume's directory structure
            GreenBookCdiDirectoryStructure rootDirectory =
                new GreenBookCdiDirectoryStructure(isoStream, isoStream.Name,
                                                   this.VolumeBaseOffset, this.DirectoryRecordForRootDirectory,
                                                   this.LogicalBlockSize, this.IsRawDump, this.SectorSize, null);

            this.DirectoryStructureArray.Add(rootDirectory);
        }
Exemplo n.º 2
0
        public void Initialize(FileStream isoStream, long offset, bool isRawDump)
        {
            byte[] rootSector;

            this.VolumeBaseOffset        = offset;
            this.FormatDescription       = Panasonic3do.FORMAT_DESCRIPTION_STRING;
            this.VolumeType              = VolumeDataType.Data;
            this.IsRawDump               = isRawDump;
            this.DirectoryStructureArray = new ArrayList();

            rootSector = CdRom.GetSectorByLba(isoStream, this.VolumeBaseOffset, 0, this.IsRawDump, (int)Panasonic3do.SECTOR_SIZE);
            rootSector = CdRom.GetDataChunkFromSector(rootSector, this.IsRawDump);

            this.RootDirectoryCount = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(rootSector, 0x60, 4)) + 1;
            this.RootDirectoryLbas  = new uint[this.RootDirectoryCount];

            for (uint i = 0; i < this.RootDirectoryCount; i++)
            {
                this.RootDirectoryLbas[i] =
                    ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(rootSector, (int)(0x64 + (i * 4)), 4));
            }

            this.LoadDirectories(isoStream);
        }
Exemplo n.º 3
0
        private void parseDirectoryRecord(
            FileStream isoStream,
            DateTime creationDateTime,
            long baseOffset,
            long directoryLba,
            uint logicalBlockSize,
            string parentDirectory,
            bool isRaw,
            int nonRawSectorSize)
        {
            uint recordSize;

            byte[] directorySector;
            byte[] directoryRecordBytes;
            uint   directoryRecordLength;
            uint   bytesRead;
            uint   currentOffset;
            long   currentLba = directoryLba;

            Panasonic3doDirectoryRecord    tempDirectoryRecord;
            Panasonic3doDirectoryStructure tempDirectory;
            Panasonic3doFileStructure      tempFile;

            // get the first sector
            directorySector       = CdRom.GetSectorByLba(isoStream, baseOffset, currentLba, isRaw, nonRawSectorSize);
            directorySector       = CdRom.GetDataChunkFromSector(directorySector, isRaw);
            directoryRecordLength = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(directorySector, 0xC, 4));

            bytesRead     = 0x14;
            currentOffset = 0x14;

            while (bytesRead < directoryRecordLength)
            {
                recordSize           = 0x48 + (4 * ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(directorySector, (int)(currentOffset + 0x40), 4)));
                directoryRecordBytes = ParseFile.ParseSimpleOffset(directorySector, (int)currentOffset, (int)recordSize);
                tempDirectoryRecord  = new Panasonic3doDirectoryRecord(directoryRecordBytes);

                if (tempDirectoryRecord.DirectoryItemTypeBytes[3] == 0x07)
                {
                    //for (uint i = 0; i < tempDirectoryRecord.SubDirectoryCount; i++)
                    //{
                    tempDirectory =
                        new Panasonic3doDirectoryStructure(isoStream, isoStream.Name,
                                                           creationDateTime, baseOffset, tempDirectoryRecord.SubDirectoryLbas[0],
                                                           logicalBlockSize, tempDirectoryRecord.DirectoryItemName,
                                                           parentDirectory, isRaw, nonRawSectorSize);
                    this.SubDirectoryArray.Add(tempDirectory);
                    //}
                }
                else
                {
                    tempFile = new Panasonic3doFileStructure(parentDirectory,
                                                             this.SourceFilePath, tempDirectoryRecord.DirectoryItemName,
                                                             baseOffset, tempDirectoryRecord.SubDirectoryLbas[0],
                                                             tempDirectoryRecord.DirectoryItemSize, isRaw, nonRawSectorSize,
                                                             creationDateTime);

                    this.FileArray.Add(tempFile);
                }

                if (tempDirectoryRecord.DirectoryItemTypeBytes[0] == 0xC0)
                {
                    break;
                }
                else if (tempDirectoryRecord.DirectoryItemTypeBytes[0] == 0x40)
                {
                    directorySector       = CdRom.GetSectorByLba(isoStream, baseOffset, ++currentLba, isRaw, nonRawSectorSize);
                    directorySector       = CdRom.GetDataChunkFromSector(directorySector, isRaw);
                    directoryRecordLength = ByteConversion.GetUInt32BigEndian(ParseFile.ParseSimpleOffset(directorySector, 0xC, 4));

                    bytesRead     = 0x14;
                    currentOffset = 0x14;
                }
                else
                {
                    bytesRead     += recordSize;
                    currentOffset += recordSize;
                }
            }
        }
Exemplo n.º 4
0
        private void parseDirectoryRecord(FileStream isoStream, long baseOffset,
                                          GreenBookCdiDirectoryRecord directoryRecord, uint logicalBlockSize,
                                          bool isRaw, int nonRawSectorSize, string parentDirectory)
        {
            byte recordSize;
            int  currentOffset;
            uint bytesRead  = 0;
            uint currentLba = directoryRecord.LocationOfExtent;

            byte[] directoryRecordBytes;
            GreenBookCdiDirectoryRecord    tempDirectoryRecord;
            GreenBookCdiDirectoryStructure tempDirectory;
            GreenBookCdiFileStructure      tempFile;

            byte[] directorySector = CdRom.GetSectorByLba(isoStream, baseOffset, currentLba, isRaw, nonRawSectorSize);
            directorySector = CdRom.GetDataChunkFromSector(directorySector, isRaw);

            currentOffset = 0;

            while (bytesRead < directoryRecord.DataLength)
            {
                recordSize = ParseFile.ParseSimpleOffset(directorySector, currentOffset, 1)[0];

                if (recordSize > 0)
                {
                    directoryRecordBytes = ParseFile.ParseSimpleOffset(directorySector, currentOffset, recordSize);
                    tempDirectoryRecord  = new GreenBookCdiDirectoryRecord(directoryRecordBytes);

                    if (!tempDirectoryRecord.FileIdentifierString.Equals(".") &&
                        !tempDirectoryRecord.FileIdentifierString.Equals("..")) // skip "this" directory
                    {
                        //if (tempDirectoryRecord.FlagMultiExtent)
                        //{
                        //    int x = 1;
                        //}

                        if (tempDirectoryRecord.FlagDirectory)
                        {
                            tempDirectory = new GreenBookCdiDirectoryStructure(isoStream, isoStream.Name, baseOffset, tempDirectoryRecord, logicalBlockSize, isRaw, nonRawSectorSize, parentDirectory);
                            this.SubDirectoryArray.Add(tempDirectory);
                        }
                        else
                        {
                            tempFile = new GreenBookCdiFileStructure(parentDirectory,
                                                                     this.SourceFilePath,
                                                                     tempDirectoryRecord.FileIdentifierString.Replace(";1", String.Empty),
                                                                     baseOffset,
                                                                     tempDirectoryRecord.LocationOfExtent,
                                                                     tempDirectoryRecord.DataLength,
                                                                     isRaw,
                                                                     nonRawSectorSize,
                                                                     tempDirectoryRecord.RecordingDateAndTime);
                            this.FileArray.Add(tempFile);
                        }
                    }
                    else if (tempDirectoryRecord.FileIdentifierString.Equals(".."))
                    {
                        this.ParentDirectoryRecord = tempDirectoryRecord;
                    }

                    bytesRead     += recordSize;
                    currentOffset += recordSize;
                }
                else if ((directoryRecord.DataLength - bytesRead) > (directorySector.Length - currentOffset))
                {
                    // move to start of next sector
                    directorySector = CdRom.GetSectorByLba(isoStream, baseOffset, ++currentLba, isRaw, nonRawSectorSize);
                    directorySector = CdRom.GetDataChunkFromSector(directorySector, isRaw);
                    bytesRead      += (uint)(logicalBlockSize - currentOffset);
                    currentOffset   = 0;
                }
                else
                {
                    break;
                }
            }
        }
Exemplo n.º 5
0
        private void parseDirectoryRecord(InitializeStruct dirInitStruct)
        {
            byte recordSize;
            int  currentOffset;
            uint bytesRead  = 0;
            uint currentLba = dirInitStruct.DirectoryRecord.LocationOfExtent;

            byte[] directoryRecordBytes;
            Iso9660DirectoryRecord    tempDirectoryRecord;
            Iso9660DirectoryStructure tempDirectory;

            Iso9660DirectoryStructure.InitializeStruct newDirInitStruct;

            Iso9660FileStructure tempFile;

            Iso9660FileStructure.InitializeStruct fileInitStruct = new Iso9660FileStructure.InitializeStruct();

            byte[] directorySector = CdRom.GetSectorByLba(dirInitStruct.IsoStream, dirInitStruct.BaseOffset, currentLba, dirInitStruct.IsRaw, dirInitStruct.NonRawSectorSize);
            directorySector = CdRom.GetDataChunkFromSector(directorySector, dirInitStruct.IsRaw);

            currentOffset = 0;

            while (bytesRead < dirInitStruct.DirectoryRecord.DataLength)
            {
                recordSize = ParseFile.ParseSimpleOffset(directorySector, currentOffset, 1)[0];

                if (recordSize > 0)
                {
                    try
                    {
                        directoryRecordBytes = ParseFile.ParseSimpleOffset(directorySector, currentOffset, recordSize);
                        tempDirectoryRecord  = new Iso9660DirectoryRecord(directoryRecordBytes, dirInitStruct.VolumeContainsXaData);

                        if (!tempDirectoryRecord.FileIdentifierString.Equals(".") &&
                            !tempDirectoryRecord.FileIdentifierString.Equals("..")) // skip "this" directory
                        {
                            if (tempDirectoryRecord.FlagDirectory)
                            {
                                newDirInitStruct = dirInitStruct;
                                newDirInitStruct.DirectoryRecord = tempDirectoryRecord;

                                tempDirectory = new Iso9660DirectoryStructure(newDirInitStruct);
                                this.SubDirectoryArray.Add(tempDirectory);
                            }
                            else
                            {
                                fileInitStruct.ParentDirectoryName = dirInitStruct.ParentDirectory;
                                fileInitStruct.SourceFilePath      = this.SourceFilePath;
                                fileInitStruct.FileName            = tempDirectoryRecord.FileIdentifierString.Replace(";1", String.Empty);
                                fileInitStruct.VolumeBaseOffset    = dirInitStruct.BaseOffset;
                                fileInitStruct.Lba              = tempDirectoryRecord.LocationOfExtent;
                                fileInitStruct.Size             = tempDirectoryRecord.DataLength;
                                fileInitStruct.IsRaw            = dirInitStruct.IsRaw;
                                fileInitStruct.NonRawSectorSize = dirInitStruct.NonRawSectorSize;
                                fileInitStruct.FileMode         = tempDirectoryRecord.ItemMode;
                                fileInitStruct.FileTime         = tempDirectoryRecord.RecordingDateAndTime;

                                tempFile = new Iso9660FileStructure(fileInitStruct);
                                this.FileArray.Add(tempFile);
                            }
                        }
                        else if (tempDirectoryRecord.FileIdentifierString.Equals(".."))
                        {
                            this.ParentDirectoryRecord = tempDirectoryRecord;
                        }

                        bytesRead     += recordSize;
                        currentOffset += recordSize;
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(String.Format("Error parsing directory structure at offset: {0}, {1}", currentOffset, ex.Message));
                    }
                }
                else if ((dirInitStruct.DirectoryRecord.DataLength - bytesRead) > (directorySector.Length - currentOffset))
                {
                    // move to start of next sector
                    directorySector = CdRom.GetSectorByLba(dirInitStruct.IsoStream, dirInitStruct.BaseOffset, ++currentLba, dirInitStruct.IsRaw, dirInitStruct.NonRawSectorSize);
                    directorySector = CdRom.GetDataChunkFromSector(directorySector, dirInitStruct.IsRaw);
                    bytesRead      += (uint)(dirInitStruct.LogicalBlockSize - currentOffset);
                    currentOffset   = 0;
                }
                else
                {
                    break;
                }
            }
        }