2022-04-17 16:57:30 +02:00
|
|
|
#include <hex/api/content_registry.hpp>
|
|
|
|
#include <hex/providers/provider.hpp>
|
|
|
|
|
2022-08-06 21:38:09 +02:00
|
|
|
#include <pl/core/evaluator.hpp>
|
2022-04-17 16:57:30 +02:00
|
|
|
|
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
|
|
|
void registerPatternLanguagePragmas() {
|
|
|
|
ContentRegistry::PatternLanguage::addPragma("endian", [](pl::PatternLanguage &runtime, const std::string &value) {
|
|
|
|
if (value == "big") {
|
|
|
|
runtime.getInternals().evaluator->setDefaultEndian(std::endian::big);
|
|
|
|
return true;
|
|
|
|
} else if (value == "little") {
|
|
|
|
runtime.getInternals().evaluator->setDefaultEndian(std::endian::little);
|
|
|
|
return true;
|
|
|
|
} else if (value == "native") {
|
|
|
|
runtime.getInternals().evaluator->setDefaultEndian(std::endian::native);
|
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
ContentRegistry::PatternLanguage::addPragma("eval_depth", [](pl::PatternLanguage &runtime, const std::string &value) {
|
|
|
|
auto limit = strtol(value.c_str(), nullptr, 0);
|
|
|
|
|
|
|
|
if (limit <= 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
runtime.getInternals().evaluator->setEvaluationDepth(limit);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
ContentRegistry::PatternLanguage::addPragma("array_limit", [](pl::PatternLanguage &runtime, const std::string &value) {
|
|
|
|
auto limit = strtol(value.c_str(), nullptr, 0);
|
|
|
|
|
|
|
|
if (limit <= 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
runtime.getInternals().evaluator->setArrayLimit(limit);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
ContentRegistry::PatternLanguage::addPragma("pattern_limit", [](pl::PatternLanguage &runtime, const std::string &value) {
|
|
|
|
auto limit = strtol(value.c_str(), nullptr, 0);
|
|
|
|
|
|
|
|
if (limit <= 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
runtime.getInternals().evaluator->setPatternLimit(limit);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
ContentRegistry::PatternLanguage::addPragma("loop_limit", [](pl::PatternLanguage &runtime, const std::string &value) {
|
|
|
|
auto limit = strtol(value.c_str(), nullptr, 0);
|
|
|
|
|
|
|
|
if (limit <= 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
runtime.getInternals().evaluator->setLoopLimit(limit);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
ContentRegistry::PatternLanguage::addPragma("base_address", [](pl::PatternLanguage &runtime, const std::string &value) {
|
|
|
|
hex::unused(runtime);
|
|
|
|
|
|
|
|
auto baseAddress = strtoull(value.c_str(), nullptr, 0);
|
|
|
|
|
|
|
|
ImHexApi::Provider::get()->setBaseAddress(baseAddress);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
ContentRegistry::PatternLanguage::addPragma("bitfield_order", [](pl::PatternLanguage &runtime, const std::string &value) {
|
|
|
|
if (value == "left_to_right") {
|
2022-08-06 21:38:09 +02:00
|
|
|
runtime.getInternals().evaluator->setBitfieldOrder(pl::core::BitfieldOrder::LeftToRight);
|
2022-04-17 16:57:30 +02:00
|
|
|
return true;
|
|
|
|
} else if (value == "right_to_left") {
|
2022-08-06 21:38:09 +02:00
|
|
|
runtime.getInternals().evaluator->setBitfieldOrder(pl::core::BitfieldOrder::RightToLeft);
|
2022-04-17 16:57:30 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2022-04-27 08:54:38 +02:00
|
|
|
|
|
|
|
ContentRegistry::PatternLanguage::addPragma("MIME", [](pl::PatternLanguage&, const std::string &value) { return !value.empty(); });
|
2022-04-17 16:57:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|