Esempio n. 1
0
        public void AssemblyMetadata_WhenCreatedAndIndexesAre4Bytes_ShouldHaveCorrectValues()
        {
            IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(4);
            Offset        offset       = 0;

            byte[] contents =
            {
                0x04, 0x80, 0x00, 0x00,
                0x01, 0x00,
                0x00, 0x00,
                0x00, 0x00,
                0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
                0x9A, 0x1D, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00
            };

            AssemblyMetadataTableRow row = new AssemblyMetadataTableRow(contents, offset, indexDetails);

            Assert.AreEqual(AssemblyHashAlgorithms.SHA1, row.HashAlgId);
            Assert.AreEqual("1.0.0.0", row.GetVersion().ToString());
            Assert.AreEqual(AssemblyFlags.SideBySideCompatible, row.Flags);
            Assert.AreEqual(0, row.PublicKey);
            Assert.AreEqual(0x1D9A, row.Name.Value);
            Assert.AreEqual(0x0000, row.Culture.Value);
        }
        public void AssemblyRef_WhenConstructed_ValuesAreCorrect()
        {
            byte[] content =
            {
                0x04, 0x00,
                0x01, 0x00,
                0x00, 0x00,
                0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
                0x63, 0x03,
                0xD9, 0x03,
                0x00, 0x00,
                0x00, 0x00
            };
            IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2);

            AssemblyRefMetadataTableRow row = new AssemblyRefMetadataTableRow(content, 0, indexDetails);

            Assert.AreEqual("4.1.0.0", row.GetVersion().ToString());
            Assert.AreEqual(AssemblyFlags.SideBySideCompatible, row.Flags);
            Assert.AreEqual(867, row.PublicKeyOrToken);
            Assert.AreEqual(985, row.Name.Value);
            Assert.AreEqual(0, row.Culture.Value);
            Assert.AreEqual(0, row.HashValue);
        }
        /// <summary>
        /// Initialises a new instance of the ModuleRefMetadataTableRow class
        /// </summary>
        /// <param name="contents">The contents of the file</param>
        /// <param name="offset">The offset of the current row</param>
        public ModuleRefMetadataTableRow(byte[] contents, Offset offset, IIndexDetails indexDetails)
        {
            this.FileOffset = offset;

            byte sizeOfStringIndex = indexDetails.GetSizeOfStringIndex();

            _name = new StringIndex(contents, sizeOfStringIndex, offset);
        }
Esempio n. 4
0
        public TypeSpecMetadataTableRow(byte[] contents, Offset offset, IIndexDetails indexDetails)
        {
            this.FileOffset = offset;

            byte sizeOfBlobIndex = indexDetails.GetSizeOfBlobIndex();

            _signiture = new BlobIndex(sizeOfBlobIndex, contents, Signatures.Signatures.TypeSpecification, offset);
        }
        /// <summary>
        /// Initialises a new instance of the FieldRVAMetadataTableRow class
        /// </summary>
        /// <param name="content">The content of the file</param>
        /// <param name="offset">The offset for the current row</param>
        public FieldRVAMetadataTableRow(byte[] content, Offset offset, IIndexDetails indexDetails)
        {
            this.FileOffset = offset;

            byte sizeOfFieldIndex = indexDetails.GetSizeOfIndex(MetadataTables.Field);

            _rva        = FieldReader.ToUInt32(content, offset.Shift(4));
            _fieldIndex = new Index(content, offset, sizeOfFieldIndex);
        }
Esempio n. 6
0
        /// <summary>
        /// Initialises a new instance of the FieldLayoutMetadataTableRow
        /// </summary>
        /// <param name="contents">The contents of the file</param>
        /// <param name="offset">The offset of the current row</param>
        public FieldLayoutMetadataTableRow(byte[] contents, Offset offset, IIndexDetails indexDetails)
        {
            this.FileOffset = offset;

            byte sizeOfFieldIndex = indexDetails.GetSizeOfIndex(MetadataTables.Field);

            _offset     = BitConverter.ToUInt32(contents, offset.Shift(4));
            _fieldIndex = new Index(contents, offset, sizeOfFieldIndex);
        }
Esempio n. 7
0
        /// <summary>
        /// Initialises a new instance of the NestedClassMetadataTableRow class
        /// </summary>
        /// <param name="contents">The contents of the file</param>
        /// <param name="offset">The offset of the current row</param>
        public NestedClassMetadataTableRow(byte[] contents, Offset offset, IIndexDetails indexDetails)
        {
            this.FileOffset = offset;

            byte sizeOfTypeDefIndex = indexDetails.GetSizeOfIndex(MetadataTables.TypeDef);

            _nestedClass    = new Index(contents, offset, sizeOfTypeDefIndex);
            _enclosingClass = new Index(contents, offset, sizeOfTypeDefIndex);
        }
        /// <summary>
        /// Initialises a new instance of the ClassLayoutMetadataTableRow
        /// </summary>
        /// <param name="contents">The contents of the file</param>
        /// <param name="offset">The offset of this row</param>
        /// <param name="sizeOfTypeDefIndex">The size of the indexes to the type def table.</param>
        public ClassLayoutMetadataTableRow(byte[] contents, Offset offset, IIndexDetails indexDetails)
        {
            this.FileOffset = offset;

            byte sizeOfTypeDefIndex = indexDetails.GetSizeOfIndex(MetadataTables.TypeDef);

            _packingSize = BitConverter.ToUInt16(contents, offset.Shift(2));
            _classSize   = BitConverter.ToUInt32(contents, offset.Shift(4));
            _parentIndex = new Index(contents, offset, sizeOfTypeDefIndex);
        }
        /// <summary>
        /// Initialises a new instance of the PropertyMapMetadataTableRow
        /// </summary>
        /// <param name="contents">The contents of the file</param>
        /// <param name="offset">The offset for this row</param>
        public PropertyMapMetadataTableRow(byte[] contents, Offset offset, IIndexDetails indexDetails)
        {
            this.FileOffset = offset;

            byte sizeOfTypeDefIndex  = indexDetails.GetSizeOfIndex(MetadataTables.TypeDef);
            byte sizeOfPropertyIndex = indexDetails.GetSizeOfIndex(MetadataTables.Property);

            _parent       = new Index(contents, offset, sizeOfTypeDefIndex);
            _propertyList = new Index(contents, offset, sizeOfPropertyIndex);
        }
        /// <summary>
        /// Initialises a new EventMapMetadataTableRow
        /// </summary>
        /// <param name="contents">The contents of the file</param>
        /// <param name="offset">The offset of the current row</param>
        public EventMapMetadataTableRow(byte[] contents, Offset offset, IIndexDetails indexDetails)
        {
            this.FileOffset = offset;

            byte typeDefIndexSize = indexDetails.GetSizeOfIndex(MetadataTables.TypeDef);
            byte eventIndexSize   = indexDetails.GetSizeOfIndex(MetadataTables.Event);

            _parentIndex    = new Index(contents, offset, typeDefIndexSize);
            _eventListIndex = new Index(contents, offset, eventIndexSize);
        }
Esempio n. 11
0
        public void EventMap_WhenCreated_OffsetIsMovedOn()
        {
            byte[]        contents     = new byte[20];
            Offset        offset       = 0;
            IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2);

            EventMapMetadataTableRow row = new EventMapMetadataTableRow(contents, offset, indexDetails);

            Assert.AreEqual(4, offset.Current);
        }
        public void NestedClass_WhenCreated_OffsetIsMovedOn()
        {
            byte[]        contents     = new byte[4];
            Offset        offset       = 0;
            IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2);

            NestedClassMetadataTableRow row = new NestedClassMetadataTableRow(contents, offset, indexDetails);

            Assert.AreEqual(4, offset.Current);
        }
        public void Module_WhenCreated_OffsetIsMovedOn()
        {
            byte[]        contents     = new byte[10];
            Offset        offset       = 0;
            IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2);

            ModuleMetadataTableRow row = new ModuleMetadataTableRow(contents, offset, indexDetails);

            Assert.AreEqual(10, offset.Current);
        }
Esempio n. 14
0
        public void DeclSecurity_WhenCreated_OffsetIsMovedOn(byte blobIndexSize, byte codedIndexSize, int expected)
        {
            byte[] content = new byte[20];
            Offset offset  = 0;
            ICodedIndexResolver resolver     = IndexHelper.CreateCodedIndexResolver(codedIndexSize);
            IIndexDetails       indexDetails = IndexHelper.CreateIndexDetails(2, 2, blobIndexSize, codedIndexSize);

            DeclSecurityMetadataTableRow row = new DeclSecurityMetadataTableRow(content, offset, resolver, indexDetails);

            Assert.AreEqual(expected, offset.Current);
        }
Esempio n. 15
0
        public void ClassLayout_WhenCreated_OffsetIsMovedOn(byte indexSize, int expected)
        {
            IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(indexSize);
            Offset        offset       = 0;

            byte[] content = new byte[20];

            ClassLayoutMetadataTableRow row = new ClassLayoutMetadataTableRow(content, offset, indexDetails);

            Assert.AreEqual(expected, offset.Current);
        }
Esempio n. 16
0
        /// <summary>
        /// Initialises a new instance of the FileMetadataTableRow class
        /// </summary>
        /// <param name="contents">The contents of the file</param>
        /// <param name="offset">The offset of the current row</param>
        public FileMetadataTableRow(byte[] contents, Offset offset, IIndexDetails indexDetails)
        {
            this.FileOffset = offset;

            byte sizeOfStringIndex = indexDetails.GetSizeOfStringIndex();
            byte sizeOfBlobIndex   = indexDetails.GetSizeOfBlobIndex();

            _flags     = (FileAttributes)FieldReader.ToUInt32(contents, offset.Shift(4));
            _nameIndex = new StringIndex(contents, sizeOfStringIndex, offset);
            _hashValue = FieldReader.ToUInt32(contents, offset.Shift(sizeOfBlobIndex), sizeOfBlobIndex);
        }
Esempio n. 17
0
        public void AssemblyRefOS_WhenCreated_OffsetIsMovedOn(byte sizeOfIndex, int expected)
        {
            IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(sizeOfIndex);
            Offset        offset       = 0;

            byte[] content = new byte[20];

            AssemblyRefOSMetadataTableRow row = new AssemblyRefOSMetadataTableRow(content, offset, indexDetails);

            Assert.AreEqual(expected, offset.Current);
        }
        public void Property_WhenCreated_OffsetIsMovedOn()
        {
            IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2);

            byte[] contents = new byte[6];
            Offset offset   = 0;

            PropertyMetadataTableRow row = new PropertyMetadataTableRow(contents, offset, indexDetails);

            Assert.AreEqual(6, offset.Current);
        }
        public void GenericConstraint_WhenCreated_OffsetIsMovedOn()
        {
            byte[] contents = new byte[10];
            Offset offset   = 0;
            ICodedIndexResolver resolver     = IndexHelper.CreateCodedIndexResolver(2);
            IIndexDetails       indexDetails = IndexHelper.CreateIndexDetails(2);

            GenericParamConstraintMetadataTableRow row = new GenericParamConstraintMetadataTableRow(contents, offset, resolver, indexDetails);

            Assert.AreEqual(4, offset.Current);
        }
Esempio n. 20
0
        public void AssemblyRefProcessor_WhenCreated_ShouldMoveOffsetOn(byte sizeOfIndex, int expected)
        {
            IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(sizeOfIndex);

            byte[] content = new byte[30];
            Offset offset  = 0;

            AssemblyRefProcessorMetadataTableRow row = new AssemblyRefProcessorMetadataTableRow(content, offset, indexDetails);

            Assert.AreEqual(expected, offset.Current);
        }
Esempio n. 21
0
        public void FieldMarshal_WhenCreated_OffsetIsMovedOn()
        {
            byte[] contents = new byte[10];
            Offset offset   = 0;
            ICodedIndexResolver resolver     = IndexHelper.CreateCodedIndexResolver(2);
            IIndexDetails       indexDetails = IndexHelper.CreateIndexDetails(2);

            FieldMarshalMetadataTableRow row = new FieldMarshalMetadataTableRow(contents, offset, resolver, indexDetails);

            Assert.AreEqual(4, offset.Current);
        }
        public void TypeSpec_WhenCreated_OffsetIsMovedOn()
        {
            IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2);

            byte[] contents = new byte[2];
            Offset offset   = 0;

            TypeSpecMetadataTableRow row = new TypeSpecMetadataTableRow(contents, offset, indexDetails);

            Assert.AreEqual(2, offset.Current);
        }
        /// <summary>
        /// Initialises a new instance of the FieldMetadataTableRow
        /// </summary>
        /// <param name="contents">The contents of the file</param>
        /// <param name="offset">The offset of the current row</param>
        public FieldMetadataTableRow(byte[] contents, Offset offset, IIndexDetails indexDetails)
        {
            this.FileOffset = offset;

            byte sizeOfStringIndex = indexDetails.GetSizeOfStringIndex();
            byte sizeOfBlobIndex   = indexDetails.GetSizeOfBlobIndex();

            _flags          = (FieldAttributes)FieldReader.ToUInt16(contents, offset.Shift(2));
            _nameIndex      = new StringIndex(contents, sizeOfStringIndex, offset);
            _signitureIndex = new BlobIndex(sizeOfBlobIndex, contents, Reflection.Signatures.Signatures.Field, offset);
        }
        public void AssemblyRef_WhenConstructedWithIndexSizes_OffsetIsMovedOn(byte blobIndex, byte stringIndex, int expected)
        {
            IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2, stringIndex, blobIndex, 2);
            Offset        offset       = 0;

            byte[] content = new byte[30];

            AssemblyRefMetadataTableRow row = new AssemblyRefMetadataTableRow(content, offset, indexDetails);

            Assert.AreEqual(expected, offset.Current);
        }
Esempio n. 25
0
        public void FieldLayout_WhenCreated_OffsetIsMovedOn()
        {
            Offset offset = 0;

            byte[]        contents     = new byte[10];
            IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2);

            FieldLayoutMetadataTableRow row = new FieldLayoutMetadataTableRow(contents, offset, indexDetails);

            Assert.AreEqual(6, offset.Current);
        }
Esempio n. 26
0
        public void AssemblyMetadata_WhenConstructedWithIndexSizes_ShouldMoveOffset(byte sizeStringIndex, byte sizeBlobIndex, int expected)
        {
            IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2, sizeStringIndex, sizeBlobIndex, 2);
            Offset        offset       = 0;

            byte[] contents = new byte[30];

            AssemblyMetadataTableRow row = new AssemblyMetadataTableRow(contents, offset, indexDetails);

            Assert.AreEqual(expected, offset.Current);
        }
        public void MemberRef_WhenCreated_OffsetIsMovedOn()
        {
            byte[] contents = new byte[10];
            ICodedIndexResolver resolver     = IndexHelper.CreateCodedIndexResolver(2);
            IIndexDetails       indexDetails = IndexHelper.CreateIndexDetails(2);
            Offset offset = 0;

            MemberRefMetadataTableRow row = new MemberRefMetadataTableRow(contents, offset, resolver, indexDetails);

            Assert.AreEqual(6, offset.Current);
        }
Esempio n. 28
0
        /// <summary>
        /// Initialises a new instance of the PropertyMetadataTableRow class
        /// </summary>
        /// <param name="contents">The contents of the file</param>
        /// <param name="offset">The offset of this row</param>
        public PropertyMetadataTableRow(byte[] contents, Offset offset, IIndexDetails indexDetails)
        {
            FileOffset = offset;

            byte sizeOfBlobIndex   = indexDetails.GetSizeOfBlobIndex();
            byte sizeOfStringIndex = indexDetails.GetSizeOfStringIndex();

            _attributes = (PropertyAttributes)FieldReader.ToUInt16(contents, offset.Shift(2));
            _nameIndex  = new StringIndex(contents, sizeOfStringIndex, offset);
            _typeIndex  = FieldReader.ToUInt32(contents, offset.Shift(sizeOfBlobIndex), sizeOfBlobIndex);
        }
Esempio n. 29
0
        /// <summary>
        /// Initialises a new instance of the AssemblyRefProcessorMetadataTableRow class
        /// </summary>
        /// <param name="contents">The contents of the file</param>
        /// <param name="offset">The offset of the current row</param>
        public AssemblyRefProcessorMetadataTableRow(byte[] contents, Offset offset, IIndexDetails indexDetails)
        {
            this.FileOffset = offset;

            byte sizeOfAssemblyRefIndex = indexDetails.GetSizeOfIndex(MetadataTables.AssemblyRef);

            offset.Shift(4);
            offset.Shift(sizeOfAssemblyRefIndex);

            _processor   = 0;
            _assemblyRef = new Index();
        }
        public void Constant_WhenCreated_OffsetIsMovedOn()
        {
            ICodedIndexResolver resolver     = IndexHelper.CreateCodedIndexResolver(2);
            IIndexDetails       indexDetails = IndexHelper.CreateIndexDetails(2);
            Offset offset = 0;

            byte[] content = new byte[30];

            ConstantMetadataTableRow row = new ConstantMetadataTableRow(content, offset, resolver, indexDetails);

            Assert.AreEqual(6, offset.Current);
        }