本文整理汇总了C#中MetadataBuilder类的典型用法代码示例。如果您正苦于以下问题:C# MetadataBuilder类的具体用法?C# MetadataBuilder怎么用?C# MetadataBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MetadataBuilder类属于命名空间,在下文中一共展示了MetadataBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CreateDebugWriter
public static ImageWriter CreateDebugWriter(ModuleDefinition module, MetadataBuilder metadata, Disposable<Stream> stream)
{
var writer = new ImageWriter (module, "PDB V1.0", metadata, stream, metadataOnly: true);
var length = metadata.text_map.GetLength ();
writer.text = new Section { SizeOfRawData = length, VirtualSize = length };
return writer;
}
开发者ID:jbevain,项目名称:cecil,代码行数:7,代码来源:ImageWriter.cs
示例2: Ctor_Errors
public void Ctor_Errors()
{
var mdBuilder = new MetadataBuilder();
Assert.Throws<ArgumentNullException>(() => new PortablePdbBuilder(null, MetadataRootBuilder.EmptyRowCounts, default(MethodDefinitionHandle)));
Assert.Throws<ArgumentNullException>(() => new PortablePdbBuilder(mdBuilder, default(ImmutableArray<int>), default(MethodDefinitionHandle)));
var rowCounts = new int[128];
rowCounts[64] = 1;
Assert.Throws<ArgumentException>(() => new PortablePdbBuilder(mdBuilder, ImmutableArray.Create(rowCounts), default(MethodDefinitionHandle)));
rowCounts = new int[64];
rowCounts[63] = 1;
Assert.Throws<ArgumentException>(() => new PortablePdbBuilder(mdBuilder, ImmutableArray.Create(rowCounts), default(MethodDefinitionHandle)));
rowCounts = new int[64];
rowCounts[(int)TableIndex.EventPtr] = 1;
Assert.Throws<ArgumentException>(() => new PortablePdbBuilder(mdBuilder, ImmutableArray.Create(rowCounts), default(MethodDefinitionHandle)));
rowCounts = new int[64];
rowCounts[(int)TableIndex.CustomDebugInformation] = 1;
Assert.Throws<ArgumentException>(() => new PortablePdbBuilder(mdBuilder, ImmutableArray.Create(rowCounts), default(MethodDefinitionHandle)));
rowCounts = new int[64];
rowCounts[(int)TableIndex.MethodDef] = -1;
Assert.Throws<ArgumentOutOfRangeException>(() => new PortablePdbBuilder(mdBuilder, ImmutableArray.Create(rowCounts), default(MethodDefinitionHandle)));
rowCounts = new int[64];
rowCounts[(int)TableIndex.GenericParamConstraint] = 0x01000000;
Assert.Throws<ArgumentOutOfRangeException>(() => new PortablePdbBuilder(mdBuilder, ImmutableArray.Create(rowCounts), default(MethodDefinitionHandle)));
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:31,代码来源:PortablePdbBuilderTests.cs
示例3: Ctor_Errors
public void Ctor_Errors()
{
var mdBuilder = new MetadataBuilder();
Assert.Throws<ArgumentNullException>(() => new MetadataRootBuilder(null));
Assert.Throws<ArgumentException>(() => new MetadataRootBuilder(mdBuilder, new string('x', 255)));
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:7,代码来源:MetadataRootBuilderTests.cs
示例4: NetTextBuilder
public NetTextBuilder(ImageNetDirectory directory)
{
_directory = directory;
ImportBuilder = new ImageImportDirectoryBuilder(directory.Assembly, directory.Assembly.ImportDirectory);
Segments.Add(ImportBuilder.AddressTablesBuilder);
Segments.Add(directory);
Segments.Add(MethodBodyTableBuilder = new MethodBodyTableBuilder());
Segments.Add(NetResourceDirectoryBuilder = new NetResourceDirectoryBuilder());
Segments.Add(DataBuilder = new NetDataTableBuilder());
if (directory.StrongNameData != null)
Segments.Add(directory.StrongNameData);
Segments.Add(Metadata = new MetadataBuilder(directory.MetadataHeader));
if (directory.Assembly.DebugDirectory != null)
{
Segments.Add(directory.Assembly.DebugDirectory);
Segments.Add(directory.Assembly.DebugDirectory.Data);
}
Segments.Add(ImportBuilder);
Segments.Add(StartupCode = new StartupCodeSegmentBuilder());
}
开发者ID:JerreS,项目名称:AsmResolver,代码行数:26,代码来源:NetTextBuilder.cs
示例5: CodeWriter
public CodeWriter (MetadataBuilder metadata)
: base (0)
{
this.code_base = metadata.text_map.GetNextRVA (TextSegment.CLIHeader);
this.current = code_base;
this.metadata = metadata;
this.standalone_signatures = new Dictionary<uint, MetadataToken> ();
}
开发者ID:mayuki,项目名称:Inazuma,代码行数:8,代码来源:CodeWriter.cs
示例6: Serialize_Errors
public void Serialize_Errors()
{
var mdBuilder = new MetadataBuilder();
var pdbBuilder = new PortablePdbBuilder(mdBuilder, MetadataRootBuilder.EmptyRowCounts, default(MethodDefinitionHandle));
var builder = new BlobBuilder();
Assert.Throws<ArgumentNullException>(() => pdbBuilder.Serialize(null));
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:8,代码来源:PortablePdbBuilderTests.cs
示例7: Serialize_Errors
public void Serialize_Errors()
{
var mdBuilder = new MetadataBuilder();
var rootBuilder = new MetadataRootBuilder(mdBuilder);
var builder = new BlobBuilder();
Assert.Throws<ArgumentNullException>(() => rootBuilder.Serialize(null, 0, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => rootBuilder.Serialize(builder, -1, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => rootBuilder.Serialize(builder, 0, -1));
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:10,代码来源:MetadataRootBuilderTests.cs
示例8: ImageWriter
ImageWriter(ModuleDefinition module, MetadataBuilder metadata, Stream stream)
: base(stream)
{
this.module = module;
this.metadata = metadata;
this.GetDebugHeader ();
this.GetWin32Resources ();
this.text_map = BuildTextMap ();
this.sections = 2; // text + reloc
this.pe64 = module.Architecture != TargetArchitecture.I386;
this.time_stamp = (uint) DateTime.UtcNow.Subtract (new DateTime (1970, 1, 1)).TotalSeconds;
}
开发者ID:sillsdev,项目名称:mono-basic,代码行数:12,代码来源:ImageWriter.cs
示例9: BuildMetadata
public static void BuildMetadata(MetadataBuilder<MainViewModel> builder) {
builder.Property(x => x.FirstName)
.Required(() => "Please enter the first name.");
builder.Property(x => x.LastName)
.Required(() => "Please enter the last name.");
builder.Property(x => x.Email)
.EmailAddressDataType(() => "Please enter a correct email address.");
AddPasswordCheck(builder.Property(x => x.Password))
.Required(() => "Please enter the password.");
AddPasswordCheck(builder.Property(x => x.ConfirmPassword))
.Required(() => "Please confirm the password.");
}
开发者ID:ruisebastiao,项目名称:DevExpress.Mvvm.Free,代码行数:12,代码来源:MainViewModel.cs
示例10: Complex
public void Complex()
{
using (var peStream = new MemoryStream())
{
var ilBuilder = new BlobBuilder();
var metadataBuilder = new MetadataBuilder();
var entryPoint = ComplexEmit(metadataBuilder, ilBuilder);
WritePEImage(peStream, metadataBuilder, ilBuilder, entryPoint);
// peStream.Position = 0;
// File.WriteAllBytes(@"c:\temp\test.dll", peStream.ToArray());
}
}
开发者ID:RoryVL,项目名称:roslyn,代码行数:14,代码来源:PEBuilderTests.cs
示例11: BasicValidation
public void BasicValidation()
{
using (var peStream = new MemoryStream())
{
var ilBuilder = new BlobBuilder();
var metadataBuilder = new MetadataBuilder();
var entryPoint = BasicValidationEmit(metadataBuilder, ilBuilder);
WritePEImage(peStream, metadataBuilder, ilBuilder, entryPoint);
peStream.Position = 0;
var r = new PEReader(peStream);
var h = r.PEHeaders;
var mdReader = r.GetMetadataReader();
}
}
开发者ID:RoryVL,项目名称:roslyn,代码行数:15,代码来源:PEBuilderTests.cs
示例12: ImageWriter
ImageWriter(ModuleDefinition module, string runtime_version, MetadataBuilder metadata, Disposable<Stream> stream, bool metadataOnly = false)
: base(stream.value)
{
this.module = module;
this.runtime_version = runtime_version;
this.text_map = metadata.text_map;
this.stream = stream;
this.metadata = metadata;
if (metadataOnly)
return;
this.pe64 = module.Architecture == TargetArchitecture.AMD64 || module.Architecture == TargetArchitecture.IA64;
this.has_reloc = module.Architecture == TargetArchitecture.I386;
this.GetDebugHeader ();
this.GetWin32Resources ();
this.BuildTextMap ();
this.sections = (ushort) (has_reloc ? 2 : 1); // text + reloc?
}
开发者ID:jbevain,项目名称:cecil,代码行数:18,代码来源:ImageWriter.cs
示例13: PatchRawSection
void PatchRawSection (ByteBuffer buffer, MetadataBuilder metadata)
{
var position = base.position;
Align (4);
buffer.WriteBytes (base.position - position);
const byte fat_format = 0x40;
const byte more_sects = 0x80;
var flags = ReadByte ();
if ((flags & fat_format) == 0) {
buffer.WriteByte (flags);
PatchRawSmallSection (buffer, metadata);
} else
PatchRawFatSection (buffer, metadata);
if ((flags & more_sects) != 0)
PatchRawSection (buffer, metadata);
}
开发者ID:mayuki,项目名称:Inazuma,代码行数:19,代码来源:CodeReader.cs
示例14: PatchRawSmallSection
void PatchRawSmallSection (ByteBuffer buffer, MetadataBuilder metadata)
{
var length = ReadByte ();
buffer.WriteByte (length);
Advance (2);
buffer.WriteUInt16 (0);
var count = length / 12;
PatchRawExceptionHandlers (buffer, metadata, count, false);
}
开发者ID:mayuki,项目名称:Inazuma,代码行数:12,代码来源:CodeReader.cs
示例15: ValidateNestedClassTable
public void ValidateNestedClassTable()
{
var builder = new MetadataBuilder();
builder.AddNestedType(MetadataTokens.TypeDefinitionHandle(2), default(TypeDefinitionHandle));
builder.AddNestedType(MetadataTokens.TypeDefinitionHandle(1), default(TypeDefinitionHandle));
Assert.Throws<InvalidOperationException>(() => builder.ValidateOrder());
builder = new MetadataBuilder();
builder.AddNestedType(MetadataTokens.TypeDefinitionHandle(1), default(TypeDefinitionHandle));
builder.AddNestedType(MetadataTokens.TypeDefinitionHandle(1), default(TypeDefinitionHandle));
Assert.Throws<InvalidOperationException>(() => builder.ValidateOrder());
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:12,代码来源:MetadataBuilderTests.cs
示例16: GetOriginalToken
static MetadataToken GetOriginalToken (MetadataBuilder metadata, MethodDefinition method)
{
MetadataToken original;
if (metadata.TryGetOriginalMethodToken (method.token, out original))
return original;
return MetadataToken.Zero;
}
开发者ID:mayuki,项目名称:Inazuma,代码行数:8,代码来源:CodeReader.cs
示例17: HeapOverflow_UserString
public void HeapOverflow_UserString()
{
string veryLargeString = new string('x', 0x00fffff0 / 2);
var builder1 = new MetadataBuilder();
Assert.Equal(0x70000001, MetadataTokens.GetToken(builder1.GetOrAddUserString(veryLargeString)));
// TODO: https://github.com/dotnet/roslyn/issues/9852
// Should throw: Assert.Throws<ImageFormatLimitationException>(() => builder1.GetOrAddUserString("123"));
// Assert.Equal(0x70fffff6, MetadataTokens.GetToken(builder1.GetOrAddUserString("12")));
// Assert.Equal(0x70fffff6, MetadataTokens.GetToken(builder1.GetOrAddUserString("12")));
Assert.Equal(0x70fffff6, MetadataTokens.GetToken(builder1.GetOrAddUserString(veryLargeString + "z")));
Assert.Throws<ImageFormatLimitationException>(() => builder1.GetOrAddUserString("12"));
var builder2 = new MetadataBuilder();
Assert.Equal(0x70000001, MetadataTokens.GetToken(builder2.GetOrAddUserString("123")));
Assert.Equal(0x70000009, MetadataTokens.GetToken(builder2.GetOrAddUserString(veryLargeString)));
Assert.Equal(0x70fffffe, MetadataTokens.GetToken(builder2.GetOrAddUserString("4"))); // TODO: should throw https://github.com/dotnet/roslyn/issues/9852
var builder3 = new MetadataBuilder(userStringHeapStartOffset: 0x00fffffe);
Assert.Equal(0x70ffffff, MetadataTokens.GetToken(builder3.GetOrAddUserString("1"))); // TODO: should throw https://github.com/dotnet/roslyn/issues/9852
var builder4 = new MetadataBuilder(userStringHeapStartOffset: 0x00fffff7);
Assert.Equal(0x70fffff8, MetadataTokens.GetToken(builder4.GetOrAddUserString("1"))); // 4B
Assert.Equal(0x70fffffc, MetadataTokens.GetToken(builder4.GetOrAddUserString("2"))); // 4B
var builder5 = new MetadataBuilder(userStringHeapStartOffset: 0x00fffff8);
Assert.Equal(0x70fffff9, MetadataTokens.GetToken(builder5.GetOrAddUserString("1"))); // 4B
Assert.Equal(0x70fffffd, MetadataTokens.GetToken(builder5.GetOrAddUserString("2"))); // 4B // TODO: should throw https://github.com/dotnet/roslyn/issues/9852
}
开发者ID:Rookieek,项目名称:roslyn,代码行数:30,代码来源:MetadataBuilderTests.cs
示例18: Add
public void Add()
{
var builder = new MetadataBuilder();
builder.AddModule(default(Int32), default(StringHandle), default(GuidHandle), default(GuidHandle), default(GuidHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.Module]);
builder.AddAssembly(default(StringHandle), default(Version), default(StringHandle), default(BlobHandle), default(AssemblyFlags), default(AssemblyHashAlgorithm));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.Assembly]);
var assemblyReference = builder.AddAssemblyReference(default(StringHandle), default(Version), default(StringHandle), default(BlobHandle), default(AssemblyFlags), default(BlobHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.AssemblyRef]);
Assert.Equal(1, MetadataTokens.GetRowNumber(assemblyReference));
var typeDefinition = builder.AddTypeDefinition(default(TypeAttributes), default(StringHandle), default(StringHandle), default(EntityHandle), default(FieldDefinitionHandle), default(MethodDefinitionHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.TypeDef]);
Assert.Equal(1, MetadataTokens.GetRowNumber(typeDefinition));
builder.AddTypeLayout(default(TypeDefinitionHandle), default(UInt16), default(UInt32));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.ClassLayout]);
builder.AddInterfaceImplementation(MetadataTokens.TypeDefinitionHandle(1), MetadataTokens.TypeDefinitionHandle(1));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.InterfaceImpl]);
builder.AddNestedType(default(TypeDefinitionHandle), default(TypeDefinitionHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.NestedClass]);
var typeReference = builder.AddTypeReference(EntityHandle.ModuleDefinition, default(StringHandle), default(StringHandle));
Assert.Equal(1, MetadataTokens.GetRowNumber(typeReference));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.TypeRef]);
builder.AddTypeSpecification(default(BlobHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.TypeSpec]);
builder.AddStandaloneSignature(default(BlobHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.StandAloneSig]);
builder.AddProperty(default(PropertyAttributes), default(StringHandle), default(BlobHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.Property]);
builder.AddPropertyMap(default(TypeDefinitionHandle), default(PropertyDefinitionHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.PropertyMap]);
builder.AddEvent(default(EventAttributes), default(StringHandle), MetadataTokens.TypeDefinitionHandle(1));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.Event]);
builder.AddEventMap(default(TypeDefinitionHandle), default(EventDefinitionHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.EventMap]);
builder.AddConstant(MetadataTokens.FieldDefinitionHandle(1), default(Object));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.Constant]);
builder.AddMethodSemantics(MetadataTokens.EventDefinitionHandle(1), default(UInt16), default(MethodDefinitionHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.MethodSemantics]);
builder.AddCustomAttribute(MetadataTokens.TypeDefinitionHandle(1), MetadataTokens.MethodDefinitionHandle(1), default(BlobHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.CustomAttribute]);
builder.AddMethodSpecification(MetadataTokens.MethodDefinitionHandle(1), default(BlobHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.MethodSpec]);
builder.AddModuleReference(default(StringHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.ModuleRef]);
builder.AddParameter(default(ParameterAttributes), default(StringHandle), default(Int32));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.Param]);
var genericParameter = builder.AddGenericParameter(MetadataTokens.MethodDefinitionHandle(1), default(GenericParameterAttributes), default(StringHandle), default(Int32));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.GenericParam]);
Assert.Equal(1, MetadataTokens.GetRowNumber(genericParameter));
builder.AddGenericParameterConstraint(default(GenericParameterHandle), MetadataTokens.TypeDefinitionHandle(1));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.GenericParamConstraint]);
builder.AddFieldDefinition(default(FieldAttributes), default(StringHandle), default(BlobHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.Field]);
builder.AddFieldLayout(default(FieldDefinitionHandle), default(Int32));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.FieldLayout]);
builder.AddMarshallingDescriptor(MetadataTokens.FieldDefinitionHandle(1), default(BlobHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.FieldMarshal]);
builder.AddFieldRelativeVirtualAddress(default(FieldDefinitionHandle), default(Int32));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.FieldRva]);
var methodDefinition = builder.AddMethodDefinition(default(MethodAttributes), default(MethodImplAttributes), default(StringHandle), default(BlobHandle), default(Int32), default(ParameterHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.MethodDef]);
Assert.Equal(1, MetadataTokens.GetRowNumber(methodDefinition));
builder.AddMethodImport(MetadataTokens.MethodDefinitionHandle(1), default(MethodImportAttributes), default(StringHandle), default(ModuleReferenceHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.ImplMap]);
builder.AddMethodImplementation(default(TypeDefinitionHandle), MetadataTokens.MethodDefinitionHandle(1), MetadataTokens.MethodDefinitionHandle(1));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.MethodImpl]);
var memberReference = builder.AddMemberReference(MetadataTokens.TypeDefinitionHandle(1), default(StringHandle), default(BlobHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.MemberRef]);
Assert.Equal(1, MetadataTokens.GetRowNumber(memberReference));
//.........这里部分代码省略.........
开发者ID:Rookieek,项目名称:roslyn,代码行数:101,代码来源:MetadataBuilderTests.cs
示例19: ValidateLocalScopeTable
public void ValidateLocalScopeTable()
{
var builder = new MetadataBuilder();
builder.AddLocalScope(MetadataTokens.MethodDefinitionHandle(2), default(ImportScopeHandle), default(LocalVariableHandle), default(LocalConstantHandle), startOffset: 0, length: 1);
builder.AddLocalScope(MetadataTokens.MethodDefinitionHandle(1), default(ImportScopeHandle), default(LocalVariableHandle), default(LocalConstantHandle), startOffset: 0, length: 1);
Assert.Throws<InvalidOperationException>(() => builder.ValidateOrder());
builder = new MetadataBuilder();
builder.AddLocalScope(MetadataTokens.MethodDefinitionHandle(1), default(ImportScopeHandle), default(LocalVariableHandle), default(LocalConstantHandle), startOffset: 1, length: 1);
builder.AddLocalScope(MetadataTokens.MethodDefinitionHandle(1), default(ImportScopeHandle), default(LocalVariableHandle), default(LocalConstantHandle), startOffset: 0, length: 1);
Assert.Throws<InvalidOperationException>(() => builder.ValidateOrder());
builder = new MetadataBuilder();
builder.AddLocalScope(MetadataTokens.MethodDefinitionHandle(1), default(ImportScopeHandle), default(LocalVariableHandle), default(LocalConstantHandle), startOffset: 0, length: 1);
builder.AddLocalScope(MetadataTokens.MethodDefinitionHandle(1), default(ImportScopeHandle), default(LocalVariableHandle), default(LocalConstantHandle), startOffset: 0, length: 2);
Assert.Throws<InvalidOperationException>(() => builder.ValidateOrder());
builder = new MetadataBuilder();
builder.AddLocalScope(MetadataTokens.MethodDefinitionHandle(1), default(ImportScopeHandle), default(LocalVariableHandle), default(LocalConstantHandle), startOffset: 0, length: 1);
builder.AddLocalScope(MetadataTokens.MethodDefinitionHandle(1), default(ImportScopeHandle), default(LocalVariableHandle), default(LocalConstantHandle), startOffset: 0, length: 1);
builder.ValidateOrder(); // ok
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:22,代码来源:MetadataBuilderTests.cs
示例20: OnBeforeAddingResources
public override void OnBeforeAddingResources(MetadataBuilder builder)
{
if (!options.DecryptMethods)
return;
methodsDecrypter.encryptNativeMethods(builder);
}
开发者ID:Helroos,项目名称:de4dot,代码行数:6,代码来源:Deobfuscator.cs
注:本文中的MetadataBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论