2016-01-05 23:01:17 +08:00
|
|
|
// textthread.cc
|
|
|
|
// 8/24/2013 jichi
|
|
|
|
// Branch IHF/TextThread.cpp, rev 133
|
|
|
|
// 8/24/2013 TODO: Clean up this file
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
# pragma warning (disable:4100) // C4100: unreference formal parameter
|
|
|
|
#endif // _MSC_VER
|
|
|
|
|
|
|
|
#include "settings.h"
|
|
|
|
#include "textthread.h"
|
|
|
|
//#include "wintimer/wintimer.h"
|
|
|
|
#include "vnrhook/include/const.h"
|
|
|
|
#include "ithsys/ithsys.h"
|
|
|
|
#include <stdio.h>
|
2018-05-25 16:34:40 +08:00
|
|
|
#include "extensions/Extensions.h"
|
2016-01-05 23:01:17 +08:00
|
|
|
|
|
|
|
MK_BASIC_TYPE(BYTE)
|
|
|
|
MK_BASIC_TYPE(ThreadParameter)
|
|
|
|
|
|
|
|
static DWORD MIN_DETECT = 0x20;
|
|
|
|
static DWORD MIN_REDETECT = 0x80;
|
|
|
|
//#define MIN_DETECT 0x20
|
|
|
|
//#define MIN_REDETECT 0x80
|
|
|
|
#ifndef CURRENT_SELECT
|
|
|
|
# define CURRENT_SELECT 0x1000
|
|
|
|
#endif
|
|
|
|
#ifndef REPEAT_NUMBER_DECIDED
|
|
|
|
# define REPEAT_NUMBER_DECIDED 0x2000
|
|
|
|
#endif
|
|
|
|
|
|
|
|
DWORD GetHookName(LPSTR str, DWORD pid, DWORD hook_addr,DWORD max);
|
|
|
|
|
|
|
|
extern Settings *settings;
|
2018-05-12 04:46:05 +08:00
|
|
|
extern HWND dummyWindow;
|
2016-01-05 23:01:17 +08:00
|
|
|
|
2018-06-11 07:15:05 +08:00
|
|
|
TextThread::TextThread(ThreadParameter tp, WORD num) :
|
2016-01-05 23:01:17 +08:00
|
|
|
//,tp
|
|
|
|
thread_number(num)
|
|
|
|
, output(nullptr)
|
|
|
|
//, comment(nullptr)
|
2018-07-12 08:18:04 +08:00
|
|
|
, status(0)
|
2018-06-11 07:15:05 +08:00
|
|
|
, tp(tp)
|
2018-07-12 08:18:04 +08:00
|
|
|
, sentenceBuffer()
|
2016-01-05 23:01:17 +08:00
|
|
|
{
|
|
|
|
}
|
2018-06-11 07:15:05 +08:00
|
|
|
|
2016-01-05 23:01:17 +08:00
|
|
|
void TextThread::Reset()
|
|
|
|
{
|
|
|
|
MyVector::Reset();
|
|
|
|
}
|
|
|
|
|
2018-07-12 08:18:04 +08:00
|
|
|
void TextThread::AddSentence()
|
2016-01-05 23:01:17 +08:00
|
|
|
{
|
2018-07-12 08:18:04 +08:00
|
|
|
std::wstring sentence;
|
|
|
|
if (status & USING_UNICODE)
|
2018-05-25 16:34:40 +08:00
|
|
|
{
|
2018-07-12 08:18:04 +08:00
|
|
|
sentence = std::wstring((wchar_t*)sentenceBuffer.data(), sentenceBuffer.size() / 2);
|
2018-05-25 16:34:40 +08:00
|
|
|
}
|
|
|
|
else
|
2018-06-12 07:49:28 +08:00
|
|
|
{
|
2018-07-12 08:18:04 +08:00
|
|
|
wchar_t* converted = new wchar_t[sentenceBuffer.size()];
|
|
|
|
sentence = std::wstring(converted, MultiByteToWideChar(932, 0, sentenceBuffer.data(), sentenceBuffer.size(), converted, sentenceBuffer.size()));
|
|
|
|
delete[] converted;
|
2018-06-12 07:49:28 +08:00
|
|
|
}
|
2018-07-12 08:18:04 +08:00
|
|
|
AddSentence(DispatchSentenceToExtensions(sentence, status));
|
|
|
|
sentenceBuffer.clear();
|
2016-01-05 23:01:17 +08:00
|
|
|
}
|
2018-05-25 16:34:40 +08:00
|
|
|
|
2018-07-12 08:18:04 +08:00
|
|
|
void TextThread::AddSentence(std::wstring sentence)
|
|
|
|
{
|
2018-07-13 05:47:22 +08:00
|
|
|
sentence.append(L"\r\n");
|
2018-07-12 08:18:04 +08:00
|
|
|
if (output) output(this, (const BYTE*)sentence.c_str(), sentence.length() * 2, false);
|
|
|
|
AddToStore((const BYTE*)sentence.c_str(), sentence.length() * 2);
|
2016-01-05 23:01:17 +08:00
|
|
|
}
|
|
|
|
|
2018-07-12 08:18:04 +08:00
|
|
|
void TextThread::AddText(const BYTE *con, int len)
|
|
|
|
{
|
|
|
|
sentenceBuffer.insert(sentenceBuffer.end(), con, con+len);
|
|
|
|
SetTimer(dummyWindow, (UINT_PTR)this, settings->splittingInterval,
|
|
|
|
[](HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
|
|
|
|
{
|
|
|
|
KillTimer(hWnd, idEvent);
|
|
|
|
((TextThread*)idEvent)->AddSentence();
|
|
|
|
});
|
|
|
|
}
|
2016-01-05 23:01:17 +08:00
|
|
|
|
2018-07-12 08:18:04 +08:00
|
|
|
void TextThread::GetEntryString(LPSTR buffer, DWORD max)
|
2016-01-05 23:01:17 +08:00
|
|
|
{
|
2018-07-16 03:37:26 +08:00
|
|
|
int len = sprintf(buffer, "%.4X:%.4d:0x%08X:0x%08X:0x%08X:",
|
2018-07-12 08:18:04 +08:00
|
|
|
thread_number, tp. pid, tp.hook, tp.retn, tp.spl);
|
|
|
|
GetHookName(buffer + len, tp.pid, tp.hook, max - len);
|
2016-01-05 23:01:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// EOF
|