2021-08-19 00:18:42 +00:00
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
#include "helpers/infrared_parser.h"
|
|
|
|
#include "infrared_app_brute_force.h"
|
|
|
|
#include "infrared_app_signal.h"
|
2021-07-22 00:07:00 +00:00
|
|
|
#include <memory>
|
2021-08-19 00:18:42 +00:00
|
|
|
#include <m-string.h>
|
|
|
|
#include <furi.h>
|
2021-06-25 13:52:27 +00:00
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredAppBruteForce::add_record(int index, const char* name) {
|
2021-06-25 13:52:27 +00:00
|
|
|
records[name].index = index;
|
|
|
|
records[name].amount = 0;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
bool InfraredAppBruteForce::calculate_messages() {
|
2022-01-10 17:13:41 +00:00
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
Storage* storage = static_cast<Storage*>(furi_record_open("storage"));
|
2022-02-18 19:53:46 +00:00
|
|
|
FlipperFormat* ff = flipper_format_file_alloc(storage);
|
|
|
|
result = flipper_format_file_open_existing(ff, universal_db_filename);
|
2021-06-25 13:52:27 +00:00
|
|
|
|
2022-01-10 17:13:41 +00:00
|
|
|
if(result) {
|
2022-02-25 15:22:58 +00:00
|
|
|
InfraredAppSignal signal;
|
2021-07-22 00:07:00 +00:00
|
|
|
|
2022-01-10 17:13:41 +00:00
|
|
|
string_t signal_name;
|
|
|
|
string_init(signal_name);
|
2022-02-18 19:53:46 +00:00
|
|
|
while(flipper_format_read_string(ff, "name", signal_name)) {
|
2022-01-10 17:13:41 +00:00
|
|
|
auto element = records.find(string_get_cstr(signal_name));
|
|
|
|
if(element != records.cend()) {
|
|
|
|
++element->second.amount;
|
|
|
|
}
|
2021-06-25 13:52:27 +00:00
|
|
|
}
|
2022-01-10 17:13:41 +00:00
|
|
|
string_clear(signal_name);
|
2021-06-25 13:52:27 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 19:53:46 +00:00
|
|
|
flipper_format_free(ff);
|
2022-01-10 17:13:41 +00:00
|
|
|
furi_record_close("storage");
|
|
|
|
return result;
|
2021-06-25 13:52:27 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredAppBruteForce::stop_bruteforce() {
|
2021-07-22 00:07:00 +00:00
|
|
|
furi_assert((current_record.size()));
|
|
|
|
|
2021-06-25 13:52:27 +00:00
|
|
|
if(current_record.size()) {
|
2022-01-10 17:13:41 +00:00
|
|
|
furi_assert(ff);
|
2021-06-25 13:52:27 +00:00
|
|
|
current_record.clear();
|
2022-02-18 19:53:46 +00:00
|
|
|
flipper_format_free(ff);
|
2022-01-10 17:13:41 +00:00
|
|
|
furi_record_close("storage");
|
2021-06-25 13:52:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
bool InfraredAppBruteForce::send_next_bruteforce(void) {
|
2021-06-25 13:52:27 +00:00
|
|
|
furi_assert(current_record.size());
|
2022-01-10 17:13:41 +00:00
|
|
|
furi_assert(ff);
|
2021-06-25 13:52:27 +00:00
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
InfraredAppSignal signal;
|
2022-01-10 17:13:41 +00:00
|
|
|
std::string signal_name;
|
|
|
|
bool result = false;
|
2021-06-25 13:52:27 +00:00
|
|
|
do {
|
2022-02-25 15:22:58 +00:00
|
|
|
result = infrared_parser_read_signal(ff, signal, signal_name);
|
2022-01-10 17:13:41 +00:00
|
|
|
} while(result && current_record.compare(signal_name));
|
2021-06-25 13:52:27 +00:00
|
|
|
|
2022-01-10 17:13:41 +00:00
|
|
|
if(result) {
|
|
|
|
signal.transmit();
|
2021-06-25 13:52:27 +00:00
|
|
|
}
|
2022-01-10 17:13:41 +00:00
|
|
|
return result;
|
2021-06-25 13:52:27 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
bool InfraredAppBruteForce::start_bruteforce(int index, int& record_amount) {
|
2021-07-22 00:07:00 +00:00
|
|
|
bool result = false;
|
|
|
|
record_amount = 0;
|
|
|
|
|
2021-06-25 13:52:27 +00:00
|
|
|
for(const auto& it : records) {
|
|
|
|
if(it.second.index == index) {
|
|
|
|
record_amount = it.second.amount;
|
2021-07-22 00:07:00 +00:00
|
|
|
if(record_amount) {
|
|
|
|
current_record = it.first;
|
|
|
|
}
|
2021-06-25 13:52:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(record_amount) {
|
2022-01-10 17:13:41 +00:00
|
|
|
Storage* storage = static_cast<Storage*>(furi_record_open("storage"));
|
2022-02-18 19:53:46 +00:00
|
|
|
ff = flipper_format_file_alloc(storage);
|
|
|
|
result = flipper_format_file_open_existing(ff, universal_db_filename);
|
2021-07-22 00:07:00 +00:00
|
|
|
if(!result) {
|
2022-02-18 19:53:46 +00:00
|
|
|
flipper_format_free(ff);
|
2022-01-10 17:13:41 +00:00
|
|
|
furi_record_close("storage");
|
2021-06-25 13:52:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-22 00:07:00 +00:00
|
|
|
return result;
|
2021-06-25 13:52:27 +00:00
|
|
|
}
|