def run(self): print("WorkerResponder started.") while True: address = self.socket.recv() self.socket.recv() msg = self.socket.recv_pyobj() cmd = msg['cmd'] worker_dir = path.join(WORK_DIR,address) print("received from {}: {}".format(address,cmd)) if cmd == WREQ.REQ_FILE: fileutil.send_file(self.socket,msg['path'],msg['target'],msg['loc'],address) elif cmd == WREQ.REP_FILE: fileutil.write_req_file(self.socket,msg['path'],msg['target'],WORK_DIR,msg['body'],address) elif cmd == WREQ.REQ_ANALYSIS: try: w = analysis_queue.get_nowait() a = w['droidblaze'] # TODO: get apk from somewhere and transfer with message app = w['file'] f = open(app,'rb') app_data = f.read() f.close() self.socket.send(address,zmq.SNDMORE) self.socket.send("",zmq.SNDMORE) self.socket.send_pyobj({'cmd':WREQ.REP_ANALYSIS,'droidblaze':a,'app':app_data}) except Empty: self.socket.send(address,zmq.SNDMORE) self.socket.send("",zmq.SNDMORE) self.socket.send_pyobj({'cmd':WREQ.DONE}) elif cmd == WREQ.FIN_ANALYSIS: a = msg['droidblaze'] ret = msg['status'] fileutil.untar(path.join(WORK_DIR,a.analysis_id),msg['result']) a.merging_summary(path.join(WORK_DIR,a.analysis_id),ret) self.socket.send(address,zmq.SNDMORE) self.socket.send("",zmq.SNDMORE) self.socket.send_pyobj({'cmd':WREQ.DONE}) elif cmd == WREQ.DONE: self.socket.send(address,zmq.SNDMORE) self.socket.send("",zmq.SNDMORE) self.socket.send_pyobj({'cmd':WREQ.DONE}) elif cmd == WREQ.STATUS: status = msg['status'] client_status[address] = status updated_client.add(address) self.socket.send(address,zmq.SNDMORE) self.socket.send("",zmq.SNDMORE) self.socket.send_pyobj({'cmd':WREQ.DONE}) else: print("what?: "+cmd)
def run(self): global status print("Worker started") while True: status = "ready" self.report_status() try: msg = msg_queue.get(True,1) except Empty: continue cmd = msg['cmd'] print("next cmd: "+cmd) if cmd == SPUB.NOTIFY_UPDATE: dist = path.join(self.workdir,DROIDBLAZE_DIST) if os.path.exists(dist): dist_md5 = fileutil.getmd5(dist) else: dist_md5 = None if not msg['md5'] == dist_md5: self.cleanup() self.socket.send_pyobj({'cmd':WREQ.REQ_FILE,'path':msg['path'],'target':DROIDBLAZE_DIST,'loc':0}) self.filetransfer() fileutil.untar(self.workdir,DROIDBLAZE_DIST) print("updated") else: print("already up to date") elif cmd == SPUB.ANALYZE_APP: self.socket.send_pyobj({'cmd':WREQ.REQ_ANALYSIS}) res = self.socket.recv_pyobj() if res['cmd'] == WREQ.REP_ANALYSIS: a = res['droidblaze'] app = path.join(self.workdir,a.target_apk) f = open(app, 'w') f.write(res['app']) f.close() ret = self.analyzer_run(a) app_tgz = path.splitext(a.target_apk)[0]+".tgz" a.tar_result(self.workdir,app_tgz) fileutil.send_file(self.socket,path.join(self.workdir,app_tgz),path.join(a.analysis_id,self.workerid,app_tgz),0) self.filetransfer() msg_queue.put({'cmd':SPUB.ANALYZE_APP}) self.socket.send_pyobj({'cmd':WREQ.FIN_ANALYSIS,'droidblaze': a,'result':path.join(self.workerid,app_tgz),'status':ret}) res = self.socket.recv_pyobj() else: print("what?: "+cmd) msg_queue.task_done()