MCPcopy Create free account
hub / github.com/ELMERIKH/PyinMemoryPE / open_token

Method open_token

windows/winobject/process.py:524–543  ·  view source on GitHub ↗

Open the Thread token if any (Impersonation) else return None. ``as_self`` tells which security context should be used :returns: :class:`~windows.winobject.token.Token` .. note:: see https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-proc

(self, flags=MAXIMUM_ALLOWED, as_self=False)

Source from the content-addressed store, hash-verified

522
523class Thread(utils.AutoHandle):
524 def open_token(self, flags=MAXIMUM_ALLOWED, as_self=False):
525 """Open the Thread token if any (Impersonation) else return None.
526 ``as_self`` tells which security context should be used
527
528 :returns: :class:`~windows.winobject.token.Token`
529
530 .. note::
531
532 see https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openthreadtoken
533
534 """
535 token_handle = HANDLE()
536 try:
537 winproxy.OpenThreadToken(self.handle, flags, as_self, byref(token_handle))
538 except WindowsError as e:
539 if e.winerror == gdef.ERROR_NO_TOKEN:
540 # No token to open: return None
541 return None
542 raise
543 return token.Token(token_handle.value)
544
545 def set_token(self, token):
546 """Set the token for the thread (impersonation). Setting the token to None revert the impersonation"""

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected