public unsafe void BuildPtrTable_SmallRefs() { const int rowSize = 4; const int secondColumnOffset = 2; var table = new byte[] { 0xAA, 0xAA, 0x05, 0x00, 0xBB, 0xBB, 0x04, 0x00, 0xCC, 0xCC, 0x02, 0x01, 0xDD, 0xDD, 0x02, 0x00, 0xEE, 0xEE, 0x01, 0x01, }; int rowCount = table.Length / rowSize; fixed(byte *tablePtr = table) { var block = new MemoryBlock(tablePtr, table.Length); Assert.Equal(0x0004U, block.PeekReference(6, smallRefSize: true)); var actual = block.BuildPtrTable(rowCount, rowSize, secondColumnOffset, isReferenceSmall: true); var expected = new uint[] { 4, 2, 1, 5, 3 }; AssertEx.Equal(expected, actual); } }
public unsafe void ValidatePeekReferenceSize() { byte[] buffer = new byte[8] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01 }; fixed(byte *bufferPtr = buffer) { var block = new MemoryBlock(bufferPtr, buffer.Length); // small ref size always fits in 16 bits Assert.Equal(0xFFFFU, block.PeekReference(0, smallRefSize: true)); Assert.Equal(0xFFFFU, block.PeekReference(4, smallRefSize: true)); Assert.Equal(0xFFFFU, block.PeekTaggedReference(0, smallRefSize: true)); Assert.Equal(0xFFFFU, block.PeekTaggedReference(4, smallRefSize: true)); Assert.Equal(0x01FFU, block.PeekTaggedReference(6, smallRefSize: true)); // large ref size throws on > RIDMask when tagged variant is not used. AssertEx.Throws <BadImageFormatException>(() => block.PeekReference(0, smallRefSize: false), MetadataResources.RowIdOrHeapOffsetTooLarge); AssertEx.Throws <BadImageFormatException>(() => block.PeekReference(4, smallRefSize: false), MetadataResources.RowIdOrHeapOffsetTooLarge); // large ref size does not throw when Tagged variant is used. Assert.Equal(0xFFFFFFFFU, block.PeekTaggedReference(0, smallRefSize: false)); Assert.Equal(0x01FFFFFFU, block.PeekTaggedReference(4, smallRefSize: false)); // bounds check applies in all cases AssertEx.Throws <BadImageFormatException>(() => block.PeekReference(7, smallRefSize: true), MetadataResources.OutOfBoundsRead); AssertEx.Throws <BadImageFormatException>(() => block.PeekReference(5, smallRefSize: false), MetadataResources.OutOfBoundsRead); } }
internal ImportScopeHandle GetParent(ImportScopeHandle handle) { int rowOffset = (handle.RowId - 1) * RowSize; return(ImportScopeHandle.FromRowId(Block.PeekReference(rowOffset + ParentOffset, _isImportScopeRefSizeSmall))); }
private MethodDefinitionHandle GetKickoffMethod(int rowId) { int rowOffset = (rowId - 1) * RowSize; return(MethodDefinitionHandle.FromRowId(Block.PeekReference(rowOffset + _kickoffMethodOffset, _isMethodRefSizeSmall))); }
internal MethodDefinitionHandle GetMethod(int rowId) { int rowOffset = (rowId - 1) * RowSize; return(MethodDefinitionHandle.FromRowId(Block.PeekReference(rowOffset + MethodOffset, _isMethodRefSmall))); }
internal DocumentHandle GetDocument(MethodDebugInformationHandle handle) { int rowOffset = (handle.RowId - 1) * RowSize; return(DocumentHandle.FromRowId(Block.PeekReference(rowOffset + DocumentOffset, _isDocumentRefSmall))); }