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 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); }
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); }
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); }
/// <summary> /// Initialises a new instance of the InterfaceImplMetadataTableRow /// </summary> /// <param name="contents">The contents of the file</param> /// <param name="offset">The offset of this row</param> public InterfaceImplMetadataTableRow(byte[] contents, Offset offset, ICodedIndexResolver resolver, IIndexDetails indexDetails) { this.FileOffset = offset; int sizeOfCodedIndex = resolver.GetSizeOfIndex(CodedIndexes.TypeDefOrRef); byte sizeOfTypeDefIndex = indexDetails.GetSizeOfIndex(MetadataTables.TypeDef); _class = new Index(contents, offset, sizeOfTypeDefIndex); _interface = resolver.Resolve(CodedIndexes.TypeDefOrRef, FieldReader.ToUInt32(contents, offset.Shift(sizeOfCodedIndex), sizeOfCodedIndex) ); }
public void Event_WhenCreated_MovesOffsetOn() { ICodedIndexResolver resolver = IndexHelper.CreateCodedIndexResolver(2); IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2); byte[] contents = new byte[20]; Offset offset = 0; EventMetadataTableRow row = new EventMetadataTableRow(contents, offset, resolver, indexDetails); Assert.AreEqual(6, offset.Current); }
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); }
/// <summary> /// Initialises a new instance of the MethodSpecMetadataTableRow class /// </summary> /// <param name="contents">The contents of the file</param> /// <param name="offset">The offset of the current row</param> public MethodSpecMetadataTableRow(byte[] contents, Offset offset, ICodedIndexResolver resolver, IIndexDetails indexDetails) { this.FileOffset = offset; int sizeOfCodedIndex = resolver.GetSizeOfIndex(CodedIndexes.MethodDefOrRef); byte sizeOfBlobIndex = indexDetails.GetSizeOfBlobIndex(); _method = resolver.Resolve(CodedIndexes.MethodDefOrRef, FieldReader.ToUInt32(contents, offset.Shift(sizeOfCodedIndex), sizeOfCodedIndex) ); _instantiation = FieldReader.ToUInt32(contents, offset.Shift(sizeOfBlobIndex), sizeOfBlobIndex); }
public void ExportedType_WhenCreated_OffsetIsMovedOn() { Offset offset = 0; byte[] contents = new byte[20]; ICodedIndexResolver resolver = IndexHelper.CreateCodedIndexResolver(2); IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2); ExportedTypeMetadataTableRow row = new ExportedTypeMetadataTableRow(contents, offset, resolver, indexDetails); Assert.AreEqual(14, offset.Current); }
public void ManifestResource_WhenCreated_OffsetIsMovedOn() { ICodedIndexResolver resolver = IndexHelper.CreateCodedIndexResolver(2); IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2); byte[] contents = new byte[12]; Offset offset = 0; ManifestResourceMetadataTableRow row = new ManifestResourceMetadataTableRow(contents, offset, resolver, indexDetails); Assert.AreEqual(12, offset.Current); }
/// <summary> /// Initialises a new instance of the MethodSemanticsMetadataTableRow class /// </summary> /// <param name="contents">The contents of the file</param> /// <param name="offset">The offset of the current row</param> public MethodSemanticsMetadataTableRow(byte[] contents, Offset offset, ICodedIndexResolver resolver, IIndexDetails indexDetails) { this.FileOffset = offset; int sizeOfCodedIndex = resolver.GetSizeOfIndex(CodedIndexes.HasSemantics); byte sizeOfMethodDefIndex = indexDetails.GetSizeOfIndex(MetadataTables.MethodDef); _semantics = (MethodSemanticsAttributes)BitConverter.ToUInt16(contents, offset.Shift(2)); _method = new Index(contents, offset, sizeOfMethodDefIndex); _association = resolver.Resolve(CodedIndexes.HasSemantics, FieldReader.ToUInt32(contents, offset.Shift(sizeOfCodedIndex), sizeOfCodedIndex) ); }
public void CustomAttribute_WhenCreated_OffsetIsMovedOn(byte blobIndexSize, int codedIndexSize, int expected) { ICodedIndexResolver resolver = IndexHelper.CreateCodedIndexResolver(codedIndexSize); IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2, 2, blobIndexSize, 2); byte sizeOfBlobIndexes = blobIndexSize; Offset offset = 0; byte[] contents = new byte[10]; CustomAttributeMetadataTableRow row = new CustomAttributeMetadataTableRow(contents, offset, resolver, indexDetails); Assert.AreEqual(expected, offset.Current); }
/// <summary> /// Initialises a new instance of the FieldMarshalMEtadataTableRow class /// </summary> /// <param name="contents">The contents of the file</param> /// <param name="offset">The offset of the current row</param> public FieldMarshalMetadataTableRow(byte[] contents, Offset offset, ICodedIndexResolver resolver, IIndexDetails indexDetails) { this.FileOffset = offset; int sizeOfHasFieldMarshalIndex = resolver.GetSizeOfIndex(CodedIndexes.HasFieldMarshall); byte sizeOfBlobIndex = indexDetails.GetSizeOfBlobIndex(); _parentIndex = resolver.Resolve( CodedIndexes.HasFieldMarshall, FieldReader.ToUInt32(contents, offset.Shift(sizeOfHasFieldMarshalIndex), sizeOfHasFieldMarshalIndex) ); _nativeTypeIndex = FieldReader.ToUInt32(contents, offset.Shift(sizeOfBlobIndex), sizeOfBlobIndex); }
/// <summary> /// Initialises a new instance of the TypeRefMetadataTableRow class /// </summary> /// <param name="contents">The file contents</param> /// <param name="offset">The offset for this entry</param> public TypeRefMetadataTableRow(byte[] contents, Offset offset, ICodedIndexResolver resolver, IIndexDetails indexDetails) { this.FileOffset = offset; int sizeOfCodedIndex = resolver.GetSizeOfIndex(CodedIndexes.ResolutionScope); byte sizeOfStringIndex = indexDetails.GetSizeOfStringIndex(); _resolutionScope = resolver.Resolve(CodedIndexes.ResolutionScope, FieldReader.ToUInt32(contents, offset.Shift(sizeOfCodedIndex), sizeOfCodedIndex) ); _nameIndex = new StringIndex(contents, sizeOfStringIndex, offset); _namespaceIndex = new StringIndex(contents, sizeOfStringIndex, offset); }
/// <summary> /// Initialises a new instance of the GenericParamMetadataTableRow class /// </summary> /// <param name="contents">The contents of the file</param> /// <param name="offset">The offset of the current row</param> public GenericParamMetadataTableRow(byte[] contents, Offset offset, ICodedIndexResolver resolver, IIndexDetails indexDetails) { this.FileOffset = offset; int sizeOfCodeIndex = resolver.GetSizeOfIndex(CodedIndexes.TypeOrMethodDef); byte sizeOfStringIndex = indexDetails.GetSizeOfStringIndex(); _number = FieldReader.ToUInt16(contents, offset.Shift(2)); _flags = (GenericParamAttributes)FieldReader.ToUInt16(contents, offset.Shift(2)); _ownerIndex = resolver.Resolve(CodedIndexes.TypeOrMethodDef, FieldReader.ToUInt32(contents, offset.Shift(sizeOfCodeIndex), sizeOfCodeIndex) ); _nameIndex = new StringIndex(contents, sizeOfStringIndex, offset); }
/// <summary> /// Initialises a new instance of the EventMetadataTableRow class /// </summary> /// <param name="contents">The contents of the file</param> /// <param name="offset">The offset of the current row</param> public EventMetadataTableRow(byte[] contents, Offset offset, ICodedIndexResolver resolver, IIndexDetails indexDetails) { this.FileOffset = offset; int typeDefOrRefIndexSize = resolver.GetSizeOfIndex(CodedIndexes.TypeDefOrRef); byte sizeOfStringIndex = indexDetails.GetSizeOfStringIndex(); _eventFlags = (EventAttributes)BitConverter.ToUInt16(contents, offset.Shift(2)); _nameIndex = new StringIndex(contents, sizeOfStringIndex, offset); _eventTypeIndex = resolver.Resolve( CodedIndexes.TypeDefOrRef, FieldReader.ToUInt32(contents, offset.Shift(typeDefOrRefIndexSize), typeDefOrRefIndexSize) ); }
public void GenericConstraint_WhenCreated_ReadsFieldsCorrectly() { byte[] contents = new byte[] { 0x01, 0x00, 0x01, 0x00 }; ICodedIndexResolver resolver = IndexHelper.CreateCodedIndexResolver(2); IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2); GenericParamConstraintMetadataTableRow row = new GenericParamConstraintMetadataTableRow(contents, 0, resolver, indexDetails); Assert.AreEqual(1, row.Owner.Value); Assert.IsNotNull(row.Owner); }
/// <summary> /// Initialises a new instance of the MemberRefMetadataTableRow /// </summary> /// <param name="contents">The contents of the file</param> /// <param name="offset">The offset of this row</param> public MemberRefMetadataTableRow(byte[] contents, Offset offset, ICodedIndexResolver resolver, IIndexDetails indexDetails) { this.FileOffset = offset; int sizeOfMemberRefParentIndex = resolver.GetSizeOfIndex(CodedIndexes.MemberRefParent); byte sizeOfStringIndex = indexDetails.GetSizeOfStringIndex(); byte sizeOfBlobIndex = indexDetails.GetSizeOfBlobIndex(); _class = resolver.Resolve(CodedIndexes.MemberRefParent, FieldReader.ToUInt32(contents, offset.Shift(sizeOfMemberRefParentIndex), sizeOfMemberRefParentIndex) ); _name = new StringIndex(contents, sizeOfStringIndex, offset); _signiture = new BlobIndex(sizeOfBlobIndex, contents, Reflection.Signatures.Signatures.MethodDef, offset); }
/// <summary> /// Initialises a new instance of the DeclSecurityMetadataTableRow /// </summary> /// <param name="contents">The contents of the file</param> /// <param name="offset">The offset of the this row</param> public DeclSecurityMetadataTableRow(byte[] contents, Offset offset, ICodedIndexResolver resolver, IIndexDetails indexDetails) { this.FileOffset = offset; int declSecurityIndexSize = resolver.GetSizeOfIndex(CodedIndexes.HasDeclSecurity); byte sizeOfBlobIndex = indexDetails.GetSizeOfBlobIndex(); _action = BitConverter.ToUInt16(contents, offset.Shift(2)); _parentIndex = resolver.Resolve( CodedIndexes.HasDeclSecurity, FieldReader.ToUInt32(contents, offset.Shift(declSecurityIndexSize), declSecurityIndexSize) ); _permissionSet = FieldReader.ToUInt32(contents, offset.Shift(sizeOfBlobIndex), sizeOfBlobIndex); }
public void InterfaceImpl_WhenCreated_FieldsAreReadCorrectly() { byte[] contents = new byte[] { 0x01, 0x00, 0x00, 0x00 }; ICodedIndexResolver resolver = IndexHelper.CreateCodedIndexResolver(2); IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2); InterfaceImplMetadataTableRow row = new InterfaceImplMetadataTableRow(contents, 0, resolver, indexDetails); Assert.AreEqual(1, row.Class.Value); Assert.IsNotNull(row.Interface); }
/// <summary> /// Initialises a new instance of the ConstantMetadataTableRow /// </summary> /// <param name="contents">The contents fo the file</param> /// <param name="offset">The offset for the current row</param> public ConstantMetadataTableRow(byte[] contents, Offset offset, ICodedIndexResolver resolver, IIndexDetails indexDetails) { this.FileOffset = offset; int hasConstantIndexSize = resolver.GetSizeOfIndex(CodedIndexes.HasConstant); byte sizeOfBlobIndex = indexDetails.GetSizeOfBlobIndex(); _type = (Signatures.ElementTypes)contents[offset.Shift(1)]; offset.Shift(1); _parentIndex = resolver.Resolve( CodedIndexes.HasConstant, FieldReader.ToUInt32(contents, offset.Shift(hasConstantIndexSize), hasConstantIndexSize) ); _valueIndex = new BlobIndex(sizeOfBlobIndex, contents, Signatures.Signatures.MethodDef, offset); }
public void FieldMarshal_WhenCreated_FieldsAreReadCorrectly() { ICodedIndexResolver resolver = IndexHelper.CreateCodedIndexResolver(2); IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2); byte[] contents = new byte[] { 0x01, 0x00, 0x01, 0x00 }; FieldMarshalMetadataTableRow row = new FieldMarshalMetadataTableRow(contents, 0, resolver, indexDetails); Assert.AreEqual(1, row.NativeType); Assert.IsNotNull(row.Parent); }
/// <summary> /// Initialises a new instance of the ImplMapMetadataTableRow class /// </summary> /// <param name="content">The content of the file</param> /// <param name="offset">The offset of the current row</param> public ImplMapMetadataTableRow(byte[] content, Offset offset, ICodedIndexResolver resolver, IIndexDetails indexDetails) { this.FileOffset = offset; int sizeOfMemberForwardedIndex = resolver.GetSizeOfIndex(CodedIndexes.MemberForwarded); byte sizeOfStringIndex = indexDetails.GetSizeOfStringIndex(); byte sizeOfModuleRefIndex = indexDetails.GetSizeOfIndex(MetadataTables.ModuleRef); _mappingFlags = (PInvokeAttributes)FieldReader.ToUInt16(content, offset.Shift(2)); _memberForward = resolver.Resolve(CodedIndexes.MemberForwarded, FieldReader.ToUInt32(content, offset.Shift(sizeOfMemberForwardedIndex), sizeOfMemberForwardedIndex) ); _importName = new StringIndex(content, sizeOfStringIndex, offset); _importScope = new Index(content, offset, sizeOfModuleRefIndex); }
/// <summary> /// Initialises a new instance of the ManifestResourceMetadataTableRow class /// </summary> /// <param name="contents">The contents of the file</param> /// <param name="offset">The offset of this current row</param> public ManifestResourceMetadataTableRow(byte[] contents, Offset offset, ICodedIndexResolver resolver, IIndexDetails indexDetails) { this.FileOffset = offset; int sizeOfImplementationIndex = resolver.GetSizeOfIndex(CodedIndexes.Implementation); byte sizeOfStringIndex = indexDetails.GetSizeOfStringIndex(); _offset = BitConverter.ToUInt32(contents, offset.Shift(4)); _flags = (ManifestResourceAttributes)BitConverter.ToUInt32(contents, offset.Shift(4)); _name = new StringIndex(contents, sizeOfStringIndex, offset); _implementation = resolver.Resolve( CodedIndexes.Implementation, FieldReader.ToUInt32(contents, offset.Shift(sizeOfImplementationIndex), sizeOfImplementationIndex) ); }
public void MemberRef_WhenCreated_ReadFieldsCorrectly() { byte[] contents = new byte[] { 0x00, 0x00, 0x01, 0x00, 0x02, 0x00 }; ICodedIndexResolver resolver = IndexHelper.CreateCodedIndexResolver(2); IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2); MemberRefMetadataTableRow row = new MemberRefMetadataTableRow(contents, 0, resolver, indexDetails); Assert.IsNotNull(row.Class); Assert.AreEqual(1, row.Name.Value); Assert.AreEqual(2, row.Signiture.Value); }
/// <summary> /// Initialises a new instance of the ExportedTypeMetadataTableRow class /// </summary> /// <param name="contents">The contents of the file</param> /// <param name="offset">The offset of the current row</param> public ExportedTypeMetadataTableRow(byte[] contents, Offset offset, ICodedIndexResolver resolver, IIndexDetails indexDetails) { this.FileOffset = offset; byte sizeOfStringIndex = indexDetails.GetSizeOfStringIndex(); int sizeOfImplementationIndex = resolver.GetSizeOfIndex(CodedIndexes.Implementation); _flags = (TypeAttributes)FieldReader.ToUInt32(contents, offset.Shift(4)); _typeDefId = FieldReader.ToUInt32(contents, offset.Shift(4)); _typeNameIndex = new StringIndex(contents, sizeOfStringIndex, offset); _typeNamespaceIndex = new StringIndex(contents, sizeOfStringIndex, offset); _implementationIndex = resolver.Resolve( CodedIndexes.Implementation, FieldReader.ToUInt32(contents, offset.Shift(sizeOfImplementationIndex), sizeOfImplementationIndex) ); }
public void MethodSpec_WhenCreated_FieldsAreReadCorrectly() { ICodedIndexResolver resolver = IndexHelper.CreateCodedIndexResolver(2); byte[] contents = new byte[] { 0x01, 0x00, 0x01, 0x00 }; Offset offset = 0; IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2); MethodSpecMetadataTableRow row = new MethodSpecMetadataTableRow(contents, offset, resolver, indexDetails); Assert.IsNotNull(row.Method); Assert.AreEqual(1, row.Instantiation); }
public void TypeRef_WhenCreated_FieldsAreReadCorrectly() { byte[] contents = new byte[] { 0x00, 0x00, 0x01, 0x00, 0x02, 0x00 }; IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2); ICodedIndexResolver resolver = IndexHelper.CreateCodedIndexResolver(2); Offset offset = 0; TypeRefMetadataTableRow row = new TypeRefMetadataTableRow(contents, offset, resolver, indexDetails); Assert.IsNotNull(row.ResolutionScope); Assert.AreEqual(1, row.Name.Value); Assert.AreEqual(2, row.Namespace.Value); }
/// <summary> /// Initialises a new instance of the CustomAttributeMetadataTableRow /// </summary> /// <param name="contents">The contents of the file</param> /// <param name="offset">The offset of the current row</param> public CustomAttributeMetadataTableRow(byte[] contents, Offset offset, ICodedIndexResolver resolver, IIndexDetails indexDetails) { int hasCustomAttributeIndexSize = resolver.GetSizeOfIndex(CodedIndexes.HasCustomAttribute); int customAttributeIndexSize = resolver.GetSizeOfIndex(CodedIndexes.CustomAttributeType); byte sizeOfBlobIndex = indexDetails.GetSizeOfBlobIndex(); this.FileOffset = offset; _parentIndex = resolver.Resolve( CodedIndexes.HasCustomAttribute, FieldReader.ToUInt32(contents, offset.Shift(hasCustomAttributeIndexSize), hasCustomAttributeIndexSize) ); _typeIndex = resolver.Resolve(CodedIndexes.CustomAttributeType, FieldReader.ToUInt32(contents, offset.Shift(customAttributeIndexSize), customAttributeIndexSize) ); _value = FieldReader.ToUInt32(contents, offset.Shift(sizeOfBlobIndex), sizeOfBlobIndex); }
public void Event_WhenCreated_ReadValuesCorrectly() { ICodedIndexResolver resolver = IndexHelper.CreateCodedIndexResolver(2); IIndexDetails indexDetails = IndexHelper.CreateIndexDetails(2); byte[] contents = new byte[] { 0x00, 0x02, 0x01, 0x00, 0x01, 0x00 }; EventMetadataTableRow row = new EventMetadataTableRow(contents, 0, resolver, indexDetails); Assert.AreEqual(EventAttributes.SpecialName, row.EventFlags); Assert.IsNotNull(row.EventType); Assert.AreEqual(1, row.Name.Value); }