2022-06-30 12:19:02 -07:00
|
|
|
/*
|
2022-06-30 11:16:29 -07:00
|
|
|
* Note2: If your flash is not formatted as FAT12 previously, you could format it using
|
|
|
|
* follow sketch https://github.com/adafruit/Adafruit_SPIFlash/tree/master/examples/SdFat_format
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
#include "src/keyboard/keyboard.h"
|
|
|
|
#include "src/led/led.h"
|
|
|
|
#include "src/msc/msc.h"
|
|
|
|
#include "src/selector/selector.h"
|
2022-07-03 10:13:32 -07:00
|
|
|
#include "src/attack/attack.h"
|
2022-07-06 12:41:52 -07:00
|
|
|
#include "src/preferences/preferences.h"
|
2022-07-06 14:32:55 -07:00
|
|
|
#include "src/duckparser/duckparser.h"
|
2022-07-13 13:09:51 -07:00
|
|
|
#include "src/format/format.h"
|
2022-06-30 11:16:29 -07:00
|
|
|
|
2022-07-03 10:08:42 -07:00
|
|
|
enum Mode {
|
|
|
|
SETUP, ATTACK
|
|
|
|
};
|
|
|
|
|
|
|
|
Mode mode;
|
|
|
|
|
2022-06-30 11:16:29 -07:00
|
|
|
void setup() {
|
2022-07-06 12:41:52 -07:00
|
|
|
// Initialize all the things
|
2022-06-30 11:16:29 -07:00
|
|
|
debug_init();
|
2022-06-30 12:19:02 -07:00
|
|
|
selector::init();
|
|
|
|
led::init();
|
2022-07-13 15:17:22 -07:00
|
|
|
|
|
|
|
// Initialize memory and ceck for problems
|
|
|
|
if (!msc::init()) {
|
|
|
|
format::start(); // Format the drive
|
|
|
|
|
|
|
|
// If it still fails, blink red LED
|
|
|
|
if (!msc::init()) {
|
|
|
|
while (true) {
|
|
|
|
led::setColor(255, 0, 0);
|
|
|
|
delay(500);
|
|
|
|
led::setColor(0, 0, 0);
|
|
|
|
delay(500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-07-06 15:30:53 -07:00
|
|
|
|
2022-07-06 13:24:23 -07:00
|
|
|
// Read the mode from the toggle switch position
|
|
|
|
mode = selector::read() ? SETUP : ATTACK;
|
2022-06-30 11:16:29 -07:00
|
|
|
|
2022-07-06 12:41:52 -07:00
|
|
|
// Preferences
|
2022-07-13 15:17:22 -07:00
|
|
|
preferences::load();
|
2022-07-06 12:41:52 -07:00
|
|
|
led::setEnable(preferences::ledEnabled());
|
2022-07-06 13:11:25 -07:00
|
|
|
keyboard::setLocale(locale::get(preferences::getDefaultLayout().c_str()));
|
2022-07-06 14:21:07 -07:00
|
|
|
keyboard::setID(preferences::getHidVid(), preferences::getHidPid(), preferences::getHidRev());
|
|
|
|
msc::setID(preferences::getMscVid().c_str(), preferences::getMscPid().c_str(), preferences::getMscRev().c_str());
|
2022-07-06 14:32:55 -07:00
|
|
|
duckparser::setDefaultDelay(preferences::getDefaultDelay());
|
2022-07-06 15:30:53 -07:00
|
|
|
|
2022-07-06 14:03:33 -07:00
|
|
|
// Start Keyboard
|
|
|
|
keyboard::init();
|
2022-07-03 10:08:42 -07:00
|
|
|
|
2022-07-06 14:21:07 -07:00
|
|
|
// Start USB Drive
|
2022-07-06 15:30:53 -07:00
|
|
|
if (preferences::mscEnabled() || (mode == SETUP)) msc::enableDrive();
|
2022-07-06 14:21:07 -07:00
|
|
|
|
2022-07-14 13:30:00 -07:00
|
|
|
// Wait 1s to give the computer time to initialize the keyboard
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
// Disable capslock if needed
|
|
|
|
if (preferences::getDisableCapslock()) {
|
|
|
|
keyboard::disableCapslock();
|
|
|
|
}
|
|
|
|
|
2022-07-13 13:09:51 -07:00
|
|
|
// Format Flash
|
2022-07-13 15:17:22 -07:00
|
|
|
if ((mode == SETUP) && preferences::getFormat()) {
|
|
|
|
led::setColor(255, 255, 255);
|
2022-07-13 13:09:51 -07:00
|
|
|
format::start(preferences::getDriveName().c_str());
|
2022-07-13 15:17:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create preferences file if it doesn't exist yet
|
|
|
|
if (!msc::exists(PREFERENCES_PATH)) {
|
2022-07-13 13:58:16 -07:00
|
|
|
preferences::save();
|
2022-07-13 13:09:51 -07:00
|
|
|
}
|
2022-07-13 13:58:16 -07:00
|
|
|
|
2022-07-03 10:08:42 -07:00
|
|
|
// ========== Setup Mode ========== //
|
|
|
|
if (mode == SETUP) {
|
2022-07-06 15:56:20 -07:00
|
|
|
led::setColor(preferences::getSetupColor()); // Set LED to blue
|
2022-07-03 10:08:42 -07:00
|
|
|
|
|
|
|
while (true) {
|
|
|
|
if (selector::changed()) {
|
|
|
|
mode = selector::read() ? SETUP : ATTACK;
|
|
|
|
|
|
|
|
if (mode == ATTACK) {
|
2022-07-06 15:56:20 -07:00
|
|
|
preferences::load(); // Reload the settings (in case the main script path changed)
|
2022-07-06 15:40:26 -07:00
|
|
|
|
2022-07-06 15:56:20 -07:00
|
|
|
led::setColor(preferences::getAttackColor()); // Turn LED red
|
|
|
|
attack::start(); // Start keystroke injection attack
|
|
|
|
led::setColor(preferences::getSetupColor()); // Set LED to blue
|
2022-07-06 15:40:26 -07:00
|
|
|
|
2022-07-03 10:08:42 -07:00
|
|
|
mode = SETUP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delay(100);
|
|
|
|
}
|
2022-07-01 15:18:33 -07:00
|
|
|
}
|
2022-07-03 10:08:42 -07:00
|
|
|
// ========== Setup Mode ========== //
|
|
|
|
else if (mode == ATTACK) {
|
2022-07-06 15:56:20 -07:00
|
|
|
led::setColor(preferences::getAttackColor()); // Turn LED red
|
|
|
|
attack::start(); // Start keystroke injection attack
|
|
|
|
led::setColor(preferences::getIdleColor()); // Turn LED green
|
2022-07-06 15:05:17 -07:00
|
|
|
|
|
|
|
while (true) {
|
|
|
|
if (selector::changed()) {
|
|
|
|
mode = selector::read() ? SETUP : ATTACK;
|
|
|
|
|
|
|
|
if (mode == ATTACK) {
|
2022-07-06 15:56:20 -07:00
|
|
|
led::setColor(preferences::getAttackColor()); // Turn LED red
|
|
|
|
attack::start(); // Start keystroke injection attack
|
|
|
|
led::setColor(preferences::getIdleColor()); // Turn LED green
|
2022-07-06 15:05:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
delay(100);
|
|
|
|
}
|
2022-07-02 09:10:32 -07:00
|
|
|
}
|
2022-07-03 09:41:25 -07:00
|
|
|
|
2022-07-03 10:08:42 -07:00
|
|
|
debugln("[Finished]");
|
2022-06-30 11:16:29 -07:00
|
|
|
}
|
|
|
|
|
2022-07-03 10:13:32 -07:00
|
|
|
void loop() {}
|