Skip to content

Commit

Permalink
Correct the implementation of DEFAULT_DELAY
Browse files Browse the repository at this point in the history
  • Loading branch information
kevthehermit committed Sep 12, 2016
1 parent 946d943 commit 613fb26
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## [0.9](https://github.com/kevthehermit/DuckToolkit/tree/0.2) (2016-11-12)
- Correct the implementation of DEFAULT_DELAY

## [0.8](https://github.com/kevthehermit/DuckToolkit/tree/0.2) (2016-09-05)
- Fix null padding for low delay values

Expand Down
41 changes: 39 additions & 2 deletions ducktoolkit/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ def parse_text(duck_text, lang_file):
duck_text = duck_text.replace("\r", "")
cmd = instruction = False

default_delay = 0

for line in duck_text.split('\n'):
if len(line) > 0:

# REM Comments
if line.startswith('REM') or line.startswith('rem'):
continue
Expand All @@ -81,6 +83,15 @@ def parse_text(duck_text, lang_file):
cmd = parsed_line[0].strip()
instruction = False

# Default Delay
if cmd in ['DEFAULT_DELAY', 'DEFAULTDELAY']:
try:
default_delay = int(instruction)
continue
except Exception as e:
error_line = e
return error_line

# Repeat
repeat_count = 1
if cmd in ['REPEAT', 'repeat']:
Expand All @@ -94,7 +105,6 @@ def parse_text(duck_text, lang_file):
instruction = last_instruction

for i in range(repeat_count):

if cmd == 'STRING':
for char in instruction:

Expand All @@ -112,8 +122,11 @@ def parse_text(duck_text, lang_file):
encoded_file.append(lang_file[char])

elif cmd == 'DELAY':
delay = int(instruction)
delay = add_delay(int(instruction))

encoded_file.append(delay)

'''
# divide by 255 add that many 0xff
# convert the reminder to hex
# e.g. 750 = FF FF F0
Expand All @@ -125,6 +138,7 @@ def parse_text(duck_text, lang_file):
_delay = hex(delay)[2:].zfill(2)
encoded_file.append('00{0}'.format(str(_delay)))
delay = 0
'''

elif cmd in lang_file.iterkeys():
if not instruction:
Expand All @@ -140,9 +154,32 @@ def parse_text(duck_text, lang_file):
else:
err_line = "Command {0} Not in Language File".format(cmd)
return err_line

# Add Default Delay
if default_delay:
encoded_file.append(add_delay(int(default_delay)))

return encoded_file


def add_delay(delay_value):

delay_return = ''

# divide by 255 add that many 0xff
# convert the reminder to hex
# e.g. 750 = FF FF F0
while delay_value > 0:
if delay_value > 255:
delay_return += '00FF'
delay_value -= 255
else:
_delay = hex(delay_value)[2:].zfill(2)
delay_return += '00{0}'.format(str(_delay))
delay_value = 0
return delay_return


def encode_script(duck_text, duck_lang):

lang_dir = os.path.join(os.path.dirname(__file__), 'languages')
Expand Down
2 changes: 0 additions & 2 deletions ducktoolkit/languages/gb.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@
"ESC": "29",
"ESCAPE": "29",
"DELAY": "00ff00ff00ff",
"DEFAULT_DELAY": "00ff00ff00ff",
"DEFAULTDELAY": "00ff00ff00ff",
"PRINTSCREEN": "46",
"INSERT": "49",
"HOME": "4a",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='ducktoolkit',
version='0.8',
version='0.9',
author='Kevin Breen, James Hall',
author_email='[email protected]',
description="USB Rubber Ducky Toolkit",
Expand Down

0 comments on commit 613fb26

Please sign in to comment.