/// <summary> /// Gets all tooltips /// </summary> /// <param name="position">Position</param> /// <returns></returns> public IEnumerable<HexStructureInfoProviderAndData<object>> GetToolTips(HexPosition position) { foreach (var provider in Providers) { var toolTip = provider.GetToolTip(position); if (toolTip != null) yield return new HexStructureInfoProviderAndData<object>(provider, toolTip); } }
void CreateHandler(ShowTabContentEventArgs e, HexViewDocumentTabContent content, HexPosition? fileOffset, AddressReference addrRef) { if (!e.Success) return; Debug.Assert(e.Tab.Content == content); var uiContext = e.Tab.UIContext as HexViewDocumentTabUIContext; Debug.Assert(uiContext != null); if (uiContext == null || fileOffset == null) return; var start = fileOffset.Value; var end = HexPosition.Min(start + addrRef.Length, HexPosition.MaxEndPosition); if (!IsVisible(uiContext.HexView, start, end)) { uiContext.HexView.Options.SetOptionValue(DefaultHexViewOptions.StartPositionId, uiContext.HexView.Buffer.Span.Start); uiContext.HexView.Options.SetOptionValue(DefaultHexViewOptions.EndPositionId, uiContext.HexView.Buffer.Span.End); RedisplayHexLines(uiContext.HexView); if (!IsVisible(uiContext.HexView, start, end)) return; } if (e.HasMovedCaret) return; if (!uiContext.HexView.VisualElement.IsLoaded) { RoutedEventHandler loaded = null; loaded = (s, e2) => { uiContext.HexView.VisualElement.Loaded -= loaded; InitializeHexView(uiContext.HexView, start, end); }; uiContext.HexView.VisualElement.Loaded += loaded; } else InitializeHexView(uiContext.HexView, start, end); e.HasMovedCaret = true; }
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; }
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); }
/// <summary> /// Gets all references /// </summary> /// <param name="position">Position</param> /// <returns></returns> public IEnumerable<HexStructureInfoProviderAndData<object>> GetReferences(HexPosition position) { foreach (var provider in Providers) { var reference = provider.GetReference(position); if (reference != null) yield return new HexStructureInfoProviderAndData<object>(provider, reference); } }
public ModuleInfo(IntPtr handle, HexPosition addr, uint size, string filename, bool memoryLayout) { ProcessHandle = handle; Address = addr; Size = size; Filename = filename; MemoryLayout = memoryLayout; }
public static void Write(HexBuffer buffer, HexPosition position, byte[] data) { if (buffer == null) throw new ArgumentNullException(nameof(buffer)); if (data == null || data.Length == 0) return; buffer.Replace(position, data); }
public override int TryReadByte(HexPosition position) { Debug.Assert(position < HexPosition.MaxEndPosition); var pos = position.ToUInt64(); var d = data; if (pos >= (ulong)d.LongLength) return -1; return d[pos]; }
public override sbyte ReadSByte(HexPosition position) { Debug.Assert(position < HexPosition.MaxEndPosition); var pos = position.ToUInt64(); var d = data; if (pos >= (ulong)d.LongLength) return 0; return (sbyte)d[pos]; }
public static void Write(IHexBufferService hexBufferService, string filename, HexPosition position, byte[] data) { if (string.IsNullOrEmpty(filename)) throw new ArgumentException(); var buffer = hexBufferService.GetOrCreate(filename); if (buffer == null) return; Write(buffer, position, data); }
private static HexPosition[] reconstructPath(Dictionary<HexPosition,HexPosition> cameFrom, HexPosition final, int size) { HexPosition[] path = new HexPosition[size]; path [size - 1] = final; for (int i = size-2; i >=0; --i) { cameFrom.TryGetValue(path[i+1],out path[i]); } return path; }
public HexProcessSimpleBufferStream(IntPtr hProcess, string name, bool isReadOnly, bool isVolatile) { this.hProcess = hProcess; Span = GetDefaultSpan(hProcess); Name = name ?? GetDefaultName(hProcess); PageSize = GetDefaultPageSize(hProcess); this.isReadOnly = isReadOnly; this.isVolatile = isVolatile; endAddress = GetEndAddress(hProcess); }
public override ushort ReadUInt16(HexPosition position) { Debug.Assert(position < HexPosition.MaxEndPosition); var pos = position.ToUInt64(); var d = data; if (pos + 1 < pos || pos + 1 >= (ulong)d.LongLength) return pos < (ulong)d.LongLength ? d[pos] : (ushort)0; return (ushort)(d[pos] | (d[pos + 1] << 8)); }
public void build_selecter(int position) { if (this.last_builder == null) return; this.build_menu.GetComponent<CanvasGroup> ().alpha = 0; this.build_menu.SetActive (false); this.last_builder.build_on (position, this.last_position); this.last_position = null; this.last_builder = null; }
public SelectVM(HexPosition start, HexPosition end, HexPosition min, HexPosition max) { StartVM = new HexPositionVM(start, a => HasErrorUpdated(), false) { Min = min, Max = max, }; EndVM = new HexPositionVM(end, a => HasErrorUpdated(), false) { Min = min, Max = max, }; }
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); }
/// <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); }
public ImageSectionHeaderVM(object owner, HexBuffer buffer, HexPosition startOffset) : base(owner) { NameVM = new StringHexField(buffer, Name, "Name", startOffset + 0, Encoding.UTF8, 8); VirtualSizeVM = new UInt32HexField(buffer, Name, "VirtualSize", startOffset + 8); VirtualAddressVM = new UInt32HexField(buffer, Name, "VirtualAddress", startOffset + 0x0C); SizeOfRawDataVM = new UInt32HexField(buffer, Name, "SizeOfRawData", startOffset + 0x10); PointerToRawDataVM = new UInt32HexField(buffer, Name, "PointerToRawData", startOffset + 0x14); PointerToRelocationsVM = new UInt32HexField(buffer, Name, "PointerToRelocations", startOffset + 0x18); PointerToLinenumbersVM = new UInt32HexField(buffer, Name, "PointerToLinenumbers", startOffset + 0x1C); NumberOfRelocationsVM = new UInt16HexField(buffer, Name, "NumberOfRelocations", startOffset + 0x20); NumberOfLinenumbersVM = new UInt16HexField(buffer, Name, "NumberOfLinenumbers", startOffset + 0x22); CharacteristicsVM = new UInt32FlagsHexField(buffer, Name, "Characteristics", startOffset + 0x24); CharacteristicsVM.Add(new BooleanHexBitField("TYPE_DSECT", 0)); CharacteristicsVM.Add(new BooleanHexBitField("TYPE_NOLOAD", 1)); CharacteristicsVM.Add(new BooleanHexBitField("TYPE_GROUP", 2)); CharacteristicsVM.Add(new BooleanHexBitField("TYPE_NO_PAD", 3)); CharacteristicsVM.Add(new BooleanHexBitField("TYPE_COPY", 4)); CharacteristicsVM.Add(new BooleanHexBitField("CNT_CODE", 5)); CharacteristicsVM.Add(new BooleanHexBitField("CNT_INITIALIZED_DATA", 6)); CharacteristicsVM.Add(new BooleanHexBitField("CNT_UNINITIALIZED_DATA", 7)); CharacteristicsVM.Add(new BooleanHexBitField("LNK_OTHER", 8)); CharacteristicsVM.Add(new BooleanHexBitField("LNK_INFO", 9)); CharacteristicsVM.Add(new BooleanHexBitField("TYPE_OVER", 10)); CharacteristicsVM.Add(new BooleanHexBitField("LNK_REMOVE", 11)); CharacteristicsVM.Add(new BooleanHexBitField("LNK_COMDAT", 12)); CharacteristicsVM.Add(new BooleanHexBitField("RESERVED", 13)); CharacteristicsVM.Add(new BooleanHexBitField("NO_DEFER_SPEC_EXC", 14)); CharacteristicsVM.Add(new BooleanHexBitField("GPREL", 15)); CharacteristicsVM.Add(new BooleanHexBitField("MEM_SYSHEAP", 16)); CharacteristicsVM.Add(new BooleanHexBitField("MEM_PURGEABLE", 17)); CharacteristicsVM.Add(new BooleanHexBitField("MEM_LOCKED", 18)); CharacteristicsVM.Add(new BooleanHexBitField("MEM_PRELOAD", 19)); CharacteristicsVM.Add(new IntegerHexBitField("Alignment", 20, 4, AlignInfos)); CharacteristicsVM.Add(new BooleanHexBitField("LNK_NRELOC_OVFL", 24)); CharacteristicsVM.Add(new BooleanHexBitField("MEM_DISCARDABLE", 25)); CharacteristicsVM.Add(new BooleanHexBitField("MEM_NOT_CACHED", 26)); CharacteristicsVM.Add(new BooleanHexBitField("MEM_NOT_PAGED", 27)); CharacteristicsVM.Add(new BooleanHexBitField("MEM_SHARED", 28)); CharacteristicsVM.Add(new BooleanHexBitField("MEM_EXECUTE", 29)); CharacteristicsVM.Add(new BooleanHexBitField("MEM_READ", 30)); CharacteristicsVM.Add(new BooleanHexBitField("MEM_WRITE", 31)); hexFields = new HexField[] { NameVM, VirtualSizeVM, VirtualAddressVM, SizeOfRawDataVM, PointerToRawDataVM, PointerToRelocationsVM, PointerToLinenumbersVM, NumberOfRelocationsVM, NumberOfLinenumbersVM, CharacteristicsVM, }; }
//Start from start, move to within distance of goal within max steps. public static HexPosition[] search(HexPosition start, HexPosition goal, int max, int distance = 0) { max += distance; //Now it's the maximum distance to the goal, instead of just the maximum number of steps. //HashSet<HexPosition> closedSet = new HashSet<HexPosition>(); // The set of nodes already evaluated. //HashSet<HexPosition> openSet = new HashSet<HexPosition>(start); // The set of tentative nodes to be evaluated, initially containing the start node Dictionary<HexPosition, HexPosition> cameFrom = new Dictionary<HexPosition, HexPosition>(); // The map of navigated nodes. Dictionary<HexPosition, int> gScore = new Dictionary<HexPosition, int>(); // Cost from start along best known path. Domain is the open and closed sets. Dictionary<HexPosition, int> fScore = new Dictionary<HexPosition, int>(); // Estimated total cost from start to goal through y. Domain is the open set. gScore.Add(start, 0); fScore.Add(start, start.dist(goal)); while (fScore.Count > 0) { HexPosition current = getMin(fScore); if (current.dist(goal) <= distance) { int length = 0; gScore.TryGetValue(current, out length); return reconstructPath(cameFrom, current, length + 1); } fScore.Remove(current); foreach (HexPosition neighbor in current.Neighbors) { if (neighbor.containsKey("Obstacle") || neighbor.containsKey("Unit")) { continue; //Make this more general. } if (gScore.ContainsKey(neighbor) && !fScore.ContainsKey(neighbor)) { continue; } int tentativeGScore = 0; gScore.TryGetValue(current, out tentativeGScore); ++tentativeGScore; if (tentativeGScore > max) { continue; } int neighborGScore = 0; gScore.TryGetValue(current, out neighborGScore); if (!fScore.ContainsKey(neighbor) || tentativeGScore < neighborGScore) { int newFScore = tentativeGScore + neighbor.dist(goal); if (newFScore > max) { continue; } cameFrom.Add(neighbor, current); gScore.Add(neighbor, tentativeGScore); fScore.Add(neighbor, newFScore); } } } return new HexPosition[0] { }; }
public StorageStreamVM(HexBuffer buffer, HexPosition startOffset, int stringLen) { IOffsetVM = new UInt32HexField(buffer, Name, "iOffset", startOffset + 0); ISizeVM = new UInt32HexField(buffer, Name, "iSize", startOffset + 4); RCNameVM = new StringHexField(buffer, Name, "rcName", startOffset + 8, Encoding.ASCII, stringLen); hexFields = new HexField[] { IOffsetVM, ISizeVM, RCNameVM, }; }
public void FormatOffset(StringBuilder dest, HexPosition position) { var offset = position.ToUInt64() << (64 - bitSize); dest.Append(prefix); for (int i = 0; i < bitSize; i += 4, offset <<= 4) { var nibble = (offset >> 60) & 0x0F; if (nibble < 10) dest.Append((char)('0' + nibble)); else dest.Append((char)((lowerCaseHex ? 'a' : 'A') + nibble - 10)); } dest.Append(suffix); }
public StorageHeaderVM(HexBuffer buffer, HexPosition startOffset) { FFlagsVM = new ByteFlagsHexField(buffer, Name, "fFlags", startOffset + 0); FFlagsVM.Add(new BooleanHexBitField("ExtraData", 0)); PadVM = new ByteHexField(buffer, Name, "pad", startOffset + 1); IStreamsVM = new UInt16HexField(buffer, Name, "iStreams", startOffset + 2); hexFields = new HexField[] { FFlagsVM, PadVM, IStreamsVM, }; }
public void build_on(int selected, HexPosition destination) { Debug.Log ("Selected " + selected.ToString ()); Settlement unit = this.buildings[selected]; GameObject unit_go = (GameObject) Instantiate (unit.gameObject, destination.getPosition(), new Quaternion()); unit_go.transform.parent = GameObject.FindGameObjectWithTag ("Units").transform; grid.AddUnit (unit); unit.SetGrid (grid); grid.ai.add_unit (unit); this.state = State.DONE; grid.state_change (this); }
public void build_place_here(HexPosition position_for_obj) { if (last_builder == null) { Debug.LogError ("last_builder is null. Cant do call back"); return; } if (last_builder.position.dist(position_for_obj) > 1){ return; } this.build_menu.SetActive (true); this.build_menu.GetComponent<CanvasGroup> ().alpha = 1; if (this.last_position == null) this.last_position = position_for_obj; }
public HexChangeImpl(HexPosition oldPosition, byte[] oldData, HexPosition newPosition, byte[] newData) { if (oldPosition > HexPosition.MaxEndPosition || oldPosition + oldData.LongLength > HexPosition.MaxEndPosition) throw new ArgumentOutOfRangeException(nameof(oldPosition)); if (newPosition > HexPosition.MaxEndPosition || newPosition + newData.LongLength > HexPosition.MaxEndPosition) throw new ArgumentOutOfRangeException(nameof(newPosition)); if (oldData == null) throw new ArgumentNullException(nameof(oldData)); if (newData == null) throw new ArgumentNullException(nameof(newData)); this.oldPosition = oldPosition; this.newPosition = newPosition; this.oldData = oldData; this.newData = newData; }
public StorageSignatureVM(HexBuffer buffer, HexPosition startOffset, int stringLen) { LSignatureVM = new UInt32HexField(buffer, Name, "lSignature", startOffset + 0); IMajorVerVM = new UInt16HexField(buffer, Name, "iMajorVer", startOffset + 4, true); IMinorVerVM = new UInt16HexField(buffer, Name, "iMinorVer", startOffset + 6, true); IExtraDataVM = new UInt32HexField(buffer, Name, "iExtraData", startOffset + 8); IVersionStringVM = new UInt32HexField(buffer, Name, "iVersionString", startOffset + 0x0C); VersionStringVM = new StringHexField(buffer, Name, "VersionString", startOffset + 0x10, Encoding.UTF8, stringLen); hexFields = new HexField[] { LSignatureVM, IMajorVerVM, IMinorVerVM, IExtraDataVM, IVersionStringVM, VersionStringVM, }; }
protected IEnumerable<HexSpan> GetValidSpans(HexBuffer buffer, HexPosition start, HexPosition upperBounds) { var pos = start; bool fullSpan = true; while (pos < HexPosition.MaxEndPosition) { var span = buffer.GetNextValidSpan(pos, upperBounds, fullSpan); if (span == null) break; var newStart = HexPosition.Max(pos, span.Value.Start); var newEnd = HexPosition.Min(upperBounds, span.Value.End); if (newStart < newEnd) yield return HexSpan.FromBounds(newStart, newEnd); pos = span.Value.End; fullSpan = false; } }
public ImageOptionalHeader32VM(HexBuffer buffer, HexPosition startOffset, HexPosition endOffset) : base(buffer, startOffset, endOffset, 0x20, 0x58) { BaseOfDataVM = new UInt32HexField(buffer, Name, "BaseOfData", startOffset + 0x18); ImageBaseVM = new UInt32HexField(buffer, Name, "ImageBase", startOffset + 0x1C); SizeOfStackReserveVM = new UInt32HexField(buffer, Name, "SizeOfStackReserve", startOffset + 0x48); SizeOfStackCommitVM = new UInt32HexField(buffer, Name, "SizeOfStackCommit", startOffset + 0x4C); SizeOfHeapReserveVM = new UInt32HexField(buffer, Name, "SizeOfHeapReserve", startOffset + 0x50); SizeOfHeapCommitVM = new UInt32HexField(buffer, Name, "SizeOfHeapCommit", startOffset + 0x54); var list = new List<HexField> { MagicVM, MajorLinkerVersionVM, MinorLinkerVersionVM, SizeOfCodeVM, SizeOfInitializedDataVM, SizeOfUninitializedDataVM, AddressOfEntryPointVM, BaseOfCodeVM, BaseOfDataVM, ImageBaseVM, SectionAlignmentVM, FileAlignmentVM, MajorOperatingSystemVersionVM, MinorOperatingSystemVersionVM, MajorImageVersionVM, MinorImageVersionVM, MajorSubsystemVersionVM, MinorSubsystemVersionVM, Win32VersionValueVM, SizeOfImageVM, SizeOfHeadersVM, CheckSumVM, SubsystemVM, DllCharacteristicsVM, SizeOfStackReserveVM, SizeOfStackCommitVM, SizeOfHeapReserveVM, SizeOfHeapCommitVM, LoaderFlagsVM, NumberOfRvaAndSizesVM, }; AddDataDirs(list, endOffset); }
public ImageCor20HeaderVM(HexBuffer buffer, HexPosition startOffset) { CbVM = new UInt32HexField(buffer, Name, "cb", startOffset + 0); MajorRuntimeVersionVM = new UInt16HexField(buffer, Name, "MajorRuntimeVersion", startOffset + 4, true); MinorRuntimeVersionVM = new UInt16HexField(buffer, Name, "MinorRuntimeVersion", startOffset + 6, true); MetaDataVM = new DataDirVM(buffer, Name, "MetaData", startOffset + 8); FlagsVM = new UInt32FlagsHexField(buffer, Name, "Flags", startOffset + 0x10); FlagsVM.Add(new BooleanHexBitField(dnSpy_AsmEditor_Resources.HexNode_Cor20Header_Flags_IL_Only, 0)); FlagsVM.Add(new BooleanHexBitField(dnSpy_AsmEditor_Resources.HexNode_Cor20Header_Flags_32BitReqd, 1)); FlagsVM.Add(new BooleanHexBitField(dnSpy_AsmEditor_Resources.HexNode_Cor20Header_Flags_ILLibrary, 2)); FlagsVM.Add(new BooleanHexBitField(dnSpy_AsmEditor_Resources.HexNode_Cor20Header_Flags_StrongNameSigned, 3)); FlagsVM.Add(new BooleanHexBitField(dnSpy_AsmEditor_Resources.HexNode_Cor20Header_Flags_NativeEntryPoint, 4)); FlagsVM.Add(new BooleanHexBitField(dnSpy_AsmEditor_Resources.HexNode_Cor20Header_Flags_TrackDebugData, 16)); FlagsVM.Add(new BooleanHexBitField(dnSpy_AsmEditor_Resources.HexNode_Cor20Header_Flags_32BitPref, 17)); EntryPointTokenRVAVM = new UInt32HexField(buffer, Name, "EntryPoint Token/RVA", startOffset + 0x14); ResourcesVM = new DataDirVM(buffer, Name, "Resources", startOffset + 0x18); StrongNameSignatureVM = new DataDirVM(buffer, Name, "StrongNameSignature", startOffset + 0x20); CodeManagerTableVM = new DataDirVM(buffer, Name, "CodeManagerTable", startOffset + 0x28); VTableFixupsVM = new DataDirVM(buffer, Name, "VTableFixups", startOffset + 0x30); ExportAddressTableJumpsVM = new DataDirVM(buffer, Name, "ExportAddressTableJumps", startOffset + 0x38); ManagedNativeHeaderVM = new DataDirVM(buffer, Name, "ManagedNativeHeader", startOffset + 0x40); hexFields = new HexField[] { CbVM, MajorRuntimeVersionVM, MinorRuntimeVersionVM, MetaDataVM.RVAVM, MetaDataVM.SizeVM, FlagsVM, EntryPointTokenRVAVM, ResourcesVM.RVAVM, ResourcesVM.SizeVM, StrongNameSignatureVM.RVAVM, StrongNameSignatureVM.SizeVM, CodeManagerTableVM.RVAVM, CodeManagerTableVM.SizeVM, VTableFixupsVM.RVAVM, VTableFixupsVM.SizeVM, ExportAddressTableJumpsVM.RVAVM, ExportAddressTableJumpsVM.SizeVM, ManagedNativeHeaderVM.RVAVM, ManagedNativeHeaderVM.SizeVM, }; }
protected IEnumerable<HexSpan> GetValidSpansReverse(HexBuffer buffer, HexPosition start, HexPosition lowerBounds) { var pos = start; bool fullSpan = true; for (;;) { var span = buffer.GetPreviousValidSpan(pos, lowerBounds, fullSpan); if (span == null) break; var newStart = HexPosition.Max(lowerBounds, span.Value.Start); var newEnd = HexPosition.Min(pos + 1, span.Value.End); if (newStart < newEnd) yield return HexSpan.FromBounds(newStart, newEnd); if (span.Value.Start == 0) break; pos = span.Value.Start - 1; fullSpan = false; } }
public override uint ReadUInt32(HexPosition position) => stream.ReadUInt32(position);
public override float ReadSingle(HexPosition position) => stream.ReadSingle(position);
public override ushort ReadUInt16BigEndian(HexPosition position) => stream.ReadUInt16BigEndian(position);
public override ulong ReadUInt64BigEndian(HexPosition position) => stream.ReadUInt64BigEndian(position);
public override double ReadDoubleBigEndian(HexPosition position) => stream.ReadDoubleBigEndian(position);
public override byte[] ReadBytes(HexPosition position, ulong length) => length == 0 ? Array.Empty <byte>() : stream.ReadBytes(position, checked ((long)length));
HexPosition?FindCore(SearchState state, HexPosition start, HexPosition upperBounds) { var patternLocal = pattern; var maskLocal = mask; var pos = start; if (pos + patternLocal.LongLength > upperBounds) { return(null); } var endPos = upperBounds - patternLocal.LongLength + 1; state.SetPosition(pos); var patternLocal0 = patternLocal[0]; var maskLocal0 = maskLocal[0]; var patternLocal1 = patternLocal.Length <= 1 ? 0 : patternLocal[1]; var maskLocal1 = maskLocal.Length <= 1 ? 0 : maskLocal[1]; var maskLocalLengthIsAtLeast2 = maskLocal.Length >= 2; loop: // This loop doesn't check the cancellation token because SearchState does that // every time it reads new memory from the buffer. if (pos >= endPos) { return(null); } int skip; HexPosition?afterPos; if (maskLocalLengthIsAtLeast2) { skip = 2; afterPos = maskLocal0 == 0xFF ? state.PositionAfter2(patternLocal0, patternLocal1, maskLocal1, endPos) : state.PositionAfterWithMask2(patternLocal0, patternLocal1, maskLocal0, maskLocal1, endPos); } else if (maskLocal0 == 0xFF) { skip = 1; afterPos = state.PositionAfter1(patternLocal0, endPos); } else { skip = 1; afterPos = state.PositionAfterWithMask1(patternLocal0, maskLocal0, endPos); } if (afterPos == null) { return(null); } pos = afterPos.Value; for (int i = skip; i < patternLocal.Length; i++) { var b = state.GetNextByte(); var m = maskLocal[i]; if ((b & m) != patternLocal[i]) { pos = pos - (skip - 1); state.SetPosition(pos); goto loop; } } return(pos - skip); }
public override ComplexData GetStructure(HexPosition position) => multiFileResources?.GetStructure(position);
RidData CreateRidData(HexPosition position, ColumnInfo column) => column.Size == 2 ? (RidData) new Rid16Data(Buffer, position, (Table)column.ColumnSize) : new Rid32Data(Buffer, position, (Table)column.ColumnSize);
public override sbyte ReadSByte(HexPosition position) => stream.ReadSByte(position);
internal static ArrayData <DataDirectoryData> CreateDataDirectoryArray(HexBuffer buffer, HexPosition position, HexPosition end) { int count = (int)Math.Min((end - position).ToUInt64() / 8, 16); var fields = new ArrayField <DataDirectoryData> [count]; var currPos = position; for (int i = 0; i < fields.Length; i++) { var field = new ArrayField <DataDirectoryData>(new DataDirectoryData(new HexBufferSpan(buffer, new HexSpan(currPos, 8))), (uint)i); fields[i] = field; currPos = field.Data.Span.End; } return(new ArrayData <DataDirectoryData>(string.Empty, new HexBufferSpan(buffer, HexSpan.FromBounds(position, currPos)), fields)); }
/// <summary> /// Gets a structure or null /// </summary> /// <param name="position">Position</param> /// <returns></returns> public virtual ComplexData GetStructure(HexPosition position) => null;
protected virtual BufferData CreateData(HexPosition position, ColumnInfo column) { if (column.ColumnSize < (ColumnSize)0x40) { return(CreateRidData(position, column)); } switch (column.ColumnSize) { case ColumnSize.Byte: if (column.Size != 1) { throw new InvalidOperationException(); } return(new ByteData(Buffer, position)); case ColumnSize.Int16: if (column.Size != 2) { throw new InvalidOperationException(); } return(new Int16Data(Buffer, position)); case ColumnSize.UInt16: if (column.Size != 2) { throw new InvalidOperationException(); } return(new UInt16Data(Buffer, position)); case ColumnSize.Int32: if (column.Size != 4) { throw new InvalidOperationException(); } return(new Int32Data(Buffer, position)); case ColumnSize.UInt32: if (column.Size != 4) { throw new InvalidOperationException(); } return(new UInt32Data(Buffer, position)); case ColumnSize.Strings: if (column.Size == 2) { return(new StringsHeapData16(Buffer, position)); } return(new StringsHeapData32(Buffer, position)); case ColumnSize.GUID: if (column.Size == 2) { return(new GUIDHeapData16(Buffer, position)); } return(new GUIDHeapData32(Buffer, position)); case ColumnSize.Blob: if (column.Size == 2) { return(new BlobHeapData16(Buffer, position)); } return(new BlobHeapData32(Buffer, position)); case ColumnSize.TypeDefOrRef: return(CreateCodedTokenData(position, column, CodedToken.TypeDefOrRef)); case ColumnSize.HasConstant: return(CreateCodedTokenData(position, column, CodedToken.HasConstant)); case ColumnSize.HasCustomAttribute: return(CreateCodedTokenData(position, column, CodedToken.HasCustomAttribute)); case ColumnSize.HasFieldMarshal: return(CreateCodedTokenData(position, column, CodedToken.HasFieldMarshal)); case ColumnSize.HasDeclSecurity: return(CreateCodedTokenData(position, column, CodedToken.HasDeclSecurity)); case ColumnSize.MemberRefParent: return(CreateCodedTokenData(position, column, CodedToken.MemberRefParent)); case ColumnSize.HasSemantic: return(CreateCodedTokenData(position, column, CodedToken.HasSemantic)); case ColumnSize.MethodDefOrRef: return(CreateCodedTokenData(position, column, CodedToken.MethodDefOrRef)); case ColumnSize.MemberForwarded: return(CreateCodedTokenData(position, column, CodedToken.MemberForwarded)); case ColumnSize.Implementation: return(CreateCodedTokenData(position, column, CodedToken.Implementation)); case ColumnSize.CustomAttributeType: return(CreateCodedTokenData(position, column, CodedToken.CustomAttributeType)); case ColumnSize.ResolutionScope: return(CreateCodedTokenData(position, column, CodedToken.ResolutionScope)); case ColumnSize.TypeOrMethodDef: return(CreateCodedTokenData(position, column, CodedToken.TypeOrMethodDef)); case ColumnSize.HasCustomDebugInformation: return(CreateCodedTokenData(position, column, CodedToken.HasCustomDebugInformation)); default: switch (column.Size) { case 1: return(new ByteData(Buffer, position)); case 2: return(new UInt16Data(Buffer, position)); case 4: return(new UInt32Data(Buffer, position)); default: throw new InvalidOperationException(); } } }
// Code is identical to PositionBefore2() with an inlined LastIndexOf() that supports masks public HexPosition?PositionBeforeWithMask2(int value1, int value2, int mask1, int mask2, HexPosition lowerBounds) { if (dataPosition == HexPosition.Zero && dataIndex < 0) { return(null); } var dataLocal = Data; for (;;) { var currPos = dataPosition + dataIndex; if (lowerBounds > currPos) { return(null); } if (dataIndex < 0) { FillPreviousData(); } int len = (int)HexPosition.Min(currPos - lowerBounds + 1, dataIndex + 1).ToUInt64(); // Our Array.LastIndexOf(): int index = -1; int dataEnd = dataIndex + 1 - len; for (int i = dataIndex; i >= dataEnd; i--) { if ((dataLocal[i] & mask1) == value1) { index = i; break; } } if (index >= 0) { index--; dataIndex = index; if (dataIndex < 0) { if (dataPosition <= lowerBounds) { return(null); } FillPreviousData(); index = dataIndex; } if ((dataLocal[index] & mask2) == value2) { dataIndex = index - 1; return(dataPosition + (index - 1)); } } else { if (dataPosition == HexPosition.Zero) { return(null); } dataIndex = -1; } } }
// Code is identical to PositionAfter2() with an inlined IndexOf() that supports masks public HexPosition?PositionAfterWithMask2(int value1, int value2, int mask1, int mask2, HexPosition end) { Debug.Assert(mask1 != 0xFF || mask2 != 0xFF, "Use the other method instead"); if (end < dataPosition) { return(null); } HexPosition newPos; var dataLocal = Data; for (;;) { if (dataIndex >= dataLength) { FillNextData(); } int len = (int)HexPosition.Min(end - (dataPosition + dataIndex), dataLength - dataIndex).ToUInt64(); // Our Array.IndexOf(): int index = -1; int dataEnd = dataIndex + len; for (int i = dataIndex; i < dataEnd; i++) { if ((dataLocal[i] & mask1) == value1) { index = i; break; } } if (index >= 0) { index++; dataIndex = index; if (index >= dataLength) { newPos = dataPosition + dataLength; if (newPos >= end) { return(null); } FillNextData(); index = 0; } if ((dataLocal[index] & mask2) == value2) { dataIndex = index + 1; return(dataPosition + index + 1); } } else { dataIndex = dataLength; newPos = dataPosition + dataLength; if (newPos >= end) { return(null); } } } }
/// <summary> /// Constructor /// </summary> /// <param name="buffer">Buffer</param> /// <param name="position">Position</param> public TimeSpanData(HexBuffer buffer, HexPosition position) : this(new HexBufferSpan(buffer, new HexSpan(position, 8))) { }
public override byte[] ReadBytes(HexPosition position, long length) => length == 0 ? Array.Empty <byte>() : stream.ReadBytes(position, length);
static DateTime ReadDateTime(HexBuffer buffer, HexPosition position) => DateTime.FromBinary(buffer.ReadInt64(position));
public override float ReadSingleBigEndian(HexPosition position) => stream.ReadSingleBigEndian(position);
/// <summary> /// Constructor /// </summary> /// <param name="buffer">Buffer</param> /// <param name="position">Position</param> public PortablePdbIdData(HexBuffer buffer, HexPosition position) : this(new HexBufferSpan(buffer, new HexSpan(position, 20))) { }
public override uint ReadUInt32BigEndian(HexPosition position) => stream.ReadUInt32BigEndian(position);
static TimeSpan ReadTimeSpan(HexBuffer buffer, HexPosition position) => new TimeSpan(buffer.ReadInt64(position));
public override double ReadDouble(HexPosition position) => stream.ReadDouble(position);
public ImageCor20HeaderNode(HexBuffer buffer, HexPosition startOffset) : base(new HexSpan(startOffset, 0x48)) { imageCor20HeaderVM = new ImageCor20HeaderVM(this, buffer, Span.Start); }
public override ulong ReadUInt64(HexPosition position) => stream.ReadUInt64(position);
public override HexBytes ReadHexBytes(HexPosition position, long length) => stream.ReadHexBytes(position, length);
public override ushort ReadUInt16(HexPosition position) => stream.ReadUInt16(position);
public override void ReadBytes(HexPosition position, byte[] destination, long destinationIndex, long length) => stream.ReadBytes(position, destination, destinationIndex, length);
public override int TryReadByte(HexPosition position) => stream.TryReadByte(position);
CodedTokenData CreateCodedTokenData(HexPosition position, ColumnInfo column, CodedToken codedToken) => column.Size == 2 ? (CodedTokenData) new CodedToken16Data(Buffer, position, codedToken) : new CodedToken32Data(Buffer, position, codedToken);