-
Notifications
You must be signed in to change notification settings - Fork 427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed ek packet parsing when there are repeated protocol layers + added raw to each layer #677
base: master
Are you sure you want to change the base?
Conversation
With ek, when protocols are repeated, the layer becomes a list of dictionaries, one for each layer. This update adds proper support for this.
…parsing Sometimes a frame layer doesn't actually exist in the packet details, so I added extra protection
…t() which didnt work
I needed raw for each layer, so I fixed this bug as well: Also fixed packet.get_raw_packet() which wasn't working since XXX_raw values were not assessable |
@@ -34,25 +34,46 @@ def _extract_packet_from_data(self, data, got_first_packet=True): | |||
|
|||
return data[start_index:linesep_location], data[linesep_location + 1:] | |||
|
|||
|
|||
def packet_from_ek_packet(json_pkt): | |||
def packet_from_ek_packet_new(json_pkt): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you mean to rename this func
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm seeing this when trying to use this branch:
>>> import pyshark
>>> file = "http_1.pcap"
>>> cap = pyshark.FileCapture(file, use_ek=True)
>>> pkt = cap[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/andrew/pyshark-fixed/src/pyshark/capture/file_capture.py", line 72, in __getitem__
self.next()
File "/home/andrew/pyshark-fixed/src/pyshark/capture/file_capture.py", line 62, in next
packet = self._packet_generator.send(None)
File "/home/andrew/pyshark-fixed/src/pyshark/capture/capture.py", line 222, in _packets_from_tshark_sync
packet, data = self.eventloop.run_until_complete(
File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
return future.result()
File "/home/andrew/pyshark-fixed/src/pyshark/tshark/output_parser/base_parser.py", line 15, in get_packets_from_stream
packet = self._parse_single_packet(packet)
File "/home/andrew/pyshark-fixed/src/pyshark/tshark/output_parser/tshark_ek.py", line 21, in _parse_single_packet
return packet_from_ek_packet(packet)
NameError: name 'packet_from_ek_packet' is not defined. Did you mean: 'packet_from_ek_packet_new'?
@@ -34,25 +34,46 @@ def _extract_packet_from_data(self, data, got_first_packet=True): | |||
|
|||
return data[start_index:linesep_location], data[linesep_location + 1:] | |||
|
|||
|
|||
def packet_from_ek_packet(json_pkt): | |||
def packet_from_ek_packet_new(json_pkt): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def packet_from_ek_packet_new(json_pkt): | |
def packet_from_ek_packet(json_pkt): |
@@ -66,11 +66,11 @@ def __dir__(self): | |||
return dir(type(self)) + list(self.__dict__.keys()) + [l.layer_name for l in self.layers] | |||
|
|||
def get_raw_packet(self) -> bytes: | |||
assert "FRAME_RAW" in self, "Packet contains no raw data. In order to contains it, " \ | |||
assert self.frame_info.has_field('raw'), "Packet contains no raw data. In order to contains it, " \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert self.frame_info.has_field('raw'), "Packet contains no raw data. In order to contains it, " \ | |
assert self.frame_info.has_field('raw'), "Packet contains no raw data. In order to include raw data, " \ |
With ek, when protocols are repeated, the layer becomes a list of dictionaries, one for each layer. This update adds proper support for this.