本文整理汇总了C#中System.Reflection.Metadata.BlobBuilder.WriteContentTo方法的典型用法代码示例。如果您正苦于以下问题:C# BlobBuilder.WriteContentTo方法的具体用法?C# BlobBuilder.WriteContentTo怎么用?C# BlobBuilder.WriteContentTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Metadata.BlobBuilder
的用法示例。
在下文中一共展示了BlobBuilder.WriteContentTo方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: 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);
}
示例3: WriteBytes
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
public void WriteBytes(BlobBuilder source)
{
if (source == null)
{
Throw.ArgumentNull(nameof(source));
}
source.WriteContentTo(ref this);
}
示例4: AddPermission
public PermissionSetEncoder AddPermission(string typeName, BlobBuilder arguments)
{
Builder.WriteSerializedString(typeName);
Builder.WriteCompressedInteger(arguments.Count);
arguments.WriteContentTo(Builder);
return new PermissionSetEncoder(Builder);
}
示例5: WriteInstructions
public ExceptionRegionEncoder WriteInstructions(BlobBuilder codeBuilder, out int bodyOffset)
{
bodyOffset = WriteHeader(codeBuilder.Count);
codeBuilder.WriteContentTo(Builder);
return CreateExceptionEncoder();
}
示例6: WriteInstructions
public ExceptionRegionEncoder WriteInstructions(BlobBuilder buffer, out int offset)
{
offset = WriteHeader(buffer.Count);
buffer.WriteContentTo(Builder);
return CreateExceptionEncoder();
}
示例7: 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());
}