本文整理汇总了C#中BlobBuilder.WriteContentTo方法的典型用法代码示例。如果您正苦于以下问题:C# BlobBuilder.WriteContentTo方法的具体用法?C# BlobBuilder.WriteContentTo怎么用?C# BlobBuilder.WriteContentTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BlobBuilder
的用法示例。
在下文中一共展示了BlobBuilder.WriteContentTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteNameTable
private static void WriteNameTable(Stream peStream)
{
var writer = new BlobBuilder(SizeOfNameTable);
foreach (char ch in CorEntryPointDll)
{
writer.WriteByte((byte)ch);
}
writer.WriteByte(0);
writer.WriteUInt16(0);
Debug.Assert(writer.Count == SizeOfNameTable);
writer.WriteContentTo(peStream);
}
示例2: WriteCorHeader
private static void WriteCorHeader(Stream peStream, CorHeader corHeader)
{
var writer = new BlobBuilder(CorHeaderSize);
writer.WriteUInt32(CorHeaderSize);
writer.WriteUInt16(corHeader.MajorRuntimeVersion);
writer.WriteUInt16(corHeader.MinorRuntimeVersion);
writer.WriteUInt32((uint)corHeader.MetadataDirectory.RelativeVirtualAddress);
writer.WriteUInt32((uint)corHeader.MetadataDirectory.Size);
writer.WriteUInt32((uint)corHeader.Flags);
writer.WriteUInt32((uint)corHeader.EntryPointTokenOrRelativeVirtualAddress);
writer.WriteUInt32((uint)(corHeader.ResourcesDirectory.Size == 0 ? 0 : corHeader.ResourcesDirectory.RelativeVirtualAddress)); // 28
writer.WriteUInt32((uint)corHeader.ResourcesDirectory.Size);
writer.WriteUInt32((uint)(corHeader.StrongNameSignatureDirectory.Size == 0 ? 0 : corHeader.StrongNameSignatureDirectory.RelativeVirtualAddress)); // 36
writer.WriteUInt32((uint)corHeader.StrongNameSignatureDirectory.Size);
writer.WriteUInt32((uint)corHeader.CodeManagerTableDirectory.RelativeVirtualAddress);
writer.WriteUInt32((uint)corHeader.CodeManagerTableDirectory.Size);
writer.WriteUInt32((uint)corHeader.VtableFixupsDirectory.RelativeVirtualAddress);
writer.WriteUInt32((uint)corHeader.VtableFixupsDirectory.Size);
writer.WriteUInt32((uint)corHeader.ExportAddressTableJumpsDirectory.RelativeVirtualAddress);
writer.WriteUInt32((uint)corHeader.ExportAddressTableJumpsDirectory.Size);
writer.WriteUInt64(0);
Debug.Assert(writer.Count == CorHeaderSize);
Debug.Assert(writer.Count % 4 == 0);
writer.WriteContentTo(peStream);
}
示例3: WriteImportAddressTable
private void WriteImportAddressTable(Stream peStream, int importTableRva)
{
var writer = new BlobBuilder(SizeOfImportAddressTable);
int ilRVA = importTableRva + 40;
int hintRva = ilRVA + (_is32bit ? 12 : 16);
// Import Address Table
if (_is32bit)
{
writer.WriteUInt32((uint)hintRva); // 4
writer.WriteUInt32(0); // 8
}
else
{
writer.WriteUInt64((uint)hintRva); // 8
writer.WriteUInt64(0); // 16
}
Debug.Assert(writer.Count == SizeOfImportAddressTable);
writer.WriteContentTo(peStream);
}
示例4: WriteImportTable
private void WriteImportTable(Stream peStream, int importTableRva, int importAddressTableRva)
{
var writer = new BlobBuilder(SizeOfImportTable);
int ilRVA = importTableRva + 40;
int hintRva = ilRVA + (_is32bit ? 12 : 16);
int nameRva = hintRva + 12 + 2;
// Import table
writer.WriteUInt32((uint)ilRVA); // 4
writer.WriteUInt32(0); // 8
writer.WriteUInt32(0); // 12
writer.WriteUInt32((uint)nameRva); // 16
writer.WriteUInt32((uint)importAddressTableRva); // 20
writer.WriteBytes(0, 20); // 40
// Import Lookup table
if (_is32bit)
{
writer.WriteUInt32((uint)hintRva); // 44
writer.WriteUInt32(0); // 48
writer.WriteUInt32(0); // 52
}
else
{
writer.WriteUInt64((uint)hintRva); // 48
writer.WriteUInt64(0); // 56
}
// Hint table
writer.WriteUInt16(0); // Hint 54|58
foreach (char ch in CorEntryPointName)
{
writer.WriteByte((byte)ch); // 65|69
}
writer.WriteByte(0); // 66|70
Debug.Assert(writer.Count == SizeOfImportTable);
writer.WriteContentTo(peStream);
}
示例5: WritePeToStream
//.........这里部分代码省略.........
nativePdbWriterOpt.AssertAllDefinitionsHaveTokens(mdWriter.Module.GetSymbolToLocationMap());
#endif
}
}
Stream peStream = getPeStream();
if (peStream == null)
{
return false;
}
ContentId nativePdbContentId = nativePdbWriterOpt?.GetContentId() ?? default(ContentId);
// the writer shall not be used after this point for writing:
nativePdbWriterOpt = null;
var metadataSerializer = mdWriter.GetTypeSystemMetadataSerializer();
var peBuilder = new PEBuilder(
machine: properties.Machine,
sectionAlignment: properties.SectionAlignment,
fileAlignment: properties.FileAlignment,
imageBase: properties.BaseAddress,
majorLinkerVersion: properties.LinkerMajorVersion,
minorLinkerVersion: properties.LinkerMinorVersion,
majorOperatingSystemVersion: 4,
minorOperatingSystemVersion: 0,
majorImageVersion: 0,
minorImageVersion: 0,
majorSubsystemVersion: properties.MajorSubsystemVersion,
minorSubsystemVersion: properties.MinorSubsystemVersion,
subsystem: properties.Subsystem,
dllCharacteristics: properties.DllCharacteristics,
imageCharacteristics: properties.ImageCharacteristics,
sizeOfStackReserve: properties.SizeOfStackReserve,
sizeOfStackCommit: properties.SizeOfStackCommit,
sizeOfHeapReserve: properties.SizeOfHeapReserve,
sizeOfHeapCommit: properties.SizeOfHeapCommit,
deterministicIdProvider: isDeterministic ? new Func<BlobBuilder, ContentId>(content => ContentId.FromHash(CryptographicHashProvider.ComputeSha1(content))) : null);
ContentId portablePdbContentId;
if (mdWriter.EmitStandaloneDebugMetadata)
{
Debug.Assert(getPortablePdbStreamOpt != null);
var debugMetadataBuilder = new BlobBuilder();
var debugMetadataSerializer = mdWriter.GetStandaloneDebugMetadataSerializer(metadataSerializer.MetadataSizes, debugEntryPointHandle);
debugMetadataSerializer.SerializeMetadata(debugMetadataBuilder, peBuilder.IdProvider, out portablePdbContentId);
// write to Portable PDB stream:
Stream portablePdbStream = getPortablePdbStreamOpt();
if (portablePdbStream != null)
{
debugMetadataBuilder.WriteContentTo(portablePdbStream);
}
}
else
{
portablePdbContentId = default(ContentId);
}
var peDirectoriesBuilder = new PEDirectoriesBuilder();
peBuilder.AddManagedSections(
peDirectoriesBuilder,
metadataSerializer,
ilBuilder,
mappedFieldDataBuilder,
managedResourceBuilder,
CreateNativeResourceSectionSerializer(context.Module),
CalculateStrongNameSignatureSize(context.Module),
entryPointHandle,
pdbPathOpt,
nativePdbContentId,
portablePdbContentId,
properties.CorFlags);
var peBlob = new BlobBuilder();
ContentId peContentId;
peBuilder.Serialize(peBlob, peDirectoriesBuilder, out peContentId);
// Patch MVID
if (!mvidFixup.IsDefault)
{
var mvidWriter = new BlobWriter(mvidFixup);
mvidWriter.WriteBytes(peContentId.Guid);
Debug.Assert(mvidWriter.RemainingBytes == 0);
}
try
{
peBlob.WriteContentTo(peStream);
}
catch (Exception e) when (!(e is OperationCanceledException))
{
throw new PeWritingException(e);
}
return true;
}
示例6: WriteTextSection
private void WriteTextSection(
Stream peStream,
SectionHeader textSection,
int importTableRva,
int importAddressTableRva,
int entryPointToken,
BlobBuilder metadataWriter,
BlobBuilder ilWriter,
BlobBuilder mappedFieldDataWriter,
BlobBuilder managedResourceWriter,
MetadataSizes metadataSizes,
ContentId nativePdbContentId,
ContentId portablePdbContentId,
out long metadataPosition)
{
// TODO: zero out all bytes:
peStream.Position = textSection.PointerToRawData;
if (_properties.RequiresStartupStub)
{
WriteImportAddressTable(peStream, importTableRva);
}
var corHeader = CreateCorHeader(metadataSizes, textSection.RelativeVirtualAddress, entryPointToken);
WriteCorHeader(peStream, corHeader);
// IL:
ilWriter.Align(4);
ilWriter.WriteContentTo(peStream);
// metadata:
metadataPosition = peStream.Position;
Debug.Assert(metadataWriter.Count % 4 == 0);
metadataWriter.WriteContentTo(peStream);
// managed resources:
Debug.Assert(managedResourceWriter.Count % 4 == 0);
managedResourceWriter.WriteContentTo(peStream);
// strong name signature:
WriteSpaceForHash(peStream, metadataSizes.StrongNameSignatureSize);
if (EmitPdb)
{
WriteDebugTable(peStream, textSection, nativePdbContentId, portablePdbContentId, metadataSizes);
}
if (_properties.RequiresStartupStub)
{
WriteImportTable(peStream, importTableRva, importAddressTableRva);
WriteNameTable(peStream);
WriteRuntimeStartupStub(peStream, importAddressTableRva);
}
// mapped field data:
mappedFieldDataWriter.WriteContentTo(peStream);
// TODO: zero out all bytes:
int alignedPosition = textSection.PointerToRawData + textSection.SizeOfRawData;
if (peStream.Position != alignedPosition)
{
peStream.Position = alignedPosition - 1;
peStream.WriteByte(0);
}
}
示例7: Write_Errors
public unsafe void Write_Errors()
{
var builder = new BlobBuilder(16);
Assert.Throws<ArgumentNullException>(() => builder.WriteUTF16((char[])null));
Assert.Throws<ArgumentNullException>(() => builder.WriteUTF16((string)null));
Assert.Throws<ArgumentNullException>(() => builder.WriteUTF8(null, allowUnpairedSurrogates: true));
Assert.Throws<ArgumentNullException>(() => builder.WriteUTF8(null, allowUnpairedSurrogates: true));
Assert.Throws<ArgumentNullException>(() => builder.TryWriteBytes((Stream)null, 0));
Assert.Throws<ArgumentNullException>(() => builder.WriteBytes(null));
Assert.Throws<ArgumentNullException>(() => builder.WriteBytes(null, 0, 0));
Assert.Throws<ArgumentNullException>(() => builder.WriteBytes((byte*)null, 0));
Assert.Throws<ArgumentNullException>(() => builder.WriteBytes(default(ImmutableArray<byte>)));
Assert.Throws<ArgumentNullException>(() => builder.WriteBytes(default(ImmutableArray<byte>), 0, 0));
var bw = default(BlobWriter);
Assert.Throws<ArgumentNullException>(() => builder.WriteContentTo(ref bw));
Assert.Throws<ArgumentNullException>(() => builder.WriteContentTo((Stream)null));
Assert.Throws<ArgumentNullException>(() => builder.WriteContentTo((BlobBuilder)null));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.TryWriteBytes(new MemoryStream(), -1));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.WriteBytes(0, -1));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.WriteBytes(new byte[] { }, 1, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.WriteBytes(new byte[] { }, 0, 1));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.WriteBytes(new byte[] { }, 0, -1));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.WriteBytes(ImmutableArray<byte>.Empty, 1, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.WriteBytes(ImmutableArray<byte>.Empty, 0, 1));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.WriteBytes(ImmutableArray<byte>.Empty, 1, -1));
}
示例8: WriteInstructions
public ExceptionRegionEncoder WriteInstructions(BlobBuilder codeBuilder, out int bodyOffset)
{
bodyOffset = WriteHeader(codeBuilder.Count);
codeBuilder.WriteContentTo(Builder);
return CreateExceptionEncoder();
}
示例9: WriteContentToStream_Errors
public void WriteContentToStream_Errors()
{
var builder = new BlobBuilder(16);
builder.WriteByte(1);
Assert.Throws<ArgumentNullException>(() => builder.WriteContentTo((Stream)null));
Assert.Throws<NotSupportedException>(() => builder.WriteContentTo(new MemoryStream(new byte[] { 1 }, writable: false)));
}
示例10: WriteContentToBlobBuilder
public void WriteContentToBlobBuilder()
{
var builder1 = new BlobBuilder(16);
for (int i = 0; i < 20; i++)
{
builder1.WriteByte((byte)i);
}
var builder2 = new BlobBuilder(256);
builder1.WriteContentTo(builder2);
AssertEx.Equal(new byte[]
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13
}, builder2.ToArray());
builder1.WriteByte(0xff);
builder1.WriteContentTo(builder2);
AssertEx.Equal(new byte[]
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13,
0xff,
}, builder2.ToArray());
}
示例11: WriteContentToStream
public void WriteContentToStream()
{
var builder = new BlobBuilder(16);
for (int i = 0; i < 20; i++)
{
builder.WriteByte((byte)i);
}
var stream = new MemoryStream();
builder.WriteContentTo(stream);
AssertEx.Equal(new byte[]
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13
}, stream.ToArray());
builder.WriteByte(0xff);
builder.WriteContentTo(stream);
AssertEx.Equal(new byte[]
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13,
0xff,
}, stream.ToArray());
}
示例12: WritePeToStream
//.........这里部分代码省略.........
majorLinkerVersion: properties.LinkerMajorVersion,
minorLinkerVersion: properties.LinkerMinorVersion,
majorOperatingSystemVersion: 4,
minorOperatingSystemVersion: 0,
majorImageVersion: 0,
minorImageVersion: 0,
majorSubsystemVersion: properties.MajorSubsystemVersion,
minorSubsystemVersion: properties.MinorSubsystemVersion,
subsystem: properties.Subsystem,
dllCharacteristics: properties.DllCharacteristics,
imageCharacteristics: properties.ImageCharacteristics,
sizeOfStackReserve: properties.SizeOfStackReserve,
sizeOfStackCommit: properties.SizeOfStackCommit,
sizeOfHeapReserve: properties.SizeOfHeapReserve,
sizeOfHeapCommit: properties.SizeOfHeapCommit);
var deterministicIdProvider = isDeterministic ?
new Func<IEnumerable<Blob>, BlobContentId>(content => BlobContentId.FromHash(CryptographicHashProvider.ComputeSha1(content))) :
null;
BlobBuilder portablePdbToEmbed = null;
if (mdWriter.EmitStandaloneDebugMetadata)
{
mdWriter.AddRemainingEmbeddedDocuments(mdWriter.Module.DebugDocumentsBuilder.EmbeddedDocuments);
var portablePdbBlob = new BlobBuilder();
var portablePdbBuilder = mdWriter.GetPortablePdbBuilder(metadataRootBuilder.Sizes, debugEntryPointHandle, deterministicIdProvider);
pdbContentId = portablePdbBuilder.Serialize(portablePdbBlob);
portablePdbVersion = portablePdbBuilder.FormatVersion;
if (getPortablePdbStreamOpt == null)
{
// embed to debug directory:
portablePdbToEmbed = portablePdbBlob;
}
else
{
// write to Portable PDB stream:
Stream portablePdbStream = getPortablePdbStreamOpt();
if (portablePdbStream != null)
{
portablePdbBlob.WriteContentTo(portablePdbStream);
}
}
}
DebugDirectoryBuilder debugDirectoryBuilder;
if (pdbPathOpt != null || isDeterministic || portablePdbToEmbed != null)
{
debugDirectoryBuilder = new DebugDirectoryBuilder();
if (pdbPathOpt != null)
{
string paddedPath = isDeterministic ? pdbPathOpt : PadPdbPath(pdbPathOpt);
debugDirectoryBuilder.AddCodeViewEntry(paddedPath, pdbContentId, portablePdbVersion);
}
if (isDeterministic)
{
debugDirectoryBuilder.AddReproducibleEntry();
}
if (portablePdbToEmbed != null)
{
debugDirectoryBuilder.AddEmbeddedPortablePdbEntry(portablePdbToEmbed, portablePdbVersion);
}
}
else
{
debugDirectoryBuilder = null;
}
var peBuilder = new ManagedPEBuilder(
peHeaderBuilder,
metadataRootBuilder,
ilBuilder,
mappedFieldDataBuilder,
managedResourceBuilder,
CreateNativeResourceSectionSerializer(context.Module),
debugDirectoryBuilder,
CalculateStrongNameSignatureSize(context.Module),
entryPointHandle,
properties.CorFlags,
deterministicIdProvider);
var peBlob = new BlobBuilder();
var peContentId = peBuilder.Serialize(peBlob);
PatchModuleVersionIds(mvidFixup, mvidStringFixup, peContentId.Guid);
try
{
peBlob.WriteContentTo(peStream);
}
catch (Exception e) when (!(e is OperationCanceledException))
{
throw new PeWritingException(e);
}
return true;
}
示例13: WriteBytes
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
public void WriteBytes(BlobBuilder source)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
source.WriteContentTo(ref this);
}
示例14: WriteRuntimeStartupStub
private void WriteRuntimeStartupStub(Stream peStream, int importAddressTableRva)
{
var writer = new BlobBuilder(16);
// entry point code, consisting of a jump indirect to _CorXXXMain
if (_is32bit)
{
//emit 0's (nops) to pad the entry point code so that the target address is aligned on a 4 byte boundary.
for (uint i = 0, n = (uint)(BitArithmeticUtilities.Align((uint)peStream.Position, 4) - peStream.Position); i < n; i++)
{
writer.WriteByte(0);
}
writer.WriteUInt16(0);
writer.WriteByte(0xff);
writer.WriteByte(0x25); //4
writer.WriteUInt32((uint)importAddressTableRva + (uint)_properties.BaseAddress); //8
}
else
{
//emit 0's (nops) to pad the entry point code so that the target address is aligned on a 8 byte boundary.
for (uint i = 0, n = (uint)(BitArithmeticUtilities.Align((uint)peStream.Position, 8) - peStream.Position); i < n; i++)
{
writer.WriteByte(0);
}
writer.WriteUInt32(0);
writer.WriteUInt16(0);
writer.WriteByte(0xff);
writer.WriteByte(0x25); //8
writer.WriteUInt64((ulong)importAddressTableRva + _properties.BaseAddress); //16
}
writer.WriteContentTo(peStream);
}
示例15: AddPermission
public PermissionSetEncoder AddPermission(string typeName, BlobBuilder encodedArguments)
{
if (typeName == null)
{
Throw.ArgumentNull(nameof(typeName));
}
if (encodedArguments == null)
{
Throw.ArgumentNull(nameof(encodedArguments));
}
if (encodedArguments.Count > BlobWriterImpl.MaxCompressedIntegerValue)
{
Throw.BlobTooLarge(nameof(encodedArguments));
}
Builder.WriteSerializedString(typeName);
Builder.WriteCompressedInteger(encodedArguments.Count);
encodedArguments.WriteContentTo(Builder);
return new PermissionSetEncoder(Builder);
}