本文整理汇总了C#中IKVM.Reflection.Writer.MetadataWriter类的典型用法代码示例。如果您正苦于以下问题:C# MetadataWriter类的具体用法?C# MetadataWriter怎么用?C# MetadataWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MetadataWriter类属于IKVM.Reflection.Writer命名空间,在下文中一共展示了MetadataWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Freeze
internal void Freeze(MetadataWriter mw)
{
if (frozen)
throw new InvalidOperationException();
frozen = true;
unalignedlength = GetLength(mw);
}
示例2: Write
internal void Write(MetadataWriter mw, uint rva)
{
foreach (int offset in linkOffsets)
{
bb.Position = offset;
bb.Write(bb.GetInt32AtCurrentPosition() + (int)rva);
}
mw.Write(bb);
}
示例3: Write
internal void Write(MetadataWriter mw)
{
int pos = mw.Position;
WriteImpl(mw);
Debug.Assert(mw.Position == pos + unalignedlength);
int align = Length - unalignedlength;
for (int i = 0; i < align; i++)
{
mw.Write((byte)0);
}
}
示例4: WriteImpl
protected override void WriteImpl(MetadataWriter mw)
{
foreach (string str in list)
{
mw.Write(System.Text.Encoding.UTF8.GetBytes(str));
mw.Write((byte)0);
}
}
示例5: WriteParamRecords
internal void WriteParamRecords(MetadataWriter mw)
{
foreach (MethodBuilder mb in methods)
{
mb.WriteParamRecords(mw);
}
}
示例6: AssertRVA
private void AssertRVA(MetadataWriter mw, uint rva)
{
Debug.Assert(mw.Position - PointerToRawData + BaseRVA == rva);
}
示例7: WriteMethodDefRecord
internal void WriteMethodDefRecord(int baseRVA, MetadataWriter mw, ref int paramList)
{
if (rva != -1)
{
mw.Write(rva + baseRVA);
}
else
{
mw.Write(0);
}
mw.Write((short)implFlags);
mw.Write((short)attributes);
mw.WriteStringIndex(nameIndex);
mw.WriteBlobIndex(signature);
mw.WriteParam(paramList);
if (parameters != null)
{
paramList += parameters.Count;
}
}
示例8: WriteTypeDefRecord
internal void WriteTypeDefRecord(MetadataWriter mw, ref int fieldList, ref int methodList)
{
mw.Write((int)attribs);
mw.WriteStringIndex(typeName);
mw.WriteStringIndex(typeNameSpace);
mw.WriteTypeDefOrRef(extends);
mw.WriteField(fieldList);
mw.WriteMethodDef(methodList);
methodList += methods.Count;
fieldList += fields.Count;
}
示例9: Write
internal void Write(MetadataWriter mw, uint sdataRVA)
{
// sort the exports by ordinal
text.moduleBuilder.unmanagedExports.Sort(CompareUnmanagedExportOrdinals);
// Now write the Export Address Table
text.AssertRVA(mw, exportAddressTableRVA);
for (int i = 0, pos = 0; i < entries; i++)
{
if (text.moduleBuilder.unmanagedExports[pos].ordinal == i + ordinalBase)
{
mw.Write(stubsRVA + (uint)pos * stubLength);
pos++;
}
else
{
mw.Write(0);
}
}
// sort the exports by name
text.moduleBuilder.unmanagedExports.Sort(CompareUnmanagedExportNames);
// Now write the Export Name Pointer Table
text.AssertRVA(mw, exportNamePointerTableRVA);
uint nameOffset = (uint)text.moduleBuilder.fileName.Length + 1;
foreach (UnmanagedExport exp in text.moduleBuilder.unmanagedExports)
{
if (exp.name != null)
{
mw.Write(namesRVA + nameOffset);
nameOffset += (uint)exp.name.Length + 1;
}
}
// Now write the Export Ordinal Table
text.AssertRVA(mw, exportOrdinalTableRVA);
foreach (UnmanagedExport exp in text.moduleBuilder.unmanagedExports)
{
if (exp.name != null)
{
mw.Write((ushort)(exp.ordinal - ordinalBase));
}
}
// Now write the actual names
text.AssertRVA(mw, namesRVA);
mw.Write(Encoding.ASCII.GetBytes(text.moduleBuilder.fileName));
mw.Write((byte)0);
foreach (UnmanagedExport exp in text.moduleBuilder.unmanagedExports)
{
if (exp.name != null)
{
mw.Write(Encoding.ASCII.GetBytes(exp.name));
mw.Write((byte)0);
}
}
text.AssertRVA(mw, namesRVA + namesLength);
// alignment padding
for (int i = (int)(stubsRVA - (namesRVA + namesLength)); i > 0; i--)
{
mw.Write((byte)0);
}
// sort the exports by ordinal
text.moduleBuilder.unmanagedExports.Sort(CompareUnmanagedExportOrdinals);
// Now write the stubs
text.AssertRVA(mw, stubsRVA);
for (int i = 0, pos = 0; i < entries; i++)
{
if (text.moduleBuilder.unmanagedExports[pos].ordinal == i + ordinalBase)
{
switch (text.peWriter.Headers.FileHeader.Machine)
{
case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_I386:
mw.Write((byte)0xFF);
mw.Write((byte)0x25);
mw.Write((uint)text.peWriter.Headers.OptionalHeader.ImageBase + text.moduleBuilder.unmanagedExports[pos].rva.initializedDataOffset + sdataRVA);
mw.Write((short)0); // alignment
break;
case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_AMD64:
mw.Write((byte)0x48);
mw.Write((byte)0xA1);
mw.Write(text.peWriter.Headers.OptionalHeader.ImageBase + text.moduleBuilder.unmanagedExports[pos].rva.initializedDataOffset + sdataRVA);
mw.Write((byte)0xFF);
mw.Write((byte)0xE0);
mw.Write(0); // alignment
break;
default:
throw new NotImplementedException();
}
pos++;
}
}
}
示例10: WriteImportDirectory
private void WriteImportDirectory(MetadataWriter mw)
{
mw.Write(ImportDirectoryRVA + 40); // ImportLookupTable
mw.Write(0); // DateTimeStamp
mw.Write(0); // ForwarderChain
mw.Write(ImportHintNameTableRVA + 14); // Name
mw.Write(ImportAddressTableRVA);
mw.Write(new byte[20]);
// Import Lookup Table
mw.Write(ImportHintNameTableRVA); // Hint/Name Table RVA
int size = 48;
if (peWriter.Headers.FileHeader.Machine != IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_I386)
{
size += 4;
mw.Write(0);
}
mw.Write(0);
// alignment padding
for (int i = (int)(ImportHintNameTableRVA - (ImportDirectoryRVA + size)); i > 0; i--)
{
mw.Write((byte)0);
}
// Hint/Name Table
AssertRVA(mw, ImportHintNameTableRVA);
mw.Write((ushort)0); // Hint
if ((peWriter.Headers.FileHeader.Characteristics & IMAGE_FILE_HEADER.IMAGE_FILE_DLL) != 0)
{
mw.Write(System.Text.Encoding.ASCII.GetBytes("_CorDllMain"));
}
else
{
mw.Write(System.Text.Encoding.ASCII.GetBytes("_CorExeMain"));
}
mw.Write((byte)0);
// Name
mw.Write(System.Text.Encoding.ASCII.GetBytes("mscoree.dll"));
mw.Write((ushort)0);
}
示例11: WriteRelocations
internal void WriteRelocations(MetadataWriter mw)
{
uint relocAddress = this.StartupStubRVA;
switch (peWriter.Headers.FileHeader.Machine)
{
case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_I386:
case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_AMD64:
relocAddress += 2;
break;
case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_IA64:
relocAddress += 0x20;
break;
}
WriteRelocationBlock(mw, relocAddress);
if (exportTables != null)
{
exportTables.WriteRelocations(mw);
}
}
示例12: WriteExportTables
private void WriteExportTables(MetadataWriter mw, uint sdataRVA)
{
if (exportTables != null)
{
exportTables.Write(mw, sdataRVA);
}
}
示例13: WriteExportDirectory
private void WriteExportDirectory(MetadataWriter mw)
{
if (ExportDirectoryLength != 0)
{
// Flags
mw.Write(0);
// Date/Time Stamp
mw.Write(peWriter.Headers.FileHeader.TimeDateStamp);
// Major Version
mw.Write((short)0);
// Minor Version
mw.Write((short)0);
// Name RVA
mw.Write(exportTables.namesRVA);
// Ordinal Base
mw.Write(exportTables.ordinalBase);
// Address Table Entries
mw.Write(exportTables.entries);
// Number of Name Pointers
mw.Write(exportTables.nameCount);
// Export Address Table RVA
mw.Write(exportTables.exportAddressTableRVA);
// Name Pointer RVA
mw.Write(exportTables.exportNamePointerTableRVA);
// Ordinal Table RVA
mw.Write(exportTables.exportOrdinalTableRVA);
}
}
示例14: WriteVTableFixups
private void WriteVTableFixups(MetadataWriter mw, uint sdataRVA)
{
foreach (ModuleBuilder.VTableFixups fixups in moduleBuilder.vtablefixups)
{
mw.Write(fixups.initializedDataOffset + sdataRVA);
mw.Write(fixups.count);
mw.Write(fixups.type);
}
}
示例15: WriteRelocationBlock
// note that we're lazy and write a new relocation block for every relocation
// even if they are in the same page (since there is typically only one anyway)
private void WriteRelocationBlock(MetadataWriter mw, uint relocAddress)
{
uint pageRVA = relocAddress & ~0xFFFU;
mw.Write(pageRVA); // PageRVA
mw.Write(0x000C); // Block Size
switch (peWriter.Headers.FileHeader.Machine)
{
case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_I386:
mw.Write(0x3000 + relocAddress - pageRVA); // Type / Offset
break;
case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_AMD64:
mw.Write(0xA000 + relocAddress - pageRVA); // Type / Offset
break;
case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_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
break;
}
}