Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions jackit/duckyparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from __future__ import print_function, absolute_import
from jackit import keymap


class DuckyParser(object):
''' Help map ducky like script to HID codes to be sent '''

Expand Down Expand Up @@ -49,11 +48,21 @@ class DuckyParser(object):
'LEFT': [80, 0]
}

# Add mouse button mappings
mouse_map = {
'MOUSE_LEFT': 1,
'MOUSE_RIGHT': 2,
'MOUSE_MIDDLE': 4,
}

blank_entry = {
"mod": 0,
"hid": 0,
"char": '',
"sleep": 0
"sleep": 0,
"mouse_x": 0,
"mouse_y": 0,
"mouse_btn": 0,
}

def __init__(self, attack_script, layout=None):
Expand Down Expand Up @@ -146,7 +155,7 @@ def parse(self):

elif line.startswith("DELAY"):
entry = self.blank_entry.copy()
entry['sleep'] = line.split()[1]
entry['sleep'] = int(line.split()[1])
entries.append(entry)

elif line.startswith("STRING"):
Expand Down Expand Up @@ -187,10 +196,37 @@ def parse(self):
entry['hid'], entry['mod'] = self.char_to_hid('RIGHT')
entries.append(entry)

# Mouse movement parsing
elif line.startswith("MOUSE_MOVE"):
entry = self.blank_entry.copy()
_, x, y = line.split()
entry['mouse_x'] = int(x)
entry['mouse_y'] = int(y)
entries.append(entry)

# Mouse click parsing
elif line.startswith("MOUSE_CLICK"):
entry = self.blank_entry.copy()
parts = line.split()
button = parts[1]
entry['mouse_btn'] = self.mouse_map.get(button.upper(), 0)
if len(parts) > 2:
entry['sleep'] = int(parts[2]) # Optional delay after click
entries.append(entry)

# Mouse press and release parsing
elif line.startswith("MOUSE_DOWN") or line.startswith("MOUSE_UP"):
entry = self.blank_entry.copy()
action, button = line.split()
entry['mouse_btn'] = self.mouse_map.get(button.upper(), 0)
if action == "MOUSE_UP":
entry['mouse_btn'] = -entry['mouse_btn'] # Negative value for release
entries.append(entry)

elif len(line) == 0:
pass

else:
print("CAN'T PROCESS... %s" % line)

return entries
return entries