USBNova/USBNova.ino

150 lines
4.7 KiB
Arduino
Raw Normal View History

#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"
2022-07-03 10:13:32 -07:00
#include "src/attack/attack.h"
#include "src/preferences/preferences.h"
2022-07-06 14:32:55 -07:00
#include "src/duckparser/duckparser.h"
#include "src/tasks/tasks.h"
2022-07-20 15:11:14 -07:00
#include "src/cli/cli.h"
2022-11-02 04:02:15 -07:00
#include "src/msc/format.h"
2022-07-16 03:44:41 -07:00
void update() {
led::update();
// cli::update();
}
void setup() {
2022-10-31 11:05:57 -07:00
led::init();
2022-07-16 03:44:41 -07:00
// Start Serial (for debug)
debug_init();
2022-07-16 03:44:41 -07:00
// Initialize memory and check for problems
if (!msc::init()) {
2022-11-01 04:23:14 -07:00
debugln("Couldnt init SD");
led::setColor(255, 0, 0, 200);
2022-10-31 11:05:57 -07:00
while(true) {
2022-11-01 04:23:14 -07:00
taks:update();
2022-10-31 11:05:57 -07:00
}
2022-07-16 03:44:41 -07:00
return;
}
2022-11-02 06:17:30 -07:00
// Read mode from selector switch
selector::init();
2022-07-16 03:44:41 -07:00
// Load setting and set USB Device IDs
preferences::load();
2022-07-06 15:30:53 -07:00
2022-11-02 06:17:30 -07:00
if(selector::position() == 2) {
hid::setID(preferences::getHid2Vid(), preferences::getHid2Pid(), preferences::getHidRev());
} else {
hid::setID(preferences::getHid1Vid(), preferences::getHid1Pid(), preferences::getHidRev());
}
msc::setID(preferences::getMscVid().c_str(), preferences::getMscPid().c_str(), preferences::getMscRev().c_str());
2022-07-16 03:44:41 -07:00
// Start Keyboard
2022-11-02 03:14:29 -07:00
if (selector::mode() == ATTACK || preferences::hidEnabled()) {
hid::init();
}
2022-07-16 03:44:41 -07:00
2022-07-06 14:21:07 -07:00
// Start USB Drive
2022-07-16 03:44:41 -07:00
if (preferences::mscEnabled() || (selector::mode() == SETUP)){
msc::enableDrive();
}
2022-07-06 14:21:07 -07:00
2022-07-16 03:44:41 -07:00
// Start LED
2022-07-15 16:06:25 -07:00
led::init();
led::setEnable(preferences::ledEnabled());
2022-07-16 03:44:41 -07:00
if (selector::mode() == SETUP) {
led::setColor(preferences::getSetupColor());
} else {
led::setColor(preferences::getAttackColor());
}
// Attack settings
2022-07-15 16:06:25 -07:00
keyboard::setLocale(locale::get(preferences::getDefaultLayout().c_str()));
duckparser::setDefaultDelay(preferences::getDefaultDelay());
2022-11-02 04:02:15 -07:00
2022-07-16 03:44:41 -07:00
// Format Flash (if specified in preferences.json)
2022-07-15 15:36:31 -07:00
if ((selector::mode() == SETUP) && preferences::getFormat()) {
led::setColor(255, 255, 255);
2022-07-16 02:53:03 -07:00
msc::format(preferences::getDriveName().c_str());
2022-11-02 04:02:15 -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-11-02 04:08:38 -07:00
// Create 1.txt file if it doesn't exist yet
if (msc::find(1) == "") {
msc::write("1.txt", "# Hello World\n", 14);
}
// Create 2.txt file if it doesn't exist yet
if (msc::find(2) == "") {
msc::write("2.txt", "# Hello World\n", 14);
}
2022-07-13 13:58:16 -07:00
2022-07-16 03:44:41 -07:00
// Setup background tasks
tasks::setCallback(update);
2022-07-15 16:06:25 -07:00
// Make sure we don't start with a mode change
selector::changed();
2022-07-16 03:44:41 -07:00
// Start attack
2022-11-07 12:34:43 -08:00
if (selector::mode() == ATTACK && !preferences::getRunOnIndicator()) {
2022-07-16 16:43:15 -07:00
delay(preferences::getInitialDelay()); // Wait to give computer time to init keyboard
2022-07-16 03:44:41 -07:00
attack::start(); // Start keystroke injection attack
led::setColor(preferences::getIdleColor()); // Set LED to green
2022-07-15 16:06:25 -07:00
}
2022-07-20 15:11:14 -07:00
// Setup CLI
cli::init();
2022-07-16 03:44:41 -07:00
debugln("[Started]");
}
2022-07-16 03:44:41 -07:00
void loop() {
2022-11-07 12:34:43 -08:00
taks:update();
2022-07-20 15:11:14 -07:00
cli::update();
2022-10-31 12:53:17 -07:00
if(selector::read() != ATTACK) return;
// Only start the attack if run-on-indicator is disabled, or indicator actually changed
2022-11-07 12:34:43 -08:00
if(preferences::getRunOnIndicator() && hid::indicatorChanged()) {
2022-10-31 12:53:17 -07:00
attack::start(); // Run script
led::setColor(preferences::getIdleColor()); // Set LED to green
2022-11-02 03:01:33 -07:00
// Don't run again
while(true) {
tasks::update();
cli::update();
}
2022-10-31 12:53:17 -07:00
} else if (selector::changed()) {
2022-07-16 03:44:41 -07:00
// ========== Setup Mode ========== //
2022-11-02 03:14:29 -07:00
if (selector::mode() == SETUP && preferences::hidEnabled()) {
2022-07-16 03:44:41 -07:00
preferences::load(); // Reload the settings (in case the main script path changed)
// Attack settings
keyboard::setLocale(locale::get(preferences::getDefaultLayout().c_str()));
duckparser::setDefaultDelay(preferences::getDefaultDelay());
2022-07-16 03:44:41 -07:00
attack::start(); // Start keystroke injection attack
led::setColor(preferences::getSetupColor()); // Set LED to blue
}
2022-07-16 03:44:41 -07:00
// ========== Attack Mode ========== //
else if (selector::mode() == ATTACK) {
// Only start the attack if run-on-indicator is disabled, or indicator actually changed
2022-10-31 12:53:17 -07:00
attack::start(); // Run script
led::setColor(preferences::getIdleColor()); // Set LED to green
}
}
}