官术网_书友最值得收藏!

  • Learning Python for Forensics
  • Preston Miller Chapin Bryce
  • 208字
  • 2021-08-20 10:17:12

Forming the prep_usb_lookup() function

In this function, we call out to the usb_lookup.py script's .get_usb_file() function. Using the local_usb_ids parameter that's provided, we can confirm whether there is a known usb.ids file path that we should use for this lookup, or whether we should reach out to the online resource at http://linux-usb.org/usb.ids to read the known USB information into the usb_file variable on line 147. This database is an open source project that hosts the VID/PID lookup database, allowing users to reference and expand on the database:

137 def prep_usb_lookup(local_usb_ids=None):
138 """
139 Prepare the lookup of USB devices through accessing the most
140 recent copy of the database at http://linux-usb.org/usb.ids
141 or using the provided file and parsing it into a queriable
142 dictionary format.
143 """
144 if local_usb_ids:
145 usb_file = open(local_usb_ids, encoding='latin1')
146 else:
147 usb_file = usb_lookup.get_usb_file()

After downloading or using a local copy, we pass the file object to the .parse_file() function to process and then return the USB VID/PID data as a Python dictionary. Instead of creating a new variable for this functionality, we can just place the return keyword in front of the function call to immediately pass the value back, as shown on line 148:

148     return usb_lookup.parse_file(usb_file) 
主站蜘蛛池模板: 海南省| 晋城| 香格里拉县| 宁安市| 台湾省| 安阳县| 六枝特区| 静宁县| 宜宾县| 大英县| 罗甸县| 上栗县| 明水县| 临泉县| 肥城市| 岢岚县| 津市市| 襄垣县| 鹤壁市| 云阳县| 霍林郭勒市| 普宁市| 临桂县| 喀喇沁旗| 利津县| 巴塘县| 合水县| 宜良县| 咸丰县| 泾源县| 萨迦县| 湾仔区| 龙江县| 卫辉市| 鹰潭市| 周口市| 东山县| 恭城| 修文县| 达拉特旗| 临沭县|