more refactoring
This commit is contained in:
parent
48450f9717
commit
6598b979b3
@ -7,9 +7,9 @@
|
||||
# DEFINES += _CRT_NON_CONFORMING_SWPRINTFS
|
||||
|
||||
set(vnrhost_src
|
||||
config.h
|
||||
hookman.h
|
||||
host.h
|
||||
pipe.h
|
||||
textthread.h
|
||||
hookman.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/defs.h"
|
||||
#include "vnrhook/include/types.h"
|
||||
#include <stdio.h>
|
||||
#include "winmutex/winmutex.h"
|
||||
#include <atlbase.h>
|
||||
|
||||
#define HM_LOCK CriticalSectionLocker locker(hmcs) // Synchronized scope for accessing private data
|
||||
@ -24,11 +24,11 @@ HookManager::HookManager() :
|
||||
reset(nullptr),
|
||||
attach(nullptr),
|
||||
detach(nullptr),
|
||||
new_thread_number(0),
|
||||
nextThreadNumber(0),
|
||||
textThreadsByParams(),
|
||||
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;
|
||||
SetCurrent(consoleTextThread);
|
||||
|
||||
@ -147,7 +147,7 @@ void HookManager::UnRegisterProcess(DWORD 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
|
||||
if (!text || !pid || len <= 0)
|
||||
@ -157,7 +157,7 @@ void HookManager::DispatchText(DWORD pid, const BYTE *text, DWORD hook, DWORD re
|
||||
TextThread *it;
|
||||
if (!(it = textThreadsByParams[tp]))
|
||||
{
|
||||
it = textThreadsByParams[tp] = new TextThread(tp, new_thread_number++, splitDelay);
|
||||
it = textThreadsByParams[tp] = new TextThread(tp, nextThreadNumber++, splitDelay);
|
||||
if (create)
|
||||
{
|
||||
create(it);
|
||||
|
@ -4,14 +4,14 @@
|
||||
// 8/23/2013 jichi
|
||||
// Branch: ITH/HookManager.h, rev 133
|
||||
|
||||
#include "config.h"
|
||||
#include <Windows.h>
|
||||
#include "textthread.h"
|
||||
#include "winmutex/winmutex.h"
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include "vnrhook/include/types.h"
|
||||
|
||||
struct ProcessRecord {
|
||||
struct ProcessRecord
|
||||
{
|
||||
HANDLE process_handle;
|
||||
HANDLE hookman_mutex;
|
||||
HANDLE hookman_section;
|
||||
@ -30,29 +30,26 @@ struct ThreadParameterHasher
|
||||
}
|
||||
};
|
||||
|
||||
class DLLEXPORT HookManager
|
||||
class __declspec(dllexport) HookManager
|
||||
{
|
||||
public:
|
||||
HookManager();
|
||||
~HookManager();
|
||||
|
||||
TextThread *FindSingle(DWORD number);
|
||||
ProcessRecord *GetProcessRecord(DWORD pid);
|
||||
HANDLE GetHostPipe(DWORD pid);
|
||||
void ClearCurrent();
|
||||
void SelectCurrent(DWORD num);
|
||||
void SetCurrent(TextThread *it);
|
||||
void AddConsoleOutput(LPCWSTR text);
|
||||
|
||||
// jichi 10/27/2013: Add const; add space.
|
||||
void DispatchText(DWORD pid, const BYTE *text, DWORD hook, DWORD retn, DWORD split, int len);
|
||||
void DispatchText(DWORD pid, DWORD hook, DWORD retn, DWORD split, const BYTE *text, int len);
|
||||
void RemoveProcessContext(DWORD pid); // private
|
||||
void RemoveSingleHook(DWORD pid, DWORD addr);
|
||||
void RegisterProcess(DWORD pid, HANDLE hostPipe);
|
||||
void UnRegisterProcess(DWORD pid);
|
||||
HookParam GetHookParam(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 RegisterThreadRemoveCallback(ThreadEventCallback cf) { remove = cf; }
|
||||
@ -69,14 +66,11 @@ private:
|
||||
CRITICAL_SECTION hmcs;
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
// Branch IHF/main.cpp, rev 111
|
||||
|
||||
#include "host.h"
|
||||
#include "pipe.h"
|
||||
#include "vnrhook/include/const.h"
|
||||
#include "vnrhook/include/defs.h"
|
||||
#include "vnrhook/include/types.h"
|
||||
@ -27,8 +28,6 @@ namespace
|
||||
}
|
||||
} // unnamed namespace
|
||||
|
||||
void CreateNewPipe();
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID unused)
|
||||
{
|
||||
switch (fdwReason)
|
||||
@ -135,8 +134,7 @@ DLLEXPORT bool InsertHook(DWORD pid, const HookParam *hp, std::string name)
|
||||
*(HookParam*)(buffer + sizeof(DWORD)) = *hp;
|
||||
if (name.size()) strcpy((char*)buffer + sizeof(DWORD) + sizeof(HookParam), name.c_str());
|
||||
DWORD unused;
|
||||
WriteFile(commandPipe, buffer, sizeof(DWORD) + sizeof(HookParam) + name.size(), &unused, nullptr);
|
||||
return true;
|
||||
return WriteFile(commandPipe, buffer, sizeof(DWORD) + sizeof(HookParam) + name.size(), &unused, nullptr);
|
||||
}
|
||||
|
||||
DLLEXPORT bool RemoveHook(DWORD pid, DWORD addr)
|
||||
|
@ -4,13 +4,11 @@
|
||||
// 8/23/2013 jichi
|
||||
// Branch: ITH/IHF.h, rev 105
|
||||
|
||||
//#include "host/settings.h"
|
||||
#include "config.h"
|
||||
#define DLLEXPORT __declspec(dllexport)
|
||||
#include "hookman.h"
|
||||
#include "vnrhook/include/types.h"
|
||||
#include <string>
|
||||
|
||||
struct HookParam;
|
||||
|
||||
DLLEXPORT void OpenHost();
|
||||
DLLEXPORT bool StartHost();
|
||||
DLLEXPORT void CloseHost();
|
||||
|
@ -1,10 +1,9 @@
|
||||
// pipe.cc
|
||||
// 8/24/2013 jichi
|
||||
// Branch IHF/pipe.cpp, rev 93
|
||||
// 8/24/2013 TODO: Clean up this file
|
||||
|
||||
#include "pipe.h"
|
||||
#include "host.h"
|
||||
#include "hookman.h"
|
||||
#include "vnrhook/include/defs.h"
|
||||
#include "vnrhook/include/const.h"
|
||||
#include <atlbase.h>
|
||||
@ -17,8 +16,6 @@ struct Pipes
|
||||
HANDLE hostPipe;
|
||||
};
|
||||
|
||||
DWORD WINAPI TextReceiver(LPVOID lpThreadParameter);
|
||||
|
||||
void CreateNewPipe()
|
||||
{
|
||||
CloseHandle(CreateThread(nullptr, 0, TextReceiver, new Pipes
|
||||
@ -64,15 +61,12 @@ DWORD WINAPI TextReceiver(LPVOID lpThreadParameter)
|
||||
}
|
||||
else
|
||||
{
|
||||
// jichi 9/28/2013: Debug raw data
|
||||
//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,
|
||||
man->DispatchText(processId,
|
||||
*(DWORD*)buffer, // Hook address
|
||||
*(DWORD*)(buffer + sizeof(DWORD)), // Return address
|
||||
*(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