/// <summary> /// Constructor /// </summary> /// <param name="path">filename to open dump file</param> public DumpReader(string path) { _file = File.OpenRead(path); long length = _file.Length; // The dump file may be many megabytes large, so we don't want to // read it all at once. Instead, doing a mapping. _fileMapping = CreateFileMapping(_file.SafeFileHandle, IntPtr.Zero, PageProtection.Readonly, 0, 0, null); if (_fileMapping.IsInvalid) { int error = Marshal.GetHRForLastWin32Error(); Marshal.ThrowExceptionForHR(error, new IntPtr(-1)); } _view = MapViewOfFile(_fileMapping, WindowsFunctions.NativeMethods.FILE_MAP_READ, 0, 0, IntPtr.Zero); if (_view.IsInvalid) { int error = Marshal.GetHRForLastWin32Error(); Marshal.ThrowExceptionForHR(error, new IntPtr(-1)); } _base = DumpPointer.DangerousMakeDumpPointer(_view.BaseAddress, (uint)length); // // Cache stuff // DumpPointer pStream; // System info. pStream = GetStream(MINIDUMP_STREAM_TYPE.SystemInfoStream); _info = pStream.PtrToStructure <MINIDUMP_SYSTEM_INFO>(); // Memory64ListStream is present in MinidumpWithFullMemory. if (TryGetStream(MINIDUMP_STREAM_TYPE.Memory64ListStream, out pStream)) { _memoryChunks = new MinidumpMemoryChunks(pStream, MINIDUMP_STREAM_TYPE.Memory64ListStream); } else { // MiniDumpNormal doesn't have a Memory64ListStream, it has a MemoryListStream. pStream = GetStream(MINIDUMP_STREAM_TYPE.MemoryListStream); _memoryChunks = new MinidumpMemoryChunks(pStream, MINIDUMP_STREAM_TYPE.MemoryListStream); } _mappedFileMemory = new LoadedFileMemoryLookups(); IsMinidump = DumpNative.IsMiniDump(_view.BaseAddress); }
/// <summary> /// Get a DumpPointer for the given stream. That can then be used to further decode the stream. /// </summary> /// <param name="type">type of stream to lookup</param> /// <param name="stream">DumpPointer refering into the stream. </param> /// <returns>True if stream was succesfully retrived</returns> private bool TryGetStream(MINIDUMP_STREAM_TYPE type, out DumpPointer stream) { EnsureValid(); bool fOk = DumpNative.MiniDumpReadDumpStream(_view.BaseAddress, type, out IntPtr pStream, out uint cbStreamSize); if (!fOk || IntPtr.Zero == pStream || cbStreamSize < 1) { stream = default; return(false); } stream = DumpPointer.DangerousMakeDumpPointer(pStream, cbStreamSize); return(true); }