コード例 #1
0
        public bool GetInformation(IMediaImage imagePlugin, out List <Partition> partitions, ulong sectorOffset)
        {
            partitions = new List <Partition>();

            if (31 + sectorOffset >= imagePlugin.Info.Sectors)
            {
                return(false);
            }

            byte[] sector = imagePlugin.ReadSector(31 + sectorOffset);
            if (sector.Length < 512)
            {
                return(false);
            }

            IntPtr tablePtr = Marshal.AllocHGlobal(512);

            Marshal.Copy(sector, 0, tablePtr, 512);
            DECLabel table = (DECLabel)Marshal.PtrToStructure(tablePtr, typeof(DECLabel));

            Marshal.FreeHGlobal(tablePtr);

            if (table.pt_magic != PT_MAGIC || table.pt_valid != PT_VALID)
            {
                return(false);
            }

            ulong counter = 0;

            foreach (Partition part in table.pt_part.Select(entry => new Partition
            {
                Start = entry.pi_blkoff,
                Offset = (ulong)(entry.pi_blkoff * sector.Length),
                Size = (ulong)entry.pi_nblocks,
                Length = (ulong)(entry.pi_nblocks * sector.Length),
                Sequence = counter,
                Scheme = Name
            }).Where(part => part.Size > 0))
            {
                partitions.Add(part);
                counter++;
            }

            return(true);
        }
コード例 #2
0
        public bool GetInformation(IMediaImage imagePlugin, out List <Partition> partitions, ulong sectorOffset)
        {
            partitions = new List <Partition>();

            if (31 + sectorOffset >= imagePlugin.Info.Sectors)
            {
                return(false);
            }

            byte[] sector = imagePlugin.ReadSector(31 + sectorOffset);

            if (sector.Length < 512)
            {
                return(false);
            }

            DECLabel table = Marshal.ByteArrayToStructureLittleEndian <DECLabel>(sector);

            if (table.pt_magic != PT_MAGIC ||
                table.pt_valid != PT_VALID)
            {
                return(false);
            }

            ulong counter = 0;

            foreach (Partition part in table.pt_part.Select(entry => new Partition
            {
                Start = entry.pi_blkoff,
                Offset = (ulong)(entry.pi_blkoff * sector.Length),
                Size = (ulong)entry.pi_nblocks,
                Length = (ulong)(entry.pi_nblocks * sector.Length),
                Sequence = counter,
                Scheme = Name
            }).Where(part => part.Size > 0))
            {
                partitions.Add(part);
                counter++;
            }

            return(true);
        }