#include "config.h" #include "debug.h" #include "src/hid/hid.h" #include "src/hid/keyboard.h" #include "src/led/led.h" #include "src/msc/msc.h" #include "src/selector/selector.h" #include "src/attack/attack.h" #include "src/preferences/preferences.h" #include "src/duckparser/duckparser.h" #include "src/tasks/tasks.h" bool started = false; void update() { led::update(); // cli::update(); } void setup() { // Start Serial (for debug) debug_init(); // Initialize memory and check for problems if (!msc::init()) { led::startBlink(255, 0, 0, 200); return; } // Load setting and set USB Device IDs preferences::load(); hid::setID(preferences::getHidVid(), preferences::getHidPid(), preferences::getHidRev()); msc::setID(preferences::getMscVid().c_str(), preferences::getMscPid().c_str(), preferences::getMscRev().c_str()); // Read mode from selector switch selector::init(); // Start Keyboard hid::init(); // Start USB Drive if (preferences::mscEnabled() || (selector::mode() == SETUP)){ msc::enableDrive(); } // Start LED led::init(); led::setEnable(preferences::ledEnabled()); if (selector::mode() == SETUP) { led::setColor(preferences::getSetupColor()); } else { led::setColor(preferences::getAttackColor()); } // Attack settings keyboard::setLocale(locale::get(preferences::getDefaultLayout().c_str())); duckparser::setDefaultDelay(preferences::getDefaultDelay()); // Format Flash (if specified in preferences.json) if ((selector::mode() == SETUP) && preferences::getFormat()) { led::setColor(255, 255, 255); msc::format(preferences::getDriveName().c_str()); } // Create preferences file if it doesn't exist yet if (!msc::exists(PREFERENCES_PATH)) { preferences::save(); } // Setup background tasks tasks::setCallback(update); // Start attack if (selector::mode() == ATTACK && !preferences::getRunOnIndicator()) { delay(1000); // Wait 1s to give the computer time to initialize the keyboard attack::start(); // Start keystroke injection attack } started = true; debugln("[Started]"); } void loop() { taks:update(); if (started && selector::changed() && selector::read() == ATTACK) { // ========== Setup Mode ========== // if (selector::mode() == SETUP) { preferences::load(); // Reload the settings (in case the main script path changed) attack::start(); // Start keystroke injection attack led::setColor(preferences::getSetupColor()); // Set LED to blue } // ========== Attack Mode ========== // else if (selector::mode() == ATTACK) { // Only start the attack if run-on-indicator is disabled, or indicator actually changed if (!preferences::getRunOnIndicator() || hid::indicatorChanged()) { attack::start(); // Run script led::setColor(preferences::getIdleColor()); // Set LED to green } } } }