示例#1
0
		public void Show(HexSpan span, int windowIndex) {
			var mc = GetMemoryToolWindowContent(windowIndex);
			Debug.Assert(mc != null);
			if (mc == null)
				return;
			ShowInMemoryWindow(mc, span);
		}
		public static bool OverlapsWith(this NormalizedHexChangeCollection changes, HexSpan span) {
			foreach (var change in changes) {
				if (change.OldSpan.OverlapsWith(span))
					return true;
			}
			return false;
		}
示例#3
0
文件: HexField.cs 项目: 0xd4d/dnSpy
		protected HexField(HexBuffer buffer, string parentName, string name, HexPosition start, int size) {
			this.buffer = buffer;
			this.parentName = parentName;
			IsVisible = true;
			Name = name;
			Span = new HexSpan(start, (ulong)size);
		}
		public ByteArrayHexBufferStream(byte[] data, string name) {
			if (data == null)
				throw new ArgumentNullException(nameof(data));
			if (name == null)
				throw new ArgumentNullException(nameof(name));
			Span = new HexSpan(0, (ulong)data.LongLength);
			Name = name;
			this.data = data;
		}
示例#5
0
		/// <summary>
		/// Gets information about a position in the stream
		/// </summary>
		/// <param name="position">Position</param>
		/// <param name="validSpan">Span of all valid data</param>
		/// <returns></returns>
		protected HexSpanInfo GetSpanInfo(HexPosition position, HexSpan validSpan) {
			if (position >= HexPosition.MaxEndPosition)
				throw new ArgumentOutOfRangeException(nameof(position));
			if (position >= validSpan.End)
				return new HexSpanInfo(HexSpan.FromBounds(validSpan.End, HexPosition.MaxEndPosition), HexSpanInfoFlags.None);
			else if (position < validSpan.Start)
				return new HexSpanInfo(HexSpan.FromBounds(HexPosition.Zero, validSpan.Start), HexSpanInfoFlags.None);
			else
				return new HexSpanInfo(validSpan, HexSpanInfoFlags.HasData);
		}
示例#6
0
		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);
		}
示例#7
0
		protected MetaDataTableVM(object owner, HexBuffer buffer, HexPosition startOffset, MDTable mdTable, HexSpan stringsHeapSpan, HexSpan guidHeapSpan) {
			this.buffer = buffer;
			this.stringsHeapSpan = stringsHeapSpan;
			this.guidHeapSpan = guidHeapSpan;
			Owner = owner;
			Span = new HexSpan(startOffset, (ulong)mdTable.Rows * mdTable.RowSize);
			Rows = mdTable.Rows;
			TableInfo = CreateTableInfo(mdTable.TableInfo);
			Collection = new VirtualizedList<MetaDataTableRecordVM>((int)Rows, CreateItem);
		}
示例#8
0
		static void SelectAndMoveCaret(WpfHexView hexView, HexSpan span) {
			if (!hexView.VisualElement.IsLoaded) {
				RoutedEventHandler loaded = null;
				loaded = (s, e) => {
					hexView.VisualElement.Loaded -= loaded;
					InitializeHexView(hexView, span);
				};
				hexView.VisualElement.Loaded += loaded;
			}
			else
				InitializeHexView(hexView, span);
		}
		public override void OnBufferChanged(NormalizedHexChangeCollection changes) {
			if (infoTuple != null) {
				var tableInfo = ((MetaDataTableNode)TreeNode.Parent.Data).TableInfo;
				foreach (var index in infoTuple.Item1) {
					var col = tableInfo.Columns[index];
					var span = new HexSpan(Span.Start + (ulong)col.Offset, (ulong)col.Size);
					if (changes.OverlapsWith(span)) {
						TreeNode.RefreshUI();
						break;
					}
				}
			}
		}
示例#10
0
		public StateMachineMethodMetaDataTableVM(object owner, HexBuffer buffer, HexPosition startOffset, MDTable mdTable, HexSpan stringsHeapSpan, HexSpan guidHeapSpan)
			: base(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan) {
		}
示例#11
0
		public CustomDebugInformationMetaDataTableVM(object owner, HexBuffer buffer, HexPosition startOffset, MDTable mdTable, HexSpan stringsHeapSpan, HexSpan guidHeapSpan)
			: base(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan) {
		}
示例#12
0
		public GenericParamConstraintMetaDataTableVM(object owner, HexBuffer buffer, HexPosition startOffset, MDTable mdTable, HexSpan stringsHeapSpan, HexSpan guidHeapSpan)
			: base(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan) {
		}
示例#13
0
		public ImportScopeMetaDataTableVM(object owner, HexBuffer buffer, HexPosition startOffset, MDTable mdTable, HexSpan stringsHeapSpan, HexSpan guidHeapSpan)
			: base(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan) {
		}
示例#14
0
文件: HexBuffer.cs 项目: 0xd4d/dnSpy
		/// <summary>
		/// Reads bytes
		/// </summary>
		/// <param name="span">Span</param>
		/// <returns></returns>
		public abstract byte[] ReadBytes(HexSpan span);
示例#15
0
		public AssemblyRefProcessorMetaDataTableVM(object owner, HexBuffer buffer, HexPosition startOffset, MDTable mdTable, HexSpan stringsHeapSpan, HexSpan guidHeapSpan)
			: base(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan) {
		}
示例#16
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();
		}
		void InvalidateCore(HexSpan span) {
			if (span.IsEmpty)
				return;
			ulong startPage = span.Start.ToUInt64() & ~pageSizeMask;
			ulong endPage = (span.End.ToUInt64() - 1) & ~pageSizeMask;
			for (int i = 0; i < cachedPages.Length; i++) {
				var cp = cachedPages[i];
				if (!cp.IsInitialized)
					continue;
				if (startPage <= cp.Offset && cp.Offset <= endPage) {
					cp.IsInitialized = false;
					//TODO: Perhaps we should just re-read the data. It's usually just one byte
				}
			}
		}
示例#18
0
		protected HexNode(HexSpan span) {
			Span = span;
		}
示例#19
0
		public void Show(HexSpan span) {
			var mc = GetMemoryToolWindowContent(span);
			if (mc == null)
				mc = memoryToolWindowContentProvider.Value.Contents[0].Content;
			ShowInMemoryWindow(mc, span);
		}
示例#20
0
		void MakeSureAddressCanBeShown(MemoryToolWindowContent mc, HexSpan span) {
			if (CanShowAll(mc, span))
				return;
			mc.HexView.Options.SetOptionValue(DefaultHexViewOptions.StartPositionId, mc.HexView.Buffer.Span.Start);
			mc.HexView.Options.SetOptionValue(DefaultHexViewOptions.EndPositionId, mc.HexView.Buffer.Span.End);
			RedisplayHexLines(mc.HexView);
		}
示例#21
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="span">Span</param>
		public HexBufferStreamSpanInvalidatedEventArgs(HexSpan span) {
			Span = span;
		}
示例#22
0
		/// <summary>
		/// Invalidates a region of memory
		/// </summary>
		/// <param name="span">Span</param>
		public abstract void Invalidate(HexSpan span);
示例#23
0
		void ShowInMemoryWindow(MemoryToolWindowContent mc, HexSpan span) {
			MakeSureAddressCanBeShown(mc, span);
			toolWindowService.Show(mc);
			SelectAndMoveCaret(mc.HexView, span);
		}
示例#24
0
		static bool IsVisible(HexView hexView, HexSpan span) =>
			span.Start >= hexView.BufferLines.StartPosition && span.End <= hexView.BufferLines.EndPosition;
示例#25
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="span">Span</param>
		/// <param name="flags">Flags</param>
		public HexSpanInfo(HexSpan span, HexSpanInfoFlags flags) {
			Span = span;
			Flags = flags;
		}
示例#26
0
		public static MetaDataTableVM Create(object owner, HexBuffer buffer, HexPosition startOffset, MDTable mdTable, HexSpan stringsHeapSpan, HexSpan guidHeapSpan) {
			switch (mdTable.Table) {
			case Table.Module:					return new ModuleMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.TypeRef:					return new TypeRefMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.TypeDef:					return new TypeDefMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.FieldPtr:				return new FieldPtrMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.Field:					return new FieldMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.MethodPtr:				return new MethodPtrMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.Method:					return new MethodMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.ParamPtr:				return new ParamPtrMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.Param:					return new ParamMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.InterfaceImpl:			return new InterfaceImplMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.MemberRef:				return new MemberRefMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.Constant:				return new ConstantMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.CustomAttribute:			return new CustomAttributeMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.FieldMarshal:			return new FieldMarshalMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.DeclSecurity:			return new DeclSecurityMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.ClassLayout:				return new ClassLayoutMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.FieldLayout:				return new FieldLayoutMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.StandAloneSig:			return new StandAloneSigMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.EventMap:				return new EventMapMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.EventPtr:				return new EventPtrMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.Event:					return new EventMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.PropertyMap:				return new PropertyMapMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.PropertyPtr:				return new PropertyPtrMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.Property:				return new PropertyMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.MethodSemantics:			return new MethodSemanticsMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.MethodImpl:				return new MethodImplMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.ModuleRef:				return new ModuleRefMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.TypeSpec:				return new TypeSpecMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.ImplMap:					return new ImplMapMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.FieldRVA:				return new FieldRVAMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.ENCLog:					return new ENCLogMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.ENCMap:					return new ENCMapMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.Assembly:				return new AssemblyMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.AssemblyProcessor:		return new AssemblyProcessorMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.AssemblyOS:				return new AssemblyOSMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.AssemblyRef:				return new AssemblyRefMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.AssemblyRefProcessor:	return new AssemblyRefProcessorMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.AssemblyRefOS:			return new AssemblyRefOSMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.File:					return new FileMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.ExportedType:			return new ExportedTypeMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.ManifestResource:		return new ManifestResourceMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.NestedClass:				return new NestedClassMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.GenericParam:			return mdTable.Columns.Count == 5 ? (MetaDataTableVM)new GenericParamMetaDataTableV11VM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan) : new GenericParamMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.MethodSpec:				return new MethodSpecMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.GenericParamConstraint:	return new GenericParamConstraintMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.Document:				return new DocumentMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.MethodDebugInformation:	return new MethodDebugInformationMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.LocalScope:				return new LocalScopeMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.LocalVariable:			return new LocalVariableMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.LocalConstant:			return new LocalConstantMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.ImportScope:				return new ImportScopeMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.StateMachineMethod:		return new StateMachineMethodMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			case Table.CustomDebugInformation:	return new CustomDebugInformationMetaDataTableVM(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan);
			default:							throw new InvalidOperationException();
			}
		}
		public override void Invalidate(HexSpan span) {
			if (span.Start <= Span.Start && span.End >= Span.End)
				ClearAll();
			else
				InvalidateCore(span);
			BufferStreamSpanInvalidated?.Invoke(this, new HexBufferStreamSpanInvalidatedEventArgs(span));
		}
示例#28
0
文件: HexBuffer.cs 项目: 0xd4d/dnSpy
		/// <summary>
		/// Gets all valid spans overlapping <paramref name="span"/>. This method merges all
		/// consecutive valid spans.
		/// </summary>
		/// <param name="span">Span</param>
		/// <param name="fullSpan">true if positions before <paramref name="span"/> should be included
		/// in the returned result. This could result in worse performance.</param>
		/// <returns></returns>
		public IEnumerable<HexSpan> GetValidSpans(HexSpan span, bool fullSpan) {
			var pos = span.Start;
			for (;;) {
				var info = GetNextValidSpan(pos, span.End, fullSpan);
				if (info == null)
					break;
				yield return info.Value;
				pos = info.Value.End;
				fullSpan = false;
			}
		}
示例#29
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();
		}
示例#30
0
		MemoryToolWindowContent GetMemoryToolWindowContent(HexSpan span) {
			foreach (var info in memoryToolWindowContentProvider.Value.Contents) {
				var mc = info.Content;
				if (CanShowAll(mc, span))
					return mc;
			}
			return null;
		}