2020-11-10 14:26:38 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-02-01 17:09:40 +00:00
|
|
|
#include <hex/ui/view.hpp>
|
2022-04-17 14:57:30 +00:00
|
|
|
#include <pl/pattern_language.hpp>
|
2022-08-06 19:38:09 +00:00
|
|
|
#include <pl/core/errors/error.hpp>
|
2021-01-13 16:28:27 +00:00
|
|
|
#include <hex/providers/provider.hpp>
|
2022-11-06 23:04:47 +00:00
|
|
|
|
2022-10-26 06:54:43 +00:00
|
|
|
#include <content/helpers/provider_extra_data.hpp>
|
2022-11-08 20:43:22 +00:00
|
|
|
#include <ui/hex_editor.hpp>
|
|
|
|
#include <ui/pattern_drawer.hpp>
|
2022-11-06 23:04:47 +00:00
|
|
|
#include <content/providers/memory_file_provider.hpp>
|
2020-11-10 14:26:38 +00:00
|
|
|
|
|
|
|
#include <cstring>
|
2020-11-21 13:39:16 +00:00
|
|
|
#include <filesystem>
|
2021-02-07 12:40:47 +00:00
|
|
|
#include <string_view>
|
Pattern Language rewrite (#111)
* Initial parser rewrite effort
Lexer and Token cleanup, Parser started over
* Greatly improved parser syntax
* Reimplemented using declarations and variable placement parsing
* Added back unions and structs
* Added enums as well as mathematical expressions (+, -, *, /, <<, >>, &, |, ^)
* Code style improvement
* Implemented arrays and fixed memory issues
* Fixed more memory issues in parser, reimplemented validator, evaluator and patterns
* Fixed builtin types, arrays and reimplemented strings
* Improved error messages
* Made character a distinct type, used for chars and strings
* Implemented padding, fixed arrays
* Added bitfields
* Added rvalue parsing, no evaluating yet
* Added .idea folder to gitignore
* Fixed build on MacOS
* Added custom implementation of integral concept if not available
* Rebased onto master
* Fixed array variable decl crash
* Added rvalues and dot syntax
* Lower case all pattern language error messages
* Fixed typo in variable name
* Fixed bug where preprocessor would not ignore commented out directives
* Reimplemented pointers
* Fixed rebase issues
2021-01-02 19:27:11 +00:00
|
|
|
#include <thread>
|
2021-01-23 13:01:23 +00:00
|
|
|
#include <vector>
|
2022-11-08 20:43:22 +00:00
|
|
|
#include <functional>
|
2020-11-10 14:26:38 +00:00
|
|
|
|
2021-01-13 16:28:27 +00:00
|
|
|
#include <TextEditor.h>
|
2020-11-12 20:20:51 +00:00
|
|
|
|
2022-08-06 19:38:09 +00:00
|
|
|
namespace pl::ptrn { class Pattern; }
|
2022-05-27 18:42:07 +00:00
|
|
|
|
2021-12-07 21:47:41 +00:00
|
|
|
namespace hex::plugin::builtin {
|
2020-11-10 14:26:38 +00:00
|
|
|
|
2021-08-28 19:51:33 +00:00
|
|
|
class ViewPatternEditor : public View {
|
2020-11-10 14:26:38 +00:00
|
|
|
public:
|
2021-08-28 19:51:33 +00:00
|
|
|
ViewPatternEditor();
|
|
|
|
~ViewPatternEditor() override;
|
2020-11-10 14:26:38 +00:00
|
|
|
|
2021-02-07 13:29:13 +00:00
|
|
|
void drawAlwaysVisible() override;
|
2020-12-22 17:10:01 +00:00
|
|
|
void drawContent() override;
|
2020-11-10 14:26:38 +00:00
|
|
|
|
|
|
|
private:
|
2022-04-17 14:57:30 +00:00
|
|
|
enum class DangerousFunctionPerms : u8 {
|
|
|
|
Ask,
|
|
|
|
Allow,
|
|
|
|
Deny
|
|
|
|
};
|
|
|
|
|
2022-07-31 18:07:15 +00:00
|
|
|
private:
|
2022-10-26 06:54:43 +00:00
|
|
|
using PlData = ProviderExtraData::Data::PatternLanguage;
|
|
|
|
|
2022-07-31 18:07:15 +00:00
|
|
|
std::unique_ptr<pl::PatternLanguage> m_parserRuntime;
|
|
|
|
|
|
|
|
std::vector<std::fs::path> m_possiblePatternFiles;
|
|
|
|
u32 m_selectedPatternFile = 0;
|
|
|
|
bool m_runAutomatically = false;
|
2023-04-06 21:01:45 +00:00
|
|
|
bool m_triggerEvaluation = false;
|
2022-07-31 18:07:15 +00:00
|
|
|
|
|
|
|
bool m_lastEvaluationProcessed = true;
|
|
|
|
bool m_lastEvaluationResult = false;
|
|
|
|
|
|
|
|
std::atomic<u32> m_runningEvaluators = 0;
|
|
|
|
std::atomic<u32> m_runningParsers = 0;
|
|
|
|
|
|
|
|
bool m_hasUnevaluatedChanges = false;
|
|
|
|
|
|
|
|
bool m_acceptPatternWindowOpen = false;
|
|
|
|
|
|
|
|
TextEditor m_textEditor;
|
|
|
|
|
2022-04-17 14:57:30 +00:00
|
|
|
std::atomic<bool> m_dangerousFunctionCalled = false;
|
|
|
|
std::atomic<DangerousFunctionPerms> m_dangerousFunctionsAllowed = DangerousFunctionPerms::Ask;
|
|
|
|
|
2022-07-31 18:07:15 +00:00
|
|
|
bool m_syncPatternSourceCode = false;
|
|
|
|
bool m_autoLoadPatterns = true;
|
|
|
|
|
2022-11-08 20:43:22 +00:00
|
|
|
std::map<prv::Provider*, std::move_only_function<void()>> m_sectionWindowDrawer;
|
2023-02-17 13:53:15 +00:00
|
|
|
|
|
|
|
ui::HexEditor m_sectionHexEditor;
|
|
|
|
|
2022-07-31 18:07:15 +00:00
|
|
|
private:
|
2022-10-26 06:54:43 +00:00
|
|
|
void drawConsole(ImVec2 size, const std::vector<std::pair<pl::core::LogConsole::Level, std::string>> &console);
|
|
|
|
void drawEnvVars(ImVec2 size, std::list<PlData::EnvVar> &envVars);
|
|
|
|
void drawVariableSettings(ImVec2 size, std::map<std::string, PlData::PatternVariable> &patternVariables);
|
2022-11-06 23:04:47 +00:00
|
|
|
void drawSectionSelector(ImVec2 size, std::map<u64, pl::api::Section> §ions);
|
2021-12-10 10:55:27 +00:00
|
|
|
|
2022-08-06 19:38:09 +00:00
|
|
|
void drawPatternTooltip(pl::ptrn::Pattern *pattern);
|
2022-05-27 18:42:07 +00:00
|
|
|
|
2022-10-26 06:54:43 +00:00
|
|
|
void loadPatternFile(const std::fs::path &path, prv::Provider *provider);
|
2021-12-18 21:56:36 +00:00
|
|
|
|
2022-10-26 06:54:43 +00:00
|
|
|
void parsePattern(const std::string &code, prv::Provider *provider);
|
|
|
|
void evaluatePattern(const std::string &code, prv::Provider *provider);
|
2022-10-21 08:03:37 +00:00
|
|
|
|
|
|
|
void registerEvents();
|
|
|
|
void registerMenuItems();
|
|
|
|
void registerHandlers();
|
2023-04-05 16:29:30 +00:00
|
|
|
|
|
|
|
void appendEditorText(const std::string &text);
|
|
|
|
void appendVariable(const std::string &type);
|
|
|
|
void appendArray(const std::string &type, size_t size);
|
2020-11-10 14:26:38 +00:00
|
|
|
};
|
|
|
|
|
2022-07-14 09:37:02 +00:00
|
|
|
}
|