当前位置: 首页>>代码示例>>C#>>正文


C# BinaryFormat.GetByte方法代码示例

本文整理汇总了C#中Mosa.ClassLib.BinaryFormat.GetByte方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryFormat.GetByte方法的具体用法?C# BinaryFormat.GetByte怎么用?C# BinaryFormat.GetByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mosa.ClassLib.BinaryFormat的用法示例。


在下文中一共展示了BinaryFormat.GetByte方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Read

        /// <summary>
        /// Reads the master boot block.
        /// </summary>
        /// <returns></returns>
        public bool Read()
        {
            valid = false;

            MasterBootBlock mbr = new MasterBootBlock(diskDevice);

            if (!mbr.Valid)
                return false;

            if ((mbr.Partitions[0].PartitionType != PartitionType.GPT) ||
                (mbr.Partitions[1].PartitionType != PartitionType.Empty) ||
                (mbr.Partitions[2].PartitionType != PartitionType.Empty) ||
                (mbr.Partitions[3].PartitionType != PartitionType.Empty) ||
                (!mbr.Partitions[0].Bootable) || (mbr.Partitions[0].StartLBA != 1))
                return false;

            BinaryFormat gpt = new BinaryFormat(diskDevice.ReadBlock(1, 1));

            if ((gpt.GetByte(0) != 45) && (gpt.GetByte(1) != 46) && (gpt.GetByte(2) != 49) && (gpt.GetByte(3) != 20) &&
                (gpt.GetByte(4) != 50) && (gpt.GetByte(5) != 41) && (gpt.GetByte(6) != 52) && (gpt.GetByte(7) != 54))
                return false;

            if ((gpt.GetUInt(GPT.Revision) != GPTConstant.SupportedRevision) ||
                (gpt.GetUInt(GPT.HeaderSize) != GPTConstant.HeaderSize) ||
                (gpt.GetUInt(GPT.Reserved) != 0) ||
                (gpt.GetUInt(GPT.PartitionStartingLBA) != 2)
                )
                return false;

            valid = true;

            return valid;
        }
开发者ID:pacificIT,项目名称:MOSA-Project,代码行数:37,代码来源:GUIDPartitionTable.cs

示例2: Compare

        /// <summary>
        /// Compares the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public bool Compare(byte[] data, uint offset, FatType type)
        {
            BinaryFormat entry = new BinaryFormat(data);

            byte first = entry.GetByte(Entry.DOSName + offset);

            if (first == FileNameAttribute.LastEntry)
                return false;

            if ((first == FileNameAttribute.Deleted) | (first == FileNameAttribute.Dot))
                return false;

            if (first == FileNameAttribute.Escape)
                return false;

            FatFileAttributes attribute = (FatFileAttributes)entry.GetByte(Entry.FileAttributes + offset);

            if ((attribute & FatFileAttributes.VolumeLabel) == FatFileAttributes.VolumeLabel)
                return true;

            return false;
        }
开发者ID:pacificIT,项目名称:MOSA-Project,代码行数:29,代码来源:Volume.cs

示例3: Compare

        /// <summary>
        /// Compares the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public bool Compare(byte[] data, uint offset, FatType type)
        {
            BinaryFormat entry = new BinaryFormat(data);

            byte first = entry.GetByte(offset + Entry.DOSName);

            if (first == FileNameAttribute.LastEntry)
                return true;

            if ((first == FileNameAttribute.Deleted) | (first == FileNameAttribute.Dot))
                return true;

            return false;
        }
开发者ID:rtownsend,项目名称:MOSA-Project,代码行数:21,代码来源:Empty.cs

示例4: Compare

        /// <summary>
        /// Compares the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public bool Compare(byte[] data, uint offset, FatType type)
        {
            BinaryFormat entry = new BinaryFormat(data);

            byte first = entry.GetByte(offset + Entry.DOSName);

            if (first == FileNameAttribute.LastEntry)
                return false;

            if ((first == FileNameAttribute.Deleted) | (first == FileNameAttribute.Dot))
                return false;

            if (first == FileNameAttribute.Escape)
                return false;

            uint startcluster = FatFileSystem.GetClusterEntry(data, offset, type);

            if (startcluster == cluster)
                return true;

            return false;
        }
开发者ID:rtownsend,项目名称:MOSA-Project,代码行数:29,代码来源:ByCluster.cs

示例5: Compare

        /// <summary>
        /// Compares the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public bool Compare(byte[] data, uint offset, FatType type)
        {
            var entry = new BinaryFormat(data);

            byte first = entry.GetByte(offset + Entry.DOSName);

            if (first == FileNameAttribute.LastEntry)
                return false;

            if ((first == FileNameAttribute.Deleted) | (first == FileNameAttribute.Dot))
                return false;

            if (first == FileNameAttribute.Escape)
                return false;

            string entryname = FatFileSystem.ExtractFileName(data, offset);

            if (entryname == name)
                return true;

            return false;
        }
开发者ID:Zahovay,项目名称:MOSA-Project,代码行数:29,代码来源:WithName.cs

示例6: FindEntry

        /// <summary>
        /// Finds the entry.
        /// </summary>
        /// <param name="compare">The compare.</param>
        /// <param name="startCluster">The start cluster.</param>
        /// <returns></returns>
        public FatFileLocation FindEntry(FatFileSystem.ICompare compare, uint startCluster)
        {
            uint activeSector = startCluster * sectorsPerCluster;

            if (startCluster == 0)
                activeSector = (fatType == FatType.FAT32) ? GetSectorByCluster(rootCluster32) : firstRootDirectorySector;

            uint increment = 0;

            for (;;)
            {
                BinaryFormat directory = new BinaryFormat(partition.ReadBlock(activeSector, 1));

                for (uint index = 0; index < entriesPerSector; index++)
                {
                    if (compare.Compare(directory.Data, index * 32, fatType))
                    {
                        FatFileAttributes attribute = (FatFileAttributes)directory.GetByte((index * Entry.EntrySize) + Entry.FileAttributes);
                        return new FatFileLocation(GetClusterEntry(directory.Data, index, fatType), activeSector, index, (attribute & FatFileAttributes.SubDirectory) != 0);
                    }

                    if (directory.GetByte(Entry.DOSName + (index * Entry.EntrySize)) == FileNameAttribute.LastEntry)
                        return new FatFileLocation();
                }

                ++increment;

                if ((startCluster == 0) && (fatType != FatType.FAT32))
                {
                    // FAT12/16 Root directory
                    if (increment >= rootDirSectors)
                        return new FatFileLocation();

                    activeSector = startCluster + increment;
                    continue;
                }
                else
                {
                    // subdirectory
                    if (increment < sectorsPerCluster)
                    {
                        // still within cluster
                        activeSector = startCluster + increment;
                        continue;
                    }

                    // exiting cluster

                    // goto next cluster (if any)
                    uint cluster = GetClusterBySector(startCluster);

                    if (cluster == 0)
                        return new FatFileLocation();

                    uint nextCluster = GetClusterEntryValue(cluster);

                    if ((IsClusterLast(nextCluster)) || (IsClusterBad(nextCluster)) || (IsClusterFree(nextCluster)) || (IsClusterReserved(nextCluster)))
                        return new FatFileLocation();

                    activeSector = (uint)(dataAreaStart + (nextCluster - 1 * sectorsPerCluster));

                    continue;
                }
            }
        }
开发者ID:pacificIT,项目名称:MOSA-Project,代码行数:71,代码来源:FatFileSystem.cs

示例7: ExtractFileName

        /// <summary>
        /// Extracts the name of the file.
        /// </summary>
        /// <param name="directory">The directory.</param>
        /// <param name="index">The index.</param>
        /// <returns></returns>
        public static string ExtractFileName(byte[] directory, uint index)
        {
            // rewrite to use string
            BinaryFormat entry = new BinaryFormat(directory);

            char[] name = new char[12];

            for (uint i = 0; i < 8; i++)
                name[i] = (char)entry.GetByte(index + i + Entry.DOSName);

            int len = 8;

            for (int i = 7; i > 0; i--)
                if (name[i] == ' ')
                    len--;
                else
                    break;

            // special case where real character is same as the delete
            if ((len >= 1) && (name[0] == (char)FileNameAttribute.Escape))
                name[0] = (char)FileNameAttribute.Deleted;

            name[len] = '.';

            len++;

            for (uint i = 0; i < 3; i++)
                name[len + i] = (char)entry.GetByte(index + i + Entry.DOSExtension);

            len = len + 3;

            int spaces = 0;
            for (int i = len - 1; i >= 0; i--)
                if (name[i] == ' ')
                    spaces++;
                else
                    break;

            if (spaces == 3)
                spaces = 4;

            len = len - spaces;

            // FIXME
            string str = string.Empty;

            for (uint i = 0; i < len; i++)
                str = str + (char)name[i];

            return str;
        }
开发者ID:pacificIT,项目名称:MOSA-Project,代码行数:57,代码来源:FatFileSystem.cs

示例8: ReadBootSector

        /// <summary>
        /// Reads the boot sector.
        /// </summary>
        /// <returns></returns>
        protected bool ReadBootSector()
        {
            valid = false;

            if (blockSize != 512)   // only going to work with 512 sector sizes (for now)
                return false;

            BinaryFormat bootSector = new BinaryFormat(partition.ReadBlock(0, 1));

            if (bootSector.GetUShort(BootSector.BootSectorSignature) != 0xAA55)
                return false;

            byte extendedBootSignature = bootSector.GetByte(BootSector.ExtendedBootSignature);
            byte extendedBootSignature32 = bootSector.GetByte(BootSector.FAT32_ExtendedBootSignature);

            if ((extendedBootSignature != 0x29) && (extendedBootSignature != 0x28) && (extendedBootSignature32 != 0x29))
                return false;

            volumeLabel = bootSector.GetString(BootSector.VolumeLabel, 8).ToString().TrimEnd();
            bytesPerSector = bootSector.GetUShort(BootSector.BytesPerSector);
            sectorsPerCluster = bootSector.GetByte(BootSector.SectorsPerCluster);
            reservedSectors = bootSector.GetByte(BootSector.ReservedSectors);
            nbrFats = bootSector.GetByte(BootSector.FatAllocationTables);
            rootEntries = bootSector.GetUShort(BootSector.MaxRootDirEntries);
            rootCluster32 = bootSector.GetUInt(BootSector.FAT32_ClusterNumberOfRoot);

            uint sectorsPerFat16 = bootSector.GetUShort(BootSector.SectorsPerFAT);
            uint sectorsPerFat32 = bootSector.GetUInt(BootSector.FAT32_SectorPerFAT);
            uint totalSectors16 = bootSector.GetUShort(BootSector.TotalSectors16);
            uint totalSectors32 = bootSector.GetUInt(BootSector.TotalSectors32);
            uint sectorsPerFat = (sectorsPerFat16 != 0) ? sectorsPerFat16 : sectorsPerFat32;
            uint fatSectors = 0;

            try
            {
                fatSectors = nbrFats * sectorsPerFat;
                clusterSizeInBytes = sectorsPerCluster * blockSize;
                rootDirSectors = (((rootEntries * 32) + (bytesPerSector - 1)) / bytesPerSector);
                firstDataSector = reservedSectors + (nbrFats * sectorsPerFat) + rootDirSectors;
                totalSectors = (totalSectors16 != 0) ? totalSectors16 : totalSectors32;
                dataSectors = totalSectors - (reservedSectors + (nbrFats * sectorsPerFat) + rootDirSectors);
                totalClusters = dataSectors / sectorsPerCluster;
                entriesPerSector = (bytesPerSector / 32);
                firstRootDirectorySector = reservedSectors + fatSectors;
                dataAreaStart = firstRootDirectorySector + rootDirSectors;
            }
            catch
            {
                return false;
            }

            // Some basic checks
            if ((nbrFats == 0) || (nbrFats > 2) || (totalSectors == 0) || (sectorsPerFat == 0))
                return false;

            if (totalClusters < 4085)
                fatType = FatType.FAT12;
            else if (totalClusters < 65525)
                fatType = FatType.FAT16;
            else
                fatType = FatType.FAT32;

            if (fatType == FatType.FAT12)
            {
                reservedClusterMark = 0xFF0;
                endOfClusterMark = 0x0FF8;
                badClusterMark = 0x0FF7;
                fatMask = 0xFFFFFFFF;
                fatEntries = sectorsPerFat * 3 * blockSize / 2;
            }
            else if (fatType == FatType.FAT16)
            {
                reservedClusterMark = 0xFFF0;
                endOfClusterMark = 0xFFF8;
                badClusterMark = 0xFFF7;
                fatMask = 0xFFFFFFFF;
                fatEntries = sectorsPerFat * blockSize / 2;
            }
            else
            { //  if (type == FatType.FAT32) {
                reservedClusterMark = 0xFFF0;
                endOfClusterMark = 0x0FFFFFF8;
                badClusterMark = 0x0FFFFFF7;
                fatMask = 0x0FFFFFFF;
                fatEntries = sectorsPerFat * blockSize / 4;
            }

            // More basic checks
            if ((fatType == FatType.FAT32) && (rootCluster32 == 0))
                return false;

            valid = true;

            serialNbr = bootSector.GetBytes(fatType != FatType.FAT32 ? BootSector.IDSerialNumber : BootSector.FAT32_IDSerialNumber, 4);

            return true;
//.........这里部分代码省略.........
开发者ID:pacificIT,项目名称:MOSA-Project,代码行数:101,代码来源:FatFileSystem.cs

示例9: Read

        /// <summary>
        /// Reads the master boot block.
        /// </summary>
        /// <returns></returns>
        public bool Read()
        {
            valid = false;

            if (diskDevice.BlockSize != 512) return false;  // only going to work with 512 sector sizes
            if (diskDevice.TotalBlocks < 3) return false;

            BinaryFormat masterboot = new BinaryFormat(diskDevice.ReadBlock(0, 1));

            if (masterboot.GetUShort(MBR.MBRSignature) != MBRConstant.MBRSignature)
                return false;

            valid = true;

            diskSignature = masterboot.GetUInt(MBR.DiskSignature);

            for (uint index = 0; index < MaxMBRPartitions; index++) {
                uint offset = MBR.FirstPartition + (index * MBRConstant.PartitionSize);

                GenericPartition partition = new GenericPartition(index);

                partition.Bootable = masterboot.GetByte(offset + PartitionRecord.Status) == MBRConstant.Bootable;
                partition.PartitionType = masterboot.GetByte(offset + PartitionRecord.PartitionType);
                partition.StartLBA = masterboot.GetUInt(offset + PartitionRecord.LBA);
                partition.TotalBlocks = masterboot.GetUInt(offset + PartitionRecord.Sectors);

                Partitions[index] = partition;
            }

            //TODO: Extended Partitions

            code = new byte[MBRConstant.CodeAreaSize];
            for (uint index = 0; index < MBRConstant.CodeAreaSize; index++)
                code[index] = masterboot.GetByte(index);

            return valid;
        }
开发者ID:hj1980,项目名称:Mosa,代码行数:41,代码来源:MasterBootBlock.cs


注:本文中的Mosa.ClassLib.BinaryFormat.GetByte方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。