Seytonic / malduino

All the Malduinos!
MIT License
208 stars 50 forks source link

MalDuino Converter: error converting SpecialKey + LetterKey combinations #4

Open davidlj95 opened 7 years ago

davidlj95 commented 7 years ago

The issue

When using the converter to convert from a RubberDucky script containing one or more special keys (CTRL, ALT, SHIFT, ...) followed by one or more an alphabetic letters in order to trigger a hotkey (like CTRL + A, CTRL + ALT + B, ...) the conversion generated does not provide a working script.

Example: Converting

CTRL ALT b
CTRL s

outputs

    delay(defaultDelay);
    Keyboard.press(KEY_LEFT_CTRL);
    Keyboard.press(KEY_LEFT_ALT);
    Keyboard.press(98);
    Keyboard.releaseAll();

    delay(defaultDelay);
    Keyboard.press(KEY_LEFT_CTRL);
    Keyboard.press(115);
    Keyboard.releaseAll();

but as the b and s letters are converted as their ASCII equivalents so their keycodes won't be triggered, making the hotkey combination never trigger.

Temporary workaround

Meanwhile the converter gets fixed, the following workaround can be used after the conversion has been generated. This has to be done for each Keyboard.press function call whose argument is a decimal integer and corresponds to the conversion of a special key(s) with alphabetic letter(s) RubberDucky script line

  1. Look for the letter keycode In the first example, we wanted CTRL + ALT + b and b was not properly converted with its keycode. We have to look in USB HID Usage Tables (page 53) for our letter keycode. We see that b keycode is, in decimal, the number 5.

  2. Change the letter keycode Now we have to change the converted ASCII number (in the example Keyboard.press(98), 98) by the obtained keycode for our letter from the usage tables (5 for key b) plus 136 (therefore 141). In our example, the line would be changed by:

    Keyboard.press(141)

    And for CTRL + S we would have changed Keyboard.press(115); for the following line Keyboard.press(158); (s keycode is 22, plus 136 equals 158)

The 136 sum operation is because of the generated Keyboard.cpp by the MalDuino converter, as arguments greater / equal than 136 are raw key codes - 136.

In order to solve it, either the converter JavaScript code or the Keyboard::press function can be changed

jtagcat commented 4 years ago

USB HID Usage Tables -> https://web.archive.org/web/20171103003506/https://www.usb.org/developers/hidpage/Hut1_12v2.pdf

jtagcat commented 4 years ago

Anything for Elite (where everything is already plain text)?