当前位置: 首页>>代码示例>>C#>>正文


C# ModuleBuilder.WriteSymbolTokenMap方法代码示例

本文整理汇总了C#中ModuleBuilder.WriteSymbolTokenMap方法的典型用法代码示例。如果您正苦于以下问题:C# ModuleBuilder.WriteSymbolTokenMap方法的具体用法?C# ModuleBuilder.WriteSymbolTokenMap怎么用?C# ModuleBuilder.WriteSymbolTokenMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ModuleBuilder的用法示例。


在下文中一共展示了ModuleBuilder.WriteSymbolTokenMap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteModuleImpl


//.........这里部分代码省略.........
			rsrc.VirtualSize = resources == null ? 0 : (uint)resources.Length;
			rsrc.SizeOfRawData = writer.ToFileAlignment(rsrc.VirtualSize);
			rsrc.Characteristics = SectionHeader.IMAGE_SCN_MEM_READ | SectionHeader.IMAGE_SCN_CNT_INITIALIZED_DATA;

			if (rsrc.SizeOfRawData != 0)
			{
				// Resource Directory
				writer.Headers.OptionalHeader.DataDirectory[2].VirtualAddress = rsrc.VirtualAddress;
				writer.Headers.OptionalHeader.DataDirectory[2].Size = rsrc.VirtualSize;
			}

			SectionHeader reloc = new SectionHeader();
			reloc.Name = ".reloc";
			reloc.VirtualAddress = rsrc.VirtualAddress + writer.ToSectionAlignment(rsrc.VirtualSize);
			if (imageFileMachine != ImageFileMachine.ARM)
			{
				reloc.VirtualSize = ((uint)moduleBuilder.unmanagedExports.Count + 1) * 12;
			}
			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 if (imageFileMachine != ImageFileMachine.ARM)
			{
				writer.Headers.OptionalHeader.AddressOfEntryPoint = code.StartupStubRVA;
			}

			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);
			code.Write(mw, sdata.VirtualAddress);

			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);

			// do the strong naming
			if (keyPair != null)
			{
				StrongName(stream, keyPair, writer.HeaderSize, text.PointerToRawData, code.StrongNameSignatureRVA - text.VirtualAddress + text.PointerToRawData, code.StrongNameSignatureLength);
			}

			if (moduleBuilder.symbolWriter != null)
			{
				moduleBuilder.WriteSymbolTokenMap();
				moduleBuilder.symbolWriter.Close();
			}
		}
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:101,代码来源:ModuleWriter.cs

示例2: WriteModule


//.........这里部分代码省略.........
				reloc.VirtualSize = 12;
				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;

				// 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.WritePEHeaders();
				writer.WriteSectionHeader(text);
				if (sdata.SizeOfRawData != 0)
				{
					writer.WriteSectionHeader(sdata);
				}
				if (rsrc.SizeOfRawData != 0)
				{
					writer.WriteSectionHeader(rsrc);
				}
				writer.WriteSectionHeader(reloc);

				fs.Seek(text.PointerToRawData, SeekOrigin.Begin);
				code.Write(mw, (int)sdata.VirtualAddress);

				fs.Seek(sdata.PointerToRawData, SeekOrigin.Begin);
				mw.Write(moduleBuilder.initializedData);

				if (rsrc.SizeOfRawData != 0)
				{
					fs.Seek(rsrc.PointerToRawData, SeekOrigin.Begin);
					resources.Write(mw, rsrc.VirtualAddress);
				}

				fs.Seek(reloc.PointerToRawData, SeekOrigin.Begin);
				// .reloc section
				uint relocAddress = code.StartupStubRVA;
				switch (imageFileMachine)
				{
					case ImageFileMachine.I386:
					case ImageFileMachine.AMD64:
						relocAddress += 2;
						break;
					case ImageFileMachine.IA64:
						relocAddress += 0x20;
						break;
				}
				uint pageRVA = relocAddress & ~0xFFFU;
				mw.Write(pageRVA);	// PageRVA
				mw.Write(0x000C);	// Block Size
				if (imageFileMachine == ImageFileMachine.I386)
				{
					mw.Write(0x3000 + relocAddress - pageRVA);				// Type / Offset
				}
				else if (imageFileMachine == ImageFileMachine.AMD64)
				{
					mw.Write(0xA000 + relocAddress - pageRVA);				// Type / Offset
				}
				else if (imageFileMachine == ImageFileMachine.IA64)
				{
					// on IA64 the StartupStubRVA is 16 byte aligned, so these two addresses won't cross a page boundary
					mw.Write((short)(0xA000 + relocAddress - pageRVA));		// Type / Offset
					mw.Write((short)(0xA000 + relocAddress - pageRVA + 8));	// Type / Offset
				}

				// file alignment
				mw.Write(new byte[writer.Headers.OptionalHeader.FileAlignment - reloc.VirtualSize]);

				// do the strong naming
				if (keyPair != null)
				{
					StrongName(fs, keyPair, writer.HeaderSize, text.PointerToRawData, code.StrongNameSignatureRVA - text.VirtualAddress + text.PointerToRawData, code.StrongNameSignatureLength);
				}
			}

			if (moduleBuilder.symbolWriter != null)
			{
				moduleBuilder.WriteSymbolTokenMap();
				moduleBuilder.symbolWriter.Close();
			}
		}
开发者ID:ikvm,项目名称:IKVM.NET-cvs-clone,代码行数:101,代码来源:ModuleWriter.cs


注:本文中的ModuleBuilder.WriteSymbolTokenMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。