-
Notifications
You must be signed in to change notification settings - Fork 9
/
USBNova.ino
136 lines (111 loc) · 4.42 KB
/
USBNova.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#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"
#include "src/cli/cli.h"
void update() {
led::update();
// cli::update();
}
void setup() {
// Start Serial (for debug) or disable it
debug_init();
// Initialize memory and check for problems
if (!msc::init()) {
led::setColor(255, 0, 0, 200);
return;
}
// Read mode from selector switch
selector::init();
// Load setting and set USB Device IDs
preferences::reset();
preferences::load();
if (selector::mode() == SETUP) preferences::save();
hid::setID(preferences::getVID(), preferences::getPID(), preferences::getVersion());
hid::setSerial(preferences::getSerial());
hid::setManufacturer(preferences::getManufacturer());
hid::setProduct(preferences::getProduct());
// Start Keyboard
if ((selector::mode() == ATTACK) || preferences::hidEnabled()) {
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();
}
// Create main_script.txt if it doesn't exist yet
if (!msc::exists(preferences::getMainScript().c_str())) {
char message[21];
sprintf(message, "# USB Nova (v%s)\n", VERSION);
msc::write(preferences::getMainScript().c_str(), message, 20);
}
// Setup background tasks
tasks::setCallback(update);
// Make sure we don't start with a mode change
selector::changed();
// Start attack
if ((selector::mode() == ATTACK) && !preferences::getRunOnIndicator()) {
delay(preferences::getInitialDelay()); // Wait to give computer time to init keyboard
attack::start(); // Start keystroke injection attack
led::setColor(preferences::getIdleColor()); // Set LED to green
}
// Setup CLI
#ifdef ENABLE_DEBUG
cli::init();
#endif // ifdef ENABLE_DEBUG
debugln("[Started]");
}
void loop() {
tasks::update();
cli::update();
if (selector::read() != ATTACK) return;
// Only start the attack if run-on-indicator is disabled, or indicator actually changed
if (preferences::getRunOnIndicator() && hid::indicatorChanged()) {
delay(100);
attack::start(); // Run script
led::setColor(preferences::getIdleColor()); // Set LED to green
} else if (selector::changed()) {
// ========== Setup Mode ========== //
if ((selector::mode() == SETUP) && preferences::hidEnabled()) {
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());
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
attack::start(); // Run script
led::setColor(preferences::getIdleColor()); // Set LED to green
}
}
}