本文整理汇总了C#中System.Reflection.Internal.MemoryBlock类的典型用法代码示例。如果您正苦于以下问题:C# MemoryBlock类的具体用法?C# MemoryBlock怎么用?C# MemoryBlock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemoryBlock类属于System.Reflection.Internal命名空间,在下文中一共展示了MemoryBlock类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: BlobReader
internal BlobReader(MemoryBlock block)
{
Debug.Assert(BitConverter.IsLittleEndian && block.Length >= 0 && (block.Pointer != null || block.Length == 0));
_block = block;
_currentPointer = block.Pointer;
_endPointer = block.Pointer + block.Length;
}
开发者ID:nandhanurrevanth,项目名称:corefx,代码行数:7,代码来源:BlobReader.cs
示例2: DefaultDecodingFallbackMatchesBcl
public unsafe void DefaultDecodingFallbackMatchesBcl()
{
byte[] buffer;
int bytesRead;
var decoder = MetadataStringDecoder.DefaultUTF8;
// dangling lead byte
fixed (byte* ptr = (buffer = new byte[] { 0xC0 }))
{
string s = new MemoryBlock(ptr, buffer.Length).PeekUtf8NullTerminated(0, null, decoder, out bytesRead);
Assert.Equal("\uFFFD", new MemoryBlock(ptr, buffer.Length).PeekUtf8NullTerminated(0, null, decoder, out bytesRead));
Assert.Equal(s, Encoding.UTF8.GetString(buffer));
Assert.Equal(buffer.Length, bytesRead);
s = new MemoryBlock(ptr, buffer.Length).PeekUtf8NullTerminated(0, Encoding.UTF8.GetBytes("Hello"), decoder, out bytesRead);
Assert.Equal("Hello\uFFFD", s);
Assert.Equal(s, "Hello" + Encoding.UTF8.GetString(buffer));
Assert.Equal(buffer.Length, bytesRead);
Assert.Equal("\uFFFD", new MemoryBlock(ptr, buffer.Length).PeekUtf8(0, buffer.Length));
}
// overlong encoding
fixed (byte* ptr = (buffer = new byte[] { (byte)'a', 0xC0, 0xAF, (byte)'b', 0x0 }))
{
var block = new MemoryBlock(ptr, buffer.Length);
Assert.Equal("a\uFFFD\uFFFDb", block.PeekUtf8NullTerminated(0, null, decoder, out bytesRead));
Assert.Equal(buffer.Length, bytesRead);
}
// TODO: There are a bunch more error cases of course, but this is enough to break the old code
// and we now just call the BCL, so from a white box perspective, we needn't get carried away.
}
开发者ID:hitomi333,项目名称:corefx,代码行数:33,代码来源:MemoryBlockTests.cs
示例3: MethodDebugInformationTableReader
internal MethodDebugInformationTableReader(
int numberOfRows,
int documentRefSize,
int blobHeapRefSize,
MemoryBlock containingBlock,
int containingBlockOffset)
{
NumberOfRows = numberOfRows;
_isDocumentRefSmall = documentRefSize == 2;
_isBlobHeapRefSizeSmall = blobHeapRefSize == 2;
_sequencePointsOffset = DocumentOffset + documentRefSize;
RowSize = _sequencePointsOffset + blobHeapRefSize;
Block = containingBlock.GetMemoryBlockAt(containingBlockOffset, RowSize * numberOfRows);
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:16,代码来源:Tables.Debug.cs
示例4: DocumentTableReader
internal DocumentTableReader(
int numberOfRows,
int guidHeapRefSize,
int blobHeapRefSize,
MemoryBlock containingBlock,
int containingBlockOffset)
{
NumberOfRows = numberOfRows;
_isGuidHeapRefSizeSmall = guidHeapRefSize == 2;
_isBlobHeapRefSizeSmall = blobHeapRefSize == 2;
_hashAlgorithmOffset = NameOffset + blobHeapRefSize;
_hashOffset = _hashAlgorithmOffset + guidHeapRefSize;
_languageOffset = _hashOffset + blobHeapRefSize;
RowSize = _languageOffset + guidHeapRefSize;
Block = containingBlock.GetMemoryBlockAt(containingBlockOffset, RowSize * numberOfRows);
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:18,代码来源:Tables.Debug.cs
示例5: ModuleTableReader
internal ModuleTableReader(
int numberOfRows,
int stringHeapRefSize,
int guidHeapRefSize,
MemoryBlock containingBlock,
int containingBlockOffset
)
{
this.NumberOfRows = numberOfRows;
_IsStringHeapRefSizeSmall = stringHeapRefSize == 2;
_IsGUIDHeapRefSizeSmall = guidHeapRefSize == 2;
_GenerationOffset = 0;
_NameOffset = _GenerationOffset + sizeof(UInt16);
_MVIdOffset = _NameOffset + stringHeapRefSize;
_EnCIdOffset = _MVIdOffset + guidHeapRefSize;
_EnCBaseIdOffset = _EnCIdOffset + guidHeapRefSize;
this.RowSize = _EnCBaseIdOffset + guidHeapRefSize;
this.Block = containingBlock.GetMemoryBlockAt(containingBlockOffset, this.RowSize * (int)numberOfRows);
}
开发者ID:jmhardison,项目名称:corefx,代码行数:19,代码来源:Tables.cs
示例6: TestUtf8NullTerminatedFastCompare
private void TestUtf8NullTerminatedFastCompare(
MemoryBlock block,
int offset,
char terminator,
string comparand,
int comparandOffset,
bool ignoreCase,
MemoryBlock.FastComparisonResult expectedResult,
int expectedFirstDifferenceIndex)
{
int actualFirstDifferenceIndex;
var actualResult = block.Utf8NullTerminatedFastCompare(offset, comparand, comparandOffset, out actualFirstDifferenceIndex, terminator, ignoreCase);
Assert.Equal(expectedResult, actualResult);
Assert.Equal(expectedFirstDifferenceIndex, actualFirstDifferenceIndex);
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:16,代码来源:MemoryBlockTests.cs
示例7: Utf8NullTerminatedFastCompare
public unsafe void Utf8NullTerminatedFastCompare()
{
byte[] heap;
MetadataStringDecoder decoder = MetadataStringDecoder.DefaultUTF8;
const bool HonorCase = false;
const bool IgnoreCase = true;
const char terminator_0 = '\0';
const char terminator_F = 'F';
const char terminator_X = 'X';
const char terminator_x = 'x';
fixed (byte* heapPtr = (heap = new byte[] { (byte)'F', 0, (byte)'X', (byte)'Y', /* U+12345 (\ud808\udf45) */ 0xf0, 0x92, 0x8d, 0x85 }))
{
var block = new MemoryBlock(heapPtr, heap.Length);
TestUtf8NullTerminatedFastCompare(block, 0, terminator_0, "F", 0, HonorCase, MemoryBlock.FastComparisonResult.Equal, 1);
TestUtf8NullTerminatedFastCompare(block, 0, terminator_0, "f", 0, IgnoreCase, MemoryBlock.FastComparisonResult.Equal, 1);
TestUtf8NullTerminatedFastCompare(block, 0, terminator_F, "", 0, IgnoreCase, MemoryBlock.FastComparisonResult.Equal, 0);
TestUtf8NullTerminatedFastCompare(block, 0, terminator_F, "*", 1, IgnoreCase, MemoryBlock.FastComparisonResult.Equal, 1);
TestUtf8NullTerminatedFastCompare(block, 0, terminator_0, "FF", 0, HonorCase, MemoryBlock.FastComparisonResult.TextStartsWithBytes, 1);
TestUtf8NullTerminatedFastCompare(block, 0, terminator_0, "fF", 0, IgnoreCase, MemoryBlock.FastComparisonResult.TextStartsWithBytes, 1);
TestUtf8NullTerminatedFastCompare(block, 0, terminator_0, "F\0", 0, HonorCase, MemoryBlock.FastComparisonResult.TextStartsWithBytes, 1);
TestUtf8NullTerminatedFastCompare(block, 0, terminator_X, "F\0", 0, HonorCase, MemoryBlock.FastComparisonResult.TextStartsWithBytes, 1);
TestUtf8NullTerminatedFastCompare(block, 2, terminator_0, "X", 0, HonorCase, MemoryBlock.FastComparisonResult.BytesStartWithText, 1);
TestUtf8NullTerminatedFastCompare(block, 2, terminator_0, "x", 0, IgnoreCase, MemoryBlock.FastComparisonResult.BytesStartWithText, 1);
TestUtf8NullTerminatedFastCompare(block, 2, terminator_x, "XY", 0, IgnoreCase, MemoryBlock.FastComparisonResult.BytesStartWithText, 2);
TestUtf8NullTerminatedFastCompare(block, 3, terminator_0, "yZ", 0, IgnoreCase, MemoryBlock.FastComparisonResult.Unequal, 1);
TestUtf8NullTerminatedFastCompare(block, 4, terminator_0, "a", 0, HonorCase, MemoryBlock.FastComparisonResult.Unequal, 0);
TestUtf8NullTerminatedFastCompare(block, 4, terminator_0, "\ud808", 0, HonorCase, MemoryBlock.FastComparisonResult.Inconclusive, 0);
TestUtf8NullTerminatedFastCompare(block, 4, terminator_0, "\ud808\udf45", 0, HonorCase, MemoryBlock.FastComparisonResult.Inconclusive, 0);
}
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:37,代码来源:MemoryBlockTests.cs
示例8: TestComparison
private static unsafe void TestComparison(MemoryBlock block, int offset, string value, string heapSubstr, MetadataStringDecoder decoder, bool ignoreCase)
{
// equals:
bool actualEq = block.Utf8NullTerminatedEquals(offset, value, decoder, terminator: '\0', ignoreCase: ignoreCase);
bool expectedEq = string.Equals(heapSubstr, value, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal);
Assert.Equal(expectedEq, actualEq);
// starts with:
bool actualSW = block.Utf8NullTerminatedStartsWith(offset, value, decoder, terminator: '\0', ignoreCase: ignoreCase);
bool expectedSW = heapSubstr.StartsWith(value, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal);
Assert.Equal(actualSW, expectedSW);
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:12,代码来源:MemoryBlockTests.cs
示例9: ConstantTableReader
internal ConstantTableReader(
int numberOfRows,
bool declaredSorted,
int hasConstantRefSize,
int blobHeapRefSize,
MemoryBlock containingBlock,
int containingBlockOffset
)
{
this.NumberOfRows = numberOfRows;
_IsHasConstantRefSizeSmall = hasConstantRefSize == 2;
_IsBlobHeapRefSizeSmall = blobHeapRefSize == 2;
_TypeOffset = 0;
_ParentOffset = _TypeOffset + sizeof(Byte) + 1; // Alignment here (+1)...
_ValueOffset = _ParentOffset + hasConstantRefSize;
this.RowSize = _ValueOffset + blobHeapRefSize;
this.Block = containingBlock.GetMemoryBlockAt(containingBlockOffset, (int)(this.RowSize * numberOfRows));
if (!declaredSorted && !CheckSorted())
{
Throw.TableNotSorted(TableIndex.Constant);
}
}
开发者ID:jmhardison,项目名称:corefx,代码行数:23,代码来源:Tables.cs
示例10: PeekReference
public unsafe void PeekReference()
{
var table = new byte[]
{
0xff, 0xff, 0xff, 0x00, // offset 0
0xff, 0xff, 0xff, 0x01, // offset 4
0xff, 0xff, 0xff, 0x1f, // offset 8
0xff, 0xff, 0xff, 0x2f, // offset 12
0xff, 0xff, 0xff, 0xff, // offset 16
};
fixed (byte* tablePtr = table)
{
var block = new MemoryBlock(tablePtr, table.Length);
Assert.Equal(0x0000ffff, block.PeekReference(0, smallRefSize: true));
Assert.Equal(0x0000ffff, block.PeekHeapReference(0, smallRefSize: true));
Assert.Equal(0x0000ffffu, block.PeekReferenceUnchecked(0, smallRefSize: true));
Assert.Equal(0x00ffffff, block.PeekReference(0, smallRefSize: false));
Assert.Throws<BadImageFormatException>(() => block.PeekReference(4, smallRefSize: false));
Assert.Throws<BadImageFormatException>(() => block.PeekReference(16, smallRefSize: false));
Assert.Equal(0x1fffffff, block.PeekHeapReference(8, smallRefSize: false));
Assert.Throws<BadImageFormatException>(() => block.PeekHeapReference(12, smallRefSize: false));
Assert.Throws<BadImageFormatException>(() => block.PeekHeapReference(16, smallRefSize: false));
Assert.Equal(0x01ffffffu, block.PeekReferenceUnchecked(4, smallRefSize: false));
Assert.Equal(0x1fffffffu, block.PeekReferenceUnchecked(8, smallRefSize: false));
Assert.Equal(0x2fffffffu, block.PeekReferenceUnchecked(12, smallRefSize: false));
Assert.Equal(0xffffffffu, block.PeekReferenceUnchecked(16, smallRefSize: false));
}
}
开发者ID:hitomi333,项目名称:corefx,代码行数:33,代码来源:MemoryBlockTests.cs
示例11: TestSearch
private unsafe void TestSearch(string heapValue, int offset, string[] values)
{
byte[] heap;
fixed (byte* heapPtr = (heap = Encoding.UTF8.GetBytes(heapValue)))
{
int actual = new MemoryBlock(heapPtr, heap.Length).BinarySearch(values, offset);
string heapSubstr = GetStringHeapValue(heapValue, offset);
int expected = Array.BinarySearch(values, heapSubstr);
Assert.Equal(expected, actual);
}
}
开发者ID:hitomi333,项目名称:corefx,代码行数:14,代码来源:MemoryBlockTests.cs
示例12: MetadataReader
/// <summary>
/// Creates a metadata reader from the metadata stored at the given memory location.
/// </summary>
/// <remarks>
/// The memory is owned by the caller and it must be kept memory alive and unmodified throughout the lifetime of the <see cref="MetadataReader"/>.
/// Use <see cref="PEReaderExtensions.GetMetadataReader(PortableExecutable.PEReader, MetadataReaderOptions, MetadataStringDecoder)"/> to obtain
/// metadata from a PE image.
/// </remarks>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="length"/> is not positive.</exception>
/// <exception cref="ArgumentNullException"><paramref name="metadata"/> is null.</exception>
/// <exception cref="ArgumentException">The encoding of <paramref name="utf8Decoder"/> is not <see cref="UTF8Encoding"/>.</exception>
/// <exception cref="PlatformNotSupportedException">The current platform is big-endian.</exception>
public unsafe MetadataReader(byte* metadata, int length, MetadataReaderOptions options, MetadataStringDecoder utf8Decoder)
{
// Do not throw here when length is 0. We'll throw BadImageFormatException later on, so that the caller doesn't need to
// worry about the image (stream) being empty and can handle all image errors by catching BadImageFormatException.
if (length < 0)
{
throw new ArgumentOutOfRangeException(nameof(length));
}
if (metadata == null)
{
throw new ArgumentNullException(nameof(metadata));
}
if (utf8Decoder == null)
{
utf8Decoder = MetadataStringDecoder.DefaultUTF8;
}
if (!(utf8Decoder.Encoding is UTF8Encoding))
{
throw new ArgumentException(SR.MetadataStringDecoderEncodingMustBeUtf8, nameof(utf8Decoder));
}
if (!BitConverter.IsLittleEndian)
{
Throw.LitteEndianArchitectureRequired();
}
this.Block = new MemoryBlock(metadata, length);
_options = options;
this.UTF8Decoder = utf8Decoder;
var headerReader = new BlobReader(this.Block);
this.ReadMetadataHeader(ref headerReader, out _versionString);
_metadataKind = GetMetadataKind(_versionString);
var streamHeaders = this.ReadStreamHeaders(ref headerReader);
// storage header and stream headers:
MemoryBlock metadataTableStream;
MemoryBlock standalonePdbStream;
this.InitializeStreamReaders(ref this.Block, streamHeaders, out _metadataStreamKind, out metadataTableStream, out standalonePdbStream);
int[] externalTableRowCountsOpt;
if (standalonePdbStream.Length > 0)
{
ReadStandalonePortablePdbStream(standalonePdbStream, out _debugMetadataHeader, out externalTableRowCountsOpt);
}
else
{
externalTableRowCountsOpt = null;
}
var tableReader = new BlobReader(metadataTableStream);
HeapSizes heapSizes;
int[] metadataTableRowCounts;
this.ReadMetadataTableHeader(ref tableReader, out heapSizes, out metadataTableRowCounts, out _sortedTables);
this.InitializeTableReaders(tableReader.GetMemoryBlockAt(0, tableReader.RemainingBytes), heapSizes, metadataTableRowCounts, externalTableRowCountsOpt);
// This previously could occur in obfuscated assemblies but a check was added to prevent
// it getting to this point
Debug.Assert(this.AssemblyTable.NumberOfRows <= 1);
// Although the specification states that the module table will have exactly one row,
// the native metadata reader would successfully read files containing more than one row.
// Such files exist in the wild and may be produced by obfuscators.
if (standalonePdbStream.Length == 0 && this.ModuleTable.NumberOfRows < 1)
{
throw new BadImageFormatException(SR.Format(SR.ModuleTableInvalidNumberOfRows, this.ModuleTable.NumberOfRows));
}
// read
this.NamespaceCache = new NamespaceCache(this);
if (_metadataKind != MetadataKind.Ecma335)
{
this.WinMDMscorlibRef = FindMscorlibAssemblyRefNoProjection();
}
}
开发者ID:SamuelEnglard,项目名称:corefx,代码行数:94,代码来源:MetadataReader.cs
示例13: InitializeTableReaders
private void InitializeTableReaders(MemoryBlock metadataTablesMemoryBlock, HeapSizes heapSizes, int[] rowCounts, int[] externalRowCountsOpt)
{
// Size of reference tags in each table.
this.TableRowCounts = rowCounts;
// TODO (https://github.com/dotnet/corefx/issues/2061):
// Shouldn't XxxPtr table be always the same size or smaller than the corresponding Xxx table?
// Compute ref sizes for tables that can have pointer tables
int fieldRefSizeSorted = GetReferenceSize(rowCounts, TableIndex.FieldPtr) > SmallIndexSize ? LargeIndexSize : GetReferenceSize(rowCounts, TableIndex.Field);
int methodRefSizeSorted = GetReferenceSize(rowCounts, TableIndex.MethodPtr) > SmallIndexSize ? LargeIndexSize : GetReferenceSize(rowCounts, TableIndex.MethodDef);
int paramRefSizeSorted = GetReferenceSize(rowCounts, TableIndex.ParamPtr) > SmallIndexSize ? LargeIndexSize : GetReferenceSize(rowCounts, TableIndex.Param);
int eventRefSizeSorted = GetReferenceSize(rowCounts, TableIndex.EventPtr) > SmallIndexSize ? LargeIndexSize : GetReferenceSize(rowCounts, TableIndex.Event);
int propertyRefSizeSorted = GetReferenceSize(rowCounts, TableIndex.PropertyPtr) > SmallIndexSize ? LargeIndexSize : GetReferenceSize(rowCounts, TableIndex.Property);
// Compute the coded token ref sizes
int typeDefOrRefRefSize = ComputeCodedTokenSize(TypeDefOrRefTag.LargeRowSize, rowCounts, TypeDefOrRefTag.TablesReferenced);
int hasConstantRefSize = ComputeCodedTokenSize(HasConstantTag.LargeRowSize, rowCounts, HasConstantTag.TablesReferenced);
int hasCustomAttributeRefSize = ComputeCodedTokenSize(HasCustomAttributeTag.LargeRowSize, rowCounts, HasCustomAttributeTag.TablesReferenced);
int hasFieldMarshalRefSize = ComputeCodedTokenSize(HasFieldMarshalTag.LargeRowSize, rowCounts, HasFieldMarshalTag.TablesReferenced);
int hasDeclSecurityRefSize = ComputeCodedTokenSize(HasDeclSecurityTag.LargeRowSize, rowCounts, HasDeclSecurityTag.TablesReferenced);
int memberRefParentRefSize = ComputeCodedTokenSize(MemberRefParentTag.LargeRowSize, rowCounts, MemberRefParentTag.TablesReferenced);
int hasSemanticsRefSize = ComputeCodedTokenSize(HasSemanticsTag.LargeRowSize, rowCounts, HasSemanticsTag.TablesReferenced);
int methodDefOrRefRefSize = ComputeCodedTokenSize(MethodDefOrRefTag.LargeRowSize, rowCounts, MethodDefOrRefTag.TablesReferenced);
int memberForwardedRefSize = ComputeCodedTokenSize(MemberForwardedTag.LargeRowSize, rowCounts, MemberForwardedTag.TablesReferenced);
int implementationRefSize = ComputeCodedTokenSize(ImplementationTag.LargeRowSize, rowCounts, ImplementationTag.TablesReferenced);
int customAttributeTypeRefSize = ComputeCodedTokenSize(CustomAttributeTypeTag.LargeRowSize, rowCounts, CustomAttributeTypeTag.TablesReferenced);
int resolutionScopeRefSize = ComputeCodedTokenSize(ResolutionScopeTag.LargeRowSize, rowCounts, ResolutionScopeTag.TablesReferenced);
int typeOrMethodDefRefSize = ComputeCodedTokenSize(TypeOrMethodDefTag.LargeRowSize, rowCounts, TypeOrMethodDefTag.TablesReferenced);
// Compute HeapRef Sizes
int stringHeapRefSize = (heapSizes & HeapSizes.StringHeapLarge) == HeapSizes.StringHeapLarge ? LargeIndexSize : SmallIndexSize;
int guidHeapRefSize = (heapSizes & HeapSizes.GuidHeapLarge) == HeapSizes.GuidHeapLarge ? LargeIndexSize : SmallIndexSize;
int blobHeapRefSize = (heapSizes & HeapSizes.BlobHeapLarge) == HeapSizes.BlobHeapLarge ? LargeIndexSize : SmallIndexSize;
// Populate the Table blocks
int totalRequiredSize = 0;
this.ModuleTable = new ModuleTableReader(rowCounts[(int)TableIndex.Module], stringHeapRefSize, guidHeapRefSize, metadataTablesMemoryBlock, totalRequiredSize);
totalRequiredSize += this.ModuleTable.Block.Length;
this.TypeRefTable = new TypeRefTableReader(rowCounts[(int)TableIndex.TypeRef], resolutionScopeRefSize, stringHeapRefSize, metadataTablesMemoryBlock, totalRequiredSize);
totalRequiredSize += this.TypeRefTable.Block.Length;
this.TypeDefTable = new TypeDefTableReader(rowCounts[(int)TableIndex.TypeDef], fieldRefSizeSorted, methodRefSizeSorted, typeDefOrRefRefSize, stringHeapRefSize, metadataTablesMemoryBlock, totalRequiredSize);
totalRequiredSize += this.TypeDefTable.Block.Length;
this.FieldPtrTable = new FieldPtrTableReader(rowCounts[(int)TableIndex.FieldPtr], GetReferenceSize(rowCounts, TableIndex.Field), metadataTablesMemoryBlock, totalRequiredSize);
totalRequiredSize += this.FieldPtrTable.Block.Length;
this.FieldTable = new FieldTableReader(rowCounts[(int)TableIndex.Field], stringHeapRefSize, blobHeapRefSize, metadataTablesMemoryBlock, totalRequiredSize);
totalRequiredSize += this.FieldTable.Block.Length;
this.MethodPtrTable = new MethodPtrTableReader(rowCounts[(int)TableIndex.MethodPtr], GetReferenceSize(rowCounts, TableIndex.MethodDef), metadataTablesMemoryBlock, totalRequiredSize);
totalRequiredSize += this.MethodPtrTable.Block.Length;
this.MethodDefTable = new MethodTableReader(rowCounts[(int)TableIndex.MethodDef], paramRefSizeSorted, stringHeapRefSize, blobHeapRefSize, metadataTablesMemoryBlock, totalRequiredSize);
totalRequiredSize += this.MethodDefTable.Block.Length;
this.ParamPtrTable = new ParamPtrTableReader(rowCounts[(int)TableIndex.ParamPtr], GetReferenceSize(rowCounts, TableIndex.Param), metadataTablesMemoryBlock, totalRequiredSize);
totalRequiredSize += this.ParamPtrTable.Block.Length;
this.ParamTable = new ParamTableReader(rowCounts[(int)TableIndex.Param], stringHeapRefSize, metadataTablesMemoryBlock, totalRequiredSize);
totalRequiredSize += this.ParamTable.Block.Length;
this.InterfaceImplTable = new InterfaceImplTableReader(rowCounts[(int)TableIndex.InterfaceImpl], IsDeclaredSorted(TableMask.InterfaceImpl), GetReferenceSize(rowCounts, TableIndex.TypeDef), typeDefOrRefRefSize, metadataTablesMemoryBlock, totalRequiredSize);
totalRequiredSize += this.InterfaceImplTable.Block.Length;
this.MemberRefTable = new MemberRefTableReader(rowCounts[(int)TableIndex.MemberRef], memberRefParentRefSize, stringHeapRefSize, blobHeapRefSize, metadataTablesMemoryBlock, totalRequiredSize);
totalRequiredSize += this.MemberRefTable.Block.Length;
this.ConstantTable = new ConstantTableReader(rowCounts[(int)TableIndex.Constant], IsDeclaredSorted(TableMask.Constant), hasConstantRefSize, blobHeapRefSize, metadataTablesMemoryBlock, totalRequiredSize);
totalRequiredSize += this.ConstantTable.Block.Length;
this.CustomAttributeTable = new CustomAttributeTableReader(rowCounts[(int)TableIndex.CustomAttribute],
IsDeclaredSorted(TableMask.CustomAttribute),
hasCustomAttributeRefSize,
customAttributeTypeRefSize,
blobHeapRefSize,
metadataTablesMemoryBlock,
totalRequiredSize);
totalRequiredSize += this.CustomAttributeTable.Block.Length;
this.FieldMarshalTable = new FieldMarshalTableReader(rowCounts[(int)TableIndex.FieldMarshal], IsDeclaredSorted(TableMask.FieldMarshal), hasFieldMarshalRefSize, blobHeapRefSize, metadataTablesMemoryBlock, totalRequiredSize);
totalRequiredSize += this.FieldMarshalTable.Block.Length;
this.DeclSecurityTable = new DeclSecurityTableReader(rowCounts[(int)TableIndex.DeclSecurity], IsDeclaredSorted(TableMask.DeclSecurity), hasDeclSecurityRefSize, blobHeapRefSize, metadataTablesMemoryBlock, totalRequiredSize);
totalRequiredSize += this.DeclSecurityTable.Block.Length;
this.ClassLayoutTable = new ClassLayoutTableReader(rowCounts[(int)TableIndex.ClassLayout], IsDeclaredSorted(TableMask.ClassLayout), GetReferenceSize(rowCounts, TableIndex.TypeDef), metadataTablesMemoryBlock, totalRequiredSize);
totalRequiredSize += this.ClassLayoutTable.Block.Length;
this.FieldLayoutTable = new FieldLayoutTableReader(rowCounts[(int)TableIndex.FieldLayout], IsDeclaredSorted(TableMask.FieldLayout), GetReferenceSize(rowCounts, TableIndex.Field), metadataTablesMemoryBlock, totalRequiredSize);
totalRequiredSize += this.FieldLayoutTable.Block.Length;
this.StandAloneSigTable = new StandAloneSigTableReader(rowCounts[(int)TableIndex.StandAloneSig], blobHeapRefSize, metadataTablesMemoryBlock, totalRequiredSize);
totalRequiredSize += this.StandAloneSigTable.Block.Length;
this.EventMapTable = new EventMapTableReader(rowCounts[(int)TableIndex.EventMap], GetReferenceSize(rowCounts, TableIndex.TypeDef), eventRefSizeSorted, metadataTablesMemoryBlock, totalRequiredSize);
totalRequiredSize += this.EventMapTable.Block.Length;
//.........这里部分代码省略.........
开发者ID:SamuelEnglard,项目名称:corefx,代码行数:101,代码来源:MetadataReader.cs
示例14: ReadStandalonePortablePdbStream
// internal for testing
internal static void ReadStandalonePortablePdbStream(MemoryBlock block, out DebugMetadataHeader debugMetadataHeader, out int[] externalTableRowCounts)
{
var reader = new BlobReader(block);
const int PdbIdSize = 20;
byte[] pdbId = reader.ReadBytes(PdbIdSize);
// ECMA-335 15.4.1.2:
// The entry point to an application shall be static.
// This entry point method can be a global method or it can appear inside a type.
// The entry point method shall either accept no arguments or a vector of strings.
// The return type of the entry point method shall be void, int32, or unsigned int32.
// The entry point method cannot be defined in a generic class.
uint entryPointToken = reader.ReadUInt32();
int entryPointRowId = (int)(entryPointToken & TokenTypeIds.RIDMask);
if (entryPointToken != 0 && ((entryPointToken & TokenTypeIds.TypeMask) != TokenTypeIds.MethodDef || entryPointRowId == 0))
{
throw new BadImageFormatException(string.Format(SR.InvalidEntryPointToken, entryPointToken));
}
ulong externalTableMask = reader.ReadUInt64();
// EnC & Ptr tables can't be referenced from standalone PDB metadata:
const ulong validTables = (ulong)TableMask.ValidPortablePdbExternalTables;
if ((externalTableMask & ~validTables) != 0)
{
throw new BadImageFormatException(string.Format(SR.UnknownTables, (TableMask)externalTableMask));
}
externalTableRowCounts = ReadMetadataTableRowCounts(ref reader, externalTableMask);
debugMetadataHeader = new DebugMetadataHeader(
ImmutableByteArrayInterop.DangerousCreateFromUnderlyingArray(ref pdbId),
MethodDefinitionHandle.FromRowId(entryPointRowId));
}
开发者ID:SamuelEnglard,项目名称:corefx,代码行数:37,代码来源:MetadataReader.cs
示例15: DeclSecurityTableReader
internal DeclSecurityTableReader(
int numberOfRows,
bool declaredSorted,
int hasDeclSecurityRefSize,
int blobHeapRefSize,
MemoryBlock containingBlock,
int containingBlockOffset
)
{
this.NumberOfRows = numberOfRows;
_IsHasDeclSecurityRefSizeSmall = hasDeclSecurityRefSize == 2;
_IsBlobHeapRefSizeSmall = blobHeapRefSize == 2;
_ActionOffset = 0;
_ParentOffset = _ActionOffset + sizeof(UInt16);
_PermissionSetOffset = _ParentOffset + hasDeclSecurityRefSize;
this.RowSize = _PermissionSetOffset + blobHeapRefSize;
this.Block = containingBlock.GetMemoryBlockAt(containingBlockOffset, (int)(this.RowSize * numberOfRows));
if (!declaredSorted && !CheckSorted())
{
Throw.TableNotSorted(TableIndex.DeclSecurity);
}
}
开发者ID:jmhardison,项目名称:corefx,代码行数:23,代码来源:Tables.cs
示例16: FieldMarshalTableReader
internal FieldMarshalTableReader(
int numberOfRows,
bool declaredSorted,
int hasFieldMarshalRefSize,
int blobHeapRefSize,
MemoryBlock containingBlock,
int containingBlockOffset
)
{
this.NumberOfRows = numberOfRows;
_IsHasFieldMarshalRefSizeSmall = hasFieldMarshalRefSize == 2;
_IsBlobHeapRefSizeSmall = blobHeapRefSize == 2;
_ParentOffset = 0;
_NativeTypeOffset = _ParentOffset + hasFieldMarshalRefSize;
this.RowSize = _NativeTypeOffset + blobHeapRefSize;
this.Block = containingBlock.GetMemoryBlockAt(containingBlockOffset, this.RowSize * numberOfRows);
if (!declaredSorted && !CheckSorted())
{
Throw.TableNotSorted(TableIndex.FieldMarshal);
}
}
开发者ID:jmhardison,项目名称:corefx,代码行数:22,代码来源:Tables.cs
示例17: TypeRefTableReader
internal TypeRefTableReader(
int numberOfRows,
int resolutionScopeRefSize,
int stringHeapRefSize,
MemoryBlock containingBlock,
int containingBlockOffset
)
{
this.NumberOfRows = numberOfRows;
_IsResolutionScopeRefSizeSmall = resolutionScopeRefSize == 2;
_IsStringHeapRefSizeSmall = stringHeapRefSize == 2;
_ResolutionScopeOffset = 0;
_NameOffset = _ResolutionScopeOffset + resolutionScopeRefSize;
_NamespaceOffset = _NameOffset + stringHeapRefSize;
this.RowSize = _NamespaceOffset + stringHeapRefSize;
this.Block = containingBlock.GetMemoryBlockAt(containingBlockOffset, (int)(this.RowSize * numberOfRows));
}
开发者ID:jmhardison,项目名称:corefx,代码行数:17,代码来源:Tables.cs
示例18: CustomAttributeTableReader
internal CustomAttributeTableReader(
int numberOfRows,
bool declaredSorted,
int hasCustomAttributeRefSize,
int customAttributeTypeRefSize,
int blobHeapRefSize,
MemoryBlock containingBlock,
int containingBlockOffset
)
{
this.NumberOfRows = numberOfRows;
_IsHasCustomAttributeRefSizeSmall = hasCustomAttributeRefSize == 2;
_IsCustomAttributeTypeRefSizeSmall = customAttributeTypeRefSize == 2;
_IsBlobHeapRefSizeSmall = blobHeapRefSize == 2;
_ParentOffset = 0;
_TypeOffset = _ParentOffset + hasCustomAttributeRefSize;
_ValueOffset = _TypeOffset + customAttributeTypeRefSize;
this.RowSize = _ValueOffset + blobHeapRefSize;
this.Block = containingBlock.GetMemoryBlockAt(containingBlockOffset, (int)(this.RowSize * numberOfRows));
this.PtrTable = null;
if (!declaredSorted && !CheckSorted())
{
this.PtrTable = this.Block.BuildPtrTable(
numberOfRows,
this.RowSize,
_ParentOffset,
_IsHasCustomAttributeRefSizeSmall);
}
}
开发者ID:jmhardison,项目名称:corefx,代码行数:30,代码来源:Tables.cs
示例19: TestComparisons
private unsafe void TestComparisons(string heapValue, int offset, string value, bool unicode = false)
{
byte[] heap;
MetadataStringDecoder decoder = MetadataStringDecoder.DefaultUTF8;
fixed (byte* heapPtr = (heap = Encoding.UTF8.GetBytes(heapValue)))
{
var block = new MemoryBlock(heapPtr, heap.Length);
string heapSubstr = GetStringHeapValue(heapValue, offset);
// compare:
if (!unicode)
{
int actualCmp = block.CompareUtf8NullTerminatedStringWithAsciiString(offset, value);
int expectedCmp = StringComparer.Ordinal.Compare(heapSubstr, value);
Assert.Equal(Math.Sign(expectedCmp), Math.Sign(actualCmp));
}
// equals:
bool actualEq = block.Utf8NullTerminatedEquals(offset, value, decoder);
bool expectedEq = StringComparer.Ordinal.Equals(heapSubstr, value);
Assert.Equal(expectedEq, actualEq);
// starts with:
bool actualSW = block.Utf8NullTerminatedStartsWith(offset, value, decoder);
bool expectedSW = heapSubstr.StartsWith(value, StringComparison.Ordinal);
Assert.Equal(actualSW, expectedSW);
}
}
开发者ID:hitomi333,项目名称:corefx,代码行数:29,代码来源:MemoryBlockTests.cs
示例20: ComparisonToInvalidByteSequenceMatchesFallback
public unsafe void ComparisonToInvalidByteSequenceMatchesFallback()
{
MetadataStringDecoder decoder = MetadataStringDecoder.DefaultUTF8;
// dangling lead byte
byte[] buffer;
fixed (byte* ptr = (buffer = new byte[] { 0xC0 }))
{
var block = new MemoryBlock(ptr, buffer.Length);
Assert.False(block.Utf8NullTerminatedStartsWith(0, new string((char)0xC0, 1), decoder));
Assert.False(block.Utf8NullTerminatedEquals(0, new string((char)0xC0, 1), decoder));
Assert.True(block.Utf8NullTerminatedStartsWith(0, "\uFFFD", decoder));
Assert.True(block.Utf8NullTerminatedEquals(0, "\uFFFD", decoder));
}
// overlong encoding
fixed (byte* ptr = (buffer = new byte[] { (byte)'a', 0xC0, 0xAF, (byte)'b', 0x0 }))
{
var block = new MemoryBlock(ptr, buffer.Length);
Assert.False(block.Utf8NullTerminatedStartsWith(0, "a\\", decoder));
Assert.False(block.Utf8NullTerminatedEquals(0, "a\\b", decoder));
Assert.True(block.Utf8NullTerminatedStartsWith(0, "a\uFFFD", decoder));
Assert.True(block.Utf8NullTerminatedEquals(0, "a\uFFFD\uFFFDb", decoder));
}
}
开发者ID:hitomi333,项目名称:corefx,代码行数:25,代码来源:MemoryBlockTests.cs
注:本文中的System.Reflection.Internal.MemoryBlock类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论