2021-08-19 00:18:42 +00:00
|
|
|
|
2022-01-10 17:13:41 +00:00
|
|
|
#include "helpers/irda_parser.h"
|
|
|
|
#include "irda_app_brute_force.h"
|
|
|
|
#include "irda_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>
|
2022-01-05 16:10:18 +00:00
|
|
|
#include <file_worker_cpp.h>
|
2021-06-25 13:52:27 +00:00
|
|
|
|
|
|
|
void IrdaAppBruteForce::add_record(int index, const char* name) {
|
|
|
|
records[name].index = index;
|
|
|
|
records[name].amount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IrdaAppBruteForce::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) {
|
|
|
|
IrdaAppSignal 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
|
|
|
}
|
|
|
|
|
|
|
|
void IrdaAppBruteForce::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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-16 16:43:54 +00:00
|
|
|
bool IrdaAppBruteForce::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-01-10 17:13:41 +00:00
|
|
|
IrdaAppSignal signal;
|
|
|
|
std::string signal_name;
|
|
|
|
bool result = false;
|
2021-06-25 13:52:27 +00:00
|
|
|
do {
|
2022-01-10 17:13:41 +00:00
|
|
|
result = irda_parser_read_signal(ff, signal, signal_name);
|
|
|
|
} 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
|
|
|
}
|
|
|
|
|
|
|
|
bool IrdaAppBruteForce::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
|
|
|
}
|