2021-08-11 20:51:06 +03:00
|
|
|
#include "irda-app-brute-force.h"
|
|
|
|
#include "irda/irda-app-file-parser.h"
|
2021-08-19 03:18:42 +03:00
|
|
|
|
2021-07-22 03:07:00 +03:00
|
|
|
#include <memory>
|
2021-08-19 03:18:42 +03:00
|
|
|
#include <m-string.h>
|
|
|
|
#include <furi.h>
|
|
|
|
#include <file-worker-cpp.h>
|
2021-06-25 16:52:27 +03: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 03:07:00 +03: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 16:52:27 +03:00
|
|
|
if(!fs_res) {
|
2021-08-19 03:18:42 +03:00
|
|
|
file_parser.reset();
|
2021-06-25 16:52:27 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(1) {
|
2021-07-22 03:07:00 +03:00
|
|
|
auto file_signal = file_parser->read_signal();
|
|
|
|
if(!file_signal) break;
|
|
|
|
|
|
|
|
auto element = records.find(file_signal->name);
|
2021-06-25 16:52:27 +03:00
|
|
|
if(element != records.cend()) {
|
|
|
|
++element->second.amount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-22 03:07:00 +03:00
|
|
|
file_parser->close();
|
2021-08-19 03:18:42 +03:00
|
|
|
file_parser.reset();
|
2021-06-25 16:52:27 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrdaAppBruteForce::stop_bruteforce() {
|
2021-07-22 03:07:00 +03:00
|
|
|
furi_assert((current_record.size()));
|
|
|
|
|
2021-06-25 16:52:27 +03:00
|
|
|
if(current_record.size()) {
|
2021-07-22 03:07:00 +03:00
|
|
|
furi_assert(file_parser);
|
2021-06-25 16:52:27 +03:00
|
|
|
current_record.clear();
|
2021-07-22 03:07:00 +03:00
|
|
|
file_parser->close();
|
2021-08-19 03:18:42 +03:00
|
|
|
file_parser.reset();
|
2021-06-25 16:52:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-16 19:43:54 +03:00
|
|
|
bool IrdaAppBruteForce::send_next_bruteforce(void) {
|
2021-06-25 16:52:27 +03:00
|
|
|
furi_assert(current_record.size());
|
2021-07-22 03:07:00 +03:00
|
|
|
furi_assert(file_parser);
|
2021-06-25 16:52:27 +03:00
|
|
|
|
2021-07-16 19:43:54 +03:00
|
|
|
std::unique_ptr<IrdaAppFileParser::IrdaFileSignal> file_signal;
|
2021-06-25 16:52:27 +03:00
|
|
|
|
|
|
|
do {
|
2021-07-22 03:07:00 +03:00
|
|
|
file_signal = file_parser->read_signal();
|
2021-07-16 19:43:54 +03:00
|
|
|
} while(file_signal && current_record.compare(file_signal->name));
|
2021-06-25 16:52:27 +03:00
|
|
|
|
2021-07-16 19:43:54 +03:00
|
|
|
if(file_signal) {
|
|
|
|
file_signal->signal.transmit();
|
2021-06-25 16:52:27 +03:00
|
|
|
}
|
2021-07-16 19:43:54 +03:00
|
|
|
return !!file_signal;
|
2021-06-25 16:52:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IrdaAppBruteForce::start_bruteforce(int index, int& record_amount) {
|
2021-07-22 03:07:00 +03:00
|
|
|
bool result = false;
|
|
|
|
record_amount = 0;
|
|
|
|
|
2021-06-25 16:52:27 +03:00
|
|
|
for(const auto& it : records) {
|
|
|
|
if(it.second.index == index) {
|
|
|
|
record_amount = it.second.amount;
|
2021-07-22 03:07:00 +03:00
|
|
|
if(record_amount) {
|
|
|
|
current_record = it.first;
|
|
|
|
}
|
2021-06-25 16:52:27 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(record_amount) {
|
2021-07-22 03:07:00 +03:00
|
|
|
file_parser = std::make_unique<IrdaAppFileParser>();
|
|
|
|
result = file_parser->open_irda_file_read(universal_db_filename);
|
|
|
|
if(!result) {
|
2021-08-19 03:18:42 +03:00
|
|
|
file_parser.reset();
|
2021-06-25 16:52:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-22 03:07:00 +03:00
|
|
|
return result;
|
2021-06-25 16:52:27 +03:00
|
|
|
}
|