def packet_generator(self, input_stream='-'): self.pcap = pcapy.open_offline(input_stream) # create the Dumper object now that we have a Reader # self.out = self.pcap.dump_open('-') while True: (hdr, pack) = self.pcap.next() if hdr is None: return # EOF # keep track of the most recent yielding packet, for diffing self.orig_packet = Packet(hdr, pack) yield Packet(hdr, pack)
def modify(packet_gen, commit_func): packet_buf = [] for packet in packet_gen('-'): for byte in packet.data: if byte >= 0x80: packet_template = Packet(packet.hdr, packet.datapack[:64] + array('c', ''.join(map(chr, packet_buf)))) packet_template.length = len(packet_template.data) packet_template.len_cap = len(packet_template.data) commit_func(packet_template) packet_buf = [] packet_buf.append(byte) else: packet_buf.append(byte)
def packet_generator(): pcap = pcapy.open_offline(test_data('testdump_usbmodify.pcap')) while True: (hdr, pack) = pcap.next() if hdr is None: return # EOF yield Packet(hdr, pack)
def run(self, pcap): """ Run the replayer loop. The loop will get each consecutive pcap packet and replay it as nearly as possible. """ if self.debug: sys.stderr.write( 'In Replayer.run\n') loops = 0 if self.debug: self.print_all() for ep in self.poll_eps: if self.debug: sys.stderr.write( 'Spawning poll thread for endpoint 0x%x\n' % ep.bEndpointAddress) thread = PollThread(ep) thread.start() if self.debug: sys.stderr.write( 'Entering Replayer run loop\n') while True: try: if self.debug: sys.stderr.write( '------------------------------------------\n') sys.stderr.write( 'In Replayer.run: Starting loop: %d \n' % loops) loops += 1 hdr, pack = pcap.next() if hdr is None: break # EOF packet = Packet(hdr, pack) if self.debug: sys.stderr.write( 'In Replayer.run: Printing pcap field info...\n') packet.print_pcap_fields() sys.stderr.write( 'In Replayer.run: Printing pcap summary info...\n') packet.print_pcap_summary() # Wait for awhile before sending next usb packet self.timer.wait_relative(packet.ts_sec, packet.ts_usec) self.send_usb_packet(packet) except Exception: sys.stderr.write("Error occured in replayer run loop. Here's the traceback\n") traceback.print_exc() break #wait for keyboard interrupt, let poll threads continue while self.poll_eps: time.sleep(5) self.reset_device()
def packet_generator(self, input_stream='-'): """Open a pcap stream specified by input_stream and yield each packet in the stream. Also create the Dumper object and store it for later use, since we need the Reader object created here in order to create the Dumper. """ self.pcap = pcapy.open_offline(input_stream) # create the Dumper object now that we have a Reader if not sys.stdout.isatty(): self.out = self.pcap.dump_open('-') while True: (hdr, pack) = self.pcap.next() if hdr is None: return # EOF # keep track of the most recent yielding packet, for diffing self.orig_packet = Packet(hdr, pack) yield Packet(hdr, pack)
def run(self): if self.source == '-' and sys.stdin.isatty(): return pcap = pcapy.open_offline(self.source) # don't output anything unless we're being piped/redirected if not (self.dest == '-' and sys.stdout.isatty()): out = pcap.dump_open(self.dest) sys.stdout.flush() self.dump_opened.emit(out) while 1: (hdr, pack) = pcap.next() if hdr is None: self.eof.emit() break self.new_packet.emit(Packet(hdr, pack))
def run(self, pcap): """ Run the replayer loop. The loop will get each consecutive pcap packet and replay it as nearly as possible. """ if self.debug: sys.stderr.write('In Replayer.run\n') loops = 0 if self.debug: self.print_all() for ep in self.poll_eps: if self.debug: sys.stderr.write('Spawning poll thread for endpoint 0x%x\n' % ep.bEndpointAddress) thread = PollThread(ep) thread.start() if self.debug: sys.stderr.write('Entering Replayer run loop\n') while True: try: if self.debug: sys.stderr.write( '------------------------------------------\n') sys.stderr.write('In Replayer.run: Starting loop: %d \n' % loops) loops += 1 hdr, pack = pcap.next() if hdr is None: break # EOF packet = Packet(hdr, pack) if self.debug: sys.stderr.write( 'In Replayer.run: Printing pcap field info...\n') packet.print_pcap_fields() sys.stderr.write( 'In Replayer.run: Printing pcap summary info...\n') packet.print_pcap_summary() # Wait for awhile before sending next usb packet self.timer.wait_relative(packet.ts_sec, packet.ts_usec) self.send_usb_packet(packet) except Exception: sys.stderr.write( "Error occured in replayer run loop. Here's the traceback\n" ) traceback.print_exc() break #wait for keyboard interrupt, let poll threads continue while self.poll_eps: time.sleep(5) self.reset_device()
while True: for pcap in pcaps: t=pcap.next() pockets.append(t) times.append(0) if pockets[0][0] is None: break time=0 poce=0 ne = " " number += 1 pack = 0 pack_tmp = 0 data = 0 for pocket in pockets: pack = Packet(pocket[0],pocket[1]) if pack.field_dict['setup'] is None: data = data or pack.data_hexdump(64) if data != pack.data_hexdump(64): ne = "#" print("{} {:7d} Data {}".format(ne, number, pack.data_hexdump(64))) ne = " " continue data = data or pack.field_dict['setup'].fields_to_str() if data != pack.field_dict['setup'].fields_to_str(): ne = "#" print("{} {:7d} Setup {}".format(ne, number, pack.field_dict['setup'].fields_to_str())) times[time] = times[time] or pack.ts_sec + pack.ts_usec/1e6 time += 1 ne = " "