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;
		}
Exemple #3
0
		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;
		}
		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);
		}
Exemple #6
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);
		}
Exemple #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);
		}
		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;
					}
				}
			}
		}
		static bool IsVisible(HexView hexView, HexSpan span) =>
			span.Start >= hexView.BufferLines.StartPosition && span.End <= hexView.BufferLines.EndPosition;
		/// <summary>
		/// Invalidates a region of memory
		/// </summary>
		/// <param name="span">Span</param>
		public abstract void Invalidate(HexSpan span);
Exemple #12
0
        /// <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,
            };
        }
Exemple #13
0
 public StorageHeaderNode(HexBuffer buffer, MetaDataHeader mdHeader)
     : base(HexSpan.FromBounds((ulong)mdHeader.StorageHeaderOffset, (ulong)mdHeader.StorageHeaderOffset + 4))
 {
     storageHeaderVM = new StorageHeaderVM(this, buffer, Span.Start);
 }
 public SimpleResData(ResourceTypeCode typeCode, HexSpan codeSpan, HexPosition position, uint length)
     : base(typeCode, codeSpan, new HexSpan(position, length), new HexSpan(position, length))
 {
 }
Exemple #15
0
 protected HexNode(HexSpan span) => Span = span;
 protected Data(DataKind kind, HexSpan span)
 {
     Kind = kind;
     Span = span;
 }
Exemple #17
0
        bool ReplaceSafe(HexPosition position, byte[] replaceWith)
        {
            var replaceSpan = new HexSpan(position, (ulong)replaceWith.LongLength);

            return(ReplaceSafe(replaceSpan, replaceWith));
        }
        ResData ReadData(Bit7String[] typeNames, HexPosition position, HexPosition endPosition)
        {
            var start   = position;
            var codeTmp = Read7BitEncodedInt32(File.Buffer, ref position);

            if (codeTmp == null)
            {
                return(null);
            }
            var  codeSpan = HexSpan.FromBounds(start, position);
            uint code     = (uint)codeTmp.Value;
            var  typeCode = (ResourceTypeCode)code;

            switch (typeCode)
            {
            case ResourceTypeCode.Null:             return(new SimpleResData(typeCode, codeSpan, position, 0));

            case ResourceTypeCode.Boolean:  return(new SimpleResData(typeCode, codeSpan, position, 1));

            case ResourceTypeCode.Char:             return(new SimpleResData(typeCode, codeSpan, position, 2));

            case ResourceTypeCode.Byte:             return(new SimpleResData(typeCode, codeSpan, position, 1));

            case ResourceTypeCode.SByte:    return(new SimpleResData(typeCode, codeSpan, position, 1));

            case ResourceTypeCode.Int16:    return(new SimpleResData(typeCode, codeSpan, position, 2));

            case ResourceTypeCode.UInt16:   return(new SimpleResData(typeCode, codeSpan, position, 2));

            case ResourceTypeCode.Int32:    return(new SimpleResData(typeCode, codeSpan, position, 4));

            case ResourceTypeCode.UInt32:   return(new SimpleResData(typeCode, codeSpan, position, 4));

            case ResourceTypeCode.Int64:    return(new SimpleResData(typeCode, codeSpan, position, 8));

            case ResourceTypeCode.UInt64:   return(new SimpleResData(typeCode, codeSpan, position, 8));

            case ResourceTypeCode.Single:   return(new SimpleResData(typeCode, codeSpan, position, 4));

            case ResourceTypeCode.Double:   return(new SimpleResData(typeCode, codeSpan, position, 8));

            case ResourceTypeCode.Decimal:  return(new SimpleResData(typeCode, codeSpan, position, 16));

            case ResourceTypeCode.DateTime: return(new SimpleResData(typeCode, codeSpan, position, 8));

            case ResourceTypeCode.TimeSpan: return(new SimpleResData(typeCode, codeSpan, position, 8));

            case ResourceTypeCode.String:
                var stringPos  = position;
                var bit7String = ReadBit7String(File.Buffer, ref stringPos, endPosition);
                if (bit7String == null)
                {
                    return(null);
                }
                return(new StringResData(typeCode, codeSpan, bit7String.Value.FullSpan, bit7String.Value));

            case ResourceTypeCode.ByteArray:
            case ResourceTypeCode.Stream:
                uint length = File.Buffer.ReadUInt32(position);
                if (position + length + 4UL > endPosition)
                {
                    return(null);
                }
                return(new ArrayResData(typeCode, codeSpan, new HexSpan(position, length + 4UL), new HexSpan(position + 4, length)));

            default:
                int userTypeIndex = (int)(code - (uint)ResourceTypeCode.UserTypes);
                if ((uint)userTypeIndex >= (uint)typeNames.Length)
                {
                    return(null);
                }
                var userType = typeNames[userTypeIndex];
                return(new TypeResData(typeCode, codeSpan, HexSpan.FromBounds(position, endPosition), userType));
            }
        }
        static DotNetMultiFileResourcesImpl TryReadCore(HexBufferFile file)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }
            if (file.Span.Length < 0x1C)
            {
                return(null);
            }
            var buffer = file.Buffer;
            var pos    = file.Span.Start;

            if (buffer.ReadUInt32(pos) != 0xBEEFCACE)
            {
                return(null);
            }

            int resMgrHeaderVersion = buffer.ReadInt32(pos + 4);
            int headerSize          = buffer.ReadInt32(pos + 8);

            if (resMgrHeaderVersion < 0 || headerSize < 0)
            {
                return(null);
            }
            pos += 0xC;

            Bit7String?resourceTypeSpan    = null;
            Bit7String?resourceSetTypeSpan = null;

            if (resMgrHeaderVersion > 1)
            {
                pos += headerSize;
            }
            else
            {
                resourceTypeSpan    = ReadBit7String(buffer, ref pos, file.Span.End);
                resourceSetTypeSpan = ReadBit7String(buffer, ref pos, file.Span.End);
                if (resourceTypeSpan == null || resourceSetTypeSpan == null)
                {
                    return(null);
                }
                var resourceType = Encoding.UTF8.GetString(buffer.ReadBytes(resourceTypeSpan.Value.StringSpan));
                if (!Regex.IsMatch(resourceType, @"^System\.Resources\.ResourceReader,\s*mscorlib,"))
                {
                    return(null);
                }
            }

            var versionPosition = pos;

            if (pos + 0x0C > file.Span.End)
            {
                return(null);
            }
            uint version = buffer.ReadUInt32(pos);

            if (version != 2)
            {
                return(null);               //TODO: Support version 1
            }
            int numResources = buffer.ReadInt32(pos + 4);
            int numTypes     = buffer.ReadInt32(pos + 8);

            if (numResources < 0 || numTypes < 0)
            {
                return(null);
            }
            pos += 0x0C;
            var typeNames = new Bit7String[numTypes];

            for (int i = 0; i < typeNames.Length; i++)
            {
                var info = ReadBit7String(buffer, ref pos, file.Span.End);
                if (info == null)
                {
                    return(null);
                }
                typeNames[i] = info.Value;
            }

            var paddingStart = pos;

            pos = file.AlignUp(pos, 8);
            var paddingSpan = HexSpan.FromBounds(paddingStart, pos);

            if (pos + (ulong)numResources * 8 + 4 > file.Span.End)
            {
                return(null);
            }
            pos += (ulong)numResources * 8;
            int dataSectionOffset = buffer.ReadInt32(pos);

            pos += 4;
            if (dataSectionOffset < 0 || dataSectionOffset < (pos - file.Span.Start))
            {
                return(null);
            }
            // Use > and not >= in case it's an empty resource
            if (dataSectionOffset > file.Span.Length)
            {
                return(null);
            }
            var dataSectionPosition = file.Span.Start + dataSectionOffset;
            var nameSectionPosition = pos;

            return(new DotNetMultiFileResourcesImpl(file, resourceTypeSpan, resourceSetTypeSpan, versionPosition, paddingSpan, typeNames, numResources, dataSectionPosition, nameSectionPosition));
        }
 public TypeResData(ResourceTypeCode typeCode, HexSpan codeSpan, HexSpan dataSpan, Bit7String utf8TypeName)
     : base(typeCode, codeSpan, dataSpan, dataSpan) => Utf8TypeName = utf8TypeName;
 public ArrayResData(ResourceTypeCode typeCode, HexSpan codeSpan, HexSpan dataSpan, HexSpan nestedFileData)
     : base(typeCode, codeSpan, dataSpan, nestedFileData)
 {
 }
 public StringResData(ResourceTypeCode typeCode, HexSpan codeSpan, HexSpan dataSpan, Bit7String utf8StringValue)
     : base(typeCode, codeSpan, dataSpan, utf8StringValue.StringSpan) => Utf8StringValue = utf8StringValue;
Exemple #23
0
		/// <summary>
		/// Reads bytes
		/// </summary>
		/// <param name="span">Span</param>
		/// <returns></returns>
		public abstract byte[] ReadBytes(HexSpan span);
 public UnicodeNameAndOffsetData(ResourceInfo owner, Bit7String bit7String)
     : base(DataKind.UnicodeNameAndOffset, HexSpan.FromBounds(bit7String.FullSpan.Start, bit7String.FullSpan.End + 4))
 {
     Owner      = owner;
     Bit7String = bit7String;
 }
Exemple #25
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="span">Span</param>
		public HexBufferStreamSpanInvalidatedEventArgs(HexSpan span) {
			Span = span;
		}
 public ResourceInfoData(ResourceInfo owner, HexSpan span)
     : base(DataKind.ResourceInfo, span) => Owner = owner;
		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();
		}
        DotNetMultiFileResourcesImpl(HexBufferFile file, Bit7String?resourceTypeSpan, Bit7String?resourceSetTypeSpan, HexPosition versionPosition, HexSpan paddingSpan, Bit7String[] typeNames, int numResources, HexPosition dataSectionPosition, HexPosition nameSectionPosition)
            : base(file)
        {
            DataSectionPosition = dataSectionPosition;
            var headerSpan = new HexBufferSpan(file.Buffer, HexSpan.FromBounds(file.Span.Start, nameSectionPosition));

            Header    = new DotNetMultiFileResourceHeaderDataImpl(headerSpan, resourceTypeSpan, resourceSetTypeSpan, versionPosition, paddingSpan, typeNames, numResources);
            dataArray = CreateDataArray(typeNames, numResources, paddingSpan.End, dataSectionPosition, nameSectionPosition, out var resourceInfos);

            var files = new List <BufferFileOptions>(resourceInfos.Length);

            foreach (var info in resourceInfos)
            {
                var data = info.ResData;
                if (data == null)
                {
                    continue;
                }
                if (data.NestedFileData.IsEmpty)
                {
                    continue;
                }
                if (!IsNestedFile(data.TypeCode))
                {
                    continue;
                }
                var name         = Encoding.Unicode.GetString(File.Buffer.ReadBytes(info.UnicodeName.StringSpan));
                var filteredName = NameUtils.FilterName(name);
                var tags         = data.TypeCode >= ResourceTypeCode.UserTypes ? tagsSerialized : tagsNonSerialized;
                files.Add(new BufferFileOptions(data.NestedFileData, filteredName, string.Empty, tags));
            }
            if (files.Count > 0)
            {
                File.CreateFiles(files.ToArray());
            }
        }
Exemple #29
0
		protected HexNode(HexSpan span) {
			Span = span;
		}
Exemple #30
0
 public void Invalidate(HexSpan span) => BufferStreamSpanInvalidated?.Invoke(this, new HexBufferStreamSpanInvalidatedEventArgs(span));
		public void Show(HexSpan span) {
			var mc = GetMemoryToolWindowContent(span);
			if (mc == null)
				mc = memoryToolWindowContentProvider.Value.Contents[0].Content;
			ShowInMemoryWindow(mc, span);
		}
Exemple #32
0
 protected HexVM(HexSpan span) => Span = span;
		void ShowInMemoryWindow(MemoryToolWindowContent mc, HexSpan span) {
			MakeSureAddressCanBeShown(mc, span);
			toolWindowService.Show(mc);
			SelectAndMoveCaret(mc.HexView, span);
		}
Exemple #34
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="buffer">Buffer</param>
 /// <param name="lengthSpan">Span of length</param>
 /// <param name="stringSpan">Span of string data</param>
 /// <param name="terminalByteSpan">Span of terminal byte (0 or 1 byte)</param>
 /// <param name="heap">Owner heap</param>
 public USHeapRecordData(HexBuffer buffer, HexSpan lengthSpan, HexSpan stringSpan, HexSpan terminalByteSpan, USHeap heap)
     : base(NAME, new HexBufferSpan(buffer, HexSpan.FromBounds(lengthSpan.Start, terminalByteSpan.End)))
 {
     if (lengthSpan.End != stringSpan.Start)
     {
         throw new ArgumentOutOfRangeException(nameof(stringSpan));
     }
     if (stringSpan.End != terminalByteSpan.Start)
     {
         throw new ArgumentOutOfRangeException(nameof(stringSpan));
     }
     if (!terminalByteSpan.IsEmpty && terminalByteSpan.Length != 1)
     {
         throw new ArgumentOutOfRangeException(nameof(terminalByteSpan));
     }
     Heap   = heap ?? throw new ArgumentNullException(nameof(heap));
     Length = new StructField <BlobEncodedUInt32Data>("Length", new BlobEncodedUInt32Data(new HexBufferSpan(buffer, lengthSpan)));
     String = new StructField <StringData>("String", new StringData(new HexBufferSpan(buffer, stringSpan), Encoding.Unicode));
     if (!terminalByteSpan.IsEmpty)
     {
         TerminalByte = new StructField <ByteData>("TerminalByte", new ByteData(new HexBufferSpan(buffer, terminalByteSpan)));
     }
     if (TerminalByte != null)
     {
         Fields = new BufferField[] {
             Length,
             String,
             TerminalByte,
         };
     }
     else
     {
         Fields = new BufferField[] {
             Length,
             String,
         };
     }
 }
Exemple #35
0
        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();
        }
Exemple #36
0
 static bool IsVisible(HexView hexView, HexSpan span) =>
 span.Start >= hexView.BufferLines.StartPosition && span.End <= hexView.BufferLines.EndPosition;
		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);
		}
Exemple #38
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();
			}
		}
Exemple #39
0
		/// <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;
			}
		}
Exemple #40
0
		public GenericParamConstraintMetaDataTableVM(object owner, HexBuffer buffer, HexPosition startOffset, MDTable mdTable, HexSpan stringsHeapSpan, HexSpan guidHeapSpan)
			: base(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan) {
		}
Exemple #41
0
 /// <summary>
 /// Creates a file. Overlapping files isn't supported.
 /// </summary>
 /// <param name="span">Span of file</param>
 /// <returns></returns>
 public HexBufferFile CreateFile(HexSpan span) =>
 CreateFiles(new BufferFileOptions(span, string.Empty, string.Empty, Array.Empty <string>())).Single();
Exemple #42
0
		public StateMachineMethodMetaDataTableVM(object owner, HexBuffer buffer, HexPosition startOffset, MDTable mdTable, HexSpan stringsHeapSpan, HexSpan guidHeapSpan)
			: base(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan) {
		}
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="resourceProvider">Owner</param>
 /// <param name="buffer">Buffer</param>
 /// <param name="lengthSpan">Span of 7-bit encoded length</param>
 /// <param name="stringSpan">Span of string data</param>
 public MultiResourceUnicodeNameAndOffsetData(DotNetMultiFileResources resourceProvider, HexBuffer buffer, HexSpan lengthSpan, HexSpan stringSpan)
     : base(NAME, new HexBufferSpan(buffer, HexSpan.FromBounds(lengthSpan.Start, stringSpan.End + 4)))
 {
     if (resourceProvider == null)
     {
         throw new ArgumentNullException(nameof(resourceProvider));
     }
     ResourceProvider = resourceProvider;
     ResourceName     = new StructField <Bit7EncodedStringData>("ResourceName", new Bit7EncodedStringData(buffer, lengthSpan, stringSpan, Encoding.Unicode));
     DataOffset       = new StructField <UInt32Data>("DataOffset", new UInt32Data(buffer, stringSpan.End));
     Fields           = new BufferField[] {
         ResourceName,
         DataOffset,
     };
 }
Exemple #44
0
        /// <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,
            };
        }
		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();
		}
		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
				}
			}
		}
Exemple #47
0
 public abstract void Show(int pid, HexSpan span);
 protected ResData(ResourceTypeCode typeCode, HexSpan codeSpan, HexSpan dataSpan, HexSpan nestedFileData)
 {
     CodeSpan       = codeSpan;
     DataSpan       = dataSpan;
     TypeCode       = typeCode;
     NestedFileData = nestedFileData;
 }
Exemple #49
0
		public AssemblyRefProcessorMetaDataTableVM(object owner, HexBuffer buffer, HexPosition startOffset, MDTable mdTable, HexSpan stringsHeapSpan, HexSpan guidHeapSpan)
			: base(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan) {
		}
Exemple #50
0
 public abstract void Show(int pid, HexSpan span, int windowIndex);
Exemple #51
0
		public ImportScopeMetaDataTableVM(object owner, HexBuffer buffer, HexPosition startOffset, MDTable mdTable, HexSpan stringsHeapSpan, HexSpan guidHeapSpan)
			: base(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan) {
		}
 /// <summary>
 /// Creates a file. Overlapping files isn't supported.
 /// </summary>
 /// <param name="span">Span of file</param>
 /// <param name="name">Name</param>
 /// <param name="filename">Filename if possible, otherwise any name</param>
 /// <param name="tags">Tags, see eg. <see cref="PredefinedBufferFileTags"/></param>
 /// <returns></returns>
 public HexBufferFile CreateFile(HexSpan span, string name, string filename, string[] tags) =>
 CreateFiles(new BufferFileOptions(span, name, filename, tags)).Single();
Exemple #53
0
		public CustomDebugInformationMetaDataTableVM(object owner, HexBuffer buffer, HexPosition startOffset, MDTable mdTable, HexSpan stringsHeapSpan, HexSpan guidHeapSpan)
			: base(owner, buffer, startOffset, mdTable, stringsHeapSpan, guidHeapSpan) {
		}
 /// <summary>
 /// Removes all files overlapping with <paramref name="span"/>
 /// </summary>
 /// <param name="span">Span</param>
 public abstract void RemoveFiles(HexSpan span);
Exemple #55
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="span">Span</param>
		/// <param name="flags">Flags</param>
		public HexSpanInfo(HexSpan span, HexSpanInfoFlags flags) {
			Span = span;
			Flags = flags;
		}
Exemple #56
0
        public FatExceptionHandlerTableImpl(HexBufferSpan span)
            : base(span)
        {
            if (span.Length < 4)
            {
                throw new ArgumentOutOfRangeException(nameof(span));
            }
            var buffer = span.Buffer;
            var pos    = span.Start.Position;

            SectFat = new StructField <FatSection>("SectFat", new FatSectionImpl(buffer, pos));

            var startPos = pos + 4;
            int elements = (int)((span.End.Position - startPos).ToUInt64() / 24);
            var fields   = new ArrayField <FatExceptionClause> [elements];
            var currPos  = startPos;

            for (int i = 0; i < fields.Length; i++)
            {
                var field = new ArrayField <FatExceptionClause>(new FatExceptionClauseImpl(buffer, currPos), (uint)i);
                fields[i] = field;
                currPos   = field.Data.Span.End;
            }
            Clauses = new StructField <ArrayData <FatExceptionClause> >("Clauses", new ArrayData <FatExceptionClause>("Clauses", new HexBufferSpan(buffer, HexSpan.FromBounds(startPos, currPos)), fields));

            Fields = new BufferField[] {
                SectFat,
                Clauses,
            };
        }
		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));
		}
Exemple #58
0
 public void InvalidateAll() => Invalidate(HexSpan.FromBounds(HexPosition.Zero, HexPosition.MaxEndPosition));
		MemoryToolWindowContent GetMemoryToolWindowContent(HexSpan span) {
			foreach (var info in memoryToolWindowContentProvider.Value.Contents) {
				var mc = info.Content;
				if (CanShowAll(mc, span))
					return mc;
			}
			return null;
		}
            // UI thread
            void DbgRuntime_ModulesChanged_UI(DbgRuntime runtime, IList <DbgModule> modules, bool added)
            {
                uiDispatcher.VerifyAccess();
                if (runtime.Process != process)
                {
                    return;
                }
                foreach (var module in modules)
                {
                    if (added && addedModules.Contains(module))
                    {
                        continue;
                    }
                    if (!module.HasAddress)
                    {
                        continue;
                    }
                    var start = new HexPosition(module.Address);
                    var end   = start + module.Size;
                    Debug.Assert(end <= HexPosition.MaxEndPosition);
                    if (end > HexPosition.MaxEndPosition)
                    {
                        continue;
                    }

                    moduleReferences.TryGetValue(start, out int refCount);
                    if (added)
                    {
                        addedModules.Add(module);
                        if (refCount == 0)
                        {
                            string[] tags;
                            switch (module.ImageLayout)
                            {
                            case DbgImageLayout.File:
                                tags = new string[] { PredefinedBufferFileTags.FileLayout };
                                break;

                            case DbgImageLayout.Memory:
                                tags = new string[] { PredefinedBufferFileTags.MemoryLayout };
                                break;

                            case DbgImageLayout.Unknown:
                            default:
                                tags = Array.Empty <string>();
                                break;
                            }
                            hexBufferFileService.CreateFile(HexSpan.FromBounds(start, end), module.Name, module.Filename, tags);
                        }
                        refCount++;
                    }
                    else
                    {
                        addedModules.Remove(module);
                        if (refCount == 0)
                        {
                            continue;
                        }
                        if (refCount == 1)
                        {
                            hexBufferFileService.RemoveFiles(HexSpan.FromBounds(start, end));
                        }
                        refCount--;
                    }
                    if (refCount == 0)
                    {
                        moduleReferences.Remove(start);
                    }
                    else
                    {
                        moduleReferences[start] = refCount;
                    }
                }
            }