1
0
mirror of synced 2024-11-27 17:10:51 +01:00
ImHex/plugins/builtin/include/content/views/view_find.hpp

110 lines
3.8 KiB
C++

#pragma once
#include <hex.hpp>
#include <imgui.h>
#include <hex/ui/view.hpp>
#include <ui/widgets.hpp>
#include <atomic>
#include <vector>
#include <IntervalTree.h>
namespace hex::plugin::builtin {
class ViewFind : public View {
public:
ViewFind();
~ViewFind() override = default;
void drawContent() override;
private:
struct Occurrence {
Region region;
enum class DecodeType { ASCII, Binary, UTF16, Unsigned, Signed, Float, Double } decodeType;
std::endian endian = std::endian::native;
};
struct BinaryPattern {
u8 mask, value;
};
struct SearchSettings {
ui::SelectedRegion range = ui::SelectedRegion::EntireData;
enum class Mode : int {
Strings,
Sequence,
Regex,
BinaryPattern,
Value
} mode = Mode::Strings;
struct Strings {
int minLength = 5;
enum class Type : int { ASCII = 0, UTF16LE = 1, UTF16BE = 2, ASCII_UTF16LE = 3, ASCII_UTF16BE = 4 } type = Type::ASCII;
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 Sequence {
std::string sequence;
} bytes;
struct Regex {
std::string pattern;
bool fullMatch = true;
} regex;
struct BinaryPattern {
std::string input;
std::vector<ViewFind::BinaryPattern> pattern;
} binaryPattern;
struct Value {
std::string inputMin, inputMax;
std::endian endian = std::endian::native;
enum class Type {
U8 = 0, U16 = 1, U32 = 2, U64 = 3,
I8 = 4, I16 = 5, I32 = 6, I64 = 7,
F32 = 8, F64 = 9
} type = Type::U8;
} value;
} m_searchSettings, m_decodeSettings;
using OccurrenceTree = interval_tree::IntervalTree<u64, Occurrence>;
std::map<prv::Provider*, std::vector<Occurrence>> m_foundOccurrences, m_sortedOccurrences;
std::map<prv::Provider*, OccurrenceTree> m_occurrenceTree;
std::map<prv::Provider*, std::string> m_currFilter;
TaskHolder m_searchTask;
bool m_settingsValid = false;
private:
static std::vector<Occurrence> searchStrings(Task &task, prv::Provider *provider, Region searchRegion, const SearchSettings::Strings &settings);
static std::vector<Occurrence> searchSequence(Task &task, prv::Provider *provider, Region searchRegion, const SearchSettings::Sequence &settings);
static std::vector<Occurrence> searchRegex(Task &task, prv::Provider *provider, Region searchRegion, const SearchSettings::Regex &settings);
static std::vector<Occurrence> searchBinaryPattern(Task &task, prv::Provider *provider, Region searchRegion, const SearchSettings::BinaryPattern &settings);
static std::vector<Occurrence> searchValue(Task &task, prv::Provider *provider, Region searchRegion, const SearchSettings::Value &settings);
static std::vector<BinaryPattern> parseBinaryPatternString(std::string string);
static std::tuple<bool, std::variant<u64, i64, float, double>, size_t> parseNumericValueInput(const std::string &input, SearchSettings::Value::Type type);
void runSearch();
std::string decodeValue(prv::Provider *provider, Occurrence occurrence) const;
};
}