本文整理汇总了C#中System.Reflection.Internal.MemoryBlock类的典型用法代码示例。如果您正苦于以下问题:C# MemoryBlock类的具体用法?C# MemoryBlock怎么用?C# MemoryBlock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemoryBlock类属于System.Reflection.Internal命名空间,在下文中一共展示了MemoryBlock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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.
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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));
}
}
示例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);
}
}
示例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();
}
}
示例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;
//.........这里部分代码省略.........
示例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));
}
示例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);
}
}