2022-07-29 13:59:57 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <hex.hpp>
|
|
|
|
|
|
|
|
#include <imgui.h>
|
|
|
|
#include <hex/ui/view.hpp>
|
2022-08-07 12:20:40 +02:00
|
|
|
#include <ui/widgets.hpp>
|
2022-07-29 13:59:57 +02:00
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-08-06 12:57:47 +02:00
|
|
|
#include <IntervalTree.h>
|
|
|
|
|
2022-07-29 13:59:57 +02:00
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
|
|
|
class ViewFind : public View {
|
|
|
|
public:
|
|
|
|
ViewFind();
|
|
|
|
~ViewFind() override = default;
|
|
|
|
|
|
|
|
void drawContent() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2022-08-03 11:38:36 +02:00
|
|
|
struct Occurrence {
|
|
|
|
Region region;
|
|
|
|
enum class DecodeType { ASCII, Binary, UTF16LE, UTF16BE } decodeType;
|
|
|
|
};
|
|
|
|
|
2022-08-03 10:19:34 +02:00
|
|
|
struct BinaryPattern {
|
|
|
|
u8 mask, value;
|
|
|
|
};
|
|
|
|
|
2022-07-29 13:59:57 +02:00
|
|
|
struct SearchSettings {
|
2022-08-07 12:20:40 +02:00
|
|
|
ui::SelectedRegion range = ui::SelectedRegion::EntireData;
|
2022-07-29 13:59:57 +02:00
|
|
|
|
|
|
|
enum class Mode : int {
|
|
|
|
Strings,
|
|
|
|
Sequence,
|
2022-08-03 10:19:34 +02:00
|
|
|
Regex,
|
|
|
|
BinaryPattern
|
2022-07-29 13:59:57 +02:00
|
|
|
} mode = Mode::Strings;
|
|
|
|
|
|
|
|
struct Strings {
|
|
|
|
int minLength = 5;
|
2022-08-03 11:38:36 +02:00
|
|
|
enum class Type : int { ASCII = 0, UTF16LE = 1, UTF16BE = 2, ASCII_UTF16LE = 3, ASCII_UTF16BE = 4 } type = Type::ASCII;
|
2022-07-29 13:59:57 +02:00
|
|
|
bool nullTermination = false;
|
|
|
|
|
|
|
|
bool m_lowerCaseLetters = true;
|
|
|
|
bool m_upperCaseLetters = true;
|
|
|
|
bool m_numbers = true;
|
|
|
|
bool m_underscores = true;
|
|
|
|
bool m_symbols = true;
|
|
|
|
bool m_spaces = true;
|
|
|
|
bool m_lineFeeds = false;
|
|
|
|
} strings;
|
|
|
|
|
|
|
|
struct Bytes {
|
|
|
|
std::string sequence;
|
|
|
|
} bytes;
|
|
|
|
|
|
|
|
struct Regex {
|
|
|
|
std::string pattern;
|
|
|
|
} regex;
|
2022-08-03 10:19:34 +02:00
|
|
|
|
|
|
|
struct BinaryPattern {
|
|
|
|
std::string input;
|
|
|
|
std::vector<ViewFind::BinaryPattern> pattern;
|
|
|
|
} binaryPattern;
|
2022-07-29 13:59:57 +02:00
|
|
|
} m_searchSettings, m_decodeSettings;
|
|
|
|
|
2022-08-06 12:57:47 +02:00
|
|
|
using OccurrenceTree = interval_tree::IntervalTree<u64, Occurrence>;
|
|
|
|
|
2022-08-03 11:38:36 +02:00
|
|
|
std::map<prv::Provider*, std::vector<Occurrence>> m_foundOccurrences, m_sortedOccurrences;
|
2022-08-06 12:57:47 +02:00
|
|
|
std::map<prv::Provider*, OccurrenceTree> m_occurrenceTree;
|
2022-09-03 23:15:30 +02:00
|
|
|
std::map<prv::Provider*, std::string> m_currFilter;
|
2022-08-06 12:57:47 +02:00
|
|
|
|
2022-08-17 16:15:36 +02:00
|
|
|
TaskHolder m_searchTask;
|
2022-07-29 13:59:57 +02:00
|
|
|
bool m_settingsValid = false;
|
|
|
|
|
|
|
|
private:
|
2022-08-03 11:38:36 +02:00
|
|
|
static std::vector<Occurrence> searchStrings(Task &task, prv::Provider *provider, Region searchRegion, SearchSettings::Strings settings);
|
|
|
|
static std::vector<Occurrence> searchSequence(Task &task, prv::Provider *provider, Region searchRegion, SearchSettings::Bytes settings);
|
|
|
|
static std::vector<Occurrence> searchRegex(Task &task, prv::Provider *provider, Region searchRegion, SearchSettings::Regex settings);
|
|
|
|
static std::vector<Occurrence> searchBinaryPattern(Task &task, prv::Provider *provider, Region searchRegion, SearchSettings::BinaryPattern settings);
|
2022-08-03 10:19:34 +02:00
|
|
|
|
|
|
|
static std::vector<BinaryPattern> parseBinaryPatternString(std::string string);
|
2022-07-29 13:59:57 +02:00
|
|
|
|
|
|
|
void runSearch();
|
2022-08-03 11:38:36 +02:00
|
|
|
std::string decodeValue(prv::Provider *provider, Occurrence occurrence) const;
|
2022-07-29 13:59:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|