Skip to content

Commit

Permalink
changed built-in list types to typing.List (#235)
Browse files Browse the repository at this point in the history
* changed built-in list types to typing.List

* fixed zbstumbler byte type mismatches
  • Loading branch information
taylorcenters authored Jul 14, 2021
1 parent 5f54af1 commit 3bbf7eb
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 24 deletions.
10 changes: 5 additions & 5 deletions killerbee/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, Any, Dict, Union
from typing import Optional, Any, Dict, Union, List

import struct
import glob
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion killerbee/daintree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions killerbee/dev_apimote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions killerbee/dev_template.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions killerbee/kbutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
'''
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions killerbee/scapy_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions tools/zbstumbler
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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):
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:]
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 3bbf7eb

Please sign in to comment.