SR2I207 prodjet, BadUSB with Arduino
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Jean-Marie Mineau eba3e3d864
what?
1 year ago
KeyboardFr Put KeyboardFr in a lib format 1 year ago
demo remove mapping folder, it was screwed anyway 1 year ago
firstTests well, it work, ish 1 year ago
test_keyboard_fr Put KeyboardFr in a lib format 1 year ago
.gitignore what? 1 year ago
README.md remove mapping folder, it was screwed anyway 1 year ago

README.md

Bad Arduino

Project for SR2I 207. We studdy here badUSB with an Arduino Leonardo.

KeyboardFr

Because we are in France (cocorico!), keyboards are in Azerty, but the Arduino librairie emulates a qwerty keyboard. We patched the library (The use of ALT-GR was NOT anticipated in the initial library) and named it KeyboardFr. It is used exactly the same way Keyboard is used, execpte we replace the Keyboard object by KeyboardFr, and include <KeyboardFr.h> instead of <Keyboard.h>.

To use it, we have to put the KeyboardFr folder in the Arduino/libraries/ (the location may vary depending the OS, on linux, it is probably ~/Arduino/libraries/).

Put the KeyboardFr lib in the Arduino libraries

To use it, we have to put the KeyboardFr folder in the Arduino/libraries/ (the location may vary depending the OS, on linux, it is probably ~/Arduino/libraries/).

cp -R KeyboardFr ~/Arduino/libraries/

Exemple

#include <KeyboardFr.h>

void setup() {
  KeyboardFr.begin();

  delay(1000);

  // Open dmenu ( win+d on i3 )
  KeyboardFr.press(KEY_LEFT_GUI);
  KeyboardFr.press('d');
  KeyboardFr.releaseAll();
  delay(100);

  // Open kate (a notepad) 
  KeyboardFr.println("kate");
  delay(1000);

  // Print stuff
  KeyboardFr.println("Lorem ipsum");
}

void loop() {
  delay(10000);
}

How we did the remapping

The SCAN CODE is the code of the physical key presed on the keyboard.

This code is the same whatever the layout, 0x04 is the scancode of the key A on an qwerty layout, but it is the also the scancode of the key Q on a azerty layout.

It's easyer for the hardware, but damm what a mess on the software level.

SO, the scan codes are converted to key codes by the OS, and the keycodes are mapped deppending on the layout. Because it is done in a lot a places in a lot of ways (setxkbmap, loadkeys, ect), it is really hard to get the scancode corresponding to a keys in an azerty layout.

We can get the scan code of a key pressed with this command, but only if the command is run in a tty, not in a terminal emulator, because something somewhere mess whith it in X11.

sudo evtest