public HexBufferLineImpl(HexBufferLineFormatter hexBufferLineFormatter, HexPosition lineNumber, ReadOnlyCollection<HexColumnType> columnOrder, HexBufferSpan bufferSpan, HexBytes hexBytes, string text, bool isOffsetColumnPresent, bool isValuesColumnPresent, bool isAsciiColumnPresent, HexPosition logicalOffset, HexCellCollection valueCells, HexCellCollection asciiCells, VST.Span offsetSpan, VST.Span fullValuesSpan, VST.Span visibleValuesSpan, VST.Span fullAsciiSpan, VST.Span visibleAsciiSpan) { if (hexBufferLineFormatter == null) throw new ArgumentNullException(nameof(hexBufferLineFormatter)); if (columnOrder == null) throw new ArgumentNullException(nameof(columnOrder)); if (bufferSpan.IsDefault) throw new ArgumentException(); if (hexBytes.IsDefault) throw new ArgumentException(); if (text == null) throw new ArgumentNullException(nameof(text)); if (valueCells.IsDefault) throw new ArgumentNullException(nameof(valueCells)); if (asciiCells.IsDefault) throw new ArgumentNullException(nameof(asciiCells)); LineProvider = hexBufferLineFormatter; LineNumber = lineNumber; ColumnOrder = columnOrder; BufferSpan = bufferSpan; HexBytes = hexBytes; Text = text; IsOffsetColumnPresent = isOffsetColumnPresent; IsValuesColumnPresent = isValuesColumnPresent; IsAsciiColumnPresent = isAsciiColumnPresent; LogicalOffset = logicalOffset; ValueCells = valueCells; AsciiCells = asciiCells; this.offsetSpan = offsetSpan; this.fullValuesSpan = fullValuesSpan; this.visibleValuesSpan = visibleValuesSpan; this.fullAsciiSpan = fullAsciiSpan; this.visibleAsciiSpan = visibleAsciiSpan; }
public HexAdornmentLayerElementImpl(VSTE.AdornmentPositioningBehavior behavior, HexBufferSpan? visualSpan, object tag, UIElement adornment, VSTE.AdornmentRemovedCallback removedCallback) { Adornment = adornment; Behavior = behavior; RemovedCallback = removedCallback; Tag = tag; VisualSpan = visualSpan; }
/// <summary> /// Constructor /// </summary> /// <param name="bufferSpan">Buffer span</param> /// <param name="flags">Flags</param> public HexLineSpan(HexBufferSpan bufferSpan, HexSpanSelectionFlags flags) { if (bufferSpan.IsDefault) throw new ArgumentException(); BufferSpan = bufferSpan; SelectionFlags = flags; TextSpan = null; }
/// <summary> /// Constructor /// </summary> /// <param name="bufferSpan">Span of field</param> /// <param name="toolTip">Tooltip to show or null</param> /// <param name="reference">A reference to some high level object that represents the data or null</param> public HexToolTipStructureSpanTag(HexBufferSpan bufferSpan, object toolTip, object reference) { if (bufferSpan.IsDefault) throw new ArgumentException(); BufferSpan = bufferSpan; ToolTip = toolTip; Reference = reference; }
static void InitializeHexView(HexView hexView, HexSpan span) { if (!IsVisible(hexView, span)) return; var bufferSpan = new HexBufferSpan(hexView.Buffer, span); hexView.Selection.Select(bufferSpan.Start, bufferSpan.End, alignPoints: false); var column = hexView.Caret.IsValuesCaretPresent ? HexColumnType.Values : HexColumnType.Ascii; hexView.Caret.MoveTo(column, bufferSpan.Start); var flags = column == HexColumnType.Values ? HexSpanSelectionFlags.Values : HexSpanSelectionFlags.Ascii; hexView.ViewScroller.EnsureSpanVisible(bufferSpan, flags, VSTE.EnsureSpanVisibleOptions.ShowStart); }
public WpfHexViewLineCollectionImpl(WpfHexView hexView, IList<WpfHexViewLine> lines) { if (hexView == null) throw new ArgumentNullException(nameof(hexView)); if (lines == null) throw new ArgumentNullException(nameof(lines)); this.hexView = hexView; this.lines = new ReadOnlyCollection<WpfHexViewLine>(lines); isValid = true; if (lines.Count == 0) formattedSpan = new HexBufferSpan(hexView.Buffer, new HexSpan(HexPosition.Zero, 0)); else formattedSpan = new HexBufferSpan(lines[0].BufferStart, lines[lines.Count - 1].BufferEnd); Debug.Assert(this.lines.Count > 0); }
public override void ShowToolTip(HexBufferSpan bufferSpan, HexSpanSelectionFlags flags, object toolTipContent, VSTA.PopupStyles style) { if (bufferSpan.IsDefault) throw new ArgumentException(); if (toolTipContent == null) throw new ArgumentNullException(nameof(toolTipContent)); if ((style & (VSTA.PopupStyles.DismissOnMouseLeaveText | VSTA.PopupStyles.DismissOnMouseLeaveTextOrContent)) == (VSTA.PopupStyles.DismissOnMouseLeaveText | VSTA.PopupStyles.DismissOnMouseLeaveTextOrContent)) throw new ArgumentOutOfRangeException(nameof(style)); ClearToolTip(); var uiElement = GetUIElement(toolTipContent); if (uiElement == null) throw new ArgumentException(); spaceReservationManager.AgentChanged += SpaceReservationManager_AgentChanged; toolTipAgent = spaceReservationManager.CreatePopupAgent(bufferSpan, flags, style, uiElement); spaceReservationManager.AddAgent(toolTipAgent); }
public static string ToHexString(HexBufferSpan span, bool upper) { if (span.IsDefault) return null; if (span.Length > int.MaxValue / 2) return null; int totalByteLength = (int)span.Length.ToUInt64(); int totalCharLength = totalByteLength * 2; var charArray = new char[totalCharLength]; int charArrayIndex = 0; var buffer = new byte[Math.Min(0x1000, totalByteLength)]; for (int pos = 0; pos < totalByteLength;) { int bytesRead = Math.Min(totalByteLength - pos, buffer.Length); span.Buffer.ReadBytes(span.Start + pos, buffer, 0, bytesRead); pos += bytesRead; for (int i = 0; i < bytesRead; i++) { var b = buffer[i]; charArray[charArrayIndex++] = NibbleToHex(b >> 4, upper); charArray[charArrayIndex++] = NibbleToHex(b & 0x0F, upper); } } return new string(charArray); }
public override bool AddAdornment(VSTE.AdornmentPositioningBehavior behavior, HexBufferSpan? visualSpan, object tag, UIElement adornment, VSTE.AdornmentRemovedCallback removedCallback) { if (adornment == null) throw new ArgumentNullException(nameof(adornment)); if (visualSpan != null && visualSpan.Value.IsDefault) throw new ArgumentException(); if (visualSpan == null && behavior == VSTE.AdornmentPositioningBehavior.TextRelative) throw new ArgumentNullException(nameof(visualSpan)); if ((uint)behavior > (uint)VSTE.AdornmentPositioningBehavior.TextRelative) throw new ArgumentOutOfRangeException(nameof(behavior)); if (layerKind != HexLayerKind.Normal) { if (behavior != VSTE.AdornmentPositioningBehavior.OwnerControlled) throw new ArgumentOutOfRangeException(nameof(behavior), "Special layers must use AdornmentPositioningBehavior.OwnerControlled"); if (visualSpan != null) throw new ArgumentOutOfRangeException(nameof(visualSpan), "Special layers must use a null visual span"); } bool canAdd = visualSpan == null || HexView.HexViewLines.IntersectsBufferSpan(visualSpan.Value); if (canAdd) { var layerElem = new HexAdornmentLayerElementImpl(behavior, visualSpan, tag, adornment, removedCallback); canvas.Children.Add(layerElem.Adornment); adornmentLayerElements.Add(layerElem); } return canAdd; }
static HexBufferSpan GetOverlapsWithSpan(HexBufferSpan span) { if (span.Length != 0) return span; if (span.Start.Position == HexPosition.MaxEndPosition) return span; return new HexBufferSpan(span.Start, 1); }
/// <summary> /// Constructor /// </summary> /// <param name="span">Span</param> protected PeOptionalHeader64Data(HexBufferSpan span) : base(NAME, span) { }
/// <summary> /// Constructor /// </summary> /// <param name="bufferSpan">Span of field</param> public HexToolTipStructureSpanTag(HexBufferSpan bufferSpan) : this(bufferSpan, null, null) { }
/// <summary> /// Returns true if the line intersects with <paramref name="bufferSpan"/> /// </summary> /// <param name="bufferSpan">Span</param> /// <returns></returns> public abstract bool IntersectsBufferSpan(HexBufferSpan bufferSpan);
/// <summary> /// Constructor /// </summary> /// <param name="span">Span</param> protected DotNetMetadataHeaderData(HexBufferSpan span) : base(NAME, span) { }
/// <summary> /// Constructor /// </summary> /// <param name="span">Span</param> protected DotNetCor20Data(HexBufferSpan span) : base(NAME, span) { }
/// <summary> /// Constructor /// </summary> /// <param name="span">Span</param> public HexBufferSpanEventArgs(HexBufferSpan span) { if (span.IsDefault) throw new ArgumentException(); Span = span; }
public static bool IsMultiLineSpan(HexView hexView, HexBufferSpan bufferSpan) { var lineNum1 = hexView.BufferLines.GetLineNumberFromPosition(bufferSpan.Start); var lineNum2 = hexView.BufferLines.GetLineNumberFromPosition(bufferSpan.End); return lineNum1 != lineNum2; }
/// <summary> /// Constructor /// </summary> /// <param name="resourceProvider">Owner</param> /// <param name="resourceInfo">Resource info</param> /// <param name="span">Span</param> protected MultiResourceDataHeaderData(DotNetMultiFileResources resourceProvider, MultiResourceInfo resourceInfo, HexBufferSpan span) : base(NAME, span) { ResourceProvider = resourceProvider ?? throw new ArgumentNullException(nameof(resourceProvider)); ResourceInfo = resourceInfo; }
/// <summary> /// Constructor /// </summary> /// <param name="index">Cell index</param> /// <param name="groupIndex">Group index</param> /// <param name="bufferSpan">Buffer span or the default value if there's no data</param> /// <param name="textSpan">Span of the text. This span doesn't include any whitespace before and after the text.</param> /// <param name="cellSpan">Span of the cell, some of the span could be whitespace</param> /// <param name="separatorSpan">Span of the cell separator</param> /// <param name="fullSpan">Includes the whole cell and separator span</param> public HexCell(int index, int groupIndex, HexBufferSpan bufferSpan, VST.Span textSpan, VST.Span cellSpan, VST.Span separatorSpan, VST.Span fullSpan) { if (index < 0) throw new ArgumentOutOfRangeException(nameof(index)); if (groupIndex < 0 || groupIndex > 1) throw new ArgumentOutOfRangeException(nameof(groupIndex)); if (cellSpan.Length == 0) throw new ArgumentOutOfRangeException(nameof(cellSpan)); if (!fullSpan.Contains(cellSpan)) throw new ArgumentOutOfRangeException(nameof(cellSpan)); HasData = !bufferSpan.IsDefault; Index = index; GroupIndex = groupIndex; BufferSpan = bufferSpan; TextSpan = textSpan; CellSpan = cellSpan; SeparatorSpan = separatorSpan; FullSpan = fullSpan; }
/// <summary> /// Constructor /// </summary> /// <param name="resourceProvider">Owner</param> /// <param name="resourceInfo">Resource info</param> /// <param name="span">Span</param> /// <param name="lengthPosition">Position of 32-bit content length which immediately follows the 7-bit encoded type code</param> public MultiResourceArrayDataHeaderData(DotNetMultiFileResources resourceProvider, MultiResourceInfo resourceInfo, HexBufferSpan span, HexPosition lengthPosition) : base(resourceProvider, resourceInfo, span) { var typeCodeSpan = new HexBufferSpan(span.Buffer, HexSpan.FromBounds(span.Start, lengthPosition)); TypeCode = new StructField <ResourceTypeCodeData>("TypeCode", ResourceTypeCodeData.Create(typeCodeSpan)); ContentLength = new StructField <UInt32Data>("ContentLength", new UInt32Data(span.Buffer, lengthPosition)); var arraySpan = new HexBufferSpan(span.Buffer, HexSpan.FromBounds(lengthPosition + 4, span.End)); Content = new StructField <VirtualArrayData <ByteData> >("Content", ArrayData.CreateVirtualByteArray(arraySpan)); Fields = new BufferField[] { TypeCode, ContentLength, Content, }; }
/// <summary> /// Constructor /// </summary> /// <param name="resourceProvider">Owner</param> /// <param name="resourceInfo">Resource info</param> /// <param name="span">Span</param> /// <param name="lengthSpan">Span of 7-bit encoded string length</param> /// <param name="stringSpan">Span of string data (UTF-8)</param> public MultiResourceStringDataHeaderData(DotNetMultiFileResources resourceProvider, MultiResourceInfo resourceInfo, HexBufferSpan span, HexSpan lengthSpan, HexSpan stringSpan) : base(resourceProvider, resourceInfo, span) { if (!span.Span.Contains(lengthSpan)) { throw new ArgumentOutOfRangeException(nameof(lengthSpan)); } if (!span.Span.Contains(stringSpan)) { throw new ArgumentOutOfRangeException(nameof(stringSpan)); } if (lengthSpan.End != stringSpan.Start) { throw new ArgumentOutOfRangeException(nameof(stringSpan)); } var typeCodeSpan = new HexBufferSpan(span.Buffer, HexSpan.FromBounds(span.Start, lengthSpan.Start)); TypeCode = new StructField <ResourceTypeCodeData>("TypeCode", ResourceTypeCodeData.Create(typeCodeSpan)); Content = new StructField <Bit7EncodedStringData>("Content", new Bit7EncodedStringData(span.Buffer, lengthSpan, stringSpan, Encoding.UTF8)); Fields = new BufferField[] { TypeCode, Content, }; }
/// <summary> /// Constructor /// </summary> /// <param name="resourceProvider">Owner</param> /// <param name="resourceInfo">Resource info</param> /// <param name="span">Span</param> /// <param name="dataPosition">Position of data which immediately follows the 7-bit encoded type code</param> public MultiResourceSimplDataHeaderData(DotNetMultiFileResources resourceProvider, MultiResourceInfo resourceInfo, HexBufferSpan span, HexPosition dataPosition) : base(resourceProvider, resourceInfo, span) { // Don't use Contains() since data length could be 0 if (dataPosition < span.Start || dataPosition > span.End) { throw new ArgumentOutOfRangeException(nameof(dataPosition)); } var typeCodeSpan = new HexBufferSpan(span.Buffer, HexSpan.FromBounds(span.Start, dataPosition)); TypeCode = new StructField <ResourceTypeCodeData>("TypeCode", ResourceTypeCodeData.Create(typeCodeSpan)); var pos = typeCodeSpan.Span.Start; var typeCode = (ResourceTypeCode)(Utils.Read7BitEncodedInt32(span.Buffer, ref pos) ?? -1); var dataSpan = new HexBufferSpan(span.Buffer, HexSpan.FromBounds(dataPosition, span.End)); switch (typeCode) { case ResourceTypeCode.String: Debug.Fail($"Use {nameof(MultiResourceStringDataHeaderData)}"); goto default; case ResourceTypeCode.ByteArray: case ResourceTypeCode.Stream: Debug.Fail($"Use {nameof(MultiResourceArrayDataHeaderData)}"); goto default; case ResourceTypeCode.Boolean: Content = new StructField <BooleanData>("Content", new BooleanData(dataSpan)); break; case ResourceTypeCode.Char: Content = new StructField <CharData>("Content", new CharData(dataSpan)); break; case ResourceTypeCode.Byte: Content = new StructField <ByteData>("Content", new ByteData(dataSpan)); break; case ResourceTypeCode.SByte: Content = new StructField <SByteData>("Content", new SByteData(dataSpan)); break; case ResourceTypeCode.Int16: Content = new StructField <Int16Data>("Content", new Int16Data(dataSpan)); break; case ResourceTypeCode.UInt16: Content = new StructField <UInt16Data>("Content", new UInt16Data(dataSpan)); break; case ResourceTypeCode.Int32: Content = new StructField <Int32Data>("Content", new Int32Data(dataSpan)); break; case ResourceTypeCode.UInt32: Content = new StructField <UInt32Data>("Content", new UInt32Data(dataSpan)); break; case ResourceTypeCode.Int64: Content = new StructField <Int64Data>("Content", new Int64Data(dataSpan)); break; case ResourceTypeCode.UInt64: Content = new StructField <UInt64Data>("Content", new UInt64Data(dataSpan)); break; case ResourceTypeCode.Single: Content = new StructField <SingleData>("Content", new SingleData(dataSpan)); break; case ResourceTypeCode.Double: Content = new StructField <DoubleData>("Content", new DoubleData(dataSpan)); break; case ResourceTypeCode.Decimal: Content = new StructField <DecimalData>("Content", new DecimalData(dataSpan)); break; case ResourceTypeCode.DateTime: Content = new StructField <DateTimeData>("Content", new DateTimeData(dataSpan)); break; case ResourceTypeCode.TimeSpan: Content = new StructField <TimeSpanData>("Content", new TimeSpanData(dataSpan)); break; case ResourceTypeCode.Null: default: Content = new StructField <VirtualArrayData <ByteData> >("Content", ArrayData.CreateVirtualByteArray(dataSpan)); break; } Fields = new BufferField[] { TypeCode, Content, }; }
public HotHeapImpl(HexBufferSpan span) : base(span) { }
public PdbHeapImpl(HexBufferSpan span) : base(span) { }
void ShowSpan(HexBufferSpan bufferSpan, VSTE.EnsureSpanVisibleOptions options) { if ((options & VSTE.EnsureSpanVisibleOptions.ShowStart) != 0) hexView.DisplayHexLineContainingBufferPosition(bufferSpan.Start, 0, VSTE.ViewRelativePosition.Top); else { var end = bufferSpan.End; if (end > hexView.BufferLines.BufferStart) end = end - 1; hexView.DisplayHexLineContainingBufferPosition(end, 0, VSTE.ViewRelativePosition.Bottom); } }
/// <summary> /// Constructor /// </summary> /// <param name="name">Structure name</param> /// <param name="span">Span</param> protected PeOptionalHeaderData(string name, HexBufferSpan span) : base(name, span) { }
/// <summary> /// Shows a tooltip /// </summary> /// <param name="bufferSpan">Buffer span</param> /// <param name="flags">Selection flags</param> /// <param name="toolTipContent">Tooltip content</param> public void ShowToolTip(HexBufferSpan bufferSpan, HexSpanSelectionFlags flags, object toolTipContent) => ShowToolTip(bufferSpan, flags, toolTipContent, VSTA.PopupStyles.None);
/// <summary> /// Constructor /// </summary> /// <param name="span">Span</param> protected TablesHeaderData(HexBufferSpan span) : base(NAME, span) { }
static NormalizedHexBufferSpanCollection CreateSpans(ReadOnlyCollection<HexViewLine> lines) { if (lines.Count == 0) return NormalizedHexBufferSpanCollection.Empty; if (lines.Count == 1) return new NormalizedHexBufferSpanCollection(lines[0].BufferSpan); var array = new HexBufferSpan[lines.Count]; for (int i = 0; i < array.Length; i++) array[i] = lines[i].BufferSpan; return new NormalizedHexBufferSpanCollection(array); }
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 is 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 is null) && visEnd is 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 is null) && visEnd is null) { visEnd = CurrentTextIndex; } visibleSpan = visStart is null ? default : VST.Span.FromBounds(visStart.Value, visEnd !.Value); fullSpan = VST.Span.FromBounds(fullStart, CurrentTextIndex); if (AsciiSpan != fullSpan) { throw new InvalidOperationException(); } return(cellList.ToArray()); }
PeOptionalHeader32DataImpl(HexBufferSpan span) : base(span) { var buffer = span.Buffer; var pos = span.Start.Position; Magic = new StructField <UInt16Data>("Magic", new UInt16Data(buffer, pos)); MajorLinkerVersion = new StructField <ByteData>("MajorLinkerVersion", new ByteData(buffer, pos + 2)); MinorLinkerVersion = new StructField <ByteData>("MinorLinkerVersion", new ByteData(buffer, pos + 3)); SizeOfCode = new StructField <UInt32Data>("SizeOfCode", new UInt32Data(buffer, pos + 4)); SizeOfInitializedData = new StructField <UInt32Data>("SizeOfInitializedData", new UInt32Data(buffer, pos + 8)); SizeOfUninitializedData = new StructField <UInt32Data>("SizeOfUninitializedData", new UInt32Data(buffer, pos + 0x0C)); AddressOfEntryPoint = new StructField <RvaData>("AddressOfEntryPoint", new RvaData(buffer, pos + 0x10)); BaseOfCode = new StructField <RvaData>("BaseOfCode", new RvaData(buffer, pos + 0x14)); BaseOfData = new StructField <RvaData>("BaseOfData", new RvaData(buffer, pos + 0x18)); ImageBase = new StructField <UInt32Data>("ImageBase", new UInt32Data(buffer, pos + 0x1C)); SectionAlignment = new StructField <UInt32Data>("SectionAlignment", new UInt32Data(buffer, pos + 0x20)); FileAlignment = new StructField <UInt32Data>("FileAlignment", new UInt32Data(buffer, pos + 0x24)); MajorOperatingSystemVersion = new StructField <UInt16Data>("MajorOperatingSystemVersion", new UInt16Data(buffer, pos + 0x28)); MinorOperatingSystemVersion = new StructField <UInt16Data>("MinorOperatingSystemVersion", new UInt16Data(buffer, pos + 0x2A)); MajorImageVersion = new StructField <UInt16Data>("MajorImageVersion", new UInt16Data(buffer, pos + 0x2C)); MinorImageVersion = new StructField <UInt16Data>("MinorImageVersion", new UInt16Data(buffer, pos + 0x2E)); MajorSubsystemVersion = new StructField <UInt16Data>("MajorSubsystemVersion", new UInt16Data(buffer, pos + 0x30)); MinorSubsystemVersion = new StructField <UInt16Data>("MinorSubsystemVersion", new UInt16Data(buffer, pos + 0x32)); Win32VersionValue = new StructField <UInt32Data>("Win32VersionValue", new UInt32Data(buffer, pos + 0x34)); SizeOfImage = new StructField <UInt32Data>("SizeOfImage", new UInt32Data(buffer, pos + 0x38)); SizeOfHeaders = new StructField <UInt32Data>("SizeOfHeaders", new UInt32Data(buffer, pos + 0x3C)); CheckSum = new StructField <UInt32Data>("CheckSum", new UInt32Data(buffer, pos + 0x40)); Subsystem = new StructField <UInt16EnumData>("Subsystem", new UInt16EnumData(buffer, pos + 0x44, subsystemEnumFieldInfos)); DllCharacteristics = new StructField <UInt16FlagsData>("DllCharacteristics", new UInt16FlagsData(buffer, pos + 0x46, dllCharacteristicsFlagInfos)); SizeOfStackReserve = new StructField <UInt32Data>("SizeOfStackReserve", new UInt32Data(buffer, pos + 0x48)); SizeOfStackCommit = new StructField <UInt32Data>("SizeOfStackCommit", new UInt32Data(buffer, pos + 0x4C)); SizeOfHeapReserve = new StructField <UInt32Data>("SizeOfHeapReserve", new UInt32Data(buffer, pos + 0x50)); SizeOfHeapCommit = new StructField <UInt32Data>("SizeOfHeapCommit", new UInt32Data(buffer, pos + 0x54)); LoaderFlags = new StructField <UInt32Data>("LoaderFlags", new UInt32Data(buffer, pos + 0x58)); NumberOfRvaAndSizes = new StructField <UInt32Data>("NumberOfRvaAndSizes", new UInt32Data(buffer, pos + 0x5C)); DataDirectory = new StructField <ArrayData <DataDirectoryData> >("DataDirectory", CreateDataDirectoryArray(buffer, pos + 0x60, span.End)); Fields = new StructField[] { Magic, MajorLinkerVersion, MinorLinkerVersion, SizeOfCode, SizeOfInitializedData, SizeOfUninitializedData, AddressOfEntryPoint, BaseOfCode, BaseOfData, ImageBase, SectionAlignment, FileAlignment, MajorOperatingSystemVersion, MinorOperatingSystemVersion, MajorImageVersion, MinorImageVersion, MajorSubsystemVersion, MinorSubsystemVersion, Win32VersionValue, SizeOfImage, SizeOfHeaders, CheckSum, Subsystem, DllCharacteristics, SizeOfStackReserve, SizeOfStackCommit, SizeOfHeapReserve, SizeOfHeapCommit, LoaderFlags, NumberOfRvaAndSizes, DataDirectory, }; }
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 is 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 is null) && visEnd is 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 is null) && visEnd is null) { visEnd = CurrentTextIndex; } visibleSpan = visStart is null ? default : VST.Span.FromBounds(visStart.Value, visEnd !.Value); fullSpan = VST.Span.FromBounds(fullStart, CurrentTextIndex); if (ValuesSpan != fullSpan) { throw new InvalidOperationException(); } return(cellList.ToArray()); }
public virtual HexBufferSpan GetBufferSpan(HexBufferSpan bufferSpan, int cellPosition) => bufferSpan;
/// <summary> /// Constructor /// </summary> /// <param name="span">Span</param> protected PeDosHeaderData(HexBufferSpan span) : base(NAME, span) { }
void ClearCells(char[] chars, bool isColumnPresent, HexCellCollection cells, HexBufferSpan visibleBytes) { if (!isColumnPresent) return; foreach (var cell in cells.GetVisibleCells()) { // Don't clear it if the cell is in the visible bytes span, this includes the case // where only some of its bytes are visible. if (visibleBytes.Contains(cell.BufferSpan)) continue; for (int i = cell.TextSpan.Start; i < cell.TextSpan.End; i++) chars[i] = ' '; } }
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(); }
/// <summary> /// Gets normalized text bounds /// </summary> /// <param name="bufferPosition">Position</param> /// <param name="flags">Flags</param> /// <returns></returns> public abstract Collection <VSTF.TextBounds> GetNormalizedTextBounds(HexBufferSpan bufferPosition, HexSpanSelectionFlags flags);
/// <summary> /// Scrolls a span into view /// </summary> /// <param name="span">Span</param> /// <param name="flags">Flags</param> /// <param name="options">Options</param> public abstract void EnsureSpanVisible(HexBufferSpan span, HexSpanSelectionFlags flags, VSTE.EnsureSpanVisibleOptions options);
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(); }
/// <summary> /// Gets normalized text bounds /// </summary> /// <param name="bufferPosition">Position</param> /// <param name="flags">Flags</param> /// <returns></returns> public abstract Collection<VSTF.TextBounds> GetNormalizedTextBounds(HexBufferSpan bufferPosition, HexSpanSelectionFlags flags);
/// <summary> /// Updates a popup agent /// </summary> /// <param name="agent">Popup agent created by <see cref="CreatePopupAgent(HexLineSpan, VSTA.PopupStyles, UIElement)"/></param> /// <param name="bufferSpan">New buffer span</param> /// <param name="flags">New selection flags</param> /// <param name="styles">New popup style</param> public void UpdatePopupAgent(HexSpaceReservationAgent agent, HexBufferSpan bufferSpan, HexSpanSelectionFlags flags, VSTA.PopupStyles styles) => UpdatePopupAgent(agent, new HexLineSpan(bufferSpan, flags), styles);
public override void RemoveMatchingAdornments(HexBufferSpan visualSpan, Predicate<HexAdornmentLayerElement> match) { if (visualSpan.IsDefault) throw new ArgumentException(); if (match == null) throw new ArgumentNullException(nameof(match)); for (int i = adornmentLayerElements.Count - 1; i >= 0; i--) { var elem = adornmentLayerElements[i]; if (elem.VisualSpan != null && visualSpan.OverlapsWith(GetOverlapsWithSpan(elem.VisualSpan.Value)) && match(elem)) { adornmentLayerElements.RemoveAt(i); canvas.Children.RemoveAt(i); elem.RemovedCallback?.Invoke(elem.Tag, elem.Adornment); } } }
/// <summary> /// Creates a popup agent /// </summary> /// <param name="bufferSpan">Buffer span</param> /// <param name="flags">Selection flags</param> /// <param name="style">Popup style</param> /// <param name="content">Popup content</param> /// <returns></returns> public HexSpaceReservationAgent CreatePopupAgent(HexBufferSpan bufferSpan, HexSpanSelectionFlags flags, VSTA.PopupStyles style, UIElement content) => CreatePopupAgent(new HexLineSpan(bufferSpan, flags), style, content);
static HexViewLine GetLine(IList<HexViewLine> lines, HexBufferSpan span) { foreach (var line in lines) { if (line.BufferSpan.OverlapsWith(span)) return line; if (span.End == line.BufferEnd && line.IsLastDocumentLine()) return line; } return null; }
public GUIDHeapImpl(HexBufferSpan span) : base(span) { }
/// <summary> /// Constructor /// </summary> /// <param name="changeSpan">The span that changed</param> public HexClassificationChangedEventArgs(HexBufferSpan changeSpan) { if (changeSpan.IsDefault) throw new ArgumentException(); ChangeSpan = changeSpan; }
public StringsHeapImpl(HexBufferSpan span) : base(span) { }
void EnsureSpanVisibleY(HexBufferSpan span, VSTE.EnsureSpanVisibleOptions options) { bool showStart = (options & VSTE.EnsureSpanVisibleOptions.ShowStart) != 0; bool minimumScroll = (options & VSTE.EnsureSpanVisibleOptions.MinimumScroll) != 0; bool alwaysCenter = (options & VSTE.EnsureSpanVisibleOptions.AlwaysCenter) != 0; var visibleSpan = VisibleSpan; bool spanIsInView = span.Start >= visibleSpan.Start && span.End <= visibleSpan.End; if (!spanIsInView) { ShowSpan(span, options); alwaysCenter = true; visibleSpan = VisibleSpan; spanIsInView = span.Start >= visibleSpan.Start && span.End <= visibleSpan.End; } if (spanIsInView) { var lines = hexView.HexViewLines.GetHexViewLinesIntersectingSpan(span); Debug.Assert(lines.Count > 0); if (lines.Count == 0) return; var first = lines[0]; var last = lines[lines.Count - 1]; if (lines.Count > 1 && last.BufferStart == span.End) last = lines[lines.Count - 2]; var firstSpan = first.BufferSpan; var lastSpan = last.BufferSpan; bool allLinesFullyVisible = first.VisibilityState == VSTF.VisibilityState.FullyVisible && last.VisibilityState == VSTF.VisibilityState.FullyVisible; if (alwaysCenter || (!allLinesFullyVisible && !minimumScroll)) { double height = last.Bottom - first.Top; double verticalDistance = (hexView.ViewportHeight - height) / 2; hexView.DisplayHexLineContainingBufferPosition(first.BufferStart, verticalDistance, VSTE.ViewRelativePosition.Top); return; } if (first.VisibilityState != VSTF.VisibilityState.FullyVisible) hexView.DisplayHexLineContainingBufferPosition(first.BufferStart, 0, VSTE.ViewRelativePosition.Top); else if (last.VisibilityState != VSTF.VisibilityState.FullyVisible) hexView.DisplayHexLineContainingBufferPosition(last.BufferStart, 0, VSTE.ViewRelativePosition.Bottom); if (showStart) { var line = hexView.HexViewLines.GetHexViewLineContainingBufferPosition(firstSpan.Start); if (line == null || line.VisibilityState != VSTF.VisibilityState.FullyVisible) ShowSpan(span, options); } else { var line = hexView.HexViewLines.GetHexViewLineContainingBufferPosition(lastSpan.Start); if (line == null || line.VisibilityState != VSTF.VisibilityState.FullyVisible) ShowSpan(span, options); } } }
public static bool IntersectsWithButDoesNotStartAtItsEnd(this NormalizedHexBufferSpanCollection coll, HexBufferSpan bufferSpan) { foreach (var span in coll) { if (bufferSpan.End != span.Start && span.IntersectsWith(bufferSpan)) { return(true); } } return(false); }
public override void EnsureSpanVisible(HexBufferSpan span, HexSpanSelectionFlags flags, VSTE.EnsureSpanVisibleOptions options) { if (span.Buffer != hexView.Buffer) throw new ArgumentException(); EnsureSpanVisibleCore(new HexLineSpan(span, flags), options); }
public TablesHeapImpl(HexBufferSpan span, TablesHeapType tablesHeapType) : base(span, tablesHeapType) { }
/// <summary> /// Selects a span /// </summary> /// <param name="selectionSpan">Span</param> /// <param name="isReversed">true if the anchor point is the end point of <paramref name="selectionSpan"/></param> /// <param name="alignPoints">true to align the span to include all bytes of the cells</param> public abstract void Select(HexBufferSpan selectionSpan, bool isReversed, bool alignPoints);
public DotNetMultiFileResourceHeaderDataImpl(HexBufferSpan span, Bit7String?resourceTypeSpan, Bit7String?resourceSetTypeSpan, HexPosition versionPosition, HexSpan paddingSpan, Bit7String[] typeNames, int numResources) : base(span) { var buffer = span.Buffer; var pos = span.Start.Position; MagicNum = new StructField <UInt32Data>("MagicNum", new UInt32Data(buffer, pos)); ResMgrHeaderVersion = new StructField <UInt32Data>("ResMgrHeaderVersion", new UInt32Data(buffer, pos + 4)); HeaderSize = new StructField <UInt32Data>("HeaderSize", new UInt32Data(buffer, pos + 8)); if (resourceTypeSpan == null) { if (resourceSetTypeSpan != null) { throw new ArgumentException(); } UnknownHeader = new StructField <VirtualArrayData <ByteData> >("Header", ArrayData.CreateVirtualByteArray(new HexBufferSpan(buffer, HexSpan.FromBounds(pos + 0x0C, versionPosition)))); } else { if (resourceSetTypeSpan == null) { throw new ArgumentNullException(nameof(resourceSetTypeSpan)); } ReaderType = new StructField <Bit7EncodedStringData>("ReaderType", new Bit7EncodedStringData(buffer, resourceTypeSpan.Value.LengthSpan, resourceTypeSpan.Value.StringSpan, Encoding.UTF8)); ResourceSetType = new StructField <Bit7EncodedStringData>("ResourceSetType", new Bit7EncodedStringData(buffer, resourceSetTypeSpan.Value.LengthSpan, resourceSetTypeSpan.Value.StringSpan, Encoding.UTF8)); } pos = versionPosition; Version = new StructField <UInt32Data>("Version", new UInt32Data(buffer, pos)); NumResources = new StructField <UInt32Data>("NumResources", new UInt32Data(buffer, pos + 4)); NumTypes = new StructField <UInt32Data>("NumTypes", new UInt32Data(buffer, pos + 8)); pos += 0x0C; var fields = new ArrayField <Bit7EncodedStringData> [typeNames.Length]; var currPos = pos; for (int i = 0; i < fields.Length; i++) { var info = typeNames[i]; var field = new ArrayField <Bit7EncodedStringData>(new Bit7EncodedStringData(buffer, info.LengthSpan, info.StringSpan, Encoding.UTF8), (uint)i); fields[i] = field; currPos = field.Data.Span.End; } TypeNames = new StructField <VariableLengthArrayData <Bit7EncodedStringData> >("TypeNames", new VariableLengthArrayData <Bit7EncodedStringData>(string.Empty, new HexBufferSpan(buffer, HexSpan.FromBounds(pos, currPos)), fields)); Alignment8 = new StructField <ArrayData <ByteData> >("Padding", ArrayData.CreateByteArray(buffer, paddingSpan.Start, (int)paddingSpan.Length.ToUInt64())); pos = paddingSpan.End; NameHashes = new StructField <VirtualArrayData <UInt32Data> >("NameHashes", ArrayData.CreateVirtualUInt32Array(new HexBufferSpan(buffer, new HexSpan(pos, (ulong)numResources * 4)))); pos += (ulong)numResources * 4; NamePositions = new StructField <VirtualArrayData <UInt32Data> >("NamePositions", ArrayData.CreateVirtualUInt32Array(new HexBufferSpan(buffer, new HexSpan(pos, (ulong)numResources * 4)))); pos += (ulong)numResources * 4; DataSectionOffset = new StructField <FileOffsetData>("DataSectionOffset", new FileOffsetData(buffer, pos)); pos += 4; if (pos != span.Span.End) { throw new ArgumentOutOfRangeException(nameof(span)); } var list = new List <BufferField>(13); list.Add(MagicNum); list.Add(ResMgrHeaderVersion); list.Add(HeaderSize); if (UnknownHeader != null) { list.Add(UnknownHeader); } if (ReaderType != null) { list.Add(ReaderType); } if (ResourceSetType != null) { list.Add(ResourceSetType); } list.Add(Version); list.Add(NumResources); list.Add(NumTypes); list.Add(TypeNames); list.Add(Alignment8); list.Add(NameHashes); list.Add(NamePositions); list.Add(DataSectionOffset); Fields = list.ToArray(); }
/// <summary> /// Shows a tooltip /// </summary> /// <param name="bufferSpan">Buffer span</param> /// <param name="flags">Selection flags</param> /// <param name="toolTipContent">Tooltip content</param> /// <param name="style">Popup style</param> public abstract void ShowToolTip(HexBufferSpan bufferSpan, HexSpanSelectionFlags flags, object toolTipContent, VSTA.PopupStyles style);
/// <summary> /// Adds an adornment. Returns true if the adornment was added. /// </summary> /// <param name="visualSpan">Span</param> /// <param name="tag">Tag</param> /// <param name="adornment">Adornment</param> /// <returns></returns> public bool AddAdornment(HexBufferSpan visualSpan, object tag, UIElement adornment) => AddAdornment(VSTE.AdornmentPositioningBehavior.TextRelative, visualSpan, tag, adornment, null);
void InvalidateSpan(HexBufferSpan span) { canvas.Dispatcher.VerifyAccess(); invalidatedRegions.Add(span); DelayLayoutLines(); }
/// <summary> /// Removes an adornment /// </summary> /// <param name="visualSpan">Span</param> public void RemoveAdornmentsByVisualSpan(HexBufferSpan visualSpan) => RemoveMatchingAdornments(visualSpan, returnTruePredicate);
/// <summary> /// Constructor /// </summary> /// <param name="bufferSpan">Span of field</param> /// <param name="kind">Field kind</param> public HexStructureField(HexBufferSpan bufferSpan, HexStructureFieldKind kind) { BufferSpan = bufferSpan; Kind = kind; }
/// <summary> /// Removes all matching adornments /// </summary> /// <param name="visualSpan">Span</param> /// <param name="match">Returns true if the adornment should be removed</param> public abstract void RemoveMatchingAdornments(HexBufferSpan visualSpan, Predicate <HexAdornmentLayerElement> match);