pykd
1from pykd import *2
3def main():4pass5
6def listCritSections():7
8ntdll = module("ntdll")9
10dbglst = ntdll.typedVarList( ntdll.RtlCriticalSectionList, "_RTL_CRITICAL_SECTION_DEBUG", "ProcessLocksList" )11
12crtlst = [ ntdll.typedVar( "_RTL_CRITICAL_SECTION", x.CriticalSection ) for x in dbglst ]13
14for crtsec in crtlst:15dprintln("")16dprintln( "CRITICAL SECTION address = %#x ( %s ) " % ( crtsec, findSymbol( crtsec ) ) )17dprintln( " Owning thread = %x" % crtsec.OwningThread )18dprintln( " Lock count = %d" % crtsec.LockCount )19
20
21def run():22
23while True:24
25if isKernelDebugging():26dprintln( "not a user debugging" )27break28
29listCritSections()30
31break32
33if __name__ == "__main__":34run()