-
Notifications
You must be signed in to change notification settings - Fork 433
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. I'm seeing this when trying to use this branch:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if USE_UJSON: | ||||||
pkt_dict = ujson.loads(json_pkt) | ||||||
else: | ||||||
pkt_dict = json.loads(json_pkt.decode('utf-8')) | ||||||
|
||||||
# We use the frame dict here and not the object access because it's faster. | ||||||
frame_dict = pkt_dict['layers'].pop('frame') | ||||||
layers = [] | ||||||
for layer in frame_dict['frame_frame_protocols'].split(':'): | ||||||
layer_dict = pkt_dict['layers'].pop(layer, None) | ||||||
if layer_dict is not None: | ||||||
layers.append(EkLayer(layer, layer_dict)) | ||||||
layers = pkt_dict['layers'] | ||||||
frame_dict = layers.pop('frame') | ||||||
if 'frame_raw' in layers: | ||||||
frame_dict['frame_frame_raw'] = layers.pop('frame_raw') | ||||||
|
||||||
# Sort the frame protocol layers first | ||||||
ek_layers = [] | ||||||
for name in frame_dict['frame_frame_protocols'].split(':'): | ||||||
raw_name = f"{name}_raw" | ||||||
if name in layers: | ||||||
layer = layers.get(name) | ||||||
layer_raw = layers.get(raw_name) | ||||||
if not layer: | ||||||
continue | ||||||
elif isinstance(layer, list): | ||||||
layer = layer.pop(0) | ||||||
layer_raw = layer_raw.pop(0) if layer_raw else None | ||||||
else: | ||||||
layers.pop(name, None) | ||||||
layers.pop(raw_name, None) | ||||||
layer[f"{name}_{raw_name}"] = layer_raw | ||||||
ek_layer = EkLayer(name, layer) | ||||||
ek_layers.append(ek_layer) | ||||||
|
||||||
# Add all leftovers | ||||||
for name, layer in pkt_dict['layers'].items(): | ||||||
layers.append(EkLayer(name, layer)) | ||||||
for name, layer in layers.items(): | ||||||
if isinstance(layer, list): | ||||||
for sub_layer in layer: | ||||||
ek_layers.append(EkLayer(name, sub_layer) ) | ||||||
else: | ||||||
ek_layers.append(EkLayer(name, layer)) | ||||||
|
||||||
return Packet(layers=layers, frame_info=EkLayer('frame', frame_dict), | ||||||
return Packet(layers=ek_layers, frame_info=EkLayer('frame', frame_dict), | ||||||
number=int(frame_dict.get('frame_frame_number', 0)), | ||||||
length=int(frame_dict['frame_frame_len']), | ||||||
sniff_time=frame_dict['frame_frame_time_epoch'], | ||||||
|
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.