From 3ad311293f182262f854f1a820ab6f10692edf1a Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Wed, 17 Oct 2018 00:42:51 -0400 Subject: [PATCH] add cyclic repetition detection in textthread --- GUI/host/textthread.cc | 7 +++++++ GUI/host/textthread.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/GUI/host/textthread.cc b/GUI/host/textthread.cc index d8df82a..519e999 100644 --- a/GUI/host/textthread.cc +++ b/GUI/host/textthread.cc @@ -6,6 +6,7 @@ #include "host.h" #include "const.h" #include +#include TextThread::TextThread(ThreadParam tp, DWORD status) : handle(threadCounter++), name(Host::GetHookName(tp.pid, tp.hook)), tp(tp), status(status) {} @@ -31,6 +32,11 @@ void TextThread::Flush() if (buffer.size() < maxBufferSize && GetTickCount() - timestamp < flushDelay) return; sentence = buffer; buffer.clear(); + + bool hasRepetition = false; + for (std::wsmatch results; std::regex_search(sentence, results, std::wregex(L"([^\\x00]{6,})\\1\\1")); hasRepetition = true) sentence = results[1]; + if (hasRepetition) repeatingChars = std::unordered_set(sentence.begin(), sentence.end()); + else repeatingChars.clear(); } AddSentence(sentence); } @@ -51,6 +57,7 @@ void TextThread::AddText(const BYTE* data, int len) buffer += status & USING_UNICODE ? std::wstring((wchar_t*)data, len / 2) : StringToWideString(std::string((char*)data, len), status & USING_UTF8 ? CP_UTF8 : SHIFT_JIS); + if (std::all_of(buffer.begin(), buffer.end(), [&](wchar_t c) { return repeatingChars.count(c) > 0; })) buffer.clear(); timestamp = GetTickCount(); } diff --git a/GUI/host/textthread.h b/GUI/host/textthread.h index 60c2d18..1edfb43 100644 --- a/GUI/host/textthread.h +++ b/GUI/host/textthread.h @@ -6,6 +6,7 @@ #include "common.h" #include "types.h" +#include class TextThread { @@ -34,6 +35,7 @@ private: std::wstring buffer; std::wstring storage; + std::unordered_set repeatingChars; std::recursive_mutex ttMutex; DWORD status;