1
0
mirror of synced 2024-11-28 09:30:51 +01:00

fix: Yara matching not being interruptable

This commit is contained in:
WerWolv 2022-10-28 14:32:28 +02:00
parent 582858c0d4
commit 5cf6baca88
3 changed files with 17 additions and 1 deletions

View File

@ -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:

View File

@ -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;

View File

@ -287,11 +287,13 @@ namespace hex::plugin::builtin {
struct ResultContext {
Task *task = nullptr;
std::vector<YaraMatch> newMatches;
std::vector<std::string> 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);