def __init__(self): # Create a pipe so we can write to stdin of the loader process. pipeReadOrig, self._pipeWrite = winKernel.CreatePipe(None, 0) # Make the read end of the pipe inheritable. pipeRead = self._duplicateAsInheritable(pipeReadOrig) winKernel.closeHandle(pipeReadOrig) # stdout/stderr of the loader process should go to nul. with file("nul", "w") as nul: nulHandle = self._duplicateAsInheritable( msvcrt.get_osfhandle(nul.fileno())) # Set the process to start with the appropriate std* handles. si = winKernel.STARTUPINFO(dwFlags=winKernel.STARTF_USESTDHANDLES, hSTDInput=pipeRead, hSTDOutput=nulHandle, hSTDError=nulHandle) pi = winKernel.PROCESS_INFORMATION() # Even if we have uiAccess privileges, they will not be inherited by default. # Therefore, explicitly specify our own process token, which causes them to be inherited. token = winKernel.OpenProcessToken(winKernel.GetCurrentProcess(), winKernel.MAXIMUM_ALLOWED) try: winKernel.CreateProcessAsUser(token, None, u"lib64/nvdaHelperRemoteLoader.exe", None, None, True, None, None, None, si, pi) # We don't need the thread handle. winKernel.closeHandle(pi.hThread) self._process = pi.hProcess except: winKernel.closeHandle(self._pipeWrite) raise finally: winKernel.closeHandle(pipeRead) winKernel.closeHandle(token)
def _duplicateAsInheritable(self, handle): curProc = winKernel.GetCurrentProcess() return winKernel.DuplicateHandle(curProc, handle, curProc, 0, True, winKernel.DUPLICATE_SAME_ACCESS)
def getCurrentProcessLogonSessionId() -> int: return getProcessLogonSessionId(winKernel.GetCurrentProcess())