From 3bbf7eb147ce9b94734ef17a1659e36690251d25 Mon Sep 17 00:00:00 2001 From: Kihomenethoth Date: Wed, 14 Jul 2021 12:42:44 -0400 Subject: [PATCH] changed built-in list types to typing.List (#235) * changed built-in list types to typing.List * fixed zbstumbler byte type mismatches --- killerbee/__init__.py | 10 +++++----- killerbee/daintree.py | 2 +- killerbee/dev_apimote.py | 4 ++-- killerbee/dev_template.py | 7 ++----- killerbee/kbutils.py | 4 ++-- killerbee/scapy_extensions.py | 4 ++-- tools/zbstumbler | 14 +++++++------- 7 files changed, 21 insertions(+), 24 deletions(-) diff --git a/killerbee/__init__.py b/killerbee/__init__.py index 4eb33c4..c3d7eaa 100644 --- a/killerbee/__init__.py +++ b/killerbee/__init__.py @@ -1,4 +1,4 @@ -from typing import Optional, Any, Dict, Union +from typing import Optional, Any, Dict, Union, List import struct import glob @@ -211,7 +211,7 @@ def __device_is(self, vendorId, productId): if self.dev.idVendor == vendorId and self.dev.idProduct == productId: return True else: return False - def get_dev_info(self) -> list[str]: + def get_dev_info(self) -> List[str]: ''' Returns device information in a list identifying the device. Implemented by the loaded driver. @rtype: List @@ -272,7 +272,7 @@ def frequency(self, channel: Optional[int]=None, page: int=0) -> int: return self.driver.capabilities.frequency(channel, page) - def get_capabilities(self) -> list[Any]: + def get_capabilities(self) -> List[Any]: ''' Returns a list of capability information for the device. @rtype: List @@ -295,7 +295,7 @@ def enter_bootloader(self) -> Any: return self.driver.enter_bootloader() - def get_bootloader_version(self) -> list[int]: + def get_bootloader_version(self) -> List[int]: ''' Gets the bootloader major and minor version. @rtype: List @@ -307,7 +307,7 @@ def get_bootloader_version(self) -> list[int]: return self.driver.get_bootloader_version() - def get_bootloader_signature(self) -> list[int]: + def get_bootloader_signature(self) -> List[int]: ''' Gets the bootloader chip signature. @rtype: List diff --git a/killerbee/daintree.py b/killerbee/daintree.py index 9e5fbc5..6ec7027 100644 --- a/killerbee/daintree.py +++ b/killerbee/daintree.py @@ -91,7 +91,7 @@ def close(self) -> None: del(self._fh) - def pnext(self) -> Optional[list[Any]]: + def pnext(self) -> Optional[List[Any]]: ''' Retrieves the next packet from the capture file. Returns a list of [Hdr, packet] where Hdr is a list of [timestamp, snaplen, plen] and diff --git a/killerbee/dev_apimote.py b/killerbee/dev_apimote.py index 809e43b..fa9d4f6 100755 --- a/killerbee/dev_apimote.py +++ b/killerbee/dev_apimote.py @@ -12,7 +12,7 @@ - Platform recognition (ApiMote versons) ''' -from typing import Optional, Dict, Union, Any +from typing import Optional, Dict, Union, Any, List import os import time @@ -82,7 +82,7 @@ def __set_capabilities(self) -> None: return # KillerBee expects the driver to implement this function - def get_dev_info(self) -> list[Union[str, Any]]: + def get_dev_info(self) -> List[Union[str, Any]]: ''' Returns device information in a list identifying the device. @rtype: List diff --git a/killerbee/dev_template.py b/killerbee/dev_template.py index e27682b..8763f9d 100755 --- a/killerbee/dev_template.py +++ b/killerbee/dev_template.py @@ -1,7 +1,4 @@ -from typing import Optional -from typing import Dict -from typing import Union -from typing import Any +from typing import Optional, Dict, Union, Any, List import os import time @@ -60,7 +57,7 @@ def check_capability(self, capab: int) -> bool: def get_capabilities(self) -> Dict[int, bool]: return self.capabilities.getlist() - def get_dev_info(self) -> list[Union[str, Any]]: + def get_dev_info(self) -> List[Union[str, Any]]: return [self.dev, "GoodFET Apimote", ""] def sniffer_on(self, channel: Optional[int]=None, page: int=0) -> None: diff --git a/killerbee/kbutils.py b/killerbee/kbutils.py index 11191e5..a8df149 100644 --- a/killerbee/kbutils.py +++ b/killerbee/kbutils.py @@ -203,7 +203,7 @@ def __call__(self, device: Any) -> bool: return False -def devlist_usb_v1x(vendor: Optional[Any]=None, product: Optional[Any]=None) -> list[Any]: +def devlist_usb_v1x(vendor: Optional[Any]=None, product: Optional[Any]=None) -> List[Any]: ''' Private function. Do not call from tools/scripts/etc. ''' @@ -246,7 +246,7 @@ def is_valid_ipv6_address(address: str) -> bool: return True return ( is_valid_ipv6_address(ip) or is_valid_ipv4_address(ip) ) -def devlist(vendor: Optional[Any]=None, product: Optional[Any]=None, gps: Optional[str]=None, include: Optional[str]=None) -> list[Any]: +def devlist(vendor: Optional[Any]=None, product: Optional[Any]=None, gps: Optional[str]=None, include: Optional[str]=None) -> List[Any]: ''' Return device information for all present devices, filtering if requested by vendor and/or product IDs on USB devices, and diff --git a/killerbee/scapy_extensions.py b/killerbee/scapy_extensions.py index 18c6a1e..d489e11 100644 --- a/killerbee/scapy_extensions.py +++ b/killerbee/scapy_extensions.py @@ -72,7 +72,7 @@ def __kb_send(kb: KillerBee, x: Union[str, Gen], channel: Optional[int]=None, pa pass return n -def __kb_recv(kb: KillerBee, count: int=0, store: int=1, prn: Optional[Any]=None, lfilter: Optional[Any]=None, stop_filter: Optional[Any]=None, verbose: Optional[int]=None, timeout: Optional[int]=None) -> list[bytes]: +def __kb_recv(kb: KillerBee, count: int=0, store: int=1, prn: Optional[Any]=None, lfilter: Optional[Any]=None, stop_filter: Optional[Any]=None, verbose: Optional[int]=None, timeout: Optional[int]=None) -> List[bytes]: kb.sniffer_on() if timeout is not None: stoptime = time.time()+timeout @@ -290,7 +290,7 @@ def kbrddain(filename: str, count: int=-1, skip: int=0) -> plist.PacketList: packetcount: int = 0 while 1: - packet: Optional[list[Any]] = cap.pnext() + packet: Optional[List[Any]] = cap.pnext() if packet is None: break; packetcount += 1 diff --git a/tools/zbstumbler b/tools/zbstumbler index c62a8d7..8cf6fbf 100644 --- a/tools/zbstumbler +++ b/tools/zbstumbler @@ -29,13 +29,13 @@ def display_details(routerdata): stackprofile = stackprofilever & 0x0f stackver = (stackprofilever & 0xf0) >>4 - print("New Network: PANID 0x{0:02X}{1:02X} Source 0x{2:02X}{3:02X}".format(ord(spanid[0]), ord(spanid[1]), ord(source[0]), ord(source[1]))) + print("New Network: PANID 0x{0:02X}{1:02X} Source 0x{2:02X}{3:02X}".format(spanid[0], spanid[1], source[0], source[1])) try: extpanidstr="" for ind in range(0,7): - extpanidstr += "%02x:"%ord(extpanid[ind]) - extpanidstr += "%02X"%ord(extpanid[-1]) + extpanidstr += "%02x:"%extpanid[ind] + extpanidstr += "%02X"%extpanid[-1] sys.stdout.write("\tExt PANID: " + extpanidstr) except IndexError: sys.stdout.write("\tExt PANID: Unknown") @@ -57,7 +57,7 @@ def display_details(routerdata): print(("\tChannel: {0}".format(channel))) if args.csvfile is not None: - csvfile.write("0x%02X%02X,0x%02X%02X,%s,%s,%s,%d\n"%(ord(spanid[0]), ord(spanid[1]), ord(source[0]), ord(source[1]), extpanidstr, stackprofilestr, stackverstr, channel)) + csvfile.write("0x%02X%02X,0x%02X%02X,%s,%s,%s,%d\n"%(spanid[0], spanid[1], source[0], source[1], extpanidstr, stackprofilestr, stackverstr, channel)) def response_handler(stumbled, packet, channel): @@ -99,7 +99,7 @@ def response_handler(stumbled, packet, channel): return value if args.verbose: - print(("Received frame is not a beacon (FCF={0}).".format(pktdecode[0].encode('utf-8').hex()))) + print("Received frame is not a beacon (FCF={0}).".format(pktdecode[0])) return None @@ -137,7 +137,7 @@ if __name__ == '__main__': csvfile.write("panid,source,extpanid,stackprofile,stackversion,channel\n") # Beacon frame - beacon = "\x03\x08\x00\xff\xff\xff\xff\x07" + beacon = b"\x03\x08\x00\xff\xff\xff\xff\x07" # Immutable strings - split beacon around sequence number field beaconp1 = beacon[0:2] beaconp2 = beacon[3:] @@ -179,7 +179,7 @@ if __name__ == '__main__': if args.verbose: print("Transmitting beacon request.") - beaconinj = ''.join([beaconp1, "%c" % seqnum, beaconp2]) + beaconinj = b''.join([beaconp1, b"%c" % seqnum, beaconp2]) # Process packets for arg_delay seconds looking for the beacon # response frame.