示例#1
0
        public override ComplexData GetStructure(HexPosition position)
        {
            if (!peHeadersSpan.Contains(position))
            {
                return(null);
            }

            var peHeaders = peHeadersImpl;

            if (peHeaders == null)
            {
                return(null);
            }

            if (peHeaders.DosHeader.Span.Span.Contains(position))
            {
                return(peHeaders.DosHeader);
            }
            if (peHeaders.FileHeader.Span.Span.Contains(position))
            {
                return(peHeaders.FileHeader);
            }
            if (peHeaders.OptionalHeader.Span.Span.Contains(position))
            {
                return(peHeaders.OptionalHeader);
            }
            if (peHeaders.Sections.Span.Span.Contains(position))
            {
                return(peHeaders.Sections);
            }

            return(null);
        }
示例#2
0
 public FieldAndStructure?GetField(HexPosition position)
 {
     foreach (var structure in hexStructures)
     {
         if (structure.Span.Contains(position))
         {
             foreach (var field in structure.HexFields)
             {
                 if (field.IsVisible && field.Span.Contains(position))
                 {
                     return(new FieldAndStructure(structure, field));
                 }
             }
         }
     }
     if (metadataTablesSpan.Contains(position))
     {
         foreach (var mdTbl in peStructureProvider.TablesStream.MetadataTables)
         {
             if (mdTbl == null || !mdTbl.Span.Contains(position))
             {
                 continue;
             }
             var offset = position - mdTbl.Span.Start;
             if (offset >= uint.MaxValue)
             {
                 break;
             }
             uint index = (uint)(offset.ToUInt64() / (uint)mdTbl.TableInfo.RowSize);
             Debug.Assert(index < mdTbl.Rows);
             if (index >= mdTbl.Rows)
             {
                 break;
             }
             var record = mdTbl.Get((int)index);
             foreach (var field in record.HexFields)
             {
                 if (field.IsVisible && field.Span.Contains(position))
                 {
                     return(new FieldAndStructure(record, field));
                 }
             }
             break;
         }
     }
     return(null);
 }
示例#3
0
        public override ComplexData GetStructure(HexPosition position)
        {
            var cor20 = this.cor20;

            if (cor20 != null)
            {
                if (cor20.Span.Span.Contains(position))
                {
                    return(cor20);
                }
                if (strongNameSignature?.Span.Span.Contains(position) == true)
                {
                    return(strongNameSignature);
                }
                var body = dotNetMethodProvider?.GetMethodBody(position);
                if (body != null)
                {
                    return(body);
                }
                var resource = dotNetResourceProvider?.GetResource(position);
                if (resource != null)
                {
                    return(resource);
                }
            }

            if (metadataSpan.Contains(position))
            {
                if (mdHeader?.Span.Span.Contains(position) == true)
                {
                    return(mdHeader);
                }
                return(dotNetMetadataHeaders?.GetStructure(position));
            }

            return(null);
        }
示例#4
0
        HexCell[] WriteAscii(HexBytes hexBytes, HexSpan visibleBytesSpan, out VST.Span fullSpan, out VST.Span visibleSpan)
        {
            Debug.Assert(showAscii);
            cellList.Clear();
            int fullStart = CurrentTextIndex;

            int?visStart = null;
            int?visEnd   = null;
            var pos      = visibleBytesSpan.Start;
            int cellPos  = 0;

            for (ulong i = 0; i < bytesPerLine; i++, pos++)
            {
                int groupIndex = (cellPos / groupSizeInBytes) & 1;

                HexBufferSpan bufferSpan;
                int           cellStart = CurrentTextIndex;
                if (visibleBytesSpan.Contains(pos))
                {
                    if (visStart == null)
                    {
                        visStart = CurrentTextIndex;
                    }
                    long index = (long)(pos - visibleBytesSpan.Start).ToUInt64();
                    int  b     = hexBytes.TryReadByte(index);
                    if (b < 0)
                    {
                        stringBuilder.Append('?');
                    }
                    else if (b < 0x20 || b > 0x7E)
                    {
                        stringBuilder.Append('.');
                    }
                    else
                    {
                        stringBuilder.Append((char)b);
                    }
                    bufferSpan = new HexBufferSpan(buffer, new HexSpan(pos, 1));
                }
                else
                {
                    if (visStart != null && visEnd == null)
                    {
                        visEnd = CurrentTextIndex;
                    }
                    stringBuilder.Append(' ');
                    bufferSpan = default;
                }
                var cellSpan      = VST.Span.FromBounds(cellStart, CurrentTextIndex);
                var separatorSpan = new VST.Span(cellSpan.End, 0);
                cellList.Add(new HexCell((int)i, groupIndex, bufferSpan, cellSpan, cellSpan, separatorSpan, cellSpan));

                cellPos++;
            }
            if ((ulong)fullStart + bytesPerLine != (ulong)CurrentTextIndex)
            {
                throw new InvalidOperationException();
            }
            if (visStart != null && visEnd == null)
            {
                visEnd = CurrentTextIndex;
            }

            visibleSpan                       = visStart == null ? default : VST.Span.FromBounds(visStart.Value, visEnd.Value);
                                     fullSpan = VST.Span.FromBounds(fullStart, CurrentTextIndex);
                                     if (AsciiSpan != fullSpan)
                                     {
                                         throw new InvalidOperationException();
                                     }
                                     return(cellList.ToArray());
        }
示例#5
0
        HexCell[] WriteValues(HexBytes hexBytes, HexSpan visibleBytesSpan, out VST.Span fullSpan, out VST.Span visibleSpan)
        {
            Debug.Assert(showValues);
            cellList.Clear();
            int fullStart = CurrentTextIndex;

            ulong cellCount = bytesPerLine / (ulong)valueFormatter.ByteCount;
            var   flags     = valuesLowerCaseHex ? HexValueFormatterFlags.LowerCaseHex : HexValueFormatterFlags.None;
            var   pos       = visibleBytesSpan.Start;
            var   end       = visibleBytesSpan.Start + bytesPerLine;
            int?  visStart  = null;
            int?  visEnd    = null;
            int   cellPos   = 0;

            for (ulong i = 0; i < cellCount; i++)
            {
                if (i != 0)
                {
                    stringBuilder.Append(' ');
                }
                int groupIndex = (cellPos / groupSizeInBytes) & 1;

                HexBufferSpan bufferSpan;
                int           cellStart = CurrentTextIndex;
                int           spaces;
                if (visibleBytesSpan.Contains(pos))
                {
                    if (visStart == null)
                    {
                        visStart = CurrentTextIndex;
                    }
                    long valueIndex = (long)(pos - visibleBytesSpan.Start).ToUInt64();
                    spaces = valueFormatter.FormatValue(stringBuilder, hexBytes, valueIndex, flags);
                    var endPos = HexPosition.Min(endPosition, pos + (ulong)valueFormatter.ByteCount);
                    bufferSpan = new HexBufferSpan(new HexBufferPoint(buffer, pos), new HexBufferPoint(buffer, endPos));
                }
                else
                {
                    if (visStart != null && visEnd == null)
                    {
                        visEnd = CurrentTextIndex;
                    }
                    stringBuilder.Append(' ', valueFormatter.FormattedLength);
                    spaces     = valueFormatter.FormattedLength;
                    bufferSpan = default;
                }
                if (cellStart + valueFormatter.FormattedLength != CurrentTextIndex)
                {
                    throw new InvalidOperationException();
                }
                var      textSpan = VST.Span.FromBounds(cellStart + spaces, CurrentTextIndex);
                var      cellSpan = VST.Span.FromBounds(cellStart, CurrentTextIndex);
                VST.Span separatorSpan;
                if (i + 1 < cellCount)
                {
                    separatorSpan = new VST.Span(CurrentTextIndex, 1);
                }
                else
                {
                    separatorSpan = new VST.Span(CurrentTextIndex, 0);
                }
                var cellFullSpan = VST.Span.FromBounds(cellStart, separatorSpan.End);
                cellList.Add(new HexCell((int)i, groupIndex, bufferSpan, textSpan, cellSpan, separatorSpan, cellFullSpan));

                pos     += (ulong)valueFormatter.ByteCount;
                cellPos += valueFormatter.ByteCount;
            }
            if (pos != end)
            {
                throw new InvalidOperationException();
            }
            if (visStart != null && visEnd == null)
            {
                visEnd = CurrentTextIndex;
            }

            visibleSpan                       = visStart == null ? default : VST.Span.FromBounds(visStart.Value, visEnd.Value);
                                     fullSpan = VST.Span.FromBounds(fullStart, CurrentTextIndex);
                                     if (ValuesSpan != fullSpan)
                                     {
                                         throw new InvalidOperationException();
                                     }
                                     return(cellList.ToArray());
        }
示例#6
0
		HexCell[] WriteAscii(HexBytes hexBytes, HexSpan visibleBytesSpan, out VST.Span fullSpan, out VST.Span visibleSpan) {
			Debug.Assert(showAscii);
			cellList.Clear();
			int fullStart = CurrentTextIndex;

			int? visStart = null;
			int? visEnd = null;
			var pos = visibleBytesSpan.Start;
			int cellPos = 0;
			for (ulong i = 0; i < bytesPerLine; i++, pos++) {
				int groupIndex = (cellPos / groupSizeInBytes) & 1;

				HexBufferSpan bufferSpan;
				int cellStart = CurrentTextIndex;
				if (visibleBytesSpan.Contains(pos)) {
					if (visStart == null)
						visStart = CurrentTextIndex;
					long index = (long)(pos - visibleBytesSpan.Start).ToUInt64();
					int b = hexBytes.TryReadByte(index);
					if (b < 0)
						stringBuilder.Append('?');
					else if (b < 0x20 || b > 0x7E)
						stringBuilder.Append('.');
					else
						stringBuilder.Append((char)b);
					bufferSpan = new HexBufferSpan(buffer, new HexSpan(pos, 1));
				}
				else {
					if (visStart != null && visEnd == null)
						visEnd = CurrentTextIndex;
					stringBuilder.Append(' ');
					bufferSpan = default(HexBufferSpan);
				}
				var cellSpan = VST.Span.FromBounds(cellStart, CurrentTextIndex);
				var separatorSpan = new VST.Span(cellSpan.End, 0);
				cellList.Add(new HexCell((int)i, groupIndex, bufferSpan, cellSpan, cellSpan, separatorSpan, cellSpan));

				cellPos++;
			}
			if ((ulong)fullStart + bytesPerLine != (ulong)CurrentTextIndex)
				throw new InvalidOperationException();
			if (visStart != null && visEnd == null)
				visEnd = CurrentTextIndex;
			visibleSpan = visStart == null ? default(VST.Span) : VST.Span.FromBounds(visStart.Value, visEnd.Value);
			fullSpan = VST.Span.FromBounds(fullStart, CurrentTextIndex);
			if (AsciiSpan != fullSpan)
				throw new InvalidOperationException();
			return cellList.ToArray();
		}
示例#7
0
		HexCell[] WriteValues(HexBytes hexBytes, HexSpan visibleBytesSpan, out VST.Span fullSpan, out VST.Span visibleSpan) {
			Debug.Assert(showValues);
			cellList.Clear();
			int fullStart = CurrentTextIndex;

			ulong cellCount = bytesPerLine / (ulong)valueFormatter.ByteCount;
			var flags = valuesLowerCaseHex ? HexValueFormatterFlags.LowerCaseHex : HexValueFormatterFlags.None;
			var pos = visibleBytesSpan.Start;
			var end = visibleBytesSpan.Start + bytesPerLine;
			int? visStart = null;
			int? visEnd = null;
			int cellPos = 0;
			for (ulong i = 0; i < cellCount; i++) {
				if (i != 0)
					stringBuilder.Append(' ');
				int groupIndex = (cellPos / groupSizeInBytes) & 1;

				HexBufferSpan bufferSpan;
				int cellStart = CurrentTextIndex;
				int spaces;
				if (visibleBytesSpan.Contains(pos)) {
					if (visStart == null)
						visStart = CurrentTextIndex;
					long valueIndex = (long)(pos - visibleBytesSpan.Start).ToUInt64();
					spaces = valueFormatter.FormatValue(stringBuilder, hexBytes, valueIndex, flags);
					var endPos = HexPosition.Min(endPosition, pos + (ulong)valueFormatter.ByteCount);
					bufferSpan = new HexBufferSpan(new HexBufferPoint(buffer, pos), new HexBufferPoint(buffer, endPos));
				}
				else {
					if (visStart != null && visEnd == null)
						visEnd = CurrentTextIndex;
					stringBuilder.Append(' ', valueFormatter.FormattedLength);
					spaces = valueFormatter.FormattedLength;
					bufferSpan = default(HexBufferSpan);
				}
				if (cellStart + valueFormatter.FormattedLength != CurrentTextIndex)
					throw new InvalidOperationException();
				var textSpan = VST.Span.FromBounds(cellStart + spaces, CurrentTextIndex);
				var cellSpan = VST.Span.FromBounds(cellStart, CurrentTextIndex);
				VST.Span separatorSpan;
				if (i + 1 < cellCount)
					separatorSpan = new VST.Span(CurrentTextIndex, 1);
				else
					separatorSpan = new VST.Span(CurrentTextIndex, 0);
				var cellFullSpan = VST.Span.FromBounds(cellStart, separatorSpan.End);
				cellList.Add(new HexCell((int)i, groupIndex, bufferSpan, textSpan, cellSpan, separatorSpan, cellFullSpan));

				pos += (ulong)valueFormatter.ByteCount;
				cellPos += valueFormatter.ByteCount;
			}
			if (pos != end)
				throw new InvalidOperationException();
			if (visStart != null && visEnd == null)
				visEnd = CurrentTextIndex;
			visibleSpan = visStart == null ? default(VST.Span) : VST.Span.FromBounds(visStart.Value, visEnd.Value);
			fullSpan = VST.Span.FromBounds(fullStart, CurrentTextIndex);
			if (ValuesSpan != fullSpan)
				throw new InvalidOperationException();
			return cellList.ToArray();
		}
示例#8
0
 public override bool IsMethodPosition(HexPosition position) => methodBodiesSpan.Contains(position);