scapy-2.3.2.patch 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. From 14ec997174b8e8fd20d22b6a97c57e19633f12a0 Mon Sep 17 00:00:00 2001
  2. From: Ilya Terentyev <bacondropped@gmail.com>
  3. Date: Tue, 1 Nov 2016 20:40:15 +0300
  4. Subject: [PATCH] update isinstance(EnumField) for scapy 2.3.3+
  5. scapy 2.3.2- requires that scapy.fields.EnumField is passed to
  6. isinstance, while scapy 2.3.3+ needs scapy.fields._EnumField.
  7. This patch accomodates pyrit for both versions.
  8. Fixes #500.
  9. ---
  10. cpyrit/pckttools.py | 13 ++++++++++++-
  11. 1 file changed, 12 insertions(+), 1 deletion(-)
  12. diff --git a/cpyrit/pckttools.py b/cpyrit/pckttools.py
  13. index 326829d..d58fff1 100644
  14. --- a/cpyrit/pckttools.py
  15. +++ b/cpyrit/pckttools.py
  16. @@ -54,12 +54,23 @@
  17. scapy.layers.dot11.PrismHeader)
  18. +def isEnumField(f):
  19. + """Return True if f is an instance of EnumField. This function tries to be
  20. + portable: scapy versions 2.3.2 and earlier need isinstance(EnumField),
  21. + while scapy 2.3.3+ requires isinstance(_EnumField).
  22. + """
  23. + try:
  24. + return isinstance(f, scapy.fields._EnumField)
  25. + except AttributeError:
  26. + return isinstance(f, scapy.fields.EnumField)
  27. +
  28. +
  29. def isFlagSet(self, name, value):
  30. """Return True if the given field 'includes' the given value.
  31. Exact behaviour of this function is specific to the field-type.
  32. """
  33. field, val = self.getfield_and_val(name)
  34. - if isinstance(field, scapy.fields.EnumField):
  35. + if isEnumField(field):
  36. if val not in field.i2s:
  37. return False
  38. return field.i2s[val] == value