Ejemplo n.º 1
0
        public MBRScan(string physicalDriveName)
        {
            const uint SectorSize = 512;

            byte[] buff = new byte[512];
            uint   nBytesRead;


            // Create handle to physical drive
            SafeFileHandle shFile = WinApi.CreateFile(physicalDriveName, FileAccess.Read, FileShare.Read, (IntPtr)0, FileMode.Open, 0, (IntPtr)0);

            if (shFile.IsInvalid)
            {
                throw new DriveNotFoundException(physicalDriveName + " not found");
            }


            // - - - - - - - - - - - - main MBR - - - - - - - - - - - - - - - - - - - -
            WinApi.ReadFile(shFile, buff, SectorSize, out nBytesRead, (IntPtr)0);
            Mbr = new MBR(buff);
            // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ~mainMBR
            shFile.Close();
            //add to Sections primary sections
            for (int sectionNumber = 0; sectionNumber < 4; sectionNumber++)
            {
                if (Mbr[sectionNumber].Type == 0xF || Mbr[sectionNumber].Type == 0x5)
                {
                    ulong baseAddr = Mbr[sectionNumber].getFirstSector();
                    EbrScan(physicalDriveName, baseAddr, 0);
                }
                else
                {
                    Sections.Add(Mbr[sectionNumber]);
                }
            }
        }// ~public MBRScan( string physicalDriveName )-----------------------------------------