|
| 1 | +import os |
| 2 | +import windows |
| 3 | +import windows.generated_def as gdef |
| 4 | +from windows.debug import symbols |
| 5 | +import argparse |
| 6 | + |
| 7 | + |
| 8 | +parser = argparse.ArgumentParser(prog=__file__, formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
| 9 | +parser.add_argument('--dbghelp', help='The path of DBG help to use (default use env:PFW_DBGHELP_PATH)') |
| 10 | +args = parser.parse_args() |
| 11 | +print(args) |
| 12 | + |
| 13 | +if args.dbghelp: |
| 14 | + symbols.set_dbghelp_path(args.dbghelp) |
| 15 | +else: |
| 16 | + if "PFW_DBGHELP_PATH" not in os.environ: |
| 17 | + print("Not dbghelp path given and no environ var 'PFW_DBGHELP_PATH' sample may fail") |
| 18 | + |
| 19 | + |
| 20 | +symbols.engine.options = 0 # Disable defered load |
| 21 | +sh = symbols.VirtualSymbolHandler() |
| 22 | + |
| 23 | +ntmod = sh.load_file(r"c:\windows\system32\ntdll.dll", addr=0x420000) |
| 24 | + |
| 25 | +print("Ntdll module is: {0}".format(ntmod)) |
| 26 | +print(" * name = {0}".format(ntmod.name)) |
| 27 | +print(" * addr = {0:#x}".format(ntmod.addr)) |
| 28 | +print(" * path = {0:}".format(ntmod.path)) |
| 29 | +print(" * type = {0:}".format(ntmod.type)) |
| 30 | +print(" * pdb = {0:}".format(ntmod.pdb)) |
| 31 | + |
| 32 | +print("") |
| 33 | +TEST_FUNCTION = "LdrLoadDll" |
| 34 | +print("Resolving function <{0}>".format(TEST_FUNCTION)) |
| 35 | +loaddll = sh["ntdll!" + TEST_FUNCTION] |
| 36 | +print("Symbol found !") |
| 37 | +print(" * __repr__: {0!r}".format(loaddll)) |
| 38 | +print(" * __str__: {0}".format(loaddll)) |
| 39 | +print(" * addr: {0:#x}".format(loaddll.addr)) |
| 40 | +print(" * name: {0}".format(loaddll.name)) |
| 41 | +print(" * fullname: {0}".format(loaddll.fullname)) |
| 42 | +print(" * module: {0}".format(loaddll.module)) |
| 43 | + |
| 44 | +print("") |
| 45 | +print("Loading kernelbase") |
| 46 | +kbasemod = sh.load_file(r"c:\windows\system32\kernelbase.dll", addr=0x1230000) |
| 47 | +print("Loaded modules are: {0}".format(sh.modules)) |
| 48 | +LOOKUP_ADDR = 0x1231242 |
| 49 | +print("Looking up address: {0:#x}".format(LOOKUP_ADDR)) |
| 50 | +lookupsym = sh[LOOKUP_ADDR] |
| 51 | +print("Symbol resolved !") |
| 52 | +print(" * __repr__: {0!r}".format(lookupsym)) |
| 53 | +print(" * __str__: {0}".format(lookupsym)) |
| 54 | +print(" * start: {0:#x}".format(lookupsym.start)) |
| 55 | +print(" * addr: {0:#x}".format(lookupsym.addr)) |
| 56 | +print(" * displacement: {0:#x}".format(lookupsym.displacement)) |
| 57 | +print(" * name: {0}".format(lookupsym.name)) |
| 58 | +print(" * fullname: {0}".format(lookupsym.fullname)) |
| 59 | +print(" * module: {0}".format(lookupsym.module)) |
0 commit comments