regex filter added

This commit is contained in:
Akash Mozumdar 2018-10-09 01:46:11 -04:00
parent d07dd5c641
commit 0166df7209
2 changed files with 3 additions and 2 deletions

View File

@ -5,6 +5,7 @@
#include "textthread.h"
#include "host.h"
#include "const.h"
#include <regex>
TextThread::TextThread(ThreadParam tp, DWORD status) : handle(ThreadCounter++), name(Host::GetHookName(tp.pid, tp.hook)), tp(tp), status(status) {}
@ -35,6 +36,7 @@ void TextThread::Flush()
void TextThread::AddSentence(std::wstring sentence)
{
sentence = std::regex_replace(sentence, std::wregex(filter), L"");
// Dispatch to extensions occurs here. Don't hold mutex! Extensions might take a while!
if (Output(this, sentence))
{
@ -49,7 +51,6 @@ 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 (Filter) Filter(buffer.data(), storage.c_str());
timestamp = GetTickCount();
}

View File

@ -13,8 +13,8 @@ public:
typedef std::function<bool(TextThread*, std::wstring&)> OutputCallback;
inline static OutputCallback Output;
inline static std::function<void(wchar_t* buffer, const wchar_t* storage)> Filter = nullptr;
inline static std::wstring filter = L"";
inline static int FlushDelay = 250; // flush every 250ms by default
inline static int MaxBufferSize = 200;
inline static int ThreadCounter = 0;