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

Introducing our script

The setupapi_parser.py script will be developed to parse the setupapi.dev.log file on Windows 7 and higher. Equipped with only modules from the standard library, we will open and read a setupapi.log file, identify and parse relevant USB information, and display it to the user in the console. As mentioned in the introduction, we will use an iterative build process to mimic a natural development cycle. Each iteration will build upon the previous while we explore new features and methods. We will encourage the development of additional iterations with challenges at the end of the chapter.

Overview

Before developing any code, let's identify the requirements and features our script must possess to accomplish the desired task. We will need to execute the following steps:

  1. Open the log file and read all lines.
  2. In each line, check for indicators of USB device entry.
  3. Parse responsive lines for timestamp and device information.
  4. Output the result to the user.

Now, let's examine the log file of interest to determine repetitive structures we can use as footholds in our script to parse relevant data. In the sample USB entry below, we see the device information on line 1 following the text "Device Install (Hardware initiated) ". This device information contains the vendor ID, device product ID, device revision, and the Unique ID of the device.

Each of these elements is separated by either an & or \ character and may contain some additional inconsequential characters. The installation time is recorded on line 2 following the ">>> Section start " text. For our purposes, we are only interested in these two lines. All other surrounding lines will be ignored.

001 >>>  [Setup online Device Install (Hardware initiated) - pci\ven_15ad&dev_07a0&subsys_07a015ad&rev_01\3&18d45aa6&0&a9]
002 >>>  Section start 2010/11/10 10:21:12.593
003 ump: Creating Install Process: DrvInst.exe 10:21:12.593
004 ndv: Retrieving device info...
005 ndv: Setting device parameters...
006 ndv: Searching Driver Store and Device Path...
007 dvi: {Build Driver List} 10:21:12.640
主站蜘蛛池模板: 塔河县| 泰和县| 基隆市| 禄劝| 西吉县| 河北区| 乌鲁木齐县| 交口县| 朝阳市| 芜湖县| 本溪市| 得荣县| 高淳县| 天峻县| 聊城市| 呼玛县| 棋牌| 浑源县| 南康市| 黄浦区| 仪征市| 奉节县| 长兴县| 永胜县| 福清市| 南宁市| 千阳县| 南通市| 仁化县| 古交市| 伊金霍洛旗| 连南| 关岭| 杭锦后旗| 石楼县| 弥勒县| 灵武市| 黑水县| 泸西县| 吉水县| 泾源县|