56 lines
1.4 KiB
C#
56 lines
1.4 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
using JD.Kernel.StaticHelpers;
|
|
|
|
namespace Packager
|
|
{
|
|
public static class MiniDump
|
|
{
|
|
#region Dll Imports
|
|
|
|
private enum Type
|
|
{
|
|
FullMemory = 0x00000002,
|
|
}
|
|
|
|
[DllImport("dbghelp.dll")]
|
|
private static extern bool MiniDumpWriteDump(
|
|
IntPtr hProcess,
|
|
Int32 processId,
|
|
IntPtr hFile,
|
|
Type dumpType,
|
|
IntPtr exceptionParam,
|
|
IntPtr userStreamParam,
|
|
IntPtr callackParam);
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
/// <summary>
|
|
/// Writes a minidump of the given process in the given file.
|
|
/// </summary>
|
|
/// <param name="filename"></param>
|
|
/// <param name="process"></param>
|
|
public static bool Write(string filename, Process process)
|
|
{
|
|
Throw.IfEmpty(filename, "filename");
|
|
Throw.IfNull(process, "process");
|
|
|
|
using (FileStream stream = System.IO.File.Create(filename))
|
|
{
|
|
try
|
|
{
|
|
MiniDumpWriteDump(process.Handle, process.Id, stream.SafeFileHandle.DangerousGetHandle(), Type.FullMemory, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
|
|
}
|
|
catch { return false; }
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|