Ejemplo n.º 1
0
 void IDotNetHeap.SetMetadata(DotNetMetadataHeaders metadata) => this.metadata = metadata;
Ejemplo n.º 2
0
        HexSpan?GetGoToMetadataSpan(DotNetMetadataHeaders mdHeaders, PeHeaders peHeaders, uint offsetTokenValue, GoToMetadataKind mdKind)
        {
            MDTable mdTable;

            switch (mdKind)
            {
            case GoToMetadataKind.Blob:
                if (mdHeaders.BlobStream == null)
                {
                    return(null);
                }
                return(new HexSpan(mdHeaders.BlobStream.Span.Span.Start + offsetTokenValue, 0));

            case GoToMetadataKind.Strings:
                if (mdHeaders.StringsStream == null)
                {
                    return(null);
                }
                return(new HexSpan(mdHeaders.StringsStream.Span.Span.Start + offsetTokenValue, 0));

            case GoToMetadataKind.US:
                if (mdHeaders.USStream == null)
                {
                    return(null);
                }
                return(new HexSpan(mdHeaders.USStream.Span.Span.Start + (offsetTokenValue & 0x00FFFFFF), 0));

            case GoToMetadataKind.GUID:
                if (mdHeaders.GUIDStream == null)
                {
                    return(null);
                }
                return(new HexSpan(mdHeaders.GUIDStream.Span.Span.Start + (offsetTokenValue - 1) * 16, 16));

            case GoToMetadataKind.Table:
                mdTable = GetMDTable(mdHeaders, offsetTokenValue);
                if (mdTable == null)
                {
                    return(null);
                }
                return(new HexSpan(mdTable.Span.Start + ((offsetTokenValue & 0x00FFFFFF) - 1) * mdTable.RowSize, mdTable.RowSize));

            case GoToMetadataKind.MemberRva:
                if (peHeaders == null)
                {
                    return(null);
                }
                mdTable = GetMDTable(mdHeaders, offsetTokenValue);
                if (mdTable == null)
                {
                    return(null);
                }
                if (mdTable.Table != Table.Method && mdTable.Table != Table.FieldRVA)
                {
                    return(null);
                }
                // Column 0 is the RVA in both Method and FieldRVA tables
                var pos = mdTable.Span.Start + ((offsetTokenValue & 0x00FFFFFF) - 1) * mdTable.RowSize;
                var rva = HexView.Buffer.ReadUInt32(pos);
                return(new HexSpan(peHeaders.RvaToBufferPosition(rva), 0));

            default: throw new InvalidOperationException();
            }
        }