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 boot.py to the root of the pico-ducky.
Copy your payload script to the pico-ducky. Copy your payload script to the pico-ducky.
Disconnect the pico from your host PC. 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. 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. Remove the jumper and reconnect to your PC to reprogram.
The default mode is USB mass storage enabled. The default mode is USB mass storage enabled.

View File

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