Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DiskImageFile"/> class.
        /// </summary>
        /// <param name="stream">The stream to read.</param>
        /// <param name="ownsStream">Indicates if the new instance should control the lifetime of the stream.</param>
        public DiskImageFile(Stream stream, Ownership ownsStream)
        {
            this.udifHeader = new UdifResourceFile();
            this.stream     = stream ?? throw new ArgumentNullException(nameof(stream));
            this.ownsStream = ownsStream;

            if (stream.Length < this.udifHeader.Size)
            {
                throw new InvalidDataException("The file is not a valid DMG file: could not read the UDIF header.");
            }

            stream.Position = stream.Length - this.udifHeader.Size;
            byte[] data = StreamUtilities.ReadExact(stream, this.udifHeader.Size);

            this.udifHeader.ReadFrom(data, 0);

            if (!this.udifHeader.SignatureValid)
            {
                throw new InvalidDataException("The file is not a valid DMG file: could not read the UDIF header.");
            }

            stream.Position = (long)this.udifHeader.XmlOffset;
            byte[] xmlData = StreamUtilities.ReadExact(stream, (int)this.udifHeader.XmlLength);
            Dictionary <string, object> plist = (Dictionary <string, object>)XmlPropertyListParser.Parse(xmlData).ToObject();

            this.resources = ResourceFork.FromPlist(plist);
            this.Buffer    = new UdifBuffer(stream, this.resources, this.udifHeader.SectorCount);
        }
Exemple #2
0
        public UdifBuffer(Stream stream, ResourceFork resources, long sectorCount)
        {
            _stream      = stream;
            _resources   = resources;
            _sectorCount = sectorCount;

            Blocks = new List <CompressedBlock>();

            foreach (Resource resource in _resources.GetAllResources("blkx"))
            {
                Blocks.Add(((BlkxResource)resource).Block);
            }
        }
Exemple #3
0
        public UdifBuffer(Stream stream, ResourceFork resources, long sectorCount)
        {
            _stream = stream;
            _resources = resources;
            _sectorCount = sectorCount;

            _blocks = new List<CompressedBlock>();

            foreach (var resource in _resources.GetAllResources("blkx"))
            {
                _blocks.Add(((BlkxResource)resource).Block);
            }
        }
Exemple #4
0
        public UdifBuffer(Stream stream, ResourceFork resources, long sectorCount)
        {
            this.stream = stream ?? throw new ArgumentNullException(nameof(stream));
            this.resources = resources ?? throw new ArgumentNullException(nameof(resources));
            this.sectorCount = sectorCount;

            this.Blocks = new List<CompressedBlock>();

            foreach (Resource resource in this.resources.GetAllResources("blkx"))
            {
                this.Blocks.Add(((BlkxResource)resource).Block);
            }
        }
Exemple #5
0
        /// <summary>
        /// Initializes a new instance of the DiskImageFile class.
        /// </summary>
        /// <param name="stream">The stream to read</param>
        /// <param name="ownsStream">Indicates if the new instance should control the lifetime of the stream.</param>
        public DiskImageFile(Stream stream, Ownership ownsStream)
        {
            _udifHeader = new UdifResourceFile();
            _stream = stream;
            _ownsStream = ownsStream;

            stream.Position = stream.Length - _udifHeader.Size;
            byte[] data = Utilities.ReadFully(stream, _udifHeader.Size);

            _udifHeader.ReadFrom(data, 0);

            if (_udifHeader.SignatureValid)
            {
                stream.Position = (long)_udifHeader.XmlOffset;
                byte[] xmlData = Utilities.ReadFully(stream, (int)_udifHeader.XmlLength);
                var plist = Plist.Parse(new MemoryStream(xmlData));

                _resources = ResourceFork.FromPlist(plist);
                _buffer = new UdifBuffer(stream, _resources, _udifHeader.SectorCount);
            }
        }
        /// <summary>
        /// Initializes a new instance of the DiskImageFile class.
        /// </summary>
        /// <param name="stream">The stream to read.</param>
        /// <param name="ownsStream">Indicates if the new instance should control the lifetime of the stream.</param>
        public DiskImageFile(Stream stream, Ownership ownsStream)
        {
            _udifHeader = new UdifResourceFile();
            _stream     = stream;
            _ownsStream = ownsStream;

            stream.Position = stream.Length - _udifHeader.Size;
            byte[] data = StreamUtilities.ReadExact(stream, _udifHeader.Size);

            _udifHeader.ReadFrom(data, 0);

            if (_udifHeader.SignatureValid)
            {
                stream.Position = (long)_udifHeader.XmlOffset;
                byte[] xmlData = StreamUtilities.ReadExact(stream, (int)_udifHeader.XmlLength);
                Dictionary <string, object> plist = Plist.Parse(new MemoryStream(xmlData));

                _resources = ResourceFork.FromPlist(plist);
                Buffer     = new UdifBuffer(stream, _resources, _udifHeader.SectorCount);
            }
        }