def pop_frames(self): # iterate over self.data and attempt to form HTTP/2 frames idx = 0 frame_size = len(h2.H2Frame()) frames = [] while len(self.data) >= frame_size: try: frame_len = h2.H2Frame(self.data).len except AssertionError: # when not enough data break except: # can't decode as a frame? what are we looking at? print("can't decode data into http/2 frame") hexdump(self.data) raise # if we've got a frame, but don't have all the data for it yet if frame_len > len(self.data): break # without adding this frame # if we pop this frame, remove its data from self.data # and push self.seq up by len(frame) frame, self.data = h2.H2Frame( self.data[:frame_size + frame_len]), self.data[frame_size + frame_len:] self.seq += frame_size + frame_len frames.append(frame) return frames
def create_packet(): xpc_obj = XPC_Root( XPC_Dictionary({ "MessageType": XPC_String("Heartbeat"), "SequenceNumber": XPC_Uint64(78789), })) xpc_bytes = xpc_obj.to_bytes() header = b'\x92\x0b\xb0)\x01\x01\x01\x00P\x00\x00\x00\x00\x00\x00\x00\x8bg\x02\x00\x00\x00\x00\x00' payload = header + xpc_bytes packet = h2.H2Frame(type=0, stream_id=1) / h2.H2DataFrame(data=payload) hexdump(packet)
#### srv_max_frm_sz = 1 << 14 srv_hdr_tbl_sz = 4096 srv_max_hdr_tbl_sz = 0 srv_global_window = 1<<14 for setting in srv_set.payload.settings: if setting.id == h2.H2Setting.SETTINGS_HEADER_TABLE_SIZE: srv_hdr_tbl_sz = setting.value elif setting.id == h2.H2Setting.SETTINGS_MAX_HEADER_LIST_SIZE: srv_max_hdr_tbl_sz = setting.value elif setting.id == h2.H2Setting.SETTINGS_INITIAL_WINDOW_SIZE: srv_global_window = setting.value #### import scapy.packet as packet srv_global_window -=len(h2.H2_CLIENT_CONNECTION_PREFACE) assert(srv_global_window >=0) print ss.send(packet.Raw(h2.H2_CLIENT_CONNECTION_PREFACE)) #### set_ack = h2.H2Frame(flags={'A'}) / h2.H2SettingsFrame() set_ack.show()