예제 #1
0
        internal override void ReadAttributeResident(byte[] data, int maxLength, int offset)
        {
            base.ReadAttributeResident(data, maxLength, offset);

            if (maxLength < 48)
            {
                throw new Exception("STANDARD_INFORMATION : max length of data stream is < 48!\n");
            }

            //                                                                                      position
            CreationTime   = NtfsHelper.FromWinFileTime(data, offset);                          //     80
            ModifiedTime   = NtfsHelper.FromWinFileTime(data, offset + 8);                      //     88
            MFTChangeTime  = NtfsHelper.FromWinFileTime(data, offset + 16);                     //     96
            AccessTime     = NtfsHelper.FromWinFileTime(data, offset + 24);                     //    104
            DosPermissions = (FileAttributes)BitConverter.ToInt32(data, offset + 32);           //    112

            MaxNumberVersions = BitConverter.ToUInt32(data, offset + 36);                       //    116
            VersionNumber     = BitConverter.ToUInt32(data, offset + 40);                       //    120
            ClassId           = BitConverter.ToUInt32(data, offset + 44);                       //    124

            // for NTFS 3.0+ version
            if (FormCode == ResidentFileFlag.Resident && ResidentHeader.ValueLength >= 72)
            {
                if (maxLength < 72)
                {
                    throw new Exception("Max length of a byte stream is less than 72!\n");
                }

                OwnerId     = BitConverter.ToUInt32(data, offset + 48);                         //    128
                SecurityId  = BitConverter.ToUInt32(data, offset + 52);                         //    132
                QuotaCharge = BitConverter.ToUInt64(data, offset + 56);                         //    136
                USN         = BitConverter.ToUInt64(data, offset + 64);                         //    144
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            string   file     = args[0];//@"C:\Users\anonymous\Downloads\boost_1_55_0.zip";//
            FileInfo fileInfo = new FileInfo(file);
            var      x        = NtfsHelper.GetFileMap(file);

            Console.WriteLine("starting VCN: " + x.StartingVcn);
            Console.WriteLine("VCN, LCN");
            for (ulong i = 0; i < x.ExtentCount; i++)
            {
                Console.WriteLine(x.NextVcn[i] + "," + x.Lcn[i]);
            }

            Console.ReadKey();

            //// MUST READ IN CLUSTER SIZE CHUNKS!
            //var buffer = new byte[fileInfo.Length + HdWalk.CLUSTER_SIZE - (fileInfo.Length % HdWalk.CLUSTER_SIZE)];

            //StringBuilder builder = new StringBuilder(260);
            //FilesLocatorNG.QueryDosDevice("C:", builder, 260);
            //// RUN AS ADMIN!!
            //using (BinaryReader reader = new BinaryReader(new DeviceStream(
            //    String.Format(@"\\.\{0}", builder.ToString().Replace(@"\Device\", "")))))//@"\\.\HarddiskVolume4")))
            //{
            //    int count = 0;
            //    long lastVcn = x.StartingVcn;
            //    for (ulong i = 0; i < x.ExtentCount; i++)
            //    {
            //        try
            //        {
            //            // ENTER BYTES NOT CLUSTER INDEX
            //            reader.BaseStream.Seek(x.Lcn[i] * HdWalk.CLUSTER_SIZE, SeekOrigin.Begin);

            //            long length = (x.NextVcn[i] - lastVcn) * HdWalk.CLUSTER_SIZE;
            //            lastVcn = x.NextVcn[i];

            //            count += reader.Read(buffer, count, (int)length);
            //        }
            //        catch (Exception e)
            //        {
            //            continue;
            //        }
            //    }
            //}

            //var buffer2 = File.ReadAllBytes(file);

            //for(int i = 0; i < fileInfo.Length; i++)
            //{
            //    if(buffer[i] != buffer2[i])
            //    {
            //        Console.WriteLine("WHY???");
            //    }
            //}

            //Console.WriteLine("Finished");
        }
예제 #3
0
        public byte[] DataWritter()
        {
            byte[] dataStream = new byte[RecordLength];
            Array.Copy(BitConverter.GetBytes((uint)TypeCode), 0, dataStream, 0, 4);
            Array.Copy(BitConverter.GetBytes(RecordLength), 0, dataStream, 4, 2);
            dataStream[6] = (byte)FormCode;
            dataStream[7] = NameLength;

            NtfsHelper.ToWinFileTime(dataStream, 8, CreationTime);
            NtfsHelper.ToWinFileTime(dataStream, 16, ModifiedTime);
            NtfsHelper.ToWinFileTime(dataStream, 24, AccessTime);
            NtfsHelper.ToWinFileTime(dataStream, 32, MFTChangeTime);
            dataStream[40] = (byte)DosPermissions;

            return(dataStream);
        }
예제 #4
0
        public byte[] DataWritter()
        {
            byte[] dataStream = new byte[RecordLength];
            Array.Copy(BitConverter.GetBytes((uint)TypeCode), 0, dataStream, 0, 4);
            Array.Copy(BitConverter.GetBytes(RecordLength), 0, dataStream, 4, 2);
            dataStream[6] = (byte)FormCode;

            NtfsHelper.ToWinFileTime(dataStream, 7, CreationTime);
            NtfsHelper.ToWinFileTime(dataStream, 15, ModifiedTime);
            NtfsHelper.ToWinFileTime(dataStream, 23, AccessTime);
            NtfsHelper.ToWinFileTime(dataStream, 31, MFTChangeTime);

            Array.Copy(BitConverter.GetBytes(AllocatedSize), 0, dataStream, 39, 8);
            Array.Copy(BitConverter.GetBytes(RealSize), 0, dataStream, 47, 8);
            dataStream[55] = (byte)FileFlags;
            dataStream[56] = FilenameLength;
            dataStream[57] = (byte)FilenameNamespace;
            Array.Copy(Encoding.ASCII.GetBytes(Filename), 0, dataStream, 58, Filename.Length);

            return(dataStream);
        }
예제 #5
0
        private const int DefaultBufferSize = 16 * 1024;         // 16KB

        public static async Task Copy(string sourceFilePath, string destinationFilePath, OverwriteMode overwriteMode = OverwriteMode.AlwaysOverwrite, CopyOptions options = CopyOptions.AllowHardLinkCreation, CancellationToken?cancellationToken = null, Action <long, long> progressCallback = null)
        {
            if (string.IsNullOrEmpty(sourceFilePath))
            {
                throw new ArgumentNullException("sourceFilePath");
            }
            if (string.IsNullOrEmpty(destinationFilePath))
            {
                throw new ArgumentNullException("destinationFilePath");
            }

            var ct = cancellationToken ?? CancellationToken.None;

            Directory.CreateDirectory(Path.GetDirectoryName(destinationFilePath));

            if (options.HasFlag(CopyOptions.AllowHardLinkCreation))
            {
                if (sourceFilePath.Length > 3 && destinationFilePath.Length > 3 &&
                    sourceFilePath[1] == Path.VolumeSeparatorChar && sourceFilePath[2] == Path.PathSeparator &&
                    sourceFilePath.Take(3).SequenceEqual(destinationFilePath.Take(3)))
                {
                    if (NtfsHelper.CreateHardLink(sourceFilePath, destinationFilePath))
                    {
                        if (progressCallback != null)
                        {
                            var length = new FileInfo(sourceFilePath).Length;
                            progressCallback(length, length);
                        }

                        return;
                    }
                }
            }

            await Win32CopyEx.Copy(sourceFilePath, destinationFilePath, overwriteMode, options, ct, progressCallback).ConfigureAwait(false);

            ct.ThrowIfCancellationRequested();
        }
예제 #6
0
        internal override void ReadAttributeResident(byte[] data, int maxLength, int offset)
        {
            base.ReadAttributeResident(data, maxLength, offset);

            //                                                                                      position
            ParentDirectory   = new MFTSegmentReference(BitConverter.ToUInt64(data, offset));   //    176
            CreationTime      = NtfsHelper.FromWinFileTime(data, offset + 8);                   //    184
            ModifiedTime      = NtfsHelper.FromWinFileTime(data, offset + 16);                  //    192
            MFTChangeTime     = NtfsHelper.FromWinFileTime(data, offset + 24);                  //    200
            AccessTime        = NtfsHelper.FromWinFileTime(data, offset + 32);                  //    208
            AllocatedSize     = BitConverter.ToUInt64(data, offset + 40);                       //    216
            RealSize          = BitConverter.ToUInt64(data, offset + 48);                       //    224
            FileFlags         = (FileAttributes)BitConverter.ToInt32(data, offset + 56);        //    232
            EASandReaparse    = BitConverter.ToUInt32(data, offset + 60);                       //    236
            FilenameLength    = data[offset + 64];                                              //    240
            FilenameNamespace = (FileNamespace)data[offset + 65];                               //    241

            if (maxLength < 66 + FilenameLength * 2)
            {
                throw new Exception("Error!\n");
            }

            Filename = Encoding.Unicode.GetString(data, offset + 66, FilenameLength * 2);       //    242
        }