Пример #1
0
        void Initialize()
        {
            int hddNumber        = ...;
            int partitionAddress = ...;

            string hardDriveName = "\\\\.\\PHYSICALDRIVE" + hddNumber;

            diskFile       = new UnmanagedFile(hardDriveName);
            bytesPerSector = GetBytesPerSector();
            bitsPerSector  = GetBitsNumber(bytesPerSector);
            diskFile.MovePointer(partitionAddress << bitsPerSector,
                                 partitionAddress >> (32 - bitsPerSector));

            byte[] fatInfo = diskFile.ReadFile(bytesPerSector);
            fatCopiesNumber       = fatInfo.AsWord(16);
            fatSize               = fatInfo.AsWord(22);
            reservedAreaSize      = fatInfo.AsWord(14);
            sectorsPerCluster     = fatInfo.AsByte(13);
            fatAddress            = reservedAreaSize;
            rootDirectoryEntities = fatInfo.AsWord(17);
            rootDirectorySector   = reservedAreaSize + (fatCopiesNumber * fatSize);

            bytesPerCluster = bytesPerSector * sectorsPerCluster;
            fatContentSize  = (uint)(fatSize * bytesPerSector);
            fatContent      = LoadFatContent();

            contents = LoadCurrentDirectoryObjects().ToList();
        }
Пример #2
0
        public HardDriveInfo(int hddNumber)
        {
            _number              = hddNumber;
            _sectorSize          = 0;
            _extendedAreaAddress = 0;
            string hardDriveName = "\\\\.\\PHYSICALDRIVE" + hddNumber;

            try
            {
                _handle = new UnmanagedFile(hardDriveName);
                byte[] mbr = ReadMbr();
                if (mbr.AsWord(0x01fe) != 0xAA55)
                {
                    throw new ErrorException("Partition is broken or not valid.");
                }

                var partitions = GetHddPartitions(mbr);
                if (_extendedAreaAddress != 0)
                {
                    int ext = _extendedAreaAddress;
                    _extendedAreaAddress = 0;

                    while (true)
                    {
                        int nextMbrAddress = ext + _extendedAreaAddress;

                        _handle.MovePointer(nextMbrAddress << _bitsPerSector, nextMbrAddress >> (32 - _bitsPerSector));
                        mbr = ReadMbr();
                        if (mbr.AsWord(0x01fe) != 0xAA55)
                        {
                            throw new ErrorException("Partition is broken or not valid.");
                        }

                        partitions.Concat(GetHddPartitions(mbr, nextMbrAddress));

                        if (_extendedAreaAddress == 0)
                        {
                            break;
                        }
                    }
                }

                Partitions = partitions;
            }
            catch (System.IO.FileNotFoundException)
            {
                Partitions = null;
            }
        }
Пример #3
0
        private byte[] GetDiskSn(int absoluteAddress, int id)
        {
            _handle.MovePointer(absoluteAddress << _bitsPerSector,
                                absoluteAddress >> (32 - _bitsPerSector));

            byte[] buffer = ReadMbr();

            switch (id)
            {
            case 0x07:
            {
                return(Enumerable.Range(72, 8).
                       Select(i => buffer.AsByte(i)).
                       ToArray());
            }

            case 0x0e:
            case 0x0c:
            case 0x0b:
            {
                return(Enumerable.Range(67, 4).
                       Select(i => buffer.AsByte(i)).
                       ToArray());
            }

            case 0x01:
            case 0x04:
            case 0x06:
            case 0x0d:
            {
                return(Enumerable.Range(39, 4).
                       Select(i => buffer.AsByte(i)).
                       ToArray());
            }

            default:
            {
                return(null);
            }
            }
        }
Пример #4
0
        byte[] LoadFatContent()
        {
            diskFile.MovePointer(fatAddress << bitsPerSector);

            return(diskFile.ReadFile(fatContentSize));
        }
Пример #5
0
        void Initialize()
        {
            int hddNumber = ...;
            int partitionAddress = ...;

            string hardDriveName = "\\\\.\\PHYSICALDRIVE" + hddNumber;
            diskFile = new UnmanagedFile(hardDriveName);
            bytesPerSector = GetBytesPerSector();
            bitsPerSector = GetBitsNumber(bytesPerSector);
            diskFile.MovePointer(partitionAddress << bitsPerSector,
                                 partitionAddress >> (32 - bitsPerSector));

            byte[] fatInfo = diskFile.ReadFile(bytesPerSector);
            fatCopiesNumber = fatInfo.AsWord(16);
            fatSize = fatInfo.AsWord(22);
            reservedAreaSize = fatInfo.AsWord(14);
            sectorsPerCluster = fatInfo.AsByte(13);
            fatAddress = reservedAreaSize;
            rootDirectoryEntities = fatInfo.AsWord(17);
            rootDirectorySector = reservedAreaSize + (fatCopiesNumber * fatSize);

            bytesPerCluster = bytesPerSector * sectorsPerCluster;
            fatContentSize = (uint)(fatSize * bytesPerSector);
            fatContent = LoadFatContent();

            contents = LoadCurrentDirectoryObjects().ToList();
        }