Add exception handling to file open

This commit is contained in:
dbisu
2022-04-03 13:52:40 -05:00
parent f79fe2cb48
commit e11b087b75
2 changed files with 17 additions and 14 deletions

View File

@@ -50,7 +50,7 @@ Enter setup mode.
Copy boot.py to the root of the pico-ducky.
Copy your payload script to the pico-ducky.
Disconnect the pico from your host PC.
Connect a jumper wire between pin 18 (GND) and pin 20 (GPIO15).
Connect a jumper wire between pin 18 (`GND`) and pin 20 (`GPIO15`).
This will prevent the pico-ducky from showing up as a USB drive when plugged into the target computer.
Remove the jumper and reconnect to your PC to reprogram.
The default mode is USB mass storage enabled.

View File

@@ -127,19 +127,22 @@ def runScript(file):
global defaultDelay
duckyScriptPath = file
f = open(duckyScriptPath,"r",encoding='utf-8')
previousLine = ""
for line in f:
line = line.rstrip()
if(line[0:6] == "REPEAT"):
for i in range(int(line[7:])):
#repeat the last command
parseLine(previousLine)
time.sleep(float(defaultDelay)/1000)
else:
parseLine(line)
previousLine = line
time.sleep(float(defaultDelay)/1000)
try:
f = open(duckyScriptPath,"r",encoding='utf-8')
previousLine = ""
for line in f:
line = line.rstrip()
if(line[0:6] == "REPEAT"):
for i in range(int(line[7:])):
#repeat the last command
parseLine(previousLine)
time.sleep(float(defaultDelay)/1000)
else:
parseLine(line)
previousLine = line
time.sleep(float(defaultDelay)/1000)
except OSError as e:
print("Unable to open file ", file)
def selectPayload():
payload = "payload.dd"