def handle_node(self, msg): meta_data = QueueNode.get_metadata(msg["task"]["nid"]) payload = QueueNode.get_payload(meta_data["info"]["exit_reason"], meta_data["id"]) results, new_payload = self.logic.process_node(payload, meta_data) if new_payload: default_info = { "method": "validate_bits", "parent": meta_data["id"], "IoControlCode": meta_data["info"]["IoControlCode"] } if self.validate_bits(new_payload, meta_data, default_info): log_slave( "Stage %s found alternative payload for node %d" % (meta_data["state"]["name"], meta_data["id"]), self.slave_id) else: log_slave( "Provided alternative payload found invalid - bug in stage %s?" % meta_data["state"]["name"], self.slave_id) if self.exec_count > EXEC_LIMIT: # Fuzzing next queue self.exec_count = 0 self.conn.send_next_queue() self.conn.send_node_done(meta_data["id"], results, new_payload)
def handle_task(self, msg): if msg["task"]["type"] == "import": meta_data = {"state": {"name": "import"}} payload = msg["task"]["payload"] elif msg["task"]["type"] == "node": meta_data = QueueNode.get_metadata(msg["task"]["nid"]) payload = QueueNode.get_payload(meta_data["info"]["exit_reason"], meta_data["id"]) print "slave %d got task %d %s" % (self.slave_id, meta_data.get( "node", {}).get("id", -1), repr(meta_data)) self.statistics.event_task(msg["task"]) results, new_payload = self.logic.process(payload, meta_data) node_id = None if new_payload != payload: default_info = { "method": "validate_bits", "parent": meta_data["id"] } if self.validate_bits(new_payload, meta_data, default_info): print("VALIDATE BITS OK") else: print( "VALIDATE BITS FAILED BUG IN TRANSFORMATION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" ) # assert False if results: node_id = meta_data["id"] self.conn.send_task_performed(node_id, results, new_payload)
def process(self, payload, metadata): start_time = time.time() update = {} while not update or time.time( ) - start_time < 3: # keep working each input until at least one seconds passed if update != {}: safe_print("internal cycle: {} and payload {}".format( repr(update), repr(payload))) abort, cur_update, cur_payload = self.statemachine( payload, metadata) if cur_payload: payload = cur_payload if cur_update: QueueNode.apply_metadata_update(update, cur_update) QueueNode.apply_metadata_update(metadata, cur_update) if abort: break return update, payload
def maybe_insert_node(self, payload, bitmap_array, node_struct): bitmap = ExecutionResult.bitmap_from_bytearray(bitmap_array, node_struct["info"]["exit_reason"], node_struct["info"]["performance"]) bitmap.lut_applied = True # since we received the bitmap from the slave, the lut was already applied backup_data = bitmap.copy_to_array() should_store, new_bytes, new_bits = self.bitmap_storage.should_store_in_queue(bitmap) new_data = bitmap.copy_to_array() if should_store: node = QueueNode(payload, bitmap_array, node_struct, write=False) node.set_new_bytes(new_bytes, write=False) node.set_new_bits(new_bits, write=False) self.queue.insert_input(node, bitmap) elif self.debug_mode: if node_struct["info"]["exit_reason"] != "regular": log_master("Payload found to be boring, not saved (exit=%s)" % node_struct["info"]["exit_reason"]) for i in range(len(bitmap_array)): if backup_data[i] != new_data[i]: assert(False), "Bitmap mangled at {} {} {}".format(i, repr(backup_data[i]), repr(new_data[i]))
def construct_node( self, payload, bitmap, new_bytes, new_bits, node_struct, ): assert "fav_bits" not in node_struct assert "level" not in node_struct assert "new_bytes" not in node_struct assert "new_bits" not in node_struct node_struct["new_bytes"] = new_bytes node_struct["new_bits"] = new_bits node = QueueNode(payload, bitmap, node_struct, write=False) node.clear_fav_bits(write=False) parent = node_struct["info"]["parent"] node.set_level(self.get_node_by_id(parent).get_level() + 1 if parent else 0, write=False) return node