diff --git a/lib/libimhex/include/hex/api/task.hpp b/lib/libimhex/include/hex/api/task.hpp index cfb4045fb..bad80eb01 100644 --- a/lib/libimhex/include/hex/api/task.hpp +++ b/lib/libimhex/include/hex/api/task.hpp @@ -33,6 +33,7 @@ namespace hex { [[nodiscard]] bool isFinished() const; [[nodiscard]] bool hadException() const; [[nodiscard]] bool wasInterrupted() const; + [[nodiscard]] bool shouldInterrupt() const; void clearException(); [[nodiscard]] std::string getExceptionMessage() const; @@ -79,6 +80,7 @@ namespace hex { [[nodiscard]] bool isRunning() const; [[nodiscard]] bool hadException() const; [[nodiscard]] bool wasInterrupted() const; + [[nodiscard]] bool shouldInterrupt() const; void interrupt(); private: diff --git a/lib/libimhex/source/api/task.cpp b/lib/libimhex/source/api/task.cpp index abe8be0ff..7d0c07cd1 100644 --- a/lib/libimhex/source/api/task.cpp +++ b/lib/libimhex/source/api/task.cpp @@ -78,6 +78,10 @@ namespace hex { return this->m_hadException; } + bool Task::shouldInterrupt() const { + return this->m_shouldInterrupt; + } + bool Task::wasInterrupted() const { return this->m_interrupted; } @@ -136,6 +140,14 @@ namespace hex { return !task->hadException(); } + bool TaskHolder::shouldInterrupt() const { + if (this->m_task.expired()) + return false; + + auto task = this->m_task.lock(); + return !task->shouldInterrupt(); + } + bool TaskHolder::wasInterrupted() const { if (this->m_task.expired()) return false; diff --git a/plugins/builtin/source/content/views/view_yara.cpp b/plugins/builtin/source/content/views/view_yara.cpp index 123aa4f93..00dd99eef 100644 --- a/plugins/builtin/source/content/views/view_yara.cpp +++ b/plugins/builtin/source/content/views/view_yara.cpp @@ -287,11 +287,13 @@ namespace hex::plugin::builtin { struct ResultContext { + Task *task = nullptr; std::vector newMatches; std::vector consoleMessages; }; ResultContext resultContext; + resultContext.task = &task; yr_rules_scan_mem_blocks( rules, &iterator, 0, [](YR_SCAN_CONTEXT *context, int message, void *data, void *userData) -> int { @@ -325,7 +327,7 @@ namespace hex::plugin::builtin { break; } - return CALLBACK_CONTINUE; + return results.task->shouldInterrupt() ? CALLBACK_ABORT : CALLBACK_CONTINUE; }, &resultContext, 0);