Example #1
0
 public Constant(ElementType constantType, DataBlobSignature value)
     : base(new MetadataToken(MetadataTokenType.Constant))
 {
     ConstantType = constantType;
     _value       = new LazyValue <DataBlobSignature>(value);
     _parent      = new LazyValue <IHasConstant>();
 }
Example #2
0
 internal FileDefinition(MetadataHeader header, MetadataToken token, MetadataRow <uint, uint, uint> row)
     : base(header, token, row)
 {
     Attributes = (FileAttributes)row.Column1;
     _name      = new LazyValue <string>(() => header.GetStream <StringStream>().GetStringByOffset(row.Column2));
     _hashValue = new LazyValue <DataBlobSignature>(() =>
                                                    DataBlobSignature.FromReader(header.GetStream <BlobStream>().CreateBlobReader(row.Column3)));
 }
Example #3
0
        public FileReference(string name, FileAttributes attributes, DataBlobSignature hashValue)
            : base(new MetadataToken(MetadataTokenType.File))
        {
            _name      = new LazyValue <string>(name);
            _hashValue = new LazyValue <DataBlobSignature>(hashValue);
            Attributes = attributes;

            CustomAttributes = new CustomAttributeCollection(this);
        }
Example #4
0
        /// <inheritdoc />
        protected override DataBlobSignature GetValue()
        {
            var reader = _parentModule.DotNetDirectory.Metadata
                         .GetStream <BlobStream>()
                         .GetBlobReaderByIndex(_row.Value);

            return(reader is null
                ? null
                : DataBlobSignature.FromReader(reader));
        }
Example #5
0
        internal FileReference(MetadataImage image, MetadataRow <FileAttributes, uint, uint> row)
            : base(row.MetadataToken)
        {
            _image     = image;
            Attributes = row.Column1;

            _name = new LazyValue <string>(()
                                           => image.Header.GetStream <StringStream>().GetStringByOffset(row.Column2));

            _hashValue = new LazyValue <DataBlobSignature>(() =>
                                                           DataBlobSignature.FromReader(image.Header.GetStream <BlobStream>().CreateBlobReader(row.Column3)));

            CustomAttributes = new CustomAttributeCollection(this);
        }
Example #6
0
        internal Constant(MetadataHeader header, MetadataToken token, MetadataRow <byte, byte, uint, uint> row)
            : base(header, token, row)
        {
            ConstantType = (ElementType)row.Column1;

            _parent = new LazyValue <IHasConstant>(() =>
            {
                var tableStream      = header.GetStream <TableStream>();
                var hasConstantToken = tableStream.GetIndexEncoder(CodedIndex.HasConstant).DecodeIndex(row.Column3);
                return(hasConstantToken.Rid != 0 ? (IHasConstant)tableStream.ResolveMember(hasConstantToken) : null);
            });

            _value = new LazyValue <DataBlobSignature>(() =>
                                                       DataBlobSignature.FromReader(header.GetStream <BlobStream>().CreateBlobReader(row.Column4)));
        }
Example #7
0
        internal AssemblyDefinition(MetadataImage image, MetadataRow <AssemblyHashAlgorithm, ushort, ushort, ushort, ushort, AssemblyAttributes, uint, uint, uint> row)
            : base(row.MetadataToken)
        {
            Image = image;
            var tableStream  = image.Header.GetStream <TableStream>();
            var stringStream = image.Header.GetStream <StringStream>();
            var blobStream   = image.Header.GetStream <BlobStream>();

            HashAlgorithm = row.Column1;
            Version       = new Version(row.Column2, row.Column3, row.Column4, row.Column5);
            Attributes    = row.Column6;

            _publicKey = new LazyValue <DataBlobSignature>(() =>
                                                           row.Column7 == 0 ? null : DataBlobSignature.FromReader(blobStream.CreateBlobReader(row.Column7)));

            _name = new LazyValue <string>(() =>
                                           stringStream.GetStringByOffset(row.Column8));

            _culture = new LazyValue <string>(() =>
                                              stringStream.GetStringByOffset(row.Column9));

            Modules = new TableMemberCollection <AssemblyDefinition, ModuleDefinition>(
                this, tableStream.GetTable(MetadataTokenType.Module), GetModuleOwner, SetModuleOwner);

            AssemblyReferences = new TableMemberCollection <AssemblyDefinition, AssemblyReference>(
                this, tableStream.GetTable(MetadataTokenType.AssemblyRef), GetReferenceOwner, SetReferenceOwner);

            ModuleReferences = new TableMemberCollection <AssemblyDefinition, ModuleReference>(
                this, tableStream.GetTable(MetadataTokenType.ModuleRef), GetReferenceOwner, SetReferenceOwner);

            Resources = new TableMemberCollection <AssemblyDefinition, ManifestResource>(
                this, tableStream.GetTable(MetadataTokenType.ManifestResource), GetResourceOwner, SetResourceOwner);

            Files = new TableMemberCollection <AssemblyDefinition, FileReference>(
                this, tableStream.GetTable(MetadataTokenType.File), GetFileOwner, SetFileOwner);

            CustomAttributes     = new CustomAttributeCollection(this);
            SecurityDeclarations = new SecurityDeclarationCollection(this);

            OperatingSystems = new TableMemberCollection <AssemblyDefinition, AssemblyOs>(
                this, tableStream.GetTable(MetadataTokenType.AssemblyOs), GetOsOwner, SetOsOwner);

            Processors = new TableMemberCollection <AssemblyDefinition, AssemblyProcessor>(
                this, tableStream.GetTable(MetadataTokenType.AssemblyProcessor), GetProcessorOwner, SetProcessorOwner);
        }
        public void PersistentPublicKey()
        {
            var newPublicKey = new DataBlobSignature(new byte[] { 0x1, 0x2, 0x3, 0x4 });

            var assembly = NetAssemblyFactory.CreateAssembly(DummyAssemblyName, true);
            var header   = assembly.NetDirectory.MetadataHeader;

            var image = header.LockMetadata();

            image.Assembly.PublicKey = newPublicKey;
            header.UnlockMetadata();

            var assemblyRow = header.GetStream <TableStream>().GetTable <AssemblyDefinitionTable>()[0];

            Assert.Equal(newPublicKey.Data, header.GetStream <BlobStream>().GetBlobByOffset(assemblyRow.Column7));

            image = header.LockMetadata();
            Assert.Equal(newPublicKey.Data, image.Assembly.PublicKey.Data);
        }
        public void PersistentHashValue()
        {
            var newHashValue = new DataBlobSignature(new byte[] { 0x1, 0x2, 0x3, 0x4 });

            var assembly = NetAssemblyFactory.CreateAssembly(DummyAssemblyName, true);
            var header   = assembly.NetDirectory.MetadataHeader;

            var image     = header.LockMetadata();
            var reference = CreateAndAddDummyReference(image);

            reference.HashValue = newHashValue;

            var mapping     = header.UnlockMetadata();
            var assemblyRow = header.GetStream <TableStream>().GetTable <AssemblyReferenceTable>()[(int)(mapping[reference].Rid - 1)];

            Assert.Equal(newHashValue.Data, header.GetStream <BlobStream>().GetBlobByOffset(assemblyRow.Column9));

            image = header.LockMetadata();
            var newReference = (AssemblyReference)image.ResolveMember(mapping[reference]);

            Assert.Equal(newHashValue.Data, newReference.HashValue.Data);
        }
Example #10
0
        internal AssemblyReference(MetadataImage image, MetadataRow <ushort, ushort, ushort, ushort, AssemblyAttributes, uint, uint, uint, uint> row)
            : base(row.MetadataToken)
        {
            var stringStream = image.Header.GetStream <StringStream>();
            var blobStream   = image.Header.GetStream <BlobStream>();

            Version    = new Version(row.Column1, row.Column2, row.Column3, row.Column4);
            Attributes = row.Column5;
            _publicKey = new LazyValue <DataBlobSignature>(() => row.Column6 == 0 ? null : DataBlobSignature.FromReader(blobStream.CreateBlobReader(row.Column6)));
            _name      = new LazyValue <string>(() => stringStream.GetStringByOffset(row.Column7));
            _culture   = new LazyValue <string>(() => stringStream.GetStringByOffset(row.Column8));
            _hashValue = new LazyValue <DataBlobSignature>(() => row.Column9 == 0 ? null : DataBlobSignature.FromReader(blobStream.CreateBlobReader(row.Column9)));

            Referrer         = image.Assembly;
            CustomAttributes = new CustomAttributeCollection(this);
            OperatingSystems = new TableMemberCollection <AssemblyReference, AssemblyRefOs>(this, MetadataTokenType.AssemblyRefOs, GetOsOwner, SetOsOwner);
            Processors       = new TableMemberCollection <AssemblyReference, AssemblyRefProcessor>(this, MetadataTokenType.AssemblyRefProcessor, GetProcessorOwner, SetProcessorOwner);
        }
Example #11
0
        internal AssemblyDefinition(MetadataHeader header, MetadataToken token,
                                    MetadataRow <uint, ushort, ushort, ushort, ushort, uint, uint, uint, uint> row)
            : base(header, token, row)
        {
            var stringStream = header.GetStream <StringStream>();
            var blobStream   = header.GetStream <BlobStream>();

            HashAlgorithm = (AssemblyHashAlgorithm)row.Column1;
            Version       = new Version(row.Column2, row.Column3, row.Column4, row.Column5);
            Attributes    = (AssemblyAttributes)row.Column6;
            _publicKey    = new LazyValue <DataBlobSignature>(() => row.Column7 == 0 ? null : DataBlobSignature.FromReader(blobStream.CreateBlobReader(row.Column7)));
            _name         = new LazyValue <string>(() => stringStream.GetStringByOffset(row.Column8));
            _culture      = new LazyValue <string>(() => stringStream.GetStringByOffset(row.Column9));
        }
Example #12
0
 /// <summary>
 /// Creates a new constant for a member, with the provided constant type and raw literal value.
 /// </summary>
 /// <param name="type">The type of the constant.</param>
 /// <param name="value">The raw literal value of the constant.</param>
 public Constant(ElementType type, DataBlobSignature value)
     : this(new MetadataToken(TableIndex.Constant, 0))
 {
     Type  = type;
     Value = value;
 }