Example #1
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);
            }
Example #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);
            }
Example #3
0
        public Iso9660(Stream stream)
        {
            VolumeDescriptor volume  = VolumeDescriptor.Create(stream, 2);
            bool             unicode = false;

            if (volume == null)
            {
                volume = VolumeDescriptor.Create(stream, 1);
            }
            else
            {
                unicode = true;
            }

            if (volume == null)
            {
                throw new FormatException();
            }

            MemoryStream rootmem    = new MemoryStream(volume.root);
            EndianReader rootreader = new EndianReader(rootmem, Endianness.BigEndian);
            //List<PathTableEntry> entries = new List<PathTableEntry>();
            PathTableEntry root = new PathTableEntry();

            rootreader.Position  = OffsetExtended;
            root.ExtendedSectors = rootreader.ReadByte();
            rootreader.Position  = OffsetSector;
            root.Sector          = rootreader.ReadUInt32();
            root.Name            = "";

            /*
             * entries.Add(root);
             *
             * uint pathtable = volume.path_table_be;
             * uint pathtablelen = volume.path_table_len_be;
             * SeekSector(stream, pathtable);
             * stream.Position += PathTableEntrySize + 2;
             *
             * for (ushort i = 1; i < 0xFFFF && stream.Position < (pathtable * SectorSize + pathtablelen); i++) {
             *      PathTableEntry entry = PathTableEntry.Create(stream, unicode);
             *      PathTableEntry parent = entries[entry.Parent - 1];
             *      parent.Children.Add(entry);
             *
             *      entries.Add(entry);
             * }
             */
            Root = Stat(new EndianReader(stream, Endianness.BigEndian), root, unicode);
        }
Example #4
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);
            }
Example #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);
        }