mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-03-12 15:10:49 +00:00
BLE TX; Added feature to randomize found substring in data (#1609)
This commit is contained in:
parent
a6ed6e3099
commit
c486572d3d
@ -188,9 +188,35 @@ void BLETxView::start() {
|
||||
is_running = true;
|
||||
}
|
||||
|
||||
char advertisementData[63] = {0};
|
||||
|
||||
strcpy(advertisementData, packets[current_packet].advertisementData);
|
||||
|
||||
if (!randomString.empty()) {
|
||||
// Check if the substring exists within the larger string
|
||||
const char* result = strstr(advertisementData, randomString.c_str());
|
||||
|
||||
if (result != NULL) {
|
||||
// Calculate the start and end positions of the substring
|
||||
int startPos = result - advertisementData;
|
||||
int endPos = startPos + randomString.length();
|
||||
|
||||
for (int i = startPos; i < endPos; i++) {
|
||||
int min = 0;
|
||||
int max = 15;
|
||||
|
||||
int hexDigit = min + std::rand() % (max - min + 1);
|
||||
|
||||
// Map the random number to a hexadecimal digit
|
||||
char randomHexChar = (hexDigit < 10) ? ('0' + hexDigit) : ('A' + hexDigit - 10);
|
||||
advertisementData[i] = randomHexChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Setup next packet configuration.
|
||||
progressbar.set_max(packets[current_packet].packet_count);
|
||||
baseband::set_btletx(channel_number, random_mac ? randomMac : packets[current_packet].macAddress, packets[current_packet].advertisementData, pduType);
|
||||
baseband::set_btletx(channel_number, random_mac ? randomMac : packets[current_packet].macAddress, advertisementData, pduType);
|
||||
}
|
||||
|
||||
void BLETxView::stop() {
|
||||
@ -284,6 +310,7 @@ BLETxView::BLETxView(NavigationView& nav)
|
||||
&options_speed,
|
||||
&options_channel,
|
||||
&options_adv_type,
|
||||
&button_random,
|
||||
&label_packet_index,
|
||||
&text_packet_index,
|
||||
&label_packets_sent,
|
||||
@ -357,6 +384,16 @@ BLETxView::BLETxView(NavigationView& nav)
|
||||
button_switch.on_select = [&nav](Button&) {
|
||||
nav.replace<BLERxView>();
|
||||
};
|
||||
|
||||
button_random.on_select = [this](Button&) {
|
||||
text_prompt(
|
||||
nav_,
|
||||
randomBuffer,
|
||||
64,
|
||||
[this](std::string& buffer) {
|
||||
on_random_data_change(buffer);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
BLETxView::BLETxView(
|
||||
@ -436,6 +473,10 @@ void BLETxView::on_data(uint32_t value, bool is_data) {
|
||||
console.write(str_console);
|
||||
}
|
||||
|
||||
void BLETxView::on_random_data_change(std::string value) {
|
||||
randomString = value;
|
||||
}
|
||||
|
||||
void BLETxView::update_current_packet(BLETxPacket packet, uint32_t currentIndex) {
|
||||
std::string formattedMacAddress = to_string_formatted_mac_address(packet.macAddress);
|
||||
|
||||
|
@ -121,6 +121,7 @@ class BLETxView : public View {
|
||||
void on_file_changed(const std::filesystem::path& new_file_path);
|
||||
void on_save_file(const std::string value);
|
||||
void on_tx_progress(const bool done);
|
||||
void on_random_data_change(std::string value);
|
||||
void update_current_packet(BLETxPacket packet, uint32_t currentIndex);
|
||||
|
||||
NavigationView& nav_;
|
||||
@ -162,11 +163,14 @@ class BLETxView : public View {
|
||||
static constexpr uint32_t max_packet_repeat_count{UINT32_MAX};
|
||||
static constexpr uint32_t max_num_packets{32};
|
||||
|
||||
std::string randomBuffer{};
|
||||
std::string randomString{};
|
||||
|
||||
BLETxPacket packets[max_num_packets];
|
||||
|
||||
PKT_TYPE pduType = {PKT_TYPE_DISCOVERY};
|
||||
|
||||
static constexpr auto header_height = 9 * 16;
|
||||
static constexpr auto header_height = 10 * 16;
|
||||
static constexpr auto switch_button_height = 3 * 16;
|
||||
|
||||
Button button_open{
|
||||
@ -238,32 +242,36 @@ class BLETxView : public View {
|
||||
{"SCAN_RSP", PKT_TYPE_SCAN_RSP},
|
||||
{"CONNECT_REQ", PKT_TYPE_CONNECT_REQ}}};
|
||||
|
||||
Button button_random{
|
||||
{0 * 8, 8 * 8, 11 * 8, 16},
|
||||
"Random Data"};
|
||||
|
||||
Labels label_packet_index{
|
||||
{{0 * 8, 10 * 8}, "Packet Index:", Color::light_grey()}};
|
||||
{{0 * 8, 12 * 8}, "Packet Index:", Color::light_grey()}};
|
||||
|
||||
Text text_packet_index{
|
||||
{13 * 8, 5 * 16, 12 * 8, 16},
|
||||
"-"};
|
||||
|
||||
Labels label_packets_sent{
|
||||
{{0 * 8, 12 * 8}, "Packets Left:", Color::light_grey()}};
|
||||
|
||||
Text text_packets_sent{
|
||||
{13 * 8, 6 * 16, 12 * 8, 16},
|
||||
"-"};
|
||||
|
||||
Labels label_packets_sent{
|
||||
{{0 * 8, 14 * 8}, "Packets Left:", Color::light_grey()}};
|
||||
|
||||
Text text_packets_sent{
|
||||
{13 * 8, 6 * 16, 14 * 8, 16},
|
||||
"-"};
|
||||
|
||||
Labels label_mac_address{
|
||||
{{0 * 8, 14 * 8}, "Mac Address:", Color::light_grey()}};
|
||||
{{0 * 8, 16 * 8}, "Mac Address:", Color::light_grey()}};
|
||||
|
||||
Text text_mac_address{
|
||||
{12 * 8, 7 * 16, 20 * 8, 16},
|
||||
{12 * 8, 8 * 16, 20 * 8, 16},
|
||||
"-"};
|
||||
|
||||
Labels label_data_packet{
|
||||
{{0 * 8, 16 * 8}, "Packet Data:", Color::light_grey()}};
|
||||
{{0 * 8, 16 * 9}, "Packet Data:", Color::light_grey()}};
|
||||
|
||||
Console console{
|
||||
{0, 8 * 16, 240, 240}};
|
||||
{0, 9 * 16, 240, 240}};
|
||||
|
||||
Button button_save_packet{
|
||||
{1 * 8, 16 * 16, 13 * 8, 2 * 16},
|
||||
|
Loading…
x
Reference in New Issue
Block a user