Exemple #1
0
        public virtual int ReadFrom(byte[] buffer, int offset)
        {
            DescriptorTag = Utilities.ToStruct<DescriptorTag>(buffer, offset);
            InformationControlBlock = Utilities.ToStruct<InformationControlBlock>(buffer, offset + 16);
            Uid = Utilities.ToUInt32LittleEndian(buffer, offset + 36);
            Gid = Utilities.ToUInt32LittleEndian(buffer, offset + 40);
            Permissions = (FilePermissions)Utilities.ToUInt32LittleEndian(buffer, offset + 44);
            FileLinkCount = Utilities.ToUInt16LittleEndian(buffer, offset + 48);
            RecordFormat = buffer[offset + 50];
            RecordDisplayAttributes = buffer[offset + 51];
            RecordLength = Utilities.ToUInt16LittleEndian(buffer, offset + 52);
            InformationLength = Utilities.ToUInt64LittleEndian(buffer, offset + 56);
            LogicalBlocksRecorded = Utilities.ToUInt64LittleEndian(buffer, offset + 64);
            AccessTime = UdfUtilities.ParseTimestamp(buffer, offset + 72);
            ModificationTime = UdfUtilities.ParseTimestamp(buffer, offset + 84);
            AttributeTime = UdfUtilities.ParseTimestamp(buffer, offset + 96);
            Checkpoint = Utilities.ToUInt32LittleEndian(buffer, offset + 108);
            ExtendedAttributeIcb = Utilities.ToStruct<LongAllocationDescriptor>(buffer, offset + 112);
            ImplementationIdentifier = Utilities.ToStruct<ImplementationEntityIdentifier>(buffer, offset + 128);
            UniqueId = Utilities.ToUInt64LittleEndian(buffer, offset + 160);
            ExtendedAttributesLength = Utilities.ToInt32LittleEndian(buffer, offset + 168);
            AllocationDescriptorsLength = Utilities.ToInt32LittleEndian(buffer, offset + 172);
            AllocationDescriptors = Utilities.ToByteArray(buffer, offset + 176 + ExtendedAttributesLength, AllocationDescriptorsLength);

            byte[] eaData = Utilities.ToByteArray(buffer, offset + 176, ExtendedAttributesLength);
            ExtendedAttributes = ReadExtendedAttributes(eaData);

            return (int)(176 + ExtendedAttributesLength + AllocationDescriptorsLength);
        }
Exemple #2
0
        public virtual int ReadFrom(byte[] buffer, int offset)
        {
            DescriptorTag           = Utilities.ToStruct <DescriptorTag>(buffer, offset);
            InformationControlBlock = Utilities.ToStruct <InformationControlBlock>(buffer, offset + 16);
            Uid                         = Utilities.ToUInt32LittleEndian(buffer, offset + 36);
            Gid                         = Utilities.ToUInt32LittleEndian(buffer, offset + 40);
            Permissions                 = (FilePermissions)Utilities.ToUInt32LittleEndian(buffer, offset + 44);
            FileLinkCount               = Utilities.ToUInt16LittleEndian(buffer, offset + 48);
            RecordFormat                = buffer[offset + 50];
            RecordDisplayAttributes     = buffer[offset + 51];
            RecordLength                = Utilities.ToUInt16LittleEndian(buffer, offset + 52);
            InformationLength           = Utilities.ToUInt64LittleEndian(buffer, offset + 56);
            LogicalBlocksRecorded       = Utilities.ToUInt64LittleEndian(buffer, offset + 64);
            AccessTime                  = UdfUtilities.ParseTimestamp(buffer, offset + 72);
            ModificationTime            = UdfUtilities.ParseTimestamp(buffer, offset + 84);
            AttributeTime               = UdfUtilities.ParseTimestamp(buffer, offset + 96);
            Checkpoint                  = Utilities.ToUInt32LittleEndian(buffer, offset + 108);
            ExtendedAttributeIcb        = Utilities.ToStruct <LongAllocationDescriptor>(buffer, offset + 112);
            ImplementationIdentifier    = Utilities.ToStruct <ImplementationEntityIdentifier>(buffer, offset + 128);
            UniqueId                    = Utilities.ToUInt64LittleEndian(buffer, offset + 160);
            ExtendedAttributesLength    = Utilities.ToInt32LittleEndian(buffer, offset + 168);
            AllocationDescriptorsLength = Utilities.ToInt32LittleEndian(buffer, offset + 172);
            ExtendedAttributes          = Utilities.ToByteArray(buffer, offset + 176, ExtendedAttributesLength);
            AllocationDescriptors       = Utilities.ToByteArray(buffer, offset + 176 + ExtendedAttributesLength, AllocationDescriptorsLength);

            return((int)(176 + ExtendedAttributesLength + AllocationDescriptorsLength));
        }
Exemple #3
0
        public static byte[] ReadExtent(UdfContext context, LongAllocationDescriptor extent)
        {
            LogicalPartition partition = context.LogicalPartitions[extent.ExtentLocation.Partition];
            long             pos       = extent.ExtentLocation.LogicalBlock * partition.LogicalBlockSize;

            return(StreamUtilities.ReadExact(partition.Content, pos, (int)extent.ExtentLength));
        }
Exemple #4
0
        private void ReadLongDescriptors(byte[] activeBuffer)
        {
            long filePos = 0;

            int i = 0;

            while (i < activeBuffer.Length)
            {
                LongAllocationDescriptor lad = Utilities.ToStruct <LongAllocationDescriptor>(activeBuffer, i);
                if (lad.ExtentLength == 0)
                {
                    break;
                }

                if (lad.Flags == ShortAllocationFlags.RecordedAndAllocated)
                {
                    CookedExtent newExtent = new CookedExtent
                    {
                        FileContentOffset = filePos,
                        Partition         = lad.ExtentLocation.Partition,
                        StartPos          = lad.ExtentLocation.LogicalBlock * (long)_blockSize,
                        Length            = lad.ExtentLength
                    };
                    _extents.Add(newExtent);
                }
                else if (lad.Flags == ShortAllocationFlags.NextExtentOfAllocationDescriptors)
                {
                    ReadExtentDescriptors(lad, filePos);
                }
                filePos += lad.ExtentLength;
                i       += lad.Size;
            }
        }
Exemple #5
0
        private void ReadExtentDescriptors(LongAllocationDescriptor lad, long filePos)
        {
            byte[] allocExtDescBin = UdfUtilities.ReadExtent(_context, lad);
            ExtentAllocationDescriptor allocExtDesc = Utilities.ToStruct <ExtentAllocationDescriptor>(allocExtDescBin, 0);
            int  i             = 0;
            long extentLengths = 0;
            var  activeBuffer  = allocExtDesc.AllocationDescriptors;

            while (i < activeBuffer.Length)
            {
                LongAllocationDescriptor extentLongAllocationDescriptor = Utilities.ToStruct <LongAllocationDescriptor>(activeBuffer, i);
                if (extentLongAllocationDescriptor.ExtentLength == 0)
                {
                    break;
                }

                if (extentLongAllocationDescriptor.Flags == ShortAllocationFlags.RecordedAndAllocated)
                {
                    CookedExtent newExtent = new CookedExtent
                    {
                        FileContentOffset = filePos + extentLengths,
                        Partition         = extentLongAllocationDescriptor.ExtentLocation.Partition,
                        StartPos          = extentLongAllocationDescriptor.ExtentLocation.LogicalBlock * (long)_blockSize,
                        Length            = extentLongAllocationDescriptor.ExtentLength
                    };
                    _extents.Add(newExtent);
                    extentLengths += newExtent.Length;
                }
                else if (extentLongAllocationDescriptor.Flags == ShortAllocationFlags.NextExtentOfAllocationDescriptors)
                {
                    ReadExtentDescriptors(extentLongAllocationDescriptor, filePos + extentLengths);
                }
                i += extentLongAllocationDescriptor.Size;
            }
        }
Exemple #6
0
        public override int ReadFrom(byte[] buffer, int offset)
        {
            DescriptorTag           = Utilities.ToStruct <DescriptorTag>(buffer, offset);
            InformationControlBlock = Utilities.ToStruct <InformationControlBlock>(buffer, offset + 16);
            Uid                         = Utilities.ToUInt32LittleEndian(buffer, offset + 36);
            Gid                         = Utilities.ToUInt32LittleEndian(buffer, offset + 40);
            Permissions                 = (FilePermissions)Utilities.ToUInt32LittleEndian(buffer, offset + 44);
            FileLinkCount               = Utilities.ToUInt16LittleEndian(buffer, offset + 48);
            RecordFormat                = buffer[offset + 50];
            RecordDisplayAttributes     = buffer[offset + 51];
            RecordLength                = Utilities.ToUInt16LittleEndian(buffer, offset + 52);
            InformationLength           = Utilities.ToUInt64LittleEndian(buffer, offset + 56);
            ObjectSize                  = Utilities.ToUInt64LittleEndian(buffer, offset + 64);
            LogicalBlocksRecorded       = Utilities.ToUInt64LittleEndian(buffer, offset + 72);
            AccessTime                  = UdfUtilities.ParseTimestamp(buffer, offset + 80);
            ModificationTime            = UdfUtilities.ParseTimestamp(buffer, offset + 92);
            CreationTime                = UdfUtilities.ParseTimestamp(buffer, offset + 104);
            AttributeTime               = UdfUtilities.ParseTimestamp(buffer, offset + 116);
            Checkpoint                  = Utilities.ToUInt32LittleEndian(buffer, offset + 128);
            ExtendedAttributeIcb        = Utilities.ToStruct <LongAllocationDescriptor>(buffer, offset + 136);
            StreamDirectoryIcb          = Utilities.ToStruct <LongAllocationDescriptor>(buffer, offset + 152);
            ImplementationIdentifier    = Utilities.ToStruct <ImplementationEntityIdentifier>(buffer, offset + 168);
            UniqueId                    = Utilities.ToUInt64LittleEndian(buffer, offset + 200);
            ExtendedAttributesLength    = Utilities.ToInt32LittleEndian(buffer, offset + 208);
            AllocationDescriptorsLength = Utilities.ToInt32LittleEndian(buffer, offset + 212);
            AllocationDescriptors       = Utilities.ToByteArray(buffer, offset + 216 + ExtendedAttributesLength,
                                                                AllocationDescriptorsLength);

            byte[] eaData = Utilities.ToByteArray(buffer, offset + 216, ExtendedAttributesLength);
            ExtendedAttributes = ReadExtendedAttributes(eaData);

            return(216 + ExtendedAttributesLength + AllocationDescriptorsLength);
        }
Exemple #7
0
        public static File FromDescriptor(UdfContext context, LongAllocationDescriptor icb)
        {
            LogicalPartition partition = context.LogicalPartitions[icb.ExtentLocation.Partition];

            byte[]        rootDirData = UdfUtilities.ReadExtent(context, icb);
            DescriptorTag rootDirTag  = EndianUtilities.ToStruct <DescriptorTag>(rootDirData, 0);

            if (rootDirTag.TagIdentifier == TagIdentifier.ExtendedFileEntry)
            {
                ExtendedFileEntry fileEntry = EndianUtilities.ToStruct <ExtendedFileEntry>(rootDirData, 0);
                if (fileEntry.InformationControlBlock.FileType == FileType.Directory)
                {
                    return(new Directory(context, partition, fileEntry));
                }
                return(new File(context, partition, fileEntry, (uint)partition.LogicalBlockSize));
            }
            if (rootDirTag.TagIdentifier == TagIdentifier.FileEntry)
            {
                FileEntry fileEntry = EndianUtilities.ToStruct <FileEntry>(rootDirData, 0);
                if (fileEntry.InformationControlBlock.FileType == FileType.Directory)
                {
                    return(new Directory(context, partition, fileEntry));
                }
                return(new File(context, partition, fileEntry, (uint)partition.LogicalBlockSize));
            }
            throw new NotImplementedException("Only ExtendedFileEntries implemented");
        }
        public int ReadFrom(byte[] buffer, int offset)
        {
            DescriptorTag           = Utilities.ToStruct <DescriptorTag>(buffer, offset);
            FileVersionNumber       = Utilities.ToUInt16LittleEndian(buffer, offset + 16);
            FileCharacteristics     = (FileCharacteristic)buffer[offset + 18];
            NameLength              = buffer[offset + 19];
            FileLocation            = Utilities.ToStruct <LongAllocationDescriptor>(buffer, offset + 20);
            ImplementationUseLength = Utilities.ToUInt16LittleEndian(buffer, offset + 36);
            ImplementationUse       = Utilities.ToByteArray(buffer, offset + 38, ImplementationUseLength);
            Name = UdfUtilities.ReadDCharacters(buffer, offset + 38 + ImplementationUseLength, NameLength);

            return(Utilities.RoundUp(38 + ImplementationUseLength + NameLength, 4));
        }
        public int ReadFrom(byte[] buffer, int offset)
        {
            DescriptorTag = Utilities.ToStruct<DescriptorTag>(buffer, offset);
            FileVersionNumber = Utilities.ToUInt16LittleEndian(buffer, offset + 16);
            FileCharacteristics = (FileCharacteristic)buffer[offset + 18];
            NameLength = buffer[offset + 19];
            FileLocation = Utilities.ToStruct<LongAllocationDescriptor>(buffer, offset + 20);
            ImplementationUseLength = Utilities.ToUInt16LittleEndian(buffer, offset + 36);
            ImplementationUse = Utilities.ToByteArray(buffer, offset + 38, ImplementationUseLength);
            Name = UdfUtilities.ReadDCharacters(buffer, offset + 38 + ImplementationUseLength, NameLength);

            return Utilities.RoundUp(38 + ImplementationUseLength + NameLength, 4);
        }
        public int ReadFrom(byte[] buffer, int offset)
        {
            DescriptorTag                  = Utilities.ToStruct <DescriptorTag>(buffer, offset);
            RecordingTime                  = UdfUtilities.ParseTimestamp(buffer, offset + 16);
            InterchangeLevel               = Utilities.ToUInt16LittleEndian(buffer, offset + 28);
            MaximumInterchangeLevel        = Utilities.ToUInt16LittleEndian(buffer, offset + 30);
            CharacterSetList               = Utilities.ToUInt32LittleEndian(buffer, offset + 32);
            MaximumCharacterSetList        = Utilities.ToUInt32LittleEndian(buffer, offset + 36);
            FileSetNumber                  = Utilities.ToUInt32LittleEndian(buffer, offset + 40);
            FileSetDescriptorNumber        = Utilities.ToUInt32LittleEndian(buffer, offset + 44);
            LogicalVolumeIdentifierCharset = Utilities.ToStruct <CharacterSetSpecification>(buffer, offset + 48);
            LogicalVolumeIdentifier        = UdfUtilities.ReadDString(buffer, offset + 112, 128);
            FileSetCharset                 = Utilities.ToStruct <CharacterSetSpecification>(buffer, offset + 240);
            FileSetIdentifier              = UdfUtilities.ReadDString(buffer, offset + 304, 32);
            CopyrightFileIdentifier        = UdfUtilities.ReadDString(buffer, offset + 336, 32);
            AbstractFileIdentifier         = UdfUtilities.ReadDString(buffer, offset + 368, 32);
            RootDirectoryIcb               = Utilities.ToStruct <LongAllocationDescriptor>(buffer, offset + 400);
            DomainIdentifier               = Utilities.ToStruct <DomainEntityIdentifier>(buffer, offset + 416);
            NextExtent = Utilities.ToStruct <LongAllocationDescriptor>(buffer, offset + 448);
            SystemStreamDirectoryIcb = Utilities.ToStruct <LongAllocationDescriptor>(buffer, offset + 464);

            return(512);
        }
        public int ReadFrom(byte[] buffer, int offset)
        {
            DescriptorTag = Utilities.ToStruct<DescriptorTag>(buffer, offset);
            RecordingTime = UdfUtilities.ParseTimestamp(buffer, offset + 16);
            InterchangeLevel = Utilities.ToUInt16LittleEndian(buffer, offset + 28);
            MaximumInterchangeLevel = Utilities.ToUInt16LittleEndian(buffer, offset + 30);
            CharacterSetList = Utilities.ToUInt32LittleEndian(buffer, offset + 32);
            MaximumCharacterSetList = Utilities.ToUInt32LittleEndian(buffer, offset + 36);
            FileSetNumber = Utilities.ToUInt32LittleEndian(buffer, offset + 40);
            FileSetDescriptorNumber = Utilities.ToUInt32LittleEndian(buffer, offset + 44);
            LogicalVolumeIdentifierCharset = Utilities.ToStruct<CharacterSetSpecification>(buffer, offset + 48);
            LogicalVolumeIdentifier = UdfUtilities.ReadDString(buffer, offset + 112, 128);
            FileSetCharset = Utilities.ToStruct<CharacterSetSpecification>(buffer, offset + 240);
            FileSetIdentifier = UdfUtilities.ReadDString(buffer, offset + 304, 32);
            CopyrightFileIdentifier = UdfUtilities.ReadDString(buffer, offset + 336, 32);
            AbstractFileIdentifier = UdfUtilities.ReadDString(buffer, offset + 368, 32);
            RootDirectoryIcb = Utilities.ToStruct<LongAllocationDescriptor>(buffer, offset + 400);
            DomainIdentifier = Utilities.ToStruct<DomainEntityIdentifier>(buffer, offset + 416);
            NextExtent = Utilities.ToStruct<LongAllocationDescriptor>(buffer, offset + 448);
            SystemStreamDirectoryIcb = Utilities.ToStruct<LongAllocationDescriptor>(buffer, offset + 464);

            return 512;
        }
        private void LoadExtents()
        {
            _extents = new List <CookedExtent>();
            byte[] activeBuffer = _fileEntry.AllocationDescriptors;

            AllocationType allocType = _fileEntry.InformationControlBlock.AllocationType;

            if (allocType == AllocationType.ShortDescriptors)
            {
                long filePos = 0;

                int i = 0;
                while (i < activeBuffer.Length)
                {
                    ShortAllocationDescriptor sad = EndianUtilities.ToStruct <ShortAllocationDescriptor>(activeBuffer, i);
                    if (sad.ExtentLength == 0)
                    {
                        break;
                    }

                    if (sad.Flags != ShortAllocationFlags.RecordedAndAllocated)
                    {
                        throw new NotImplementedException(
                                  "Extents that are not 'recorded and allocated' not implemented");
                    }

                    CookedExtent newExtent = new CookedExtent
                    {
                        FileContentOffset = filePos,
                        Partition         = int.MaxValue,
                        StartPos          = sad.ExtentLocation * (long)_blockSize,
                        Length            = sad.ExtentLength
                    };
                    _extents.Add(newExtent);

                    filePos += sad.ExtentLength;
                    i       += sad.Size;
                }
            }
            else if (allocType == AllocationType.Embedded)
            {
                // do nothing
            }
            else if (allocType == AllocationType.LongDescriptors)
            {
                long filePos = 0;

                int i = 0;
                while (i < activeBuffer.Length)
                {
                    LongAllocationDescriptor lad = EndianUtilities.ToStruct <LongAllocationDescriptor>(activeBuffer, i);
                    if (lad.ExtentLength == 0)
                    {
                        break;
                    }

                    CookedExtent newExtent = new CookedExtent
                    {
                        FileContentOffset = filePos,
                        Partition         = lad.ExtentLocation.Partition,
                        StartPos          = lad.ExtentLocation.LogicalBlock * (long)_blockSize,
                        Length            = lad.ExtentLength
                    };
                    _extents.Add(newExtent);

                    filePos += lad.ExtentLength;
                    i       += lad.Size;
                }
            }
            else
            {
                throw new NotImplementedException("Allocation Type: " +
                                                  _fileEntry.InformationControlBlock.AllocationType);
            }
        }
Exemple #13
0
 public static byte[] ReadExtent(UdfContext context, LongAllocationDescriptor extent)
 {
     LogicalPartition partition = context.LogicalPartitions[extent.ExtentLocation.Partition];
     long pos = extent.ExtentLocation.LogicalBlock * partition.LogicalBlockSize;
     return Utilities.ReadFully(partition.Content, pos, (int)extent.ExtentLength);
 }
        private void ReadExtentDescriptors(LongAllocationDescriptor lad, long filePos)
        {
            byte[] allocExtDescBin = UdfUtilities.ReadExtent(_context, lad);
            ExtentAllocationDescriptor allocExtDesc = Utilities.ToStruct<ExtentAllocationDescriptor>(allocExtDescBin, 0);
            int i = 0;
            long extentLengths = 0;
            var activeBuffer = allocExtDesc.AllocationDescriptors;
            while (i < activeBuffer.Length)
            {
                LongAllocationDescriptor extentLongAllocationDescriptor = Utilities.ToStruct<LongAllocationDescriptor>(activeBuffer, i);
                if (extentLongAllocationDescriptor.ExtentLength == 0)
                {
                    break;
                }

                if (extentLongAllocationDescriptor.Flags == ShortAllocationFlags.RecordedAndAllocated)
                {
                    CookedExtent newExtent = new CookedExtent
                    {
                        FileContentOffset = filePos + extentLengths,
                        Partition = extentLongAllocationDescriptor.ExtentLocation.Partition,
                        StartPos = extentLongAllocationDescriptor.ExtentLocation.LogicalBlock*(long) _blockSize,
                        Length = extentLongAllocationDescriptor.ExtentLength
                    };
                    _extents.Add(newExtent);
                    extentLengths += newExtent.Length;
                }
                else if (extentLongAllocationDescriptor.Flags == ShortAllocationFlags.NextExtentOfAllocationDescriptors)
                {
                    ReadExtentDescriptors(extentLongAllocationDescriptor, filePos + extentLengths);
                }
                i += extentLongAllocationDescriptor.Size;
            }
        }
Exemple #15
0
        public static File FromDescriptor(UdfContext context, LongAllocationDescriptor icb)
        {
            LogicalPartition partition = context.LogicalPartitions[icb.ExtentLocation.Partition];

            byte[] rootDirData = UdfUtilities.ReadExtent(context, icb);
            DescriptorTag rootDirTag = Utilities.ToStruct<DescriptorTag>(rootDirData, 0);

            if (rootDirTag.TagIdentifier == TagIdentifier.ExtendedFileEntry)
            {
                ExtendedFileEntry fileEntry = Utilities.ToStruct<ExtendedFileEntry>(rootDirData, 0);
                if (fileEntry.InformationControlBlock.FileType == FileType.Directory)
                {
                    return new Directory(context, partition, fileEntry);
                }
                else
                {
                    return new File(context, partition, fileEntry, (uint)partition.LogicalBlockSize);
                }
            }
            else if (rootDirTag.TagIdentifier == TagIdentifier.FileEntry)
            {
                FileEntry fileEntry = Utilities.ToStruct<FileEntry>(rootDirData, 0);
                if (fileEntry.InformationControlBlock.FileType == FileType.Directory)
                {
                    return new Directory(context, partition, fileEntry);
                }
                else
                {
                    return new File(context, partition, fileEntry, (uint)partition.LogicalBlockSize);
                }
            }
            else
            {
                throw new NotImplementedException("Only ExtendedFileEntries implemented");
            }
        }