def send_webkit_message(self, message): self.logger.info('=' * 80) self.logger.info("request:%s" % message) data = self._plist_to_bin(message) data_len = len(data) if self.is_complete_supported: tmp_data = struct.pack('!L', len(data)) + data self.send(tmp_data) return for i in xrange(0, data_len, self.MAX_PLIST_LEN): is_partial = data_len - i > self.MAX_PLIST_LEN if is_partial: partial_msg = data[i:i + self.MAX_PLIST_LEN] if PY2: partial_msg = Data(partial_msg) else: partial_msg = partial_msg.encode() tmp_data = {self.PARTIAL_MSG: partial_msg} else: final_msg = data[i:data_len - i] if PY2: final_msg = Data(final_msg) else: final_msg = final_msg.encode() tmp_data = {self.FINAL_MSG: final_msg} tmp_data = self._plist_to_bin(tmp_data) tmp_data = struct.pack('!L', len(tmp_data)) + tmp_data self.send(tmp_data)
def send_webkit_socket_data(self, data, page_id): if page_id != self.page_id: self._setup_webkit_socket(page_id) self.seq += 1 data["id"] = self.seq data = json.dumps(data) if PY2: wrapped_data = Data(data) else: wrapped_data = data.encode() data = { '__argument': { 'WIRSenderKey': self.sender_key, 'WIRConnectionIdentifierKey': self.conn_id, 'WIRApplicationIdentifierKey': self.app_id, 'WIRSocketDataKey': wrapped_data, 'WIRPageIdentifierKey': int(page_id) }, '__selector': EnumSelector.SEND_FORWARD_SOCKET_DATA } self.send_webkit_message(data)
def send_webkit_socket_data(self, data, page_id): if page_id != self.page_id: self._setup_webkit_socket(page_id) if self.is_target_domain: resp = self.recv_webkit_socket_data(True) if resp['method'] == 'Target.targetCreated': self._on_target_created(resp['params']) if self.is_target_domain: self.is_target_wrapped = True self.seq += 1 data["id"] = self.seq data = { "method": "Target.sendMessageToTarget", "params": { "targetId": self.target_id, "message": json.dumps(data) } } self.seq += 1 data["id"] = self.seq data = json.dumps(data) if PY2: wrapped_data = Data(data) else: wrapped_data = data.encode() data = { '__argument': { 'WIRSenderKey': self.sender_key, 'WIRConnectionIdentifierKey': self.conn_id, 'WIRApplicationIdentifierKey': self.app_id, 'WIRSocketDataKey': wrapped_data, 'WIRPageIdentifierKey': int(page_id) }, '__selector': EnumSelector.SEND_FORWARD_SOCKET_DATA } self.send_webkit_message(data)
def unlock_token(self, value): if isinstance(value, NSData): self._unlock_token = NSData.encode('base64') else: self._unlock_token = value