import argparse
import ntoseye
def main() -> None:
ap = argparse.ArgumentParser(description=__doc__)
ap.add_argument("--backend", default="memory", choices=["memory", "gdb", "kd"])
ap.add_argument("--connect", default=None)
ap.add_argument("--name", default="lsass.exe", help="process image name to attach to")
args = ap.parse_args()
with ntoseye.attach(backend=args.backend, connect=args.connect) as dbg:
proc = next((p for p in dbg.processes() if p.ImageFileName == args.name), None)
if proc is None:
raise SystemExit(f"process {args.name!r} not found")
pid = proc.UniqueProcessId
print(f"attaching to {args.name} (pid {pid}, eprocess {proc.addr:#x})")
dbg.attach_process(pid) print("current process:", dbg.current_process())
print(f" UniqueProcessId : {proc.UniqueProcessId}")
print(f" ImageFileName : {proc.ImageFileName}")
print(f" ActiveThreads : {proc.ActiveThreads}")
print(f" threads (walked): {len(proc.threads())}")
dbg.detach()
if __name__ == "__main__":
main()