Ejemplo n.º 1
0
        internal GuidPartitionTable(byte[] bytes)
        {
            #region Header

            GuidPartitionTableHeader GPTHeader = new GuidPartitionTableHeader(Helper.GetSubArray(bytes, 0x00, SECTOR_SIZE));
            Revision                 = GPTHeader.Revision;
            HeaderSize               = GPTHeader.HeaderSize;
            MyLBA                    = GPTHeader.MyLBA;
            AlternateLBA             = GPTHeader.AlternateLBA;
            FirstUsableLBA           = GPTHeader.FirstUsableLBA;
            LastUsableLBA            = GPTHeader.LastUsableLBA;
            DiskGuid                 = GPTHeader.DiskGUID;
            PartitionEntryLBA        = GPTHeader.PartitionEntryLBA;
            NumberOfPartitionEntries = GPTHeader.NumberOfPartitionEntries;
            SizeOfPartitionEntry     = GPTHeader.SizeOfPartitionEntry;

            #endregion Header

            // Get PartitionTable
            List <GuidPartitionTableEntry> partitionList = new List <GuidPartitionTableEntry>();

            for (int i = 0; i < (bytes.Length - SECTOR_SIZE); i += (int)GPTHeader.SizeOfPartitionEntry)
            {
                // Instantiate a GuidPartitionTableEntry object
                GuidPartitionTableEntry entry = new GuidPartitionTableEntry(Helper.GetSubArray(bytes, (i + SECTOR_SIZE), (int)GPTHeader.SizeOfPartitionEntry));
                // If entry's PartitionTypeGUID is 00000000-0000-0000-0000-000000000000 then it is not a partition
                if (entry.PartitionTypeGuid == new Guid("00000000-0000-0000-0000-000000000000"))
                {
                    break;
                }
                partitionList.Add(entry);
            }

            PartitionTable = partitionList.ToArray();
        }
Ejemplo n.º 2
0
        internal GuidPartitionTable(byte[] bytes)
        {
            #region Header

            GuidPartitionTableHeader GPTHeader = new GuidPartitionTableHeader(Helper.GetSubArray(bytes, 0x00, SECTOR_SIZE));
            Revision = GPTHeader.Revision;
            HeaderSize = GPTHeader.HeaderSize;
            MyLBA = GPTHeader.MyLBA;
            AlternateLBA = GPTHeader.AlternateLBA;
            FirstUsableLBA = GPTHeader.FirstUsableLBA;
            LastUsableLBA = GPTHeader.LastUsableLBA;
            DiskGuid = GPTHeader.DiskGUID;
            PartitionEntryLBA = GPTHeader.PartitionEntryLBA;
            NumberOfPartitionEntries = GPTHeader.NumberOfPartitionEntries;
            SizeOfPartitionEntry = GPTHeader.SizeOfPartitionEntry;

            #endregion Header

            // Get PartitionTable
            List<GuidPartitionTableEntry> partitionList = new List<GuidPartitionTableEntry>();

            for (int i = 0; i < (bytes.Length - SECTOR_SIZE); i += (int)GPTHeader.SizeOfPartitionEntry)
            {
                // Instantiate a GuidPartitionTableEntry object
                GuidPartitionTableEntry entry = new GuidPartitionTableEntry(Helper.GetSubArray(bytes, (i + SECTOR_SIZE), (int)GPTHeader.SizeOfPartitionEntry));
                // If entry's PartitionTypeGUID is 00000000-0000-0000-0000-000000000000 then it is not a partition
                if (entry.PartitionTypeGuid == new Guid("00000000-0000-0000-0000-000000000000"))
                {
                    break;
                }
                partitionList.Add(entry);
            }

            PartitionTable = partitionList.ToArray();
        }
Ejemplo n.º 3
0
        internal GuidPartitionTable(string devicePath)
        {
            MasterBootRecord mbr = MasterBootRecord.Get(devicePath);

            if (mbr.PartitionTable[0].SystemId == "EFI_GPT_DISK")
            {
                using (FileStream streamToRead = Helper.getFileStream(devicePath))
                {
                    // Get Header
                    GuidPartitionTableHeader GPTHeader = new GuidPartitionTableHeader(Helper.readDrive(streamToRead, GPT_OFFSET, SECTOR_SIZE));
                    Revision                 = GPTHeader.Revision;
                    HeaderSize               = GPTHeader.HeaderSize;
                    MyLBA                    = GPTHeader.MyLBA;
                    AlternateLBA             = GPTHeader.AlternateLBA;
                    FirstUsableLBA           = GPTHeader.FirstUsableLBA;
                    LastUsableLBA            = GPTHeader.LastUsableLBA;
                    DiskGuid                 = GPTHeader.DiskGUID;
                    PartitionEntryLBA        = GPTHeader.PartitionEntryLBA;
                    NumberOfPartitionEntries = GPTHeader.NumberOfPartitionEntries;
                    SizeOfPartitionEntry     = GPTHeader.SizeOfPartitionEntry;

                    // Get PartitionTable
                    List <GuidPartitionTableEntry> partitionList = new List <GuidPartitionTableEntry>();

                    bool Continue = true;

                    // Iterate through sectors that contain the GPT Entry Array
                    for (ulong j = GPTHeader.PartitionEntryLBA; (j < GPTHeader.PartitionEntryLBA + (GPTHeader.NumberOfPartitionEntries / (SECTOR_SIZE / GPTHeader.SizeOfPartitionEntry))); j++)
                    {
                        // Read one sector
                        byte[] partitionSectorBytes = Helper.readDrive(streamToRead, (SECTOR_SIZE * (long)j), SECTOR_SIZE);

                        // Iterate through Partition Entries in Sector
                        // Sectors (512 bytes) / Partitions (128 bytes) = 4 partitions per sector
                        for (int i = 0; i < 512; i += (int)GPTHeader.SizeOfPartitionEntry)
                        {
                            // Instantiate a GuidPartitionTableEntry object
                            GuidPartitionTableEntry entry = new GuidPartitionTableEntry(Helper.GetSubArray(partitionSectorBytes, i, (int)GPTHeader.SizeOfPartitionEntry));

                            // If entry's PartitionTypeGUID is 00000000-0000-0000-0000-000000000000 then it is not a partition
                            if (entry.PartitionTypeGuid == new Guid("00000000-0000-0000-0000-000000000000"))
                            {
                                Continue = false;
                                break;
                            }
                            partitionList.Add(entry);
                        }

                        if (!Continue)
                        {
                            break;
                        }
                    }

                    PartitionTable = partitionList.ToArray();
                }
            }
            else
            {
                throw new Exception("No GPT found. Please use Get-MBR cmdlet");
            }
        }
Ejemplo n.º 4
0
        internal GuidPartitionTable(string devicePath)
        {
            MasterBootRecord mbr = MasterBootRecord.Get(devicePath);
            if (mbr.PartitionTable[0].SystemId == "EFI_GPT_DISK")
            {
                using (FileStream streamToRead = Helper.getFileStream(devicePath))
                {
                    // Get Header
                    GuidPartitionTableHeader GPTHeader = new GuidPartitionTableHeader(Helper.readDrive(streamToRead, GPT_OFFSET, SECTOR_SIZE));
                    Revision = GPTHeader.Revision;
                    HeaderSize = GPTHeader.HeaderSize;
                    MyLBA = GPTHeader.MyLBA;
                    AlternateLBA = GPTHeader.AlternateLBA;
                    FirstUsableLBA = GPTHeader.FirstUsableLBA;
                    LastUsableLBA = GPTHeader.LastUsableLBA;
                    DiskGuid = GPTHeader.DiskGUID;
                    PartitionEntryLBA = GPTHeader.PartitionEntryLBA;
                    NumberOfPartitionEntries = GPTHeader.NumberOfPartitionEntries;
                    SizeOfPartitionEntry = GPTHeader.SizeOfPartitionEntry;

                    // Get PartitionTable
                    List<GuidPartitionTableEntry> partitionList = new List<GuidPartitionTableEntry>();

                    bool Continue = true;

                    // Iterate through sectors that contain the GPT Entry Array
                    for(ulong j = GPTHeader.PartitionEntryLBA; (j < GPTHeader.PartitionEntryLBA + (GPTHeader.NumberOfPartitionEntries / (SECTOR_SIZE / GPTHeader.SizeOfPartitionEntry))); j++)
                    {
                        // Read one sector
                        byte[] partitionSectorBytes = Helper.readDrive(streamToRead, (SECTOR_SIZE * (long)j), SECTOR_SIZE);

                        // Iterate through Partition Entries in Sector
                        // Sectors (512 bytes) / Partitions (128 bytes) = 4 partitions per sector
                        for (int i = 0; i < 512; i += (int)GPTHeader.SizeOfPartitionEntry)
                        {
                            // Instantiate a GuidPartitionTableEntry object
                            GuidPartitionTableEntry entry = new GuidPartitionTableEntry(Helper.GetSubArray(partitionSectorBytes, i, (int)GPTHeader.SizeOfPartitionEntry));

                            // If entry's PartitionTypeGUID is 00000000-0000-0000-0000-000000000000 then it is not a partition
                            if (entry.PartitionTypeGuid == new Guid("00000000-0000-0000-0000-000000000000"))
                            {
                                Continue = false;
                                break;
                            }
                            partitionList.Add(entry);
                        }

                        if (!Continue)
                        {
                            break;
                        }
                    }

                    PartitionTable = partitionList.ToArray();

                }
            }
            else
            {
                throw new Exception("No GPT found. Please use Get-MBR cmdlet");
            }
        }