2021-06-25 13:52:27 +00:00
|
|
|
#include "irda-app-brute-force.hpp"
|
|
|
|
|
|
|
|
void IrdaAppBruteForce::add_record(int index, const char* name) {
|
|
|
|
records[name].index = index;
|
|
|
|
records[name].amount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IrdaAppBruteForce::calculate_messages() {
|
|
|
|
bool fs_res = false;
|
|
|
|
fs_res = file_parser.get_fs_api().file.open(
|
|
|
|
&file, universal_db_filename, FSAM_READ, FSOM_OPEN_EXISTING);
|
|
|
|
if(!fs_res) {
|
|
|
|
file_parser.get_sd_api().show_error(file_parser.get_sd_api().context, "Can't open file");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
file_parser.reset();
|
|
|
|
while(1) {
|
2021-07-16 16:43:54 +00:00
|
|
|
auto message = file_parser.read_signal(&file);
|
2021-06-25 13:52:27 +00:00
|
|
|
if(!message) break;
|
|
|
|
auto element = records.find(message->name);
|
|
|
|
if(element != records.cend()) {
|
|
|
|
++element->second.amount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
file_parser.get_fs_api().file.close(&file);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrdaAppBruteForce::stop_bruteforce() {
|
|
|
|
if(current_record.size()) {
|
|
|
|
file_parser.get_fs_api().file.close(&file);
|
|
|
|
current_record.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: [FL-1418] replace with timer-chained consequence of messages.
|
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());
|
|
|
|
|
2021-07-16 16:43:54 +00:00
|
|
|
std::unique_ptr<IrdaAppFileParser::IrdaFileSignal> file_signal;
|
2021-06-25 13:52:27 +00:00
|
|
|
|
|
|
|
do {
|
2021-07-16 16:43:54 +00:00
|
|
|
file_signal = file_parser.read_signal(&file);
|
|
|
|
} while(file_signal && current_record.compare(file_signal->name));
|
2021-06-25 13:52:27 +00:00
|
|
|
|
2021-07-16 16:43:54 +00:00
|
|
|
if(file_signal) {
|
|
|
|
file_signal->signal.transmit();
|
2021-06-25 13:52:27 +00:00
|
|
|
}
|
2021-07-16 16:43:54 +00:00
|
|
|
return !!file_signal;
|
2021-06-25 13:52:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IrdaAppBruteForce::start_bruteforce(int index, int& record_amount) {
|
|
|
|
file_parser.reset();
|
|
|
|
for(const auto& it : records) {
|
|
|
|
if(it.second.index == index) {
|
|
|
|
record_amount = it.second.amount;
|
|
|
|
current_record = it.first;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(record_amount) {
|
|
|
|
bool fs_res = file_parser.get_fs_api().file.open(
|
|
|
|
&file, universal_db_filename, FSAM_READ, FSOM_OPEN_EXISTING);
|
|
|
|
if(fs_res) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
file_parser.get_sd_api().show_error(
|
|
|
|
file_parser.get_sd_api().context, "Can't open file");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|