Skip to content

Commit

Permalink
update isinstance(EnumField) for scapy 2.3.3+
Browse files Browse the repository at this point in the history
scapy 2.3.2- requires that scapy.fields.EnumField is passed to
isinstance, while scapy 2.3.3+ needs scapy.fields._EnumField.
This patch accomodates pyrit for both versions.
Fixes #500.
  • Loading branch information
Ilya Terentyev committed Nov 1, 2016
1 parent e95b3df commit 14ec997
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cpyrit/pckttools.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,23 @@
scapy.layers.dot11.PrismHeader)


def isEnumField(f):
"""Return True if f is an instance of EnumField. This function tries to be
portable: scapy versions 2.3.2 and earlier need isinstance(EnumField),
while scapy 2.3.3+ requires isinstance(_EnumField).
"""
try:
return isinstance(f, scapy.fields._EnumField)
except AttributeError:
return isinstance(f, scapy.fields.EnumField)


def isFlagSet(self, name, value):
"""Return True if the given field 'includes' the given value.
Exact behaviour of this function is specific to the field-type.
"""
field, val = self.getfield_and_val(name)
if isinstance(field, scapy.fields.EnumField):
if isEnumField(field):
if val not in field.i2s:

This comment has been minimized.

Copy link
@MicroInnovationLLC

MicroInnovationLLC Sep 10, 2020

Depending on the type of pcap file you analyze, it may encounter the following:
File "/usr/local/lib/python2.7/dist-packages/cpyrit/pckttools.py", line 82, in isFlagSet
if val not in field.i2s:
TypeError: argument of type 'NoneType' is not iterable

By Adding the following after if isEnumField(field): and before if val not in field.i2s:
if field.i2s is None:
return False

It will catch field.i2s variable when it is Null.

return False
return field.i2s[val] == value
Expand Down

0 comments on commit 14ec997

Please sign in to comment.