Exemple #1
0
        public HexToolTipInfoCollection(HexToolTipInfo[] infos)
        {
            if (infos == null)
            {
                throw new ArgumentNullException(nameof(infos));
            }
            if (infos.Length == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(infos));
            }
            this.infos = infos;

            var start = infos[0].BufferSpan.Start;
            var end   = infos[0].BufferSpan.End;

            for (int i = 1; i < infos.Length; i++)
            {
                var span = infos[i].BufferSpan;
                if (span.Start < start)
                {
                    start = span.Start;
                }
                if (span.End > end)
                {
                    end = span.End;
                }
            }
            FullBufferSpan = HexBufferSpan.FromBounds(start, end);

            Array.Sort(infos, (a, b) => {
                if ((a.ToolTip != null) != (b.ToolTip != null))
                {
                    return(a.ToolTip != null ? -1 : 1);
                }
                if (a.BufferSpan.Length != b.BufferSpan.Length)
                {
                    return(a.BufferSpan.Length.CompareTo(b.BufferSpan.Length));
                }
                return(Array.IndexOf(infos, a) - Array.IndexOf(infos, b));
            });
            BufferSpan = infos[0].BufferSpan;
            Debug.Assert(infos[0].ToolTip != null);

            int index = 0;

            foreach (var info in infos.OrderBy(a => a.BufferSpan.Start))
            {
                if (info.ClassificationType == null)
                {
                    info.ClassificationType = info.ToolTip != null ?
                                              CTC.ThemeClassificationTypeNameKeys.HexToolTipServiceCurrentField :
                                              (index & 1) == 0 ? CTC.ThemeClassificationTypeNameKeys.HexToolTipServiceField0 :
                                              CTC.ThemeClassificationTypeNameKeys.HexToolTipServiceField1;
                    if (info.ToolTip == null)
                    {
                        index++;
                    }
                }
            }
        }
        public override IEnumerable <HexStructureField> GetFields(HexPosition position)
        {
            var info = hexBufferFileService.GetFileAndStructure(position);

            if (info is null)
            {
                yield break;
            }

            var structure = info.Value.Structure;
            var field     = structure.GetSimpleField(position);

            Debug2.Assert(field is not null);
            if (field is null)
            {
                yield break;
            }
            yield return(new HexStructureField(field.Data.Span, HexStructureFieldKind.CurrentField));

            var indexes = hexFileStructureInfoService.GetSubStructureIndexes(position);

            if (indexes is not null)
            {
                if (indexes.Length == 0)
                {
                    for (int i = 0; i < structure.FieldCount; i++)
                    {
                        var span = structure.GetFieldByIndex(i).Data.Span;
                        yield return(new HexStructureField(span, HexStructureFieldKind.SubStructure));
                    }
                }
                else
                {
                    for (int i = 0; i < indexes.Length; i++)
                    {
                        var start = structure.GetFieldByIndex(indexes[i].Start).Data.Span.Start;
                        var end   = structure.GetFieldByIndex(indexes[i].End - 1).Data.Span.End;
                        var span  = HexBufferSpan.FromBounds(start, end);
                        yield return(new HexStructureField(span, HexStructureFieldKind.SubStructure));
                    }
                }
            }
            else
            {
                yield return(new HexStructureField(structure.Span, HexStructureFieldKind.Structure));
            }
        }
        public FatMethodBodyImpl(DotNetMethodProvider methodProvider, HexBufferSpan span, ReadOnlyCollection <uint> tokens, HexSpan instructionsSpan, HexSpan ehSpan, bool fatEH)
            : base(methodProvider, span, tokens)
        {
            var buffer = span.Buffer;
            var pos    = span.Start.Position;

            Flags_Size     = new StructField <UInt16FlagsData>("Flags", new UInt16FlagsData(buffer, pos, fatHeaderFlagsFlagInfos));
            MaxStack       = new StructField <UInt16Data>("MaxStack", new UInt16Data(buffer, pos + 2));
            CodeSize       = new StructField <UInt32Data>("CodeSize", new UInt32Data(buffer, pos + 4));
            LocalVarSigTok = new StructField <TokenData>("LocalVarSigTok", new TokenData(buffer, pos + 8));
            Instructions   = new StructField <VirtualArrayData <ByteData> >(TinyMethodBodyImpl.InstructionsFieldName, ArrayData.CreateVirtualByteArray(new HexBufferSpan(span.Buffer, instructionsSpan), TinyMethodBodyImpl.InstructionsFieldName));
            if (!ehSpan.IsEmpty)
            {
                ExceptionHandlerTable ehTable;
                if (fatEH)
                {
                    ehTable = new FatExceptionHandlerTableImpl(new HexBufferSpan(buffer, ehSpan));
                }
                else
                {
                    ehTable = new SmallExceptionHandlerTableImpl(new HexBufferSpan(buffer, ehSpan));
                }
                EHTable = new StructField <ExceptionHandlerTable>("EHTable", ehTable);

                var paddingSpan = HexBufferSpan.FromBounds(Instructions.Data.Span.End, EHTable.Data.Span.Start);
                Padding = new StructField <VirtualArrayData <ByteData> >("Padding", ArrayData.CreateVirtualByteArray(paddingSpan));
            }
            var fields = new List <BufferField>(7)
            {
                Flags_Size,
                MaxStack,
                CodeSize,
                LocalVarSigTok,
                Instructions,
            };

            if (Padding is not null)
            {
                fields.Add(Padding);
            }
            if (EHTable is not null)
            {
                fields.Add(EHTable);
            }
            Fields = fields.ToArray();
        }
Exemple #4
0
        public InvalidMethodBodyImpl(DotNetMethodProvider methodProvider, HexBufferSpan span, ReadOnlyCollection <uint> tokens)
            : base(methodProvider, span, tokens)
        {
            var buffer = span.Buffer;
            var pos    = span.Start.Position;

            Instructions = new StructField <VirtualArrayData <ByteData> >(TinyMethodBodyImpl.InstructionsFieldName, ArrayData.CreateVirtualByteArray(HexBufferSpan.FromBounds(span.Start, span.End), TinyMethodBodyImpl.InstructionsFieldName));
            Fields       = new BufferField[] {
                Instructions,
            };
        }
Exemple #5
0
        public TinyMethodBodyImpl(DotNetMethodProvider methodProvider, HexBufferSpan span, ReadOnlyCollection <uint> tokens)
            : base(methodProvider, span, tokens)
        {
            var buffer = span.Buffer;
            var pos    = span.Start.Position;

            Flags_CodeSize = new StructField <ByteFlagsData>("Flags_CodeSize", new ByteFlagsData(buffer, pos, flagsCodeSizeFlagInfos));
            Instructions   = new StructField <VirtualArrayData <ByteData> >(InstructionsFieldName, ArrayData.CreateVirtualByteArray(HexBufferSpan.FromBounds(span.Start + 1, span.End), InstructionsFieldName));
            Fields         = new BufferField[] {
                Flags_CodeSize,
                Instructions,
            };
        }
 public DotNetEmbeddedResourceImpl(DotNetResourceProvider resourceProvider, HexBufferSpan span, uint token)
     : base(resourceProvider, span, token)
 {
     if (span.Length < 4)
     {
         throw new ArgumentOutOfRangeException(nameof(span));
     }
     Size    = new StructField <UInt32Data>("Size", new UInt32Data(span.Buffer, span.Start.Position));
     Content = new StructField <VirtualArrayData <ByteData> >("Content", ArrayData.CreateVirtualByteArray(HexBufferSpan.FromBounds(span.Start + 4, span.End)));
     Fields  = new BufferField[] {
         Size,
         Content,
     };
 }