本文整理汇总了C#中ModuleBuilder.__SetModuleVersionId方法的典型用法代码示例。如果您正苦于以下问题:C# ModuleBuilder.__SetModuleVersionId方法的具体用法?C# ModuleBuilder.__SetModuleVersionId怎么用?C# ModuleBuilder.__SetModuleVersionId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModuleBuilder
的用法示例。
在下文中一共展示了ModuleBuilder.__SetModuleVersionId方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteModuleImpl
//.........这里部分代码省略.........
}
SectionHeader reloc = new SectionHeader();
reloc.Name = ".reloc";
reloc.VirtualAddress = rsrc.VirtualAddress + writer.ToSectionAlignment(rsrc.VirtualSize);
reloc.VirtualSize = code.PackRelocations();
reloc.PointerToRawData = rsrc.PointerToRawData + rsrc.SizeOfRawData;
reloc.SizeOfRawData = writer.ToFileAlignment(reloc.VirtualSize);
reloc.Characteristics = SectionHeader.IMAGE_SCN_MEM_READ | SectionHeader.IMAGE_SCN_CNT_INITIALIZED_DATA | SectionHeader.IMAGE_SCN_MEM_DISCARDABLE;
if (reloc.SizeOfRawData != 0)
{
// Base Relocation Directory
writer.Headers.OptionalHeader.DataDirectory[5].VirtualAddress = reloc.VirtualAddress;
writer.Headers.OptionalHeader.DataDirectory[5].Size = reloc.VirtualSize;
}
writer.Headers.OptionalHeader.SizeOfCode = text.SizeOfRawData;
writer.Headers.OptionalHeader.SizeOfInitializedData = sdata.SizeOfRawData + rsrc.SizeOfRawData + reloc.SizeOfRawData;
writer.Headers.OptionalHeader.SizeOfUninitializedData = 0;
writer.Headers.OptionalHeader.SizeOfImage = reloc.VirtualAddress + writer.ToSectionAlignment(reloc.VirtualSize);
writer.Headers.OptionalHeader.SizeOfHeaders = text.PointerToRawData;
writer.Headers.OptionalHeader.BaseOfCode = code.BaseRVA;
writer.Headers.OptionalHeader.BaseOfData = sdata.VirtualAddress;
writer.Headers.OptionalHeader.ImageBase = (ulong)moduleBuilder.__ImageBase;
if (imageFileMachine == ImageFileMachine.IA64)
{
// apparently for IA64 AddressOfEntryPoint points to the address of the entry point
// (i.e. there is an additional layer of indirection), so we add the offset to the pointer
writer.Headers.OptionalHeader.AddressOfEntryPoint = code.StartupStubRVA + 0x20;
}
else
{
writer.Headers.OptionalHeader.AddressOfEntryPoint = code.StartupStubRVA + writer.Thumb;
}
writer.WritePEHeaders();
writer.WriteSectionHeader(text);
if (sdata.SizeOfRawData != 0)
{
writer.WriteSectionHeader(sdata);
}
if (rsrc.SizeOfRawData != 0)
{
writer.WriteSectionHeader(rsrc);
}
if (reloc.SizeOfRawData != 0)
{
writer.WriteSectionHeader(reloc);
}
stream.Seek(text.PointerToRawData, SeekOrigin.Begin);
uint guidHeapOffset;
code.Write(mw, sdata.VirtualAddress, out guidHeapOffset);
if (sdata.SizeOfRawData != 0)
{
stream.Seek(sdata.PointerToRawData, SeekOrigin.Begin);
mw.Write(moduleBuilder.initializedData);
}
if (rsrc.SizeOfRawData != 0)
{
stream.Seek(rsrc.PointerToRawData, SeekOrigin.Begin);
resources.Write(mw, rsrc.VirtualAddress);
}
if (reloc.SizeOfRawData != 0)
{
stream.Seek(reloc.PointerToRawData, SeekOrigin.Begin);
code.WriteRelocations(mw);
}
// file alignment
stream.SetLength(reloc.PointerToRawData + reloc.SizeOfRawData);
// if we don't have a guid, generate one based on the contents of the assembly
if (moduleBuilder.universe.Deterministic && moduleBuilder.GetModuleVersionIdOrEmpty() == Guid.Empty)
{
Guid guid = GenerateModuleVersionId(stream);
stream.Position = guidHeapOffset + (moduleVersionIdIndex - 1) * 16;
stream.Write(guid.ToByteArray(), 0, 16);
moduleBuilder.__SetModuleVersionId(guid);
}
// do the strong naming
if (keyPair != null)
{
StrongName(stream, keyPair, writer.HeaderSize, text.PointerToRawData, code.StrongNameSignatureRVA - text.VirtualAddress + text.PointerToRawData, code.StrongNameSignatureLength);
}
#if !NO_SYMBOL_WRITER
if (moduleBuilder.symbolWriter != null)
{
moduleBuilder.WriteSymbolTokenMap();
moduleBuilder.symbolWriter.Close();
}
#endif
}