• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Ecma335.MetadataBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Reflection.Metadata.Ecma335.MetadataBuilder的典型用法代码示例。如果您正苦于以下问题:C# MetadataBuilder类的具体用法?C# MetadataBuilder怎么用?C# MetadataBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MetadataBuilder类属于System.Reflection.Metadata.Ecma335命名空间,在下文中一共展示了MetadataBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: WritePEImage

        private static void WritePEImage(
            Stream peStream, 
            MetadataBuilder metadataBuilder, 
            BlobBuilder ilBuilder, 
            MethodDefinitionHandle entryPointHandle,
            Blob mvidFixup = default(Blob),
            byte[] privateKeyOpt = null)
        {
            var peBuilder = new ManagedPEBuilder(
                entryPointHandle.IsNil ? PEHeaderBuilder.CreateLibraryHeader() : PEHeaderBuilder.CreateExecutableHeader(),
                new MetadataRootBuilder(metadataBuilder),
                ilBuilder,
                entryPoint: entryPointHandle,
                flags: CorFlags.ILOnly | (privateKeyOpt != null ? CorFlags.StrongNameSigned : 0),
                deterministicIdProvider: content => s_contentId);

            var peBlob = new BlobBuilder();

            var contentId = peBuilder.Serialize(peBlob);

            if (!mvidFixup.IsDefault)
            {
                new BlobWriter(mvidFixup).WriteGuid(contentId.Guid);
            }

            if (privateKeyOpt != null)
            {
                peBuilder.Sign(peBlob, content => SigningUtilities.CalculateRsaSignature(content, privateKeyOpt));
            }

            peBlob.WriteContentTo(peStream);
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:32,代码来源:PEBuilderTests.cs


示例2: Baseline

        public void Baseline()
        {
            var mdBuilder = new MetadataBuilder();

            mdBuilder.AddModule(0, default(StringHandle), default(GuidHandle), default(GuidHandle), default(GuidHandle));

            var rootBuilder = new MetadataRootBuilder(mdBuilder);
            var mdBlob = new BlobBuilder();
            rootBuilder.Serialize(mdBlob, 0, 0);

            // validate sizes table rows that reference guids:
            using (var mdProvider = MetadataReaderProvider.FromMetadataImage(mdBlob.ToImmutableArray()))
            {
                var mdReader = mdProvider.GetMetadataReader();

                Assert.Equal(2 + 3 * 2 + 2, mdReader.ModuleTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.TypeRefTable.RowSize);
                Assert.Equal(4 + 2 + 2 + 2 + 2 + 2, mdReader.TypeDefTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.FieldTable.RowSize);
                Assert.Equal(8 + 2 + 2 + 2, mdReader.MethodDefTable.RowSize);
                Assert.Equal(4 + 2, mdReader.ParamTable.RowSize);
                Assert.Equal(2 + 2, mdReader.InterfaceImplTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.MemberRefTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.ConstantTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.CustomAttributeTable.RowSize);
                Assert.Equal(2 + 2, mdReader.FieldMarshalTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.DeclSecurityTable.RowSize);
                Assert.Equal(6 + 2, mdReader.ClassLayoutTable.RowSize);
                Assert.Equal(4 + 2, mdReader.FieldLayoutTable.RowSize);
                Assert.Equal(2, mdReader.StandAloneSigTable.RowSize);
                Assert.Equal(2 + 2, mdReader.EventMapTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.EventTable.RowSize);
                Assert.Equal(2 + 2, mdReader.PropertyMapTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.PropertyTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.MethodSemanticsTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.MethodImplTable.RowSize);
                Assert.Equal(2, mdReader.ModuleRefTable.RowSize);
                Assert.Equal(2, mdReader.TypeSpecTable.RowSize);
                Assert.Equal(2 + 2 + 2 + 2, mdReader.ImplMapTable.RowSize);
                Assert.Equal(4 + 2, mdReader.FieldRvaTable.RowSize);
                Assert.Equal(16 + 2 + 2 + 2, mdReader.AssemblyTable.RowSize);
                Assert.Equal(12 + 2 + 2 + 2 + 2, mdReader.AssemblyRefTable.RowSize);
                Assert.Equal(4 + 2 + 2, mdReader.FileTable.RowSize);
                Assert.Equal(8 + 2 + 2 + 2, mdReader.ExportedTypeTable.RowSize);
                Assert.Equal(8 + 2 + 2, mdReader.ManifestResourceTable.RowSize);
                Assert.Equal(2 + 2, mdReader.NestedClassTable.RowSize);
                Assert.Equal(4 + 2 + 2, mdReader.GenericParamTable.RowSize);
                Assert.Equal(2 + 2, mdReader.MethodSpecTable.RowSize);
                Assert.Equal(2 + 2, mdReader.GenericParamConstraintTable.RowSize);
                Assert.Equal(2 + 2 + 2 + 2, mdReader.DocumentTable.RowSize);
                Assert.Equal(2 + 2, mdReader.MethodDebugInformationTable.RowSize);
                Assert.Equal(2 + 2 + 2 + 2 + 4 + 4, mdReader.LocalScopeTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.LocalVariableTable.RowSize);
                Assert.Equal(2 + 2, mdReader.LocalConstantTable.RowSize);
                Assert.Equal(2 + 2, mdReader.ImportScopeTable.RowSize);
                Assert.Equal(2 + 2, mdReader.StateMachineMethodTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.CustomDebugInformationTable.RowSize);
            }
        }
开发者ID:AndreGleichner,项目名称:corefx,代码行数:59,代码来源:LargeTablesAndHeapsTests.cs


示例3: TypeSystemMetadataSerializer

 public TypeSystemMetadataSerializer(
     MetadataBuilder tables, 
     string metadataVersion,
     bool isMinimalDelta)
     : base(tables, CreateSizes(tables, EmptyRowCounts, isMinimalDelta, isStandaloneDebugMetadata: false), metadataVersion)
 {
     
 }
开发者ID:nbilling,项目名称:corefx,代码行数:8,代码来源:MetadataSerializer.cs


示例4: StandaloneDebugMetadataSerializer

 public StandaloneDebugMetadataSerializer(
     MetadataBuilder builder, 
     ImmutableArray<int> typeSystemRowCounts,
     MethodDefinitionHandle entryPoint,
     bool isMinimalDelta)
     : base(builder, CreateSizes(builder, typeSystemRowCounts, isMinimalDelta, isStandaloneDebugMetadata: true), DebugMetadataVersionString)
 {
     _entryPoint = entryPoint;
 }
开发者ID:nbilling,项目名称:corefx,代码行数:9,代码来源:MetadataSerializer.cs


示例5: BuildMetadataImage

        private static BlobBuilder BuildMetadataImage()
        {
            var mdBuilder = new MetadataBuilder();
            mdBuilder.AddModule(0, default(StringHandle), default(GuidHandle), default(GuidHandle), default(GuidHandle));

            var rootBuilder = new MetadataRootBuilder(mdBuilder, "v9.9.9.9");

            var builder = new BlobBuilder();
            rootBuilder.Serialize(builder, 0, 0);

            return builder;
        }
开发者ID:swaroop-sridhar,项目名称:corefx,代码行数:12,代码来源:MetadataReaderProviderTests.cs


示例6: BasicValidation

        public void BasicValidation()
        {
            using (var peStream = new MemoryStream())
            {
                var ilBuilder = new BlobBuilder();
                var metadataBuilder = new MetadataBuilder();
                var entryPoint = BasicValidationEmit(metadataBuilder, ilBuilder);
                WritePEImage(peStream, metadataBuilder, ilBuilder, entryPoint);

                peStream.Position = 0;
                VerifyPE(peStream);
            }
        }
开发者ID:MichalStrehovsky,项目名称:corefx,代码行数:13,代码来源:PEBuilderTests.cs


示例7: WritePEImage

        private static void WritePEImage(Stream peStream, MetadataBuilder metadataBuilder, BlobBuilder ilBuilder, MethodDefinitionHandle entryPointHandle)
        {
            var mappedFieldDataBuilder = new BlobBuilder();
            var managedResourceDataBuilder = new BlobBuilder();

            var peBuilder = new PEBuilder(
                machine: 0,
                sectionAlignment: 0x2000,
                fileAlignment: 0x200,
                imageBase: 0x00400000,
                majorLinkerVersion: 0x30, // (what is ref.emit using?)
                minorLinkerVersion: 0,
                majorOperatingSystemVersion: 4,
                minorOperatingSystemVersion: 0,
                majorImageVersion: 0,
                minorImageVersion: 0,
                majorSubsystemVersion: 4,
                minorSubsystemVersion: 0,
                subsystem: Subsystem.WindowsCui,
                dllCharacteristics: DllCharacteristics.DynamicBase | DllCharacteristics.NxCompatible | DllCharacteristics.NoSeh | DllCharacteristics.TerminalServerAware,
                imageCharacteristics: entryPointHandle.IsNil ? Characteristics.Dll : Characteristics.ExecutableImage,
                sizeOfStackReserve: 0x00100000,
                sizeOfStackCommit: 0x1000,
                sizeOfHeapReserve: 0x00100000,
                sizeOfHeapCommit: 0x1000);

            var peDirectoriesBuilder = new PEDirectoriesBuilder();

            peBuilder.AddManagedSections(
                peDirectoriesBuilder,
                new TypeSystemMetadataSerializer(metadataBuilder, "v4.0.30319", isMinimalDelta: false),
                ilBuilder,
                mappedFieldDataBuilder,
                managedResourceDataBuilder,
                nativeResourceSectionSerializer: null,
                strongNameSignatureSize: 0,
                entryPoint: entryPointHandle,
                pdbPathOpt: null,
                nativePdbContentId: default(ContentId),
                portablePdbContentId: default(ContentId),
                corFlags: CorFlags.ILOnly);

            var peBlob = new BlobBuilder();
            ContentId peContentId;
            peBuilder.Serialize(peBlob, peDirectoriesBuilder, out peContentId);

            peBlob.WriteContentTo(peStream);
        }
开发者ID:MichalStrehovsky,项目名称:corefx,代码行数:48,代码来源:PEBuilderTests.cs


示例8: BuildPEWithDebugDirectory

        public static byte[] BuildPEWithDebugDirectory(DebugDirectoryBuilder debugDirectoryBuilder)
        {
            var peStream = new MemoryStream();
            var ilBuilder = new BlobBuilder();
            var metadataBuilder = new MetadataBuilder();

            var peBuilder = new ManagedPEBuilder(
                PEHeaderBuilder.CreateLibraryHeader(),
                new MetadataRootBuilder(metadataBuilder),
                ilBuilder,
                debugDirectoryBuilder: debugDirectoryBuilder);

            var peImageBuilder = new BlobBuilder();
            peBuilder.Serialize(peImageBuilder);
            return peImageBuilder.ToArray();
        }
开发者ID:Corillian,项目名称:corefx,代码行数:16,代码来源:TestBuilders.cs


示例9: MetadataRootBuilder

        /// <summary>
        /// Creates a builder of a metadata root.
        /// </summary>
        /// <param name="tablesAndHeaps">
        /// Builder populated with metadata entities stored in tables and values stored in heaps.
        /// The entities and values will be enumerated when serializing the metadata root.
        /// </param>
        /// <param name="metadataVersion">
        /// The version string written to the metadata header. The default value is "v4.0.30319".
        /// </param>
        /// <exception cref="ArgumentNullException"><paramref name="tablesAndHeaps"/> is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="metadataVersion"/> is too long (the number of bytes when UTF8-encoded must be less than 255).</exception>
        public MetadataRootBuilder(MetadataBuilder tablesAndHeaps, string metadataVersion = null)
        {
            if (tablesAndHeaps == null)
            {
                Throw.ArgumentNull(nameof(tablesAndHeaps));
            }

            Debug.Assert(BlobUtilities.GetUTF8ByteCount(DefaultMetadataVersionString) == DefaultMetadataVersionString.Length);
            int metadataVersionByteCount = metadataVersion != null ? BlobUtilities.GetUTF8ByteCount(metadataVersion) : DefaultMetadataVersionString.Length;

            if (metadataVersionByteCount > MetadataSizes.MaxMetadataVersionByteCount)
            {
                Throw.InvalidArgument(SR.MetadataVersionTooLong, nameof(metadataVersion));
            }

            _tablesAndHeaps = tablesAndHeaps;
            MetadataVersion = metadataVersion ?? DefaultMetadataVersionString;
            _serializedMetadata = tablesAndHeaps.GetSerializedMetadata(EmptyRowCounts, metadataVersionByteCount, isStandaloneDebugMetadata: false);
        }
开发者ID:AndreGleichner,项目名称:corefx,代码行数:31,代码来源:MetadataRootBuilder.cs


示例10: PortablePdbBuilder

        /// <summary>
        /// Creates a builder of a Portable PDB image.
        /// </summary>
        /// <param name="tablesAndHeaps">
        /// Builder populated with debug metadata entities stored in tables and values stored in heaps.
        /// The entities and values will be enumerated when serializing the Portable PDB image.
        /// </param>
        /// <param name="typeSystemRowCounts">
        /// Row counts of all tables that the associated type-system metadata contain.
        /// Each slot in the array corresponds to a table (<see cref="TableIndex"/>).
        /// The length of the array must be equal to <see cref="MetadataTokens.TableCount"/>.
        /// </param>
        /// <param name="entryPoint">
        /// Entry point method definition handle.
        /// </param>
        /// <param name="idProvider">
        /// Function calculating id of content represented as a sequence of blobs.
        /// If not specified a default function that ignores the content and returns current time-based content id is used 
        /// (<see cref="BlobContentId.GetTimeBasedProvider()"/>).
        /// You must specify a deterministic function to produce a deterministic Portable PDB image.
        /// </param>
        /// <exception cref="ArgumentNullException"><paramref name="tablesAndHeaps"/> or <paramref name="typeSystemRowCounts"/> is null.</exception>
        public PortablePdbBuilder(
            MetadataBuilder tablesAndHeaps, 
            ImmutableArray<int> typeSystemRowCounts,
            MethodDefinitionHandle entryPoint,
            Func<IEnumerable<Blob>, BlobContentId> idProvider = null)
        {
            if (tablesAndHeaps == null)
            {
                Throw.ArgumentNull(nameof(tablesAndHeaps));
            }

            ValidateTypeSystemRowCounts(typeSystemRowCounts);
            
            _builder = tablesAndHeaps;
            _entryPoint = entryPoint;

            Debug.Assert(BlobUtilities.GetUTF8ByteCount(MetadataVersion) == MetadataVersion.Length);
            _serializedMetadata = tablesAndHeaps.GetSerializedMetadata(typeSystemRowCounts, MetadataVersion.Length, isStandaloneDebugMetadata: true);

            IdProvider = idProvider ?? BlobContentId.GetTimeBasedProvider();
        }
开发者ID:AndreGleichner,项目名称:corefx,代码行数:43,代码来源:PortablePdbBuilder.cs


示例11: Complex

        public void Complex()
        {
            using (var peStream = new MemoryStream())
            {
                var ilBuilder = new BlobBuilder();
                var metadataBuilder = new MetadataBuilder();
                Blob mvidFixup;
                var entryPoint = ComplexEmit(metadataBuilder, ilBuilder, out mvidFixup);

                WritePEImage(peStream, metadataBuilder, ilBuilder, entryPoint, mvidFixup);
                VerifyPE(peStream);
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:13,代码来源:PEBuilderTests.cs


示例12: Others

        public void Others()
        {
            var mdBuilder = new MetadataBuilder();

            mdBuilder.SetCapacity(TableIndex.Constant, 0x10000);
            mdBuilder.SetCapacity(TableIndex.CustomAttribute, 0x10000);
            mdBuilder.SetCapacity(TableIndex.FieldMarshal, 0x10000);
            mdBuilder.SetCapacity(TableIndex.EventMap, 0x10000);
            mdBuilder.SetCapacity(TableIndex.PropertyMap, 0x10000);
            mdBuilder.SetCapacity(TableIndex.MethodSemantics, 0x10000);
            mdBuilder.SetCapacity(TableIndex.MethodImpl, 0x10000);
            mdBuilder.SetCapacity(TableIndex.NestedClass, 0x10000);
            mdBuilder.SetCapacity(TableIndex.CustomDebugInformation, 0x10000);
            object one = 1;

            for (int i = 0; i < 0x10000; i++)
            {
                mdBuilder.AddConstant(default(ParameterHandle), one);
                mdBuilder.AddCustomAttribute(default(ParameterHandle), default(MethodDefinitionHandle), default(BlobHandle));
                mdBuilder.AddMarshallingDescriptor(default(ParameterHandle), default(BlobHandle));
                mdBuilder.AddEventMap(default(TypeDefinitionHandle), default(EventDefinitionHandle));
                mdBuilder.AddPropertyMap(default(TypeDefinitionHandle), default(PropertyDefinitionHandle));
                mdBuilder.AddMethodSemantics(default(EventDefinitionHandle), 0, default(MethodDefinitionHandle));
                mdBuilder.AddMethodImplementation(default(TypeDefinitionHandle), default(MethodDefinitionHandle), default(MethodDefinitionHandle));
                mdBuilder.AddNestedType(default(TypeDefinitionHandle), default(TypeDefinitionHandle));
                mdBuilder.AddCustomDebugInformation(default(ParameterHandle), default(GuidHandle), default(BlobHandle));
            }

            mdBuilder.AddModule(0, default(StringHandle), default(GuidHandle), default(GuidHandle), default(GuidHandle));

            var rootBuilder = new MetadataRootBuilder(mdBuilder);
            var mdBlob = new BlobBuilder();
            rootBuilder.Serialize(mdBlob, 0, 0);

            // validate sizes table rows that reference guids:
            using (var mdProvider = MetadataReaderProvider.FromMetadataImage(mdBlob.ToImmutableArray()))
            {
                var mdReader = mdProvider.GetMetadataReader();

                Assert.Equal(2 + 3 * 2 + 2, mdReader.ModuleTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.TypeRefTable.RowSize);
                Assert.Equal(4 + 2 + 2 + 2 + 2 + 2, mdReader.TypeDefTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.FieldTable.RowSize);
                Assert.Equal(8 + 2 + 2 + 2, mdReader.MethodDefTable.RowSize);
                Assert.Equal(4 + 2, mdReader.ParamTable.RowSize);
                Assert.Equal(2 + 2, mdReader.InterfaceImplTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.MemberRefTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.ConstantTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.CustomAttributeTable.RowSize);
                Assert.Equal(2 + 2, mdReader.FieldMarshalTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.DeclSecurityTable.RowSize);
                Assert.Equal(6 + 2, mdReader.ClassLayoutTable.RowSize);
                Assert.Equal(4 + 2, mdReader.FieldLayoutTable.RowSize);
                Assert.Equal(2, mdReader.StandAloneSigTable.RowSize);
                Assert.Equal(2 + 2, mdReader.EventMapTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.EventTable.RowSize);
                Assert.Equal(2 + 2, mdReader.PropertyMapTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.PropertyTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.MethodSemanticsTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.MethodImplTable.RowSize);
                Assert.Equal(2, mdReader.ModuleRefTable.RowSize);
                Assert.Equal(2, mdReader.TypeSpecTable.RowSize);
                Assert.Equal(2 + 2 + 2 + 2, mdReader.ImplMapTable.RowSize);
                Assert.Equal(4 + 2, mdReader.FieldRvaTable.RowSize);
                Assert.Equal(16 + 2 + 2 + 2, mdReader.AssemblyTable.RowSize);
                Assert.Equal(12 + 2 + 2 + 2 + 2, mdReader.AssemblyRefTable.RowSize);
                Assert.Equal(4 + 2 + 2, mdReader.FileTable.RowSize);
                Assert.Equal(8 + 2 + 2 + 2, mdReader.ExportedTypeTable.RowSize);
                Assert.Equal(8 + 2 + 2, mdReader.ManifestResourceTable.RowSize);
                Assert.Equal(2 + 2, mdReader.NestedClassTable.RowSize);
                Assert.Equal(4 + 2 + 2, mdReader.GenericParamTable.RowSize);
                Assert.Equal(2 + 2, mdReader.MethodSpecTable.RowSize);
                Assert.Equal(2 + 2, mdReader.GenericParamConstraintTable.RowSize);
                Assert.Equal(2 + 2 + 2 + 2, mdReader.DocumentTable.RowSize);
                Assert.Equal(2 + 2, mdReader.MethodDebugInformationTable.RowSize);
                Assert.Equal(2 + 2 + 2 + 2 + 4 + 4, mdReader.LocalScopeTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.LocalVariableTable.RowSize);
                Assert.Equal(2 + 2, mdReader.LocalConstantTable.RowSize);
                Assert.Equal(2 + 2, mdReader.ImportScopeTable.RowSize);
                Assert.Equal(2 + 2, mdReader.StateMachineMethodTable.RowSize);
                Assert.Equal(2 + 2 + 2, mdReader.CustomDebugInformationTable.RowSize);
            }
        }
开发者ID:AndreGleichner,项目名称:corefx,代码行数:83,代码来源:LargeTablesAndHeapsTests.cs


示例13: NativeResources

        public unsafe void NativeResources()
        {
            var peStream = new MemoryStream();
            var ilBuilder = new BlobBuilder();
            var metadataBuilder = new MetadataBuilder();
            
            var peBuilder = new ManagedPEBuilder(
                PEHeaderBuilder.CreateLibraryHeader(),
                new MetadataRootBuilder(metadataBuilder),
                ilBuilder,
                nativeResources: new TestResourceSectionBuilder(),
                deterministicIdProvider: content => s_contentId);
            
            var peBlob = new BlobBuilder();
            
            var contentId = peBuilder.Serialize(peBlob);
            
            peBlob.WriteContentTo(peStream);

            peStream.Position = 0;
            var peReader = new PEReader(peStream);
            var sectionHeader = peReader.PEHeaders.SectionHeaders.Single(s => s.Name == ".rsrc");

            var image = peReader.GetEntireImage();

            var reader = new BlobReader(image.Pointer + sectionHeader.PointerToRawData, sectionHeader.SizeOfRawData);
            Assert.Equal(0x12345678, reader.ReadInt32());
            Assert.Equal(sectionHeader.PointerToRawData, reader.ReadInt32());
            Assert.Equal(sectionHeader.VirtualAddress, reader.ReadInt32());
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:30,代码来源:PEBuilderTests.cs


示例14: BasicValidationEmit

        private static MethodDefinitionHandle BasicValidationEmit(MetadataBuilder metadata, BlobBuilder ilBuilder)
        {
            metadata.AddModule(
                0, 
                metadata.GetOrAddString("ConsoleApplication.exe"), 
                metadata.GetOrAddGuid(Guid.NewGuid()),
                default(GuidHandle), 
                default(GuidHandle));

            metadata.AddAssembly(
                metadata.GetOrAddString("ConsoleApplication"),
                version: new Version(0, 0, 0, 0),
                culture: default(StringHandle),
                publicKey: default(BlobHandle),
                flags: default(AssemblyFlags),
                hashAlgorithm: AssemblyHashAlgorithm.Sha1);

            var mscorlibAssemblyRef = metadata.AddAssemblyReference(
                name: metadata.GetOrAddString("mscorlib"),
                version: new Version(4, 0, 0, 0),
                culture: default(StringHandle),
                publicKeyOrToken: metadata.GetOrAddBlob(ImmutableArray.Create<byte>(0xB7, 0x7A, 0x5C, 0x56, 0x19, 0x34, 0xE0, 0x89)),
                flags: default(AssemblyFlags),
                hashValue: default(BlobHandle));

            var systemObjectTypeRef = metadata.AddTypeReference(
                mscorlibAssemblyRef,
                metadata.GetOrAddString("System"),
                metadata.GetOrAddString("Object"));

            var systemConsoleTypeRefHandle = metadata.AddTypeReference(
                mscorlibAssemblyRef,
                metadata.GetOrAddString("System"),
                metadata.GetOrAddString("Console"));

            var consoleWriteLineSignature = new BlobBuilder();

            new BlobEncoder(consoleWriteLineSignature).
                MethodSignature().
                Parameters(1,
                    returnType => returnType.Void(),
                    parameters => parameters.AddParameter().Type().String());

            var consoleWriteLineMemberRef = metadata.AddMemberReference(
                systemConsoleTypeRefHandle,
                metadata.GetOrAddString("WriteLine"),
                metadata.GetOrAddBlob(consoleWriteLineSignature));

            var parameterlessCtorSignature = new BlobBuilder();

            new BlobEncoder(parameterlessCtorSignature).
                MethodSignature(isInstanceMethod: true).
                Parameters(0, returnType => returnType.Void(), parameters => { });

            var parameterlessCtorBlobIndex = metadata.GetOrAddBlob(parameterlessCtorSignature);

            var objectCtorMemberRef = metadata.AddMemberReference(
                systemObjectTypeRef,
                metadata.GetOrAddString(".ctor"),
                parameterlessCtorBlobIndex);

            var mainSignature = new BlobBuilder();

            new BlobEncoder(mainSignature).
                MethodSignature().
                Parameters(0, returnType => returnType.Void(), parameters => { });

            var methodBodies = new MethodBodiesEncoder(ilBuilder);

            var codeBuilder = new BlobBuilder();
            var branchBuilder = new BranchBuilder();
            InstructionEncoder il;

            //
            // Program::.ctor
            //
            int ctorBodyOffset;
            il = new InstructionEncoder(codeBuilder);

            // ldarg.0
            il.LoadArgument(0);

            // call instance void [mscorlib]System.Object::.ctor()
            il.Call(objectCtorMemberRef);

            // ret
            il.OpCode(ILOpCode.Ret);

            methodBodies.AddMethodBody().WriteInstructions(codeBuilder, out ctorBodyOffset);
            codeBuilder.Clear();

            //
            // Program::Main
            //
            int mainBodyOffset;
            il = new InstructionEncoder(codeBuilder, branchBuilder);
            var endLabel = il.DefineLabel();

            // .try
            int tryOffset = il.Offset;
//.........这里部分代码省略.........
开发者ID:MichalStrehovsky,项目名称:corefx,代码行数:101,代码来源:PEBuilderTests.cs


示例15: NativeResources_BadImpl

        public unsafe void NativeResources_BadImpl()
        {
            var peStream = new MemoryStream();
            var ilBuilder = new BlobBuilder();
            var metadataBuilder = new MetadataBuilder();

            var peBuilder = new ManagedPEBuilder(
                PEHeaderBuilder.CreateLibraryHeader(),
                new MetadataRootBuilder(metadataBuilder),
                ilBuilder,
                nativeResources: new BadResourceSectionBuilder(),
                deterministicIdProvider: content => s_contentId);

            var peBlob = new BlobBuilder();

            Assert.Throws<NotImplementedException>(() => peBuilder.Serialize(peBlob));
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:17,代码来源:PEBuilderTests.cs


示例16: ComplexEmit

        private static MethodDefinitionHandle ComplexEmit(MetadataBuilder metadata, BlobBuilder ilBuilder)
        {
            metadata.AddModule(
                0,
                metadata.GetOrAddString("ConsoleApplication.exe"),
                metadata.GetOrAddGuid(Guid.NewGuid()),
                default(GuidHandle),
                default(GuidHandle));

            metadata.AddAssembly(
                metadata.GetOrAddString("ConsoleApplication"),
                version: new Version(0, 0, 0, 0),
                culture: default(StringHandle),
                publicKey: default(BlobHandle),
                flags: default(AssemblyFlags),
                hashAlgorithm: AssemblyHashAlgorithm.Sha1);

            var mscorlibAssemblyRef = metadata.AddAssemblyReference(
                name: metadata.GetOrAddString("mscorlib"),
                version: new Version(4, 0, 0, 0),
                culture: default(StringHandle),
                publicKeyOrToken: metadata.GetOrAddBlob(ImmutableArray.Create<byte>(0xB7, 0x7A, 0x5C, 0x56, 0x19, 0x34, 0xE0, 0x89)),
                flags: default(AssemblyFlags),
                hashValue: default(BlobHandle));

            // TypeRefs:

            var systemObjectTypeRef = metadata.AddTypeReference(mscorlibAssemblyRef, metadata.GetOrAddString("System"), metadata.GetOrAddString("Object"));
            var dictionaryTypeRef = metadata.AddTypeReference(mscorlibAssemblyRef, metadata.GetOrAddString("System.Collections.Generic"), metadata.GetOrAddString("Dictionary`2"));
            var strignBuilderTypeRef = metadata.AddTypeReference(mscorlibAssemblyRef, metadata.GetOrAddString("System.Text"), metadata.GetOrAddString("StringBuilder"));
            var typeTypeRef = metadata.AddTypeReference(mscorlibAssemblyRef, metadata.GetOrAddString("System"), metadata.GetOrAddString("Type"));
            var int32TypeRef = metadata.AddTypeReference(mscorlibAssemblyRef, metadata.GetOrAddString("System"), metadata.GetOrAddString("Int32"));
            var runtimeTypeHandleRef = metadata.AddTypeReference(mscorlibAssemblyRef, metadata.GetOrAddString("System"), metadata.GetOrAddString("RuntimeTypeHandle"));
            var invalidOperationExceptionTypeRef = metadata.AddTypeReference(mscorlibAssemblyRef, metadata.GetOrAddString("System"), metadata.GetOrAddString("InvalidOperationException"));

            // TypeDefs:

            metadata.AddTypeDefinition(
               default(TypeAttributes),
               default(StringHandle),
               metadata.GetOrAddString("<Module>"),
               baseType: default(EntityHandle),
               fieldList: MetadataTokens.FieldDefinitionHandle(1),
               methodList: MetadataTokens.MethodDefinitionHandle(1));

            var baseClassTypeDef = metadata.AddTypeDefinition(
                TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.AutoLayout | TypeAttributes.BeforeFieldInit | TypeAttributes.Abstract,
                metadata.GetOrAddString("Lib"),
                metadata.GetOrAddString("BaseClass"),
                systemObjectTypeRef,
                fieldList: MetadataTokens.FieldDefinitionHandle(1),
                methodList: MetadataTokens.MethodDefinitionHandle(1));

            var derivedClassTypeDef = metadata.AddTypeDefinition(
                TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.AutoLayout | TypeAttributes.BeforeFieldInit,
                metadata.GetOrAddString("Lib"),
                metadata.GetOrAddString("DerivedClass"),
                baseClassTypeDef,
                fieldList: MetadataTokens.FieldDefinitionHandle(4),
                methodList: MetadataTokens.MethodDefinitionHandle(1));

            // FieldDefs:

            // Field1
            var baseClassNumberFieldDef = metadata.AddFieldDefinition(
                FieldAttributes.Private,
                metadata.GetOrAddString("_number"),
                metadata.GetOrAddBlob(BuildSignature(e => e.FieldSignature().Int32())));

            // Field2
            var baseClassNegativeFieldDef = metadata.AddFieldDefinition(
                FieldAttributes.Assembly,
                metadata.GetOrAddString("negative"),
                metadata.GetOrAddBlob(BuildSignature(e => e.FieldSignature().Boolean())));

            // Field3
            var derivedClassSumCacheFieldDef = metadata.AddFieldDefinition(
                FieldAttributes.Assembly,
                metadata.GetOrAddString("_sumCache"),
                metadata.GetOrAddBlob(BuildSignature(e => 
                {
                    var inst = e.FieldSignature().GenericInstantiation(isValueType: false, typeRefDefSpec: dictionaryTypeRef, genericArgumentCount: 2);
                    inst.AddArgument().Int32();
                    inst.AddArgument().Object();
                })));

            // Field4
            var derivedClassCountFieldDef = metadata.AddFieldDefinition(
                FieldAttributes.Assembly,
                metadata.GetOrAddString("_count"),
                metadata.GetOrAddBlob(BuildSignature(e => e.FieldSignature().SZArray().Int32())));

            // Field5
            var derivedClassBCFieldDef = metadata.AddFieldDefinition(
              FieldAttributes.Assembly,
              metadata.GetOrAddString("_bc"),
              metadata.GetOrAddBlob(BuildSignature(e => e.FieldSignature().TypeDefOrRefOrSpec(isValueType: false, typeRefDefSpec: baseClassTypeDef))));

            var methodBodies = new MethodBodiesEncoder(ilBuilder);

//.........这里部分代码省略.........
开发者ID:MichalStrehovsky,项目名称:corefx,代码行数:101,代码来源:PEBuilderTests.cs


示例17: MetadataSerializer

 public MetadataSerializer(MetadataBuilder tables, MetadataSizes sizes, string metadataVersion)
 {
     _tables = tables;
     _sizes = sizes;
     _metadataVersion = metadataVersion;
 }
开发者ID:nbilling,项目名称:corefx,代码行数:6,代码来源:MetadataSerializer.cs


示例18: CreateSizes

        internal static MetadataSizes CreateSizes(MetadataBuilder tables, ImmutableArray<int> externalRowCounts, bool isMinimalDelta, bool isStandaloneDebugMetadata)
        {
            tables.CompleteHeaps();

            return new MetadataSizes(
                tables.GetRowCounts(),
                externalRowCounts,
                tables.GetHeapSizes(),
                isMinimalDelta,
                isStandaloneDebugMetadata);
        }
开发者ID:nbilling,项目名称:corefx,代码行数:11,代码来源:MetadataSerializer.cs


示例19: HeapOverflow_UserString

        public void HeapOverflow_UserString()
        {
            string veryLargeString = new string('x', 0x00fffff0 / 2);

            var builder1 = new MetadataBuilder();
            Assert.Equal(0x70000001, MetadataTokens.GetToken(builder1.GetOrAddUserString(veryLargeString)));

            // TODO: https://github.com/dotnet/roslyn/issues/9852
            // Should throw: Assert.Throws<ImageFormatLimitationException>(() => builder1.GetOrAddUserString("123"));
            // Assert.Equal(0x70fffff6, MetadataTokens.GetToken(builder1.GetOrAddUserString("12")));
            // Assert.Equal(0x70fffff6, MetadataTokens.GetToken(builder1.GetOrAddUserString("12")));
            Assert.Equal(0x70fffff6, MetadataTokens.GetToken(builder1.GetOrAddUserString(veryLargeString + "z")));
            Assert.Throws<ImageFormatLimitationException>(() => builder1.GetOrAddUserString("12"));

            var builder2 = new MetadataBuilder();
            Assert.Equal(0x70000001, MetadataTokens.GetToken(builder2.GetOrAddUserString("123")));
            Assert.Equal(0x70000009, MetadataTokens.GetToken(builder2.GetOrAddUserString(veryLargeString)));
            Assert.Equal(0x70fffffe, MetadataTokens.GetToken(builder2.GetOrAddUserString("4"))); // TODO: should throw https://github.com/dotnet/roslyn/issues/9852

            var builder3 = new MetadataBuilder(userStringHeapStartOffset: 0x00fffffe);
            Assert.Equal(0x70ffffff, MetadataTokens.GetToken(builder3.GetOrAddUserString("1"))); // TODO: should throw https://github.com/dotnet/roslyn/issues/9852

            var builder4 = new MetadataBuilder(userStringHeapStartOffset: 0x00fffff7);
            Assert.Equal(0x70fffff8, MetadataTokens.GetToken(builder4.GetOrAddUserString("1"))); // 4B
            Assert.Equal(0x70fffffc, MetadataTokens.GetToken(builder4.GetOrAddUserString("2"))); // 4B 

            var builder5 = new MetadataBuilder(userStringHeapStartOffset: 0x00fffff8);
            Assert.Equal(0x70fffff9, MetadataTokens.GetToken(builder5.GetOrAddUserString("1"))); // 4B
            Assert.Equal(0x70fffffd, MetadataTokens.GetToken(builder5.GetOrAddUserString("2"))); // 4B // TODO: should throw https://github.com/dotnet/roslyn/issues/9852
        }
开发者ID:MichalStrehovsky,项目名称:corefx,代码行数:30,代码来源:MetadataBuilderTests.cs


示例20: Add

        public void Add()
        {
            var builder = new MetadataBuilder();

            builder.AddModule(default(Int32), default(StringHandle), default(GuidHandle), default(GuidHandle), default(GuidHandle));
            Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.Module]);

            builder.AddAssembly(default(StringHandle), default(Version), default(StringHandle), default(BlobHandle), default(AssemblyFlags), default(AssemblyHashAlgorithm));
            Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.Assembly]);

            var assemblyReference = builder.AddAssemblyReference(default(StringHandle), default(Version), default(StringHandle), default(BlobHandle), default(AssemblyFlags), default(BlobHandle));
            Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.AssemblyRef]);
            Assert.Equal(1, MetadataTokens.GetRowNumber(assemblyReference));

            var typeDefinition = builder.AddTypeDefinition(default(TypeAttributes), default(StringHandle), default(StringHandle), default(EntityHandle), default(FieldDefinitionHandle), default(MethodDefinitionHandle));
            Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.TypeDef]);
            Assert.Equal(1, MetadataTokens.GetRowNumber(typeDefinition));

            builder.AddTypeLayout(default(TypeDefinitionHandle), default(UInt16), default(UInt32));
            Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.ClassLayout]);

            builder.AddInterfaceImplementation(MetadataTokens.TypeDefinitionHandle(1), MetadataTokens.TypeDefinitionHandle(1));
       

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Ecma335.MetadataSizes类代码示例发布时间:2022-05-26
下一篇:
C# Hosting.DirectoryCatalog类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap