Пример #1
0
        private async Task <MinidumpMemoryReader> GetMemoryReader()
        {
            List <MinidumpSegment> segments = new List <MinidumpSegment>();

            FileStream fileStream = File.Open(_crashDump, FileMode.Open, FileAccess.Read, FileShare.Read);

            byte[]? buffer = ArrayPool <byte> .Shared.Rent(128);

            try
            {
                for (int i = 0; i < _directories.Length; i++)
                {
                    if (_directories[i].StreamType == MinidumpStreamType.MemoryListStream)
                    {
                        // MINIDUMP_MEMORY_LIST only contains a count followed by MINIDUMP_MEMORY_DESCRIPTORs
                        uint count = await ReadAsync <uint>(fileStream, buffer, _directories[i].Rva).ConfigureAwait(false);

                        int byteCount = ResizeBytesForArray <MinidumpMemoryDescriptor>(count, ref buffer);

                        if (await fileStream.ReadAsync(buffer, 0, byteCount).ConfigureAwait(false) == byteCount)
                        {
                            AddSegments(segments, buffer, byteCount);
                        }
                    }
                    else if (_directories[i].StreamType == MinidumpStreamType.Memory64ListStream)
                    {
                        MinidumpMemory64List memList64 = await ReadAsync <MinidumpMemory64List>(fileStream, buffer, _directories[i].Rva).ConfigureAwait(false);

                        int byteCount = ResizeBytesForArray <MinidumpMemoryDescriptor>(memList64.NumberOfMemoryRanges, ref buffer);

                        if (await fileStream.ReadAsync(buffer, 0, byteCount).ConfigureAwait(false) == byteCount)
                        {
                            AddSegments(segments, memList64.Rva, buffer, byteCount);
                        }
                    }
                }
            }
            finally
            {
                if (buffer != null)
                {
                    ArrayPool <byte> .Shared.Return(buffer);
                }
            }

            MinidumpSegment[] result = segments.Where(s => s.Size > 0).OrderBy(s => s.VirtualAddress).ToArray();
            return(new MinidumpMemoryReader(result, fileStream, PointerSize));
        }
Пример #2
0
        private ImmutableArray <MinidumpSegment> GetSegments(Stream stream)
        {
            List <MinidumpSegment> segments = new List <MinidumpSegment>();

            byte[]? buffer = ArrayPool <byte> .Shared.Rent(128);

            try
            {
                for (int i = 0; i < _directories.Length; i++)
                {
                    if (_directories[i].StreamType == MinidumpStreamType.MemoryListStream)
                    {
                        // MINIDUMP_MEMORY_LIST only contains a count followed by MINIDUMP_MEMORY_DESCRIPTORs
                        uint count     = Read <uint>(stream, _directories[i].Rva);
                        int  byteCount = ResizeBytesForArray <MinidumpMemoryDescriptor>(count, ref buffer);

                        if (stream.Read(buffer, 0, byteCount) == byteCount)
                        {
                            AddSegments(segments, buffer, byteCount);
                        }
                    }
                    else if (_directories[i].StreamType == MinidumpStreamType.Memory64ListStream)
                    {
                        MinidumpMemory64List memList64 = Read <MinidumpMemory64List>(stream, _directories[i].Rva);
                        int byteCount = ResizeBytesForArray <MinidumpMemoryDescriptor>(memList64.NumberOfMemoryRanges, ref buffer);

                        if (stream.Read(buffer, 0, byteCount) == byteCount)
                        {
                            AddSegments(segments, memList64.Rva, buffer, byteCount);
                        }
                    }
                }
            }
            finally
            {
                if (buffer != null)
                {
                    ArrayPool <byte> .Shared.Return(buffer);
                }
            }

            return(segments.Where(s => s.Size > 0).OrderBy(s => s.VirtualAddress).ToImmutableArray());
        }