Exemple #1
0
        public NonResidentData(byte[] rawBytes)
        {
            StartingVirtualClusterNumber = BitConverter.ToUInt64(rawBytes, 0x10);
            EndingVirtualClusterNumber   = BitConverter.ToUInt64(rawBytes, 0x18);

            var offsetToDataRuns = BitConverter.ToUInt16(rawBytes, 0x20);

            AllocatedSize   = BitConverter.ToUInt64(rawBytes, 0x28);
            ActualSize      = BitConverter.ToUInt64(rawBytes, 0x30);
            InitializedSize = BitConverter.ToUInt64(rawBytes, 0x38);

            var index = (int)offsetToDataRuns;  //set index into bytes to start reading offsets

            DataRuns = new List <DataRun>();

            var drStart = rawBytes[index];

            while (drStart != 0)
            {
                var offsetLength        = (byte)((drStart & 0xF0) >> 4); //left nibble
                var clusterLenByteCount = (byte)(drStart & 0x0F);        //right nibble
                index += 1;

                var runLenBytes = new byte[8]; //length should never exceed 8, so start with 8
                Buffer.BlockCopy(rawBytes, index, runLenBytes, 0, clusterLenByteCount);

                index += clusterLenByteCount;

                var clusterRunLength = BitConverter.ToUInt64(runLenBytes, 0);

                var clusterBytes = new byte[8]; //length should never exceed 8, so start with 8

                //copy in what we have
                Buffer.BlockCopy(rawBytes, index, clusterBytes, 0, offsetLength);

                //we can safely get our cluster #
                var clusterNumber = BitConverter.ToInt64(clusterBytes, 0);


                index += offsetLength;

                var dr = new DataRun(clusterRunLength, clusterNumber);
                DataRuns.Add(dr);

                drStart = rawBytes[index];
            }
        }
Exemple #2
0
        public AttributeList(byte[] rawBytes) : base(rawBytes)
        {
            DataRuns = new List <DataRun>();
            AttributeInformations = new List <AttributeInfo>();

            //TODO Refactor using the NonResident and ResidentData classes?

            if (IsResident)
            {
                var index = ContentOffset;

                while (index < rawBytes.Length)
                {
                    var size   = BitConverter.ToInt16(rawBytes, index + 4);
                    var buffer = new byte[size];
                    Buffer.BlockCopy(rawBytes, index, buffer, 0, size);

                    var er = new AttributeInfo(buffer);

                    AttributeInformations.Add(er);

                    index += size;
                }
            }
            else
            {
                StartingVirtualCluster = BitConverter.ToUInt64(rawBytes, 0x10);
                EndingVirtualCluster   = BitConverter.ToUInt64(rawBytes, 0x18);
                OffsetToDataRun        = BitConverter.ToUInt16(rawBytes, 0x20);
                AllocatedSize          = BitConverter.ToUInt64(rawBytes, 0x28);
                ActualSize             = BitConverter.ToUInt64(rawBytes, 0x30);
                InitializedSize        = BitConverter.ToUInt64(rawBytes, 0x38);

                var index = OffsetToDataRun;

                var hasAnother = rawBytes[index] > 0;

                //when data is split across several entries, must find them all and process in order of
                //StartingVCN: 0x0 EndingVCN: 0x57C
                //StartingVCN: 0x57D EndingVCN: 0x138F
                //so things go back in right order

                //TODO this should be a function vs here and in Data class.

                while (hasAnother)
                {
                    var drStart = rawBytes[index];
                    index += 1;

                    var clustersToReadAtOffset = (byte)(drStart & 0x0F);
                    var offsetToRun            = (byte)((drStart & 0xF0) >> 4);

                    var clusterCountRaw = new byte[8];
                    var offsetToRunRaw  = new byte[8];

                    Buffer.BlockCopy(rawBytes, index, clusterCountRaw, 0, clustersToReadAtOffset);

                    index += clustersToReadAtOffset;
                    Buffer.BlockCopy(rawBytes, index, offsetToRunRaw, 0, offsetToRun);
                    index += offsetToRun;

                    var clusterCount = BitConverter.ToUInt64(clusterCountRaw, 0);
                    var offset       = BitConverter.ToInt64(offsetToRunRaw, 0);

                    var dr = new DataRun(clusterCount, offset);
                    DataRuns.Add(dr);

                    hasAnother = rawBytes[index] > 0;
                }
            }
        }