2021-08-29 14:18:45 +02:00
|
|
|
#include <hex/api/content_registry.hpp>
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2021-09-25 16:24:08 +02:00
|
|
|
#include <hex/helpers/net.hpp>
|
2021-08-29 22:15:18 +02:00
|
|
|
|
2022-08-06 21:38:09 +02:00
|
|
|
#include <pl/core/token.hpp>
|
|
|
|
#include <pl/core/log_console.hpp>
|
|
|
|
#include <pl/core/evaluator.hpp>
|
2022-04-17 16:57:30 +02:00
|
|
|
#include <pl/patterns/pattern.hpp>
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
|
|
|
void registerPatternLanguageFunctions() {
|
2022-08-06 21:38:09 +02:00
|
|
|
using namespace pl::core;
|
2022-04-17 16:57:30 +02:00
|
|
|
using FunctionParameterCount = pl::api::FunctionParameterCount;
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-09-15 09:34:59 +02:00
|
|
|
pl::api::Namespace nsHexCore = { "builtin", "hex", "core" };
|
|
|
|
{
|
|
|
|
/* get_selection() */
|
|
|
|
ContentRegistry::PatternLanguage::addDangerousFunction(nsHexCore, "get_selection", FunctionParameterCount::none(), [](Evaluator *, auto) -> std::optional<Token::Literal> {
|
|
|
|
if (!ImHexApi::HexEditor::isSelectionValid())
|
|
|
|
return std::numeric_limits<u128>::max();
|
|
|
|
|
|
|
|
auto selection = ImHexApi::HexEditor::getSelection();
|
|
|
|
|
|
|
|
return u128(u128(selection->getStartAddress()) << 64 | u128(selection->getSize()));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
pl::api::Namespace nsHexHttp = { "builtin", "hex", "http" };
|
2021-09-25 16:24:08 +02:00
|
|
|
{
|
|
|
|
/* get(url) */
|
2022-09-15 09:34:59 +02:00
|
|
|
ContentRegistry::PatternLanguage::addDangerousFunction(nsHexHttp, "get", FunctionParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
|
2021-09-25 16:24:08 +02:00
|
|
|
const auto url = Token::literalToString(params[0], false);
|
|
|
|
|
|
|
|
hex::Net net;
|
|
|
|
return net.getString(url).get().body;
|
2021-12-20 20:40:28 +01:00
|
|
|
});
|
2021-09-25 16:24:08 +02:00
|
|
|
}
|
2021-01-22 18:01:39 +01:00
|
|
|
}
|
2021-09-21 21:29:18 +02:00
|
|
|
}
|