mirror of
https://github.com/Artikash/Textractor.git
synced 2024-12-23 17:04:12 +08:00
more refactoring
This commit is contained in:
parent
48450f9717
commit
6598b979b3
@ -7,9 +7,9 @@
|
|||||||
# DEFINES += _CRT_NON_CONFORMING_SWPRINTFS
|
# DEFINES += _CRT_NON_CONFORMING_SWPRINTFS
|
||||||
|
|
||||||
set(vnrhost_src
|
set(vnrhost_src
|
||||||
config.h
|
|
||||||
hookman.h
|
hookman.h
|
||||||
host.h
|
host.h
|
||||||
|
pipe.h
|
||||||
textthread.h
|
textthread.h
|
||||||
hookman.cc
|
hookman.cc
|
||||||
host.cc
|
host.cc
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
// config.h
|
|
||||||
// 8/23/2013 jichi
|
|
||||||
// The first header file that are included by all source files.
|
|
||||||
|
|
||||||
#define IHF // for dll import
|
|
||||||
#define DLLEXPORT __declspec(dllexport)
|
|
||||||
|
|
||||||
// EOF
|
|
@ -12,7 +12,7 @@
|
|||||||
#include "vnrhook/include/const.h"
|
#include "vnrhook/include/const.h"
|
||||||
#include "vnrhook/include/defs.h"
|
#include "vnrhook/include/defs.h"
|
||||||
#include "vnrhook/include/types.h"
|
#include "vnrhook/include/types.h"
|
||||||
#include <stdio.h>
|
#include "winmutex/winmutex.h"
|
||||||
#include <atlbase.h>
|
#include <atlbase.h>
|
||||||
|
|
||||||
#define HM_LOCK CriticalSectionLocker locker(hmcs) // Synchronized scope for accessing private data
|
#define HM_LOCK CriticalSectionLocker locker(hmcs) // Synchronized scope for accessing private data
|
||||||
@ -24,11 +24,11 @@ HookManager::HookManager() :
|
|||||||
reset(nullptr),
|
reset(nullptr),
|
||||||
attach(nullptr),
|
attach(nullptr),
|
||||||
detach(nullptr),
|
detach(nullptr),
|
||||||
new_thread_number(0),
|
nextThreadNumber(0),
|
||||||
textThreadsByParams(),
|
textThreadsByParams(),
|
||||||
processRecordsByIds()
|
processRecordsByIds()
|
||||||
{
|
{
|
||||||
TextThread* consoleTextThread = textThreadsByParams[{ 0, -1UL, -1UL, -1UL }] = new TextThread({ 0, -1UL, -1UL, -1UL }, new_thread_number++, splitDelay);
|
TextThread* consoleTextThread = textThreadsByParams[{ 0, -1UL, -1UL, -1UL }] = new TextThread({ 0, -1UL, -1UL, -1UL }, nextThreadNumber++, splitDelay);
|
||||||
consoleTextThread->Status() |= USING_UNICODE;
|
consoleTextThread->Status() |= USING_UNICODE;
|
||||||
SetCurrent(consoleTextThread);
|
SetCurrent(consoleTextThread);
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ void HookManager::UnRegisterProcess(DWORD pid)
|
|||||||
detach(pid);
|
detach(pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HookManager::DispatchText(DWORD pid, const BYTE *text, DWORD hook, DWORD retn, DWORD spl, int len)
|
void HookManager::DispatchText(DWORD pid, DWORD hook, DWORD retn, DWORD spl, const BYTE *text, int len)
|
||||||
{
|
{
|
||||||
// jichi 20/27/2013: When PID is zero, the text comes from console, which I don't need
|
// jichi 20/27/2013: When PID is zero, the text comes from console, which I don't need
|
||||||
if (!text || !pid || len <= 0)
|
if (!text || !pid || len <= 0)
|
||||||
@ -157,7 +157,7 @@ void HookManager::DispatchText(DWORD pid, const BYTE *text, DWORD hook, DWORD re
|
|||||||
TextThread *it;
|
TextThread *it;
|
||||||
if (!(it = textThreadsByParams[tp]))
|
if (!(it = textThreadsByParams[tp]))
|
||||||
{
|
{
|
||||||
it = textThreadsByParams[tp] = new TextThread(tp, new_thread_number++, splitDelay);
|
it = textThreadsByParams[tp] = new TextThread(tp, nextThreadNumber++, splitDelay);
|
||||||
if (create)
|
if (create)
|
||||||
{
|
{
|
||||||
create(it);
|
create(it);
|
||||||
|
@ -4,14 +4,14 @@
|
|||||||
// 8/23/2013 jichi
|
// 8/23/2013 jichi
|
||||||
// Branch: ITH/HookManager.h, rev 133
|
// Branch: ITH/HookManager.h, rev 133
|
||||||
|
|
||||||
#include "config.h"
|
#include <Windows.h>
|
||||||
#include "textthread.h"
|
#include "textthread.h"
|
||||||
#include "winmutex/winmutex.h"
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "vnrhook/include/types.h"
|
#include "vnrhook/include/types.h"
|
||||||
|
|
||||||
struct ProcessRecord {
|
struct ProcessRecord
|
||||||
|
{
|
||||||
HANDLE process_handle;
|
HANDLE process_handle;
|
||||||
HANDLE hookman_mutex;
|
HANDLE hookman_mutex;
|
||||||
HANDLE hookman_section;
|
HANDLE hookman_section;
|
||||||
@ -30,29 +30,26 @@ struct ThreadParameterHasher
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class DLLEXPORT HookManager
|
class __declspec(dllexport) HookManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HookManager();
|
HookManager();
|
||||||
~HookManager();
|
~HookManager();
|
||||||
|
|
||||||
TextThread *FindSingle(DWORD number);
|
TextThread *FindSingle(DWORD number);
|
||||||
ProcessRecord *GetProcessRecord(DWORD pid);
|
ProcessRecord *GetProcessRecord(DWORD pid);
|
||||||
|
HANDLE GetHostPipe(DWORD pid);
|
||||||
void ClearCurrent();
|
void ClearCurrent();
|
||||||
void SelectCurrent(DWORD num);
|
void SelectCurrent(DWORD num);
|
||||||
void SetCurrent(TextThread *it);
|
void SetCurrent(TextThread *it);
|
||||||
void AddConsoleOutput(LPCWSTR text);
|
void AddConsoleOutput(LPCWSTR text);
|
||||||
|
void DispatchText(DWORD pid, DWORD hook, DWORD retn, DWORD split, const BYTE *text, int len);
|
||||||
// jichi 10/27/2013: Add const; add space.
|
|
||||||
void DispatchText(DWORD pid, const BYTE *text, DWORD hook, DWORD retn, DWORD split, int len);
|
|
||||||
void RemoveProcessContext(DWORD pid); // private
|
void RemoveProcessContext(DWORD pid); // private
|
||||||
void RemoveSingleHook(DWORD pid, DWORD addr);
|
void RemoveSingleHook(DWORD pid, DWORD addr);
|
||||||
void RegisterProcess(DWORD pid, HANDLE hostPipe);
|
void RegisterProcess(DWORD pid, HANDLE hostPipe);
|
||||||
void UnRegisterProcess(DWORD pid);
|
void UnRegisterProcess(DWORD pid);
|
||||||
HookParam GetHookParam(DWORD pid, DWORD addr);
|
HookParam GetHookParam(DWORD pid, DWORD addr);
|
||||||
std::wstring GetHookName(DWORD pid, DWORD addr);
|
std::wstring GetHookName(DWORD pid, DWORD addr);
|
||||||
//void SetName(DWORD);
|
|
||||||
|
|
||||||
HANDLE GetHostPipe(DWORD pid);
|
|
||||||
|
|
||||||
void RegisterThreadCreateCallback(ThreadEventCallback cf) { create = cf; }
|
void RegisterThreadCreateCallback(ThreadEventCallback cf) { create = cf; }
|
||||||
void RegisterThreadRemoveCallback(ThreadEventCallback cf) { remove = cf; }
|
void RegisterThreadRemoveCallback(ThreadEventCallback cf) { remove = cf; }
|
||||||
@ -69,14 +66,11 @@ private:
|
|||||||
CRITICAL_SECTION hmcs;
|
CRITICAL_SECTION hmcs;
|
||||||
|
|
||||||
TextThread *current;
|
TextThread *current;
|
||||||
ThreadEventCallback create,
|
|
||||||
remove,
|
|
||||||
reset;
|
|
||||||
ProcessEventCallback attach,
|
|
||||||
detach;
|
|
||||||
WORD register_count,
|
|
||||||
new_thread_number;
|
|
||||||
|
|
||||||
|
ThreadEventCallback create, remove, reset;
|
||||||
|
ProcessEventCallback attach, detach;
|
||||||
|
|
||||||
|
WORD nextThreadNumber;
|
||||||
unsigned int splitDelay;
|
unsigned int splitDelay;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
// Branch IHF/main.cpp, rev 111
|
// Branch IHF/main.cpp, rev 111
|
||||||
|
|
||||||
#include "host.h"
|
#include "host.h"
|
||||||
|
#include "pipe.h"
|
||||||
#include "vnrhook/include/const.h"
|
#include "vnrhook/include/const.h"
|
||||||
#include "vnrhook/include/defs.h"
|
#include "vnrhook/include/defs.h"
|
||||||
#include "vnrhook/include/types.h"
|
#include "vnrhook/include/types.h"
|
||||||
@ -27,8 +28,6 @@ namespace
|
|||||||
}
|
}
|
||||||
} // unnamed namespace
|
} // unnamed namespace
|
||||||
|
|
||||||
void CreateNewPipe();
|
|
||||||
|
|
||||||
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID unused)
|
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID unused)
|
||||||
{
|
{
|
||||||
switch (fdwReason)
|
switch (fdwReason)
|
||||||
@ -135,8 +134,7 @@ DLLEXPORT bool InsertHook(DWORD pid, const HookParam *hp, std::string name)
|
|||||||
*(HookParam*)(buffer + sizeof(DWORD)) = *hp;
|
*(HookParam*)(buffer + sizeof(DWORD)) = *hp;
|
||||||
if (name.size()) strcpy((char*)buffer + sizeof(DWORD) + sizeof(HookParam), name.c_str());
|
if (name.size()) strcpy((char*)buffer + sizeof(DWORD) + sizeof(HookParam), name.c_str());
|
||||||
DWORD unused;
|
DWORD unused;
|
||||||
WriteFile(commandPipe, buffer, sizeof(DWORD) + sizeof(HookParam) + name.size(), &unused, nullptr);
|
return WriteFile(commandPipe, buffer, sizeof(DWORD) + sizeof(HookParam) + name.size(), &unused, nullptr);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DLLEXPORT bool RemoveHook(DWORD pid, DWORD addr)
|
DLLEXPORT bool RemoveHook(DWORD pid, DWORD addr)
|
||||||
|
@ -4,13 +4,11 @@
|
|||||||
// 8/23/2013 jichi
|
// 8/23/2013 jichi
|
||||||
// Branch: ITH/IHF.h, rev 105
|
// Branch: ITH/IHF.h, rev 105
|
||||||
|
|
||||||
//#include "host/settings.h"
|
#define DLLEXPORT __declspec(dllexport)
|
||||||
#include "config.h"
|
|
||||||
#include "hookman.h"
|
#include "hookman.h"
|
||||||
|
#include "vnrhook/include/types.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
struct HookParam;
|
|
||||||
|
|
||||||
DLLEXPORT void OpenHost();
|
DLLEXPORT void OpenHost();
|
||||||
DLLEXPORT bool StartHost();
|
DLLEXPORT bool StartHost();
|
||||||
DLLEXPORT void CloseHost();
|
DLLEXPORT void CloseHost();
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
// pipe.cc
|
// pipe.cc
|
||||||
// 8/24/2013 jichi
|
// 8/24/2013 jichi
|
||||||
// Branch IHF/pipe.cpp, rev 93
|
// Branch IHF/pipe.cpp, rev 93
|
||||||
// 8/24/2013 TODO: Clean up this file
|
|
||||||
|
|
||||||
|
#include "pipe.h"
|
||||||
#include "host.h"
|
#include "host.h"
|
||||||
#include "hookman.h"
|
|
||||||
#include "vnrhook/include/defs.h"
|
#include "vnrhook/include/defs.h"
|
||||||
#include "vnrhook/include/const.h"
|
#include "vnrhook/include/const.h"
|
||||||
#include <atlbase.h>
|
#include <atlbase.h>
|
||||||
@ -17,8 +16,6 @@ struct Pipes
|
|||||||
HANDLE hostPipe;
|
HANDLE hostPipe;
|
||||||
};
|
};
|
||||||
|
|
||||||
DWORD WINAPI TextReceiver(LPVOID lpThreadParameter);
|
|
||||||
|
|
||||||
void CreateNewPipe()
|
void CreateNewPipe()
|
||||||
{
|
{
|
||||||
CloseHandle(CreateThread(nullptr, 0, TextReceiver, new Pipes
|
CloseHandle(CreateThread(nullptr, 0, TextReceiver, new Pipes
|
||||||
@ -64,15 +61,12 @@ DWORD WINAPI TextReceiver(LPVOID lpThreadParameter)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// jichi 9/28/2013: Debug raw data
|
man->DispatchText(processId,
|
||||||
//ITH_DEBUG_DWORD9(RecvLen - 0xc,
|
|
||||||
// buffer[0xc], buffer[0xd], buffer[0xe], buffer[0xf],
|
|
||||||
// buffer[0x10], buffer[0x11], buffer[0x12], buffer[0x13]);
|
|
||||||
man->DispatchText(processId, buffer + HEADER_SIZE,
|
|
||||||
*(DWORD*)buffer, // Hook address
|
*(DWORD*)buffer, // Hook address
|
||||||
*(DWORD*)(buffer + sizeof(DWORD)), // Return address
|
*(DWORD*)(buffer + sizeof(DWORD)), // Return address
|
||||||
*(DWORD*)(buffer + sizeof(DWORD) * 2), // Split
|
*(DWORD*)(buffer + sizeof(DWORD) * 2), // Split
|
||||||
bytesRead - HEADER_SIZE
|
buffer + HEADER_SIZE, // Data
|
||||||
|
bytesRead - HEADER_SIZE // Data size
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
11
vnr/texthook/pipe.h
Normal file
11
vnr/texthook/pipe.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// pipe.h
|
||||||
|
// 7/19/2018 Artikash
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
|
void CreateNewPipe();
|
||||||
|
DWORD WINAPI TextReceiver(LPVOID lpThreadParam);
|
||||||
|
|
||||||
|
// EOF
|
Loading…
x
Reference in New Issue
Block a user