9
def printGdtEntry( addr ):
11
dprintln( "GDT Entry: %x" % addr )
13
attr = ptrByte( addr + 5 ) + ( ( ptrByte( addr + 6 ) & 0xF0 ) << 4 )
15
limit = ptrWord( addr ) + ( ( ptrByte( addr + 6 ) & 0xF ) << 16 )
17
base = ptrWord( addr + 2 ) + ( ptrByte( addr + 4) << 16 ) + ( ptrByte( addr + 7 ) << 24 )
24
base = ( ptrDWord( addr + 8 ) << 32 ) + base
27
limit = ( limit << 12 ) | 0xFFF
30
dprint( "attr: %x ( " % attr + "".join( [ ( attr & ( 1 << ( 11 - i ) ) ) and "1" or "0" for i in range(0,12) ] ) + " )" )
31
dprint( " base: %x" % base )
32
dprintln( " limit: %x" % limit )
36
for s in ( "cs", "es", "ds", "ss", "gs", "fs", "tr" ):
37
dprintln( s + " (%x):" % reg(s) )
38
printGdtEntry( gdtr + ( reg( s ) & 0xFFF8 ) )
46
dprintln( "!py gdt help - Print out this message" )
47
dprintln( "!py gdt x - Print out gdt entry. The gdt entry's base is got from gdtr" )
48
dprintln( "!py gdt x y - Print out gdt entry. The gdt entry's base is x, y - offset" )
51
if __name__ == "__main__":
54
print "script is launch out of windbg"
62
elif sys.argv[1] == "help":
65
elif len( sys.argv )==2:
66
printGdtEntry( gdtr + ( int( sys.argv[1], 16 ) & 0xFFF8 ) )
69
printGdtEntry( int( sys.argv[1], 16 ) + ( int( sys.argv[2], 16 ) & 0xFFF8 ) )