/// <summary>
        /// 读取数据
        /// </summary>
        /// <param name="dirverHandle"></param>
        /// <param name="newTechnologyFileSystem"></param>
        /// <param name="buffer"></param>
        /// <returns></returns>
        public IEnumerable <byte[]> ReadData(Microsoft.Win32.SafeHandles.SafeFileHandle dirverHandle, NewTechnologyFileSystem newTechnologyFileSystem, byte[] buffer = null)
        {
            int bytePerCluster = (int)newTechnologyFileSystem.BytePerCluster;

            foreach (ClusterStream clusterStream in ClusterStreams)
            {
                if (!Kernel32.SetFilePointer(dirverHandle, clusterStream.Offset * bytePerCluster))
                {
                    yield return(null);

                    break;
                }
                for (long ClusterCount = clusterStream.ClusterCount; ClusterCount > 0; --ClusterCount)
                {
                    if (buffer == null || buffer.Length < bytePerCluster)
                    {
                        buffer = new byte[bytePerCluster];
                    }
                    if (Kernel32.ReadFile(dirverHandle, buffer, bytePerCluster) != bytePerCluster)
                    {
                        yield return(null);

                        goto RETURN;
                    }
                    yield return(buffer);
                }
            }
            RETURN :;
        }
示例#2
0
 /// <summary>
 /// 保存第一个扇区数据(基本数据)
 /// </summary>
 /// <param name="dirverHandle"></param>
 /// <param name="newTechnologyFileSystem"></param>
 /// <returns></returns>
 public bool WriteSector(Microsoft.Win32.SafeHandles.SafeFileHandle dirverHandle, NewTechnologyFileSystem newTechnologyFileSystem)
 {
     if (Kernel32.SetFilePointer(dirverHandle, fileIndex + startIndex) && Kernel32.GetFilePointer(dirverHandle) == fileIndex + startIndex)
     {
         byte[] buffer = Buffer;
         if (startIndex != 0)
         {
             buffer = new byte[newTechnologyFileSystem.BytePerSector];
             System.Buffer.BlockCopy(Buffer, startIndex, buffer, 0, buffer.Length);
         }
         int writeSize = Kernel32.WriteFileWithLockVolume(dirverHandle, buffer, newTechnologyFileSystem.BytePerSector);
         return(writeSize == newTechnologyFileSystem.BytePerSector);
     }
     return(false);
 }
示例#3
0
        /// <summary>
        /// 枚举索引项集合
        /// </summary>
        /// <param name="dirverHandle"></param>
        /// <param name="newTechnologyFileSystem"></param>
        /// <param name="buffer"></param>
        /// <returns></returns>
        public IEnumerable <FileIndexEntry> GetIndexEntrys(Microsoft.Win32.SafeHandles.SafeFileHandle dirverHandle, NewTechnologyFileSystem newTechnologyFileSystem, byte[] buffer = null)
        {
            foreach (MainFileTableAttribute mainFileTableAttribute in Attributes)
            {
                switch (mainFileTableAttribute.Type)
                {
                case MainFileTableAttributeType.IndexRoot:
                    IndexRootAttribute IndexRootAttribute = new IndexRootAttribute(mainFileTableAttribute);
                    foreach (FileIndexEntry fileIndexEntry in IndexRootAttribute.IndexEntrys)
                    {
                        yield return(fileIndexEntry);
                    }
                    break;

                case MainFileTableAttributeType.IndexAllocation:
                    ClusterStreamAttribute indexAllocationAttribute = new ClusterStreamAttribute(mainFileTableAttribute);
                    foreach (byte[] data in indexAllocationAttribute.ReadData(dirverHandle, newTechnologyFileSystem, buffer))
                    {
                        if (data != null)
                        {
                            FileIndex fileIndex = new FileIndex(data);
                            if (fileIndex.Buffer == null)
                            {
                                break;
                            }
                            foreach (FileIndexEntry fileIndexEntry in fileIndex.IndexEntrys)
                            {
                                yield return(fileIndexEntry);
                            }
                        }
                    }
                    break;
                }
            }
        }
示例#4
0
 /// <summary>
 /// 调试检查第一个扇区数据(基本数据)是否和内存数据是否一致
 /// </summary>
 /// <param name="dirverHandle"></param>
 /// <param name="newTechnologyFileSystem"></param>
 /// <returns></returns>
 public unsafe bool CheckSector(Microsoft.Win32.SafeHandles.SafeFileHandle dirverHandle, NewTechnologyFileSystem newTechnologyFileSystem)
 {
     if (Kernel32.SetFilePointer(dirverHandle, fileIndex + startIndex))
     {
         byte[] buffer = new byte[newTechnologyFileSystem.BytePerSector];
         if (Kernel32.ReadFile(dirverHandle, buffer) == buffer.Length)
         {
             fixed(byte *bufferFixed = Buffer, readBufferFixed = buffer)
             {
                 return(AutoCSer.Memory.Common.EqualNotNull(bufferFixed + startIndex, readBufferFixed, buffer.Length));
             }
         }
     }
     return(false);
 }
示例#5
0
 /// <summary>
 /// 获取文件记录的起始扇区号,每一项占用2个扇区
 /// </summary>
 /// <param name="NTFS"></param>
 /// <returns></returns>
 public ulong GetSectorIndex(NewTechnologyFileSystem NTFS)
 {
     return(NTFS.MainFileTableSectorIndex + (MainFileTableIndex << 1));
 }