Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the PartitionMap class.
        /// </summary>
        /// <param name="stream">Stream containing the contents of a disk.</param>
        public PartitionMap(Stream stream)
        {
            _stream = stream;

            stream.Position = 0;
            byte[] initialBytes = Utilities.ReadFully(stream, 1024);

            BlockZero b0 = new BlockZero();
            b0.ReadFrom(initialBytes, 0);

            PartitionMapEntry initialPart = new PartitionMapEntry(_stream);
            initialPart.ReadFrom(initialBytes, 512);

            byte[] partTableData = Utilities.ReadFully(stream, (int)(initialPart.MapEntries - 1) * 512);

            _partitions = new PartitionMapEntry[initialPart.MapEntries - 1];
            for (uint i = 0; i < initialPart.MapEntries - 1; ++i)
            {
                _partitions[i] = new PartitionMapEntry(_stream);
                _partitions[i].ReadFrom(partTableData, (int)(512 * i));
            }
        }
        public override bool DetectIsPartitioned(Stream s)
        {
            if (s.Length < 1024)
            {
                return false;
            }

            s.Position = 0;

            byte[] initialBytes = Utilities.ReadFully(s, 1024);

            BlockZero b0 = new BlockZero();
            b0.ReadFrom(initialBytes, 0);
            if (b0.Signature != 0x4552)
            {
                return false;
            }

            PartitionMapEntry initialPart = new PartitionMapEntry(s);
            initialPart.ReadFrom(initialBytes, 512);

            return initialPart.Signature == 0x504d;
        }