Beispiel #1
0
            public static VolumeDescriptor Create(Stream stream, byte index)
            {
                EndianReader reader = new EndianReader(stream, Endianness.BigEndian);

                for (int sector = 16; sector < 32; sector++)
                {
                    SeekSector(stream, sector);
                    byte id = reader.ReadByte();
                    if (Util.Encoding.GetString(reader.ReadBytes(6)) == "CD001\x01" && id == index)
                    {
                        SeekSector(stream, sector);
                        return(Create(stream));
                    }
                }

                return(null);
            }
Beispiel #2
0
            public static DirectoryEntry Create(EndianReader reader, bool unicode)
            {
                DirectoryEntry dir = new DirectoryEntry();

                byte entrysize = reader.ReadByte();

                if (entrysize == 0)                   // Will only happen if the entry we're reading won't fit in the current sector
                {
                    reader.Position = Util.RoundUp(reader.Position, SectorSize);
                    entrysize       = reader.ReadByte();
                }

                byte[]       data        = reader.ReadBytes(entrysize - 1);
                EndianReader entryreader = new EndianReader(new MemoryStream(data), Endianness.BigEndian);

                entryreader.Position = OffsetExtended - 1;
                dir.ExtendedSectors  = entryreader.ReadByte();
                entryreader.Position = OffsetSector - 1;
                dir.Sector           = entryreader.ReadUInt32();
                entryreader.Position = OffsetSize - 1;
                dir.Size             = entryreader.ReadUInt32();
                entryreader.Position = OffsetFlags - 1;
                dir.Flags            = entryreader.ReadByte();
                entryreader.Position = OffsetNameLen - 1;
                byte namelen = entryreader.ReadByte();

                dir.Name = (unicode ? Encoding.Unicode : Util.Encoding).GetString(entryreader.ReadBytes(namelen)).Trim('\0');

                if (dir.Name.Contains(';'))
                {
                    dir.Name = dir.Name.Split(';')[0];
                }

                if (dir.Name.Length > 0 && dir.Name[0] == '\x0001')
                {
                    return(null);
                }

                return(dir);
            }
Beispiel #3
0
            public static VolumeDescriptor Create(Stream stream)
            {
                VolumeDescriptor vd = new VolumeDescriptor();

                EndianReader reader = new EndianReader(stream, Endianness.BigEndian);

                vd.id = reader.ReadUInt64();
                reader.ReadBytes(vd.system_id);
                reader.ReadBytes(vd.volume_id);
                vd.zero            = reader.ReadUInt64();
                vd.total_sector_le = reader.ReadUInt32(Endianness.LittleEndian);
                vd.total_sect_be   = reader.ReadUInt32();
                reader.ReadBytes(vd.zero2);

                vd.volume_set_size   = reader.ReadUInt32();
                vd.volume_seq_nr     = reader.ReadUInt32();
                vd.sector_size_le    = reader.ReadUInt16(Endianness.LittleEndian);
                vd.sector_size_be    = reader.ReadUInt16();
                vd.path_table_len_le = reader.ReadUInt32(Endianness.LittleEndian);
                vd.path_table_len_be = reader.ReadUInt32();
                vd.path_table_le     = reader.ReadUInt32(Endianness.LittleEndian);
                vd.path_table_2nd_le = reader.ReadUInt32(Endianness.LittleEndian);
                vd.path_table_be     = reader.ReadUInt32();
                vd.path_table_2nd_be = reader.ReadUInt32();

                reader.ReadBytes(vd.root);
                reader.ReadBytes(vd.volume_set_id);
                reader.ReadBytes(vd.publisher_id);
                reader.ReadBytes(vd.data_preparer_id);
                reader.ReadBytes(vd.application_id);

                reader.ReadBytes(vd.copyright_file_id);
                reader.ReadBytes(vd.abstract_file_id);
                reader.ReadBytes(vd.bibliographical_file_id);

                return(vd);
            }
Beispiel #4
0
            public static PathTableEntry Create(Stream stream, bool unicode)
            {
                PathTableEntry entry      = new PathTableEntry();
                EndianReader   reader     = new EndianReader(stream, Endianness.BigEndian);
                byte           namelength = reader.ReadByte();

                entry.ExtendedSectors = reader.ReadByte();
                entry.Sector          = reader.ReadUInt32();
                entry.Parent          = reader.ReadUInt16();
                entry.Name            = (unicode ? Encoding.Unicode : Util.Encoding).GetString(reader.ReadBytes(namelength)).Trim('\0');
                if (namelength % 2 != 0)
                {
                    reader.ReadByte();
                }
                return(entry);
            }
Beispiel #5
0
        public static Mid Create(Stream stream)
        {
            EndianReader reader = new EndianReader(stream, Endianness.BigEndian);

            if (reader.ReadUInt32() != 0x4D546864)
            {
                return(null);
            }
            if (reader.ReadUInt32() != 6)
            {
                return(null);
            }

            Mid mid = new Mid();

            mid.Type = (MidiType)reader.ReadUInt16();
            ushort tracks   = reader.ReadUInt16();
            ushort division = reader.ReadUInt16();

            if ((division & 0x8000) == 0)
            {
                mid.Division = new TicksPerBeatDivision((ushort)(division & 0x7FFF));
            }
            else
            {
                mid.Division = new FramesPerSecondDivision()
                {
                    FramesPerSecond = (byte)((division & 0x7F00) >> 8),
                    TicksPerFrame   = (byte)(division & 0x00FF)
                }
            };
            for (int i = 0; i < tracks; i++)
            {
                Track track = new Track();
                if (reader.ReadUInt32() != 0x4D54726B)
                {
                    return(null);
                }
                uint size = reader.ReadUInt32();
                uint pos  = (uint)stream.Position;

                byte oldb = 0;
                while (stream.Position - pos < size)
                {
                    uint delta = (uint)Mid.ReadVariable(stream);
                    byte b     = reader.ReadByte();

                    if (b == 0xFF)                       // Meta Event
                    {
                        MetaEvent e = new MetaEvent();
                        e.DeltaTime = delta;
                        e.Type      = reader.ReadByte();

                        uint length = (uint)Mid.ReadVariable(stream);
                        e.Data = reader.ReadBytes((int)length);
                        track.Events.Add(e);
                        //if (e.Type == 0x2F) // End Track meta event
                        //break;
                    }
                    else if (b == 0xF0)
                    {
                        throw new NotImplementedException();
                    }
                    else if (b == 0xF7)
                    {
                        throw new NotImplementedException();
                    }
                    else                         // Channel Event
                    {
                        ChannelEvent e = new ChannelEvent();
                        e.DeltaTime = delta;

                        if ((b & 0x80) == 0)
                        {
                            e.Parameter1 = b;
                            b            = oldb;
                        }
                        else
                        {
                            oldb         = b;
                            e.Parameter1 = (byte)reader.ReadByte();
                        }

                        e.Type = (byte)(b >> 4);

                        e.Channel = (byte)(b & 0x0F);
                        if (e.Type != 0xC && e.Type != 0xD)
                        {
                            e.Parameter2 = (byte)reader.ReadByte();
                        }
                        track.Events.Add(e);
                    }
                }

                mid.Tracks.Add(track);
            }

            return(mid);
        }