예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="devicePath"></param>
        /// <returns></returns>
        public static byte[] GetBytes(string devicePath)
        {
            MasterBootRecord mbr = MasterBootRecord.Get(devicePath);

            List <byte> byteList = new List <byte>();

            if (mbr.PartitionTable[0].SystemId == "EFI_GPT_DISK")
            {
                using (FileStream streamToRead = Helper.getFileStream(devicePath))
                {
                    byte[] headerBytes = Helper.readDrive(streamToRead, GPT_OFFSET, SECTOR_SIZE);

                    long partitionTableOffset = BitConverter.ToInt64(headerBytes, 0x48);
                    uint partitionCount       = BitConverter.ToUInt32(headerBytes, 0x50);
                    uint partitionSize        = BitConverter.ToUInt32(headerBytes, 0x54);

                    long partitionBufferSize = partitionCount * partitionSize;

                    if (!((partitionBufferSize % 512) == 0))
                    {
                        partitionBufferSize = partitionBufferSize + (SECTOR_SIZE - (partitionBufferSize % SECTOR_SIZE));
                    }

                    byte[] partitionBytes = Helper.readDrive(streamToRead, partitionTableOffset * SECTOR_SIZE, partitionBufferSize);

                    byteList.AddRange(headerBytes);
                    byteList.AddRange(partitionBytes);
                }

                return(byteList.ToArray());
            }
            else
            {
                throw new Exception("No GPT found. Please use Get-MBR cmdlet");
            }
        }
예제 #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="drivePath"></param>
 /// <returns></returns>
 public static MasterBootRecord Get(string drivePath)
 {
     // Read Master Boot Record (first 512 bytes) from disk
     return(new MasterBootRecord(MasterBootRecord.GetBytes(drivePath), drivePath));
 }