Improve object manager doc + add samples

This commit is contained in:
hakril
2018-07-13 14:24:55 +02:00
parent eb3b13016f
commit c19241098a
7 changed files with 224 additions and 13 deletions
+35
View File
@@ -0,0 +1,35 @@
import argparse
import windows
import windows.generated_def as gdef
def obj_with_link(obj):
target = obj.target
if target is None:
return str(obj)
return "{0} -> <{1}>".format(obj, target)
def find_name(root, findname):
TODO = [root]
while TODO:
try:
for name, obj in TODO.pop().items():
if findname in name:
print("* {0}".format(obj_with_link(obj)))
if obj.type == "Directory":
TODO.append(obj)
except gdef.NtStatusException as e:
print("<{0}> -> {1}".format(obj.fullname, e.name))
parser = argparse.ArgumentParser(prog=__file__)
parser.add_argument('name', nargs='?', default="ls", help='The name of the object to find')
res = parser.parse_args()
objmanag = windows.system.object_manager
print("Looking for object name containing <{0}>".format(res.name))
find_name(objmanag.root, res.name)
+44
View File
@@ -0,0 +1,44 @@
import sys
import os.path
sys.path.append(os.path.abspath(__file__ + "\..\.."))
import windows
import windows.generated_def as gdef
object_manager = windows.system.object_manager
print("Object manager is {0}".format(object_manager))
root = object_manager.root
print("Root object is {0}".format(root))
print("")
print("Listing some of root-subobject:")
# Kernel object of type 'Directory' are iterable
for i, (name, obj) in enumerate(root.items()):
print(" * {0}: {1}".format(name, obj))
if i == 3:
break
print("")
print(r"Retrieving <\Rpc Control\lsasspirpc>:")
# You can retrieve this value in one request
x1 = root[r"\Rpc Control\lsasspirpc"]
# Sub-directory also allow __getitem__
x2 = root["Rpc Control"]["lsasspirpc"]
# You can directly request the object manager that will request `root`
x3 = object_manager[r"\Rpc Control\lsasspirpc"]
assert x1.fullname == x2.fullname == x3.fullname
lsasspirpc = x1
print("Object is: {0}".format(lsasspirpc))
print(" * name: <{0}>".format(lsasspirpc.name))
print(" * path: <{0}>".format(lsasspirpc.path))
print(" * fullname: <{0}>".format(lsasspirpc.fullname))
print(" * type: <{0}>".format(lsasspirpc.type))
print(" * target: <{0}>".format(lsasspirpc.target)) # None on non-symlink
print("")
print("Looking for a SymbolicLink in <ArcName>")
slo = [o for o in root["ArcName"].values() if o.type == "SymbolicLink"][0]
print("Object is: {0}".format(slo))
print(" * name: <{0}>".format(slo.name))
print(" * target: <{0}>".format(slo.target))
+22
View File
@@ -0,0 +1,22 @@
import argparse
import windows
import windows.generated_def as gdef
def obj_with_link(obj):
target = obj.target
if target is None:
return str(obj)
return "{0} -> <{1}>".format(obj, target)
def fulllistdir(dir, depth=0):
for name, obj in dir.items():
print("{0} * {1}".format(" " * depth, obj_with_link(obj)))
if obj.type == "Directory":
try:
fulllistdir(obj, depth + 4)
except gdef.NtStatusException as e:
print("{0} * {1}".format(" " * (depth + 4), e))
fulllistdir(windows.system.object_manager.root)