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()
def run(self): print("ServerCaster started.") while True: self.rutineJobs() try: msg = cast_queue.get(True,10) except Empty: continue cmd = msg['cmd'] print("next cmd: "+cmd) if cmd == CREQ.NOTIFY_UPDATE: md5 = fileutil.getmd5(msg['file']) self.socket.send_pyobj({'cmd':SPUB.NOTIFY_UPDATE,'path':msg['file'],'md5':md5}) elif cmd == CREQ.ANALYZE_APP: self.socket.send_pyobj({'cmd':SPUB.ANALYZE_APP}) elif cmd == CREQ.NOTIFY_STOP: self.socket.send_pyobj({'cmd':SPUB.NOTIFY_STOP,'address':msg['address']}) cast_queue.task_done()