def run(self): """Create and run PIPE server. @return: operation status. """ while self.do_run: # Create the Named Pipe. h_pipe = KERNEL32.CreateNamedPipeA( self.pipe_name, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, BUFSIZE, BUFSIZE, 0, None) if h_pipe == INVALID_HANDLE_VALUE: return False # If we receive a connection to the pipe, we invoke the handler. if KERNEL32.ConnectNamedPipe( h_pipe, None) or KERNEL32.GetLastError() == ERROR_PIPE_CONNECTED: handler = PipeHandler(h_pipe) handler.daemon = True handler.start() else: KERNEL32.CloseHandle(h_pipe) return True
def run(self): while self.do_run: flags = FILE_FLAG_WRITE_THROUGH if self.message: pipe_handle = KERNEL32.CreateNamedPipeA( self.pipe_name, PIPE_ACCESS_DUPLEX | flags, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, BUFSIZE, BUFSIZE, 0, None) else: pipe_handle = KERNEL32.CreateNamedPipeA( self.pipe_name, PIPE_ACCESS_INBOUND | flags, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, 0, BUFSIZE, 0, None) if pipe_handle == INVALID_HANDLE_VALUE: log.warning("Error opening logging pipe server.") continue if KERNEL32.ConnectNamedPipe(pipe_handle, None) or \ KERNEL32.GetLastError() == ERROR_PIPE_CONNECTED: handler = self.pipe_handler(pipe_handle, **self.kwargs) handler.daemon = True handler.start() else: KERNEL32.CloseHandle(pipe_handle)
def run(self): """Create and run Log Server. @return: operation status. """ try: while self.do_run: # Create the Named Pipe. # If we receive a connection to the pipe, we invoke the handler. if KERNEL32.ConnectNamedPipe(self.h_pipe, None) or KERNEL32.GetLastError( ) == ERROR_PIPE_CONNECTED: self.handle_logs() KERNEL32.CloseHandle(self.h_pipe) self.resultserver_socket.close() return True except Exception as e: print(e) self.resultserver_socket.close() if self.h_pipe != 0: KERNEL32.CloseHandle(self.h_pipe) error_exc = traceback.format_exc() log.exception(error_exc) return True
def run(self): while self.do_run: # Create the Named Pipe. sd = SECURITY_DESCRIPTOR() sa = SECURITY_ATTRIBUTES() ADVAPI32.InitializeSecurityDescriptor(byref(sd), 1) ADVAPI32.SetSecurityDescriptorDacl(byref(sd), True, None, False) sa.nLength = sizeof(SECURITY_ATTRIBUTES) sa.bInheritHandle = False sa.lpSecurityDescriptor = addressof(sd) # flags = FILE_FLAG_WRITE_THROUGH if self.message: pipe_handle = KERNEL32.CreateNamedPipeW( self.pipe_name, PIPE_ACCESS_DUPLEX, # | flags, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, BUFSIZE, BUFSIZE, 0, byref(sa), # None, ) else: pipe_handle = KERNEL32.CreateNamedPipeW( self.pipe_name, PIPE_ACCESS_INBOUND, # | flags, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, 0, BUFSIZE, 0, byref(sa), # None, ) if pipe_handle == INVALID_HANDLE_VALUE: log.warning("Error opening logging pipe server") continue if KERNEL32.ConnectNamedPipe( pipe_handle, None) or KERNEL32.GetLastError() == ERROR_PIPE_CONNECTED: handler = self.pipe_handler(pipe_handle, **self.kwargs) handler.daemon = True handler.start() self.handlers.add(handler) else: KERNEL32.CloseHandle(pipe_handle)
def run(self): """Create and run PIPE server. @return: operation status. """ try: while self.do_run: # Create the Named Pipe. sd = SECURITY_DESCRIPTOR() sa = SECURITY_ATTRIBUTES() ADVAPI32.InitializeSecurityDescriptor(byref(sd), 1) ADVAPI32.SetSecurityDescriptorDacl(byref(sd), True, None, False) sa.nLength = sizeof(SECURITY_ATTRIBUTES) sa.bInheritHandle = False sa.lpSecurityDescriptor = addressof(sd) h_pipe = KERNEL32.CreateNamedPipeA(self.pipe_name, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, BUFSIZE, BUFSIZE, 0, byref(sa)) if h_pipe == INVALID_HANDLE_VALUE: return False # If we receive a connection to the pipe, we invoke the handler. if KERNEL32.ConnectNamedPipe(h_pipe, None) or KERNEL32.GetLastError() == ERROR_PIPE_CONNECTED: handler = PipeHandler(h_pipe, self.config, self.options) handler.daemon = True handler.start() else: KERNEL32.CloseHandle(h_pipe) return True except Exception as e: error_exc = traceback.format_exc() log.exception(error_exc) return True