2021-08-11 17:51:06 +00:00
|
|
|
#include "irda-app-brute-force.h"
|
|
|
|
#include "irda/irda-app-file-parser.h"
|
2021-07-22 00:07:00 +00:00
|
|
|
#include "m-string.h"
|
|
|
|
#include <file-worker-cpp.h>
|
|
|
|
#include <memory>
|
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() {
|
|
|
|
bool fs_res = false;
|
2021-07-22 00:07:00 +00:00
|
|
|
furi_assert(!file_parser);
|
|
|
|
|
|
|
|
file_parser = std::make_unique<IrdaAppFileParser>();
|
|
|
|
fs_res = file_parser->open_irda_file_read(universal_db_filename);
|
2021-06-25 13:52:27 +00:00
|
|
|
if(!fs_res) {
|
2021-07-22 00:07:00 +00:00
|
|
|
file_parser.reset(nullptr);
|
2021-06-25 13:52:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(1) {
|
2021-07-22 00:07:00 +00:00
|
|
|
auto file_signal = file_parser->read_signal();
|
|
|
|
if(!file_signal) break;
|
|
|
|
|
|
|
|
auto element = records.find(file_signal->name);
|
2021-06-25 13:52:27 +00:00
|
|
|
if(element != records.cend()) {
|
|
|
|
++element->second.amount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-22 00:07:00 +00:00
|
|
|
file_parser->close();
|
|
|
|
file_parser.reset(nullptr);
|
2021-06-25 13:52:27 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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()) {
|
2021-07-22 00:07:00 +00:00
|
|
|
furi_assert(file_parser);
|
2021-06-25 13:52:27 +00:00
|
|
|
current_record.clear();
|
2021-07-22 00:07:00 +00:00
|
|
|
file_parser->close();
|
|
|
|
file_parser.reset(nullptr);
|
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());
|
2021-07-22 00:07:00 +00:00
|
|
|
furi_assert(file_parser);
|
2021-06-25 13:52:27 +00:00
|
|
|
|
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-22 00:07:00 +00:00
|
|
|
file_signal = file_parser->read_signal();
|
2021-07-16 16:43:54 +00:00
|
|
|
} 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) {
|
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) {
|
2021-07-22 00:07:00 +00:00
|
|
|
file_parser = std::make_unique<IrdaAppFileParser>();
|
|
|
|
result = file_parser->open_irda_file_read(universal_db_filename);
|
|
|
|
if(!result) {
|
|
|
|
(void)file_parser.reset(nullptr);
|
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
|
|
|
}
|