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); }
private static void WritePEImage( Stream peStream, MetadataBuilder metadataBuilder, BlobBuilder ilBuilder, MethodDefinitionHandle entryPointHandle, Blob mvidFixup = default(Blob), byte[] privateKeyOpt = null, bool publicSigned = false, Machine machine = 0, BlobBuilder?mappedFieldData = null) { var peHeaderBuilder = new PEHeaderBuilder(imageCharacteristics: entryPointHandle.IsNil ? Characteristics.Dll : Characteristics.ExecutableImage, machine: machine); var peBuilder = new ManagedPEBuilder( peHeaderBuilder, new MetadataRootBuilder(metadataBuilder), ilBuilder, entryPoint: entryPointHandle, flags: CorFlags.ILOnly | (privateKeyOpt != null || publicSigned ? CorFlags.StrongNameSigned : 0), deterministicIdProvider: content => s_contentId, mappedFieldData: mappedFieldData); 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); }
private static void WritePEImage( Stream peStream, MetadataBuilder metadataBuilder, BlobBuilder ilBuilder, MethodDefinitionHandle entryPointHandle, byte[] privateKeyOpt = null) { var mappedFieldDataBuilder = new BlobBuilder(); var managedResourceDataBuilder = new BlobBuilder(); var peBuilder = new ManagedPEBuilder( entryPointHandle.IsNil ? PEHeaderBuilder.CreateLibraryHeader() : PEHeaderBuilder.CreateExecutableHeader(), new TypeSystemMetadataSerializer(metadataBuilder, "v4.0.30319", isMinimalDelta: false), ilBuilder, mappedFieldDataBuilder, managedResourceDataBuilder, nativeResourceSectionSerializer: null, strongNameSignatureSize: 128, entryPoint: entryPointHandle, pdbPathOpt: null, nativePdbContentId: default(ContentId), portablePdbContentId: default(ContentId), corFlags: CorFlags.ILOnly | (privateKeyOpt != null ? CorFlags.StrongNameSigned : 0), deterministicIdProvider: content => s_contentId); var peBlob = new BlobBuilder(); ContentId contentId; peBuilder.Serialize(peBlob, out contentId); if (privateKeyOpt != null) { peBuilder.Sign(peBlob, content => SigningUtilities.CalculateRsaSignature(content, privateKeyOpt)); } peBlob.WriteContentTo(peStream); }