def _serve_oneshot(self): t = OneShotServer(SlaveService, hostname = self.host, port = self.port, reuse_addr = True, ipv6 = self.ipv6, authenticator = self.authenticator, registrar = self.registrar, auto_register = self.auto_register) sys.stdout.write("rpyc-oneshot\n") sys.stdout.write("%s\t%s\n" % (t.host, t.port)) sys.stdout.flush() t.start()
class FakeRemoteAgent(threading.Thread): """ A fake agent used for tests of the RPyC interface """ def __init__(self, port, handle_job_func, update_image_aliases_func=(lambda aliases: ""), get_task_directory_hashes_func=(lambda: []), update_task_directory_func=(lambda remote_tar_file, to_delete: "")): threading.Thread.__init__(self) self.port = port self.handle_job_func = handle_job_func self.update_image_aliases_func = update_image_aliases_func self.get_task_directory_hashes_func = get_task_directory_hashes_func self.update_task_directory_func = update_task_directory_func self.start() def run(self): try: self._backend_server = OneShotServer(self._get_agent_backend_service(), port=self.port, protocol_config={"allow_public_attrs": True, 'allow_pickle': True}) self._backend_server.start() except EOFError: pass def close(self): self._backend_server.close() def _get_agent_backend_service(self): """ Returns a RPyC service associated with this Agent """ handle_job = self.handle_job_func update_image_aliases_func = self.update_image_aliases_func get_task_directory_hashes_func = self.get_task_directory_hashes_func update_task_directory_func = self.update_task_directory_func class AgentService(rpyc.Service): def exposed_update_image_aliases(self, image_aliases): update_image_aliases_func(image_aliases) def exposed_get_task_directory_hashes(self): return get_task_directory_hashes_func() def exposed_update_task_directory(self, remote_tar_file, to_delete): update_task_directory_func(remote_tar_file.read(), copy.deepcopy(to_delete)) def exposed_new_job(self, job_id, course_id, task_id, inputdata, debug, callback_status, callback_return): """ Creates, executes and returns the results of a new job """ try: retval = handle_job(job_id, course_id, task_id, inputdata, debug, callback_status) except Exception as e: callback_return({"result": "crash", "text": "An error occured in the Agent: {}".format(str(e))}) return callback_return(retval) return AgentService
def serve_threaded(hostname="localhost", port=4455): """This will run a rpyc server in IDA, so a custom script client will be able to access IDA api. WARNING: IDA will be locked until the client script terminates. """ print('Running server') server = OneShotServer(SlaveService, hostname=hostname, port=port, reuse_addr=True, ipv6=False, authenticator=None, auto_register=False) server.logger.quiet = False return server.start()
def run(self): try: self._backend_server = OneShotServer(self._get_agent_backend_service(), port=self.port, protocol_config={"allow_public_attrs": True, 'allow_pickle': True}) self._backend_server.start() except EOFError: pass
def main(): port = int(idc.ARGV[1]) if idc.ARGV[1:] else 18861 thread_mode = idc.ARGV[2] == 'threaded' if idc.ARGV[2:] else False print('Received arguments: port=%s, thread_mode=%s' % (port, thread_mode)) # :note: For speed, we don't want to idc.Wait() here, # but you might want to call it in your code # to make sure that autoanalysis has finished. if thread_mode: thread = threading.Thread(target=main_thread, args=(port, thread_mode)) thread.daemon = True thread.start() else: srv = OneShotServer(SlaveService, port=port) # OneShotServer is a LIE so we have to do some shit # this is copied from https://github.com/tomerfiliba/rpyc/blob/master/rpyc/utils/server.py # specifically, the start method. if stuff breaks look here! srv._listen() srv._register() srv.accept() idc.Exit(0)
def run_server(): OneShotServer(SlaveService, socket_path=sock_path).start()
def setUp(self): self.server = OneShotServer(MyService, port=18878, auto_register=False) self.server.logger.quiet = False self.thd = self.server._start_in_thread()
class GhcompService(rpyc.ClassicService): def on_connect(self, conn): print('Incoming connection.') super(GhcompService, self).on_connect(conn) import ghpythonlib.components as ghcomp self.ghcomp = ghcomp def on_disconnect(self, conn): print('Disconnected.') def get_component(self, component_name, is_cluster_component=False): component = getattr(self.ghcomp, component_name) if is_cluster_component: component = getattr( component, component_name ) # TODO: improve ghcomp to get clusters the same way we get compiled components, thus removing the need for a custom getter return component if __name__ == '__main__': import rhinoscriptsyntax as rs port = rs.GetInteger("Server bind port", 18871, 1023, 65535) server = OneShotServer(GhcompService, hostname='localhost', port=port, listener_timeout=None) server.start()
""" import rpyc import gdb # Default Settings if 'HOSTNAME' not in locals(): HOSTNAME = '127.0.0.1' if 'PORT' not in locals(): PORT = 18861 # The Service class GDBService(rpyc.Service): def on_disconnect(self, conn): gdb.execute('quit') def exposed_gdb(self): return gdb if __name__ == "__main__": from rpyc.utils.server import OneShotServer server = OneShotServer(GDBService, hostname=HOSTNAME, port=PORT, protocol_config={ 'allow_public_attrs': True, }) server.start()
# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import threading # idc is just within IDA, so make pylint stop complaining import idc # pylint: disable=F0401 # pylint: disable=W0403 # :note: Those should be relative imports, but IDA doesn't like them. from rpyc.core import SlaveService from rpyc.utils.server import OneShotServer, ThreadedServer if __name__ == "__main__": print "Received arguments: {}".format(idc.ARGV) port = int(idc.ARGV[1]) if idc.ARGV[1:] else 18861 mode = idc.ARGV[2] if idc.ARGV[2:] else "oneshot" # :note: For speed, we don't want to idc.Wait() here, # but you might want to call it in your code # to make sure that autoanalysis has finished. if mode == "threaded": ThreadedServer(SlaveService, port=port).start() else: OneShotServer(SlaveService, port=port).start() idc.Exit(0)