private MinidumpSegment FindSegment(ulong position) { int min = 0; int max = _segments.Count - 1; while (min <= max) { int mid = (min + max) / 2; MinidumpSegment current = _segments[mid]; if (position < current.VirtualAddress) { max = mid - 1; } else if (position >= current.VirtualAddress + current.Size) { min = mid + 1; } else { Debug.Assert(current.Contains(position)); return(current); } } return(null); }
public MinidumpVirtualAddressSpace(ReadOnlyCollection <MinidumpSegment> segments, IAddressSpace addressSpace) { _addressSpace = addressSpace; _segments = segments; MinidumpSegment last = segments.Last(); _length = last.VirtualAddress + last.Size; }
public uint Read(ulong position, byte[] buffer, uint bufferOffset, uint count) { if (count == 0) { return(0); } MinidumpSegment seg = FindSegment(position); if (seg == null) { return(0); } // TODO: What if they read past the end of the segment? Debug.Assert(position >= seg.VirtualAddress); ulong offset = position - seg.VirtualAddress + seg.FileOffset; return(_addressSpace.Read(offset, buffer, bufferOffset, count)); }
private List <MinidumpSegment> CreateSegmentList() { List <MinidumpSegment> ranges = new List <MinidumpSegment>(); foreach (MinidumpDirectory item in _directory) { if (item.StreamType == MinidumpStreamType.MemoryListStream) { MinidumpMemoryDescriptor[] memoryRegions = _dataSourceReader.ReadCountedArray <MinidumpMemoryDescriptor>(_position + item.Rva); foreach (var region in memoryRegions) { MinidumpSegment range = new MinidumpSegment(region); ranges.Add(range); } } else if (item.StreamType == MinidumpStreamType.Memory64ListStream) { ulong position = item.Rva; ulong count = _dataSourceReader.Read <ulong>(ref position); ulong rva = _dataSourceReader.Read <ulong>(ref position); MinidumpMemoryDescriptor64[] memoryRegions = _dataSourceReader.ReadArray <MinidumpMemoryDescriptor64>(position + _position, checked ((uint)count)); foreach (var region in memoryRegions) { MinidumpSegment range = new MinidumpSegment(region, rva); ranges.Add(range); rva += region.DataSize; } } } ranges.Sort((MinidumpSegment a, MinidumpSegment b) => a.VirtualAddress.CompareTo(b.VirtualAddress)); return(ranges); }