-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
150 lines (126 loc) · 4.24 KB
/
main.cpp
File metadata and controls
150 lines (126 loc) · 4.24 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <thread>
#include "flipper_scan/flipper_scan.h"
#include "ble_spam/ble_spam.h"
#include "core/MessageDispatcher.h"
#include <cli/cli.h>
#include <cli/clifilesession.h>
#include "core/globals.h"
int main() {
isFlipperScanRunning.store(false);
isBleSpamRunning.store(false);
isMessageDispatcherRunning.store(true);
// ---- Dispatcher (ONE output authority)
MessageDispatcher msgDispatcher(std::cout);
auto rootMenu = std::make_unique<cli::Menu>("BTMagus");
// ================== FLIPPER SCAN ==================
auto flipperScanMenu = std::make_unique<cli::Menu>(
"flipper_scan",
"Scan for nearby flippers",
"flipper_scan"
);
flipperScanMenu->Insert(
"run",
[&msgDispatcher](std::ostream& out) {
if (isFlipperScanRunning.load()) {
out << "Scan is already running!\n";
return;
}
out << "Scan is starting...\n";
isFlipperScanRunning.store(true);
std::thread(scanStart, std::ref(msgDispatcher)).detach();
},
"Scan for nearby flippers"
);
flipperScanMenu->Insert(
"stop",
[](std::ostream& out) {
if (!isFlipperScanRunning.load()) {
out << "No scan is currently running.\n";
return;
}
out << "Stopping scan...\n";
isFlipperScanRunning.store(false);
},
"Stop the current scan"
);
flipperScanMenu->Insert(
"status",
[](std::ostream& out) {
out << (isFlipperScanRunning.load()
? "Scan is currently RUNNING\n"
: "Scan is NOT running\n");
},
"Check scan status"
);
flipperScanMenu->Insert(
"show",
[](std::ostream& out) {
std::lock_guard lock(BTDevicesMutex);
if (BTDevices.empty()) {
out << "You haven't scanned for bluetooth devices yet!\n";
return;
}
bool has_flipper = false;
for (auto& device : BTDevices) {
if (device.amIFlipper() || device.amISpoofedFlipper()) {
has_flipper = true;
out << "------------------------------\n";
out << (device.amIFlipper() ? "🐬 | " : "🎭 | ");
out << device.Name << " | " << device.Address << '\n';
out << "UUIDS:\n";
for (const auto& uuid : device.Uuids)
out << uuid << '\n';
out << "------------------------------\n";
}
}
if (!has_flipper)
out << "No flippers have been detected yet.\n";
},
"Show a list of detected flippers"
);
// ================== BLE SPAM ==================
auto bleSpamMenu = std::make_unique<cli::Menu>(
"ble_spam",
"Spam BLE devices with false advertisements.",
"ble_spam"
);
bleSpamMenu->Insert(
"run",
[&msgDispatcher](std::ostream& out) {
if (isBleSpamRunning.load()) {
out << "BLE spam already running.\n";
return;
}
out << "Running BLE spam...\n";
isBleSpamRunning.store(true);
std::thread(startBleSpam, std::ref(msgDispatcher)).detach();
},
"Run BLE Spam"
);
bleSpamMenu->Insert(
"stop",
[](std::ostream& out) {
if (!isBleSpamRunning.load()) {
out << "BLE spam is not currently running.\n";
return;
}
out << "Stopping BLE spam...\n";
isBleSpamRunning.store(false);
},
"Stop BLE spam"
);
// ================== MENU SETUP ==================
rootMenu->Insert(std::move(flipperScanMenu));
rootMenu->Insert(std::move(bleSpamMenu));
cli::Cli cli(std::move(rootMenu));
// ================== EXIT ==================
cli.ExitAction([](auto& out) {
isFlipperScanRunning.store(false);
isBleSpamRunning.store(false);
isMessageDispatcherRunning.store(false);
out << "Bye.\n";
});
cli::CliFileSession input(cli);
input.Start();
return 0;
}