Skip to content

Commit 790c19a

Browse files
committed
patterns: Go back to working pattern language
1 parent 9659381 commit 790c19a

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

plugins/builtin/source/content/views/view_pattern_data.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace hex::plugin::builtin {
7474
const auto &sections = ContentRegistry::PatternLanguage::getRuntime().getSections();
7575

7676
(*m_patternDrawer)[0] = createDefaultDrawer();
77-
for (const auto &id : sections | std::views::keys) {
77+
for (const auto &[id, section] : sections) {
7878
(*m_patternDrawer)[id] = createDefaultDrawer();
7979
}
8080
});
@@ -143,9 +143,11 @@ namespace hex::plugin::builtin {
143143

144144
if (ImGui::BeginPopup("##PatternDataContextMenu")) {
145145
if (ImGui::MenuItemEx("hex.builtin.view.pattern_data.section.view_raw"_lang, ICON_VS_OPEN_PREVIEW)) {
146-
if (auto it = sections.find(selectedSection); it != sections.end()) {
147-
const auto &[sectionId, section] = *it;
148-
ImHexApi::Provider::add<prv::MemoryProvider>(section.data, section.name);
146+
if (TRY_LOCK(ContentRegistry::PatternLanguage::getRuntimeLock())) {
147+
if (auto it = sections.find(selectedSection); it != sections.end()) {
148+
const auto &[sectionId, section] = *it;
149+
ImHexApi::Provider::add<prv::MemoryProvider>(section.data, section.name);
150+
}
149151
}
150152
}
151153
ImGui::EndPopup();

plugins/decompress/source/content/pl_functions.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace hex::plugin::decompress {
5454
ContentRegistry::PatternLanguage::addFunction(nsHexDec, "zlib_decompress", FunctionParameterCount::exactly(3), [](Evaluator *evaluator, auto params) -> std::optional<Token::Literal> {
5555
#if IMHEX_FEATURE_ENABLED(ZLIB)
5656
auto compressedData = getCompressedData(evaluator, params[0]);
57-
auto &section = evaluator->getRuntime().getSection(u64(params[1].toUnsigned()));
57+
auto &section = evaluator->getSection(u64(params[1].toUnsigned()));
5858
auto windowSize = u64(params[2].toUnsigned());
5959

6060
z_stream stream = { };
@@ -105,7 +105,7 @@ namespace hex::plugin::decompress {
105105
ContentRegistry::PatternLanguage::addFunction(nsHexDec, "bzip_decompress", FunctionParameterCount::exactly(2), [](Evaluator *evaluator, auto params) -> std::optional<Token::Literal> {
106106
#if IMHEX_FEATURE_ENABLED(BZIP2)
107107
auto compressedData = getCompressedData(evaluator, params[0]);
108-
auto &section = evaluator->getRuntime().getSection(u64(params[1].toUnsigned()));
108+
auto &section = evaluator->getSection(u64(params[1].toUnsigned()));
109109

110110
bz_stream stream = { };
111111
if (BZ2_bzDecompressInit(&stream, 0, 1) != Z_OK) {
@@ -156,7 +156,7 @@ namespace hex::plugin::decompress {
156156
ContentRegistry::PatternLanguage::addFunction(nsHexDec, "lzma_decompress", FunctionParameterCount::exactly(2), [](Evaluator *evaluator, auto params) -> std::optional<Token::Literal> {
157157
#if IMHEX_FEATURE_ENABLED(LIBLZMA)
158158
auto compressedData = getCompressedData(evaluator, params[0]);
159-
auto &section = evaluator->getRuntime().getSection(u64(params[1].toUnsigned()));
159+
auto &section = evaluator->getSection(u64(params[1].toUnsigned()));
160160

161161
lzma_stream stream = LZMA_STREAM_INIT;
162162
constexpr static i64 MemoryLimit = 0x40000000; // 1GiB
@@ -216,7 +216,7 @@ namespace hex::plugin::decompress {
216216
ContentRegistry::PatternLanguage::addFunction(nsHexDec, "zstd_decompress", FunctionParameterCount::exactly(2), [](Evaluator *evaluator, auto params) -> std::optional<Token::Literal> {
217217
#if IMHEX_FEATURE_ENABLED(ZSTD)
218218
auto compressedData = getCompressedData(evaluator, params[0]);
219-
auto &section = evaluator->getRuntime().getSection(i64(params[1].toUnsigned()));
219+
auto &section = evaluator->getSection(i64(params[1].toUnsigned()));
220220

221221
ZSTD_DCtx* dctx = ZSTD_createDCtx();
222222
if (dctx == nullptr) {
@@ -286,7 +286,7 @@ namespace hex::plugin::decompress {
286286
ContentRegistry::PatternLanguage::addFunction(nsHexDec, "lz4_decompress", FunctionParameterCount::exactly(3), [](Evaluator *evaluator, auto params) -> std::optional<Token::Literal> {
287287
#if IMHEX_FEATURE_ENABLED(LZ4)
288288
auto compressedData = getCompressedData(evaluator, params[0]);
289-
auto &section = evaluator->getRuntime().getSection(u64(params[1].toUnsigned()));
289+
auto &section = evaluator->getSection(u64(params[1].toUnsigned()));
290290
bool frame = params[2].toBoolean();
291291

292292
if (frame) {

plugins/disassembler/source/content/pl_builtin_types.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ namespace hex::plugin::disasm {
105105
cs_option(capstone, CS_OPT_SKIPDATA, CS_OPT_ON);
106106

107107
const auto sectionId = evaluator->getSectionId();
108-
std::vector<u8> data(std::min<u64>(32, evaluator->getRuntime().getSectionSize(sectionId) - address));
108+
std::vector<u8> data(std::min<u64>(32, evaluator->getSectionSize(sectionId) - address));
109109
evaluator->readData(address, data.data(), data.size(), sectionId);
110110

111111
auto *instruction = cs_malloc(capstone);

0 commit comments

Comments
 (0)