2016-01-06 00:01:17 +09: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
|
|
|
|
|
2018-07-17 17:01:56 -04:00
|
|
|
#include "host.h"
|
2016-01-06 00:01:17 +09:00
|
|
|
#include "textthread.h"
|
|
|
|
//#include "wintimer/wintimer.h"
|
|
|
|
#include "vnrhook/include/const.h"
|
2018-07-17 17:01:56 -04:00
|
|
|
#include "vnrhook/include/types.h"
|
2016-01-06 00:01:17 +09:00
|
|
|
#include <stdio.h>
|
2018-05-25 04:34:40 -04:00
|
|
|
#include "extensions/Extensions.h"
|
2016-01-06 00:01:17 +09:00
|
|
|
|
2018-07-17 17:01:56 -04:00
|
|
|
extern HookManager* man;
|
2016-01-06 00:01:17 +09:00
|
|
|
|
2018-07-17 17:01:56 -04:00
|
|
|
DWORD GetHookName(LPSTR str, DWORD pid, DWORD hook_addr, DWORD max)
|
|
|
|
{
|
|
|
|
if (!pid)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
DWORD len = 0;
|
|
|
|
max--; //for '\0' magic marker.
|
|
|
|
|
|
|
|
//if (pid == 0) {
|
|
|
|
// len = wcslen(HookNameInitTable[0]);
|
|
|
|
// if (len >= max)
|
|
|
|
// len = max;
|
|
|
|
// memcpy(str, HookNameInitTable[0], len << 1);
|
|
|
|
// str[len] = 0;
|
|
|
|
// return len;
|
|
|
|
//}
|
2016-01-06 00:01:17 +09:00
|
|
|
|
2018-07-17 17:01:56 -04:00
|
|
|
//::man->LockProcessHookman(pid);
|
|
|
|
ProcessRecord *pr = ::man->GetProcessRecord(pid);
|
|
|
|
if (!pr)
|
|
|
|
return 0;
|
|
|
|
WaitForSingleObject(pr->hookman_mutex, 0);
|
|
|
|
const Hook *hks = (const Hook *)pr->hookman_map;
|
|
|
|
for (int i = 0; i < MAX_HOOK; i++)
|
|
|
|
if (hks[i].Address() == hook_addr) {
|
|
|
|
len = hks[i].NameLength();
|
|
|
|
if (len >= max)
|
|
|
|
len = max;
|
|
|
|
ReadProcessMemory(pr->process_handle, hks[i].Name(), str, len, &len);
|
|
|
|
if (str[len - 1] == 0)
|
|
|
|
len--;
|
|
|
|
else
|
|
|
|
str[len] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReleaseMutex(pr->hookman_mutex);
|
|
|
|
//::man->UnlockProcessHookman(pid);
|
|
|
|
return len;
|
|
|
|
}
|
2016-01-06 00:01:17 +09:00
|
|
|
|
2018-05-11 16:46:05 -04:00
|
|
|
extern HWND dummyWindow;
|
2016-01-06 00:01:17 +09:00
|
|
|
|
2018-07-17 17:01:56 -04:00
|
|
|
TextThread::TextThread(ThreadParameter tp, unsigned int threadNumber, unsigned int splitDelay) :
|
|
|
|
thread_number(threadNumber),
|
|
|
|
splitDelay(splitDelay),
|
|
|
|
output(nullptr),
|
|
|
|
status(0),
|
|
|
|
tp(tp),
|
|
|
|
sentenceBuffer()
|
2016-01-06 00:01:17 +09:00
|
|
|
{
|
|
|
|
}
|
2018-06-10 19:15:05 -04:00
|
|
|
|
2016-01-06 00:01:17 +09:00
|
|
|
void TextThread::Reset()
|
|
|
|
{
|
|
|
|
MyVector::Reset();
|
|
|
|
}
|
|
|
|
|
2018-07-11 20:18:04 -04:00
|
|
|
void TextThread::AddSentence()
|
2016-01-06 00:01:17 +09:00
|
|
|
{
|
2018-07-11 20:18:04 -04:00
|
|
|
std::wstring sentence;
|
|
|
|
if (status & USING_UNICODE)
|
2018-05-25 04:34:40 -04:00
|
|
|
{
|
2018-07-11 20:18:04 -04:00
|
|
|
sentence = std::wstring((wchar_t*)sentenceBuffer.data(), sentenceBuffer.size() / 2);
|
2018-05-25 04:34:40 -04:00
|
|
|
}
|
|
|
|
else
|
2018-06-11 19:49:28 -04:00
|
|
|
{
|
2018-07-11 20:18:04 -04: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-11 19:49:28 -04:00
|
|
|
}
|
2018-07-11 20:18:04 -04:00
|
|
|
AddSentence(DispatchSentenceToExtensions(sentence, status));
|
|
|
|
sentenceBuffer.clear();
|
2016-01-06 00:01:17 +09:00
|
|
|
}
|
2018-05-25 04:34:40 -04:00
|
|
|
|
2018-07-11 20:18:04 -04:00
|
|
|
void TextThread::AddSentence(std::wstring sentence)
|
|
|
|
{
|
2018-07-12 17:47:22 -04:00
|
|
|
sentence.append(L"\r\n");
|
2018-07-11 20:18:04 -04: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-06 00:01:17 +09:00
|
|
|
}
|
|
|
|
|
2018-07-11 20:18:04 -04:00
|
|
|
void TextThread::AddText(const BYTE *con, int len)
|
|
|
|
{
|
|
|
|
sentenceBuffer.insert(sentenceBuffer.end(), con, con+len);
|
2018-07-17 17:01:56 -04:00
|
|
|
SetTimer(dummyWindow, (UINT_PTR)this, splitDelay,
|
2018-07-11 20:18:04 -04:00
|
|
|
[](HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
|
|
|
|
{
|
|
|
|
KillTimer(hWnd, idEvent);
|
|
|
|
((TextThread*)idEvent)->AddSentence();
|
|
|
|
});
|
|
|
|
}
|
2016-01-06 00:01:17 +09:00
|
|
|
|
2018-07-11 20:18:04 -04:00
|
|
|
void TextThread::GetEntryString(LPSTR buffer, DWORD max)
|
2016-01-06 00:01:17 +09:00
|
|
|
{
|
2018-07-15 15:37:26 -04:00
|
|
|
int len = sprintf(buffer, "%.4X:%.4d:0x%08X:0x%08X:0x%08X:",
|
2018-07-11 20:18:04 -04:00
|
|
|
thread_number, tp. pid, tp.hook, tp.retn, tp.spl);
|
|
|
|
GetHookName(buffer + len, tp.pid, tp.hook, max - len);
|
2016-01-06 00:01:17 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// EOF
|