patterns: Go back to working pattern language

This commit is contained in:
WerWolv 2025-09-01 22:54:51 +02:00
parent 9659381378
commit 790c19a1cd
4 changed files with 13 additions and 11 deletions

@ -1 +1 @@
Subproject commit a81154b73d6774a085d44d6836c17f5daf634063
Subproject commit f97999d4da8f64df0706227f8b5a6a861e5a95ff

View File

@ -74,7 +74,7 @@ namespace hex::plugin::builtin {
const auto &sections = ContentRegistry::PatternLanguage::getRuntime().getSections();
(*m_patternDrawer)[0] = createDefaultDrawer();
for (const auto &id : sections | std::views::keys) {
for (const auto &[id, section] : sections) {
(*m_patternDrawer)[id] = createDefaultDrawer();
}
});
@ -143,11 +143,13 @@ namespace hex::plugin::builtin {
if (ImGui::BeginPopup("##PatternDataContextMenu")) {
if (ImGui::MenuItemEx("hex.builtin.view.pattern_data.section.view_raw"_lang, ICON_VS_OPEN_PREVIEW)) {
if (TRY_LOCK(ContentRegistry::PatternLanguage::getRuntimeLock())) {
if (auto it = sections.find(selectedSection); it != sections.end()) {
const auto &[sectionId, section] = *it;
ImHexApi::Provider::add<prv::MemoryProvider>(section.data, section.name);
}
}
}
ImGui::EndPopup();
}
}

View File

@ -54,7 +54,7 @@ namespace hex::plugin::decompress {
ContentRegistry::PatternLanguage::addFunction(nsHexDec, "zlib_decompress", FunctionParameterCount::exactly(3), [](Evaluator *evaluator, auto params) -> std::optional<Token::Literal> {
#if IMHEX_FEATURE_ENABLED(ZLIB)
auto compressedData = getCompressedData(evaluator, params[0]);
auto &section = evaluator->getRuntime().getSection(u64(params[1].toUnsigned()));
auto &section = evaluator->getSection(u64(params[1].toUnsigned()));
auto windowSize = u64(params[2].toUnsigned());
z_stream stream = { };
@ -105,7 +105,7 @@ namespace hex::plugin::decompress {
ContentRegistry::PatternLanguage::addFunction(nsHexDec, "bzip_decompress", FunctionParameterCount::exactly(2), [](Evaluator *evaluator, auto params) -> std::optional<Token::Literal> {
#if IMHEX_FEATURE_ENABLED(BZIP2)
auto compressedData = getCompressedData(evaluator, params[0]);
auto &section = evaluator->getRuntime().getSection(u64(params[1].toUnsigned()));
auto &section = evaluator->getSection(u64(params[1].toUnsigned()));
bz_stream stream = { };
if (BZ2_bzDecompressInit(&stream, 0, 1) != Z_OK) {
@ -156,7 +156,7 @@ namespace hex::plugin::decompress {
ContentRegistry::PatternLanguage::addFunction(nsHexDec, "lzma_decompress", FunctionParameterCount::exactly(2), [](Evaluator *evaluator, auto params) -> std::optional<Token::Literal> {
#if IMHEX_FEATURE_ENABLED(LIBLZMA)
auto compressedData = getCompressedData(evaluator, params[0]);
auto &section = evaluator->getRuntime().getSection(u64(params[1].toUnsigned()));
auto &section = evaluator->getSection(u64(params[1].toUnsigned()));
lzma_stream stream = LZMA_STREAM_INIT;
constexpr static i64 MemoryLimit = 0x40000000; // 1GiB
@ -216,7 +216,7 @@ namespace hex::plugin::decompress {
ContentRegistry::PatternLanguage::addFunction(nsHexDec, "zstd_decompress", FunctionParameterCount::exactly(2), [](Evaluator *evaluator, auto params) -> std::optional<Token::Literal> {
#if IMHEX_FEATURE_ENABLED(ZSTD)
auto compressedData = getCompressedData(evaluator, params[0]);
auto &section = evaluator->getRuntime().getSection(i64(params[1].toUnsigned()));
auto &section = evaluator->getSection(i64(params[1].toUnsigned()));
ZSTD_DCtx* dctx = ZSTD_createDCtx();
if (dctx == nullptr) {
@ -286,7 +286,7 @@ namespace hex::plugin::decompress {
ContentRegistry::PatternLanguage::addFunction(nsHexDec, "lz4_decompress", FunctionParameterCount::exactly(3), [](Evaluator *evaluator, auto params) -> std::optional<Token::Literal> {
#if IMHEX_FEATURE_ENABLED(LZ4)
auto compressedData = getCompressedData(evaluator, params[0]);
auto &section = evaluator->getRuntime().getSection(u64(params[1].toUnsigned()));
auto &section = evaluator->getSection(u64(params[1].toUnsigned()));
bool frame = params[2].toBoolean();
if (frame) {

View File

@ -105,7 +105,7 @@ namespace hex::plugin::disasm {
cs_option(capstone, CS_OPT_SKIPDATA, CS_OPT_ON);
const auto sectionId = evaluator->getSectionId();
std::vector<u8> data(std::min<u64>(32, evaluator->getRuntime().getSectionSize(sectionId) - address));
std::vector<u8> data(std::min<u64>(32, evaluator->getSectionSize(sectionId) - address));
evaluator->readData(address, data.data(), data.size(), sectionId);
auto *instruction = cs_malloc(capstone);