pykd/snippets/avl.py
SND\kernelnet_cp de82f9d737 [samples] updated: refactored samples
git-svn-id: https://pykd.svn.codeplex.com/svn@63978 9b283d60-5439-405e-af05-b73fd8c4d996
2011-04-14 16:01:29 +00:00

57 lines
1.4 KiB
Python

#
#
#
import sys
import re
from pykd import isWindbgExt
from pykd import dprintln
from pykd import expr
from pykd import typedVar
from pykd import addr64
from pykd import sizeof
def addTableChilds( table, links ):
table.append( links.getAddress() + sizeof( "nt", "_RTL_BALANCED_LINKS" ) )
if links.LeftChild != 0:
addTableChilds( table, typedVar("nt", "_RTL_BALANCED_LINKS", links.LeftChild) )
if links.RightChild != 0:
addTableChilds( table, typedVar("nt", "_RTL_BALANCED_LINKS", links.RightChild) )
def getAVLTable( addr ):
table = []
avl = typedVar( "nt", "_RTL_AVL_TABLE", addr )
addTableChilds( table, avl.BalancedRoot )
return table
def printUsage():
dprintln( "!py avl [addr] (type)")
if __name__ == "__main__":
if not isWindbgExt():
print "this script should be run within windbg"
quit(0)
if len( sys.argv ) < 2:
printUsage()
quit(0)
if len( sys.argv ) == 2:
items = getAVLTable( addr64( expr( sys.argv[1] ) ) )
dprintln( "\n".join( [ "<link cmd=\"db 0x%x\">db 0x%x</link>" % ( entry, entry ) for entry in items ] ), True )
else:
items = getAVLTable( addr64( expr( sys.argv[1] ) ) )
dprintln( "\n".join( [ "<link cmd=\"dt %s 0x%x\">dt %s</link>" % ( sys.argv[2], entry, sys.argv[2] ) for entry in items ] ), True )