mirror of
https://github.com/HIllya51/LunaHook.git
synced 2024-12-26 13:14:13 +08:00
fix
Update LunaHostDll.cpp
This commit is contained in:
parent
3ca489a8b7
commit
083bbe41cf
@ -62,7 +62,7 @@ include(generate_product_version)
|
|||||||
|
|
||||||
set(VERSION_MAJOR 3)
|
set(VERSION_MAJOR 3)
|
||||||
set(VERSION_MINOR 1)
|
set(VERSION_MINOR 1)
|
||||||
set(VERSION_PATCH 3)
|
set(VERSION_PATCH 4)
|
||||||
set(VERSION_REVISION 0)
|
set(VERSION_REVISION 0)
|
||||||
|
|
||||||
if(BUILD_CORE)
|
if(BUILD_CORE)
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
#include"host.h"
|
#include "host.h"
|
||||||
#include"hookcode.h"
|
#include "hookcode.h"
|
||||||
#include"defs.h"
|
#include "defs.h"
|
||||||
#include"winevent.hpp"
|
#include "winevent.hpp"
|
||||||
#define C_LUNA_API extern "C" __declspec(dllexport)
|
#define C_LUNA_API extern "C" __declspec(dllexport)
|
||||||
BOOL APIENTRY DllMain(HMODULE hModule,
|
BOOL APIENTRY DllMain(HMODULE hModule,
|
||||||
DWORD ul_reason_for_call,
|
DWORD ul_reason_for_call,
|
||||||
LPVOID lpReserved
|
LPVOID lpReserved)
|
||||||
)
|
|
||||||
{
|
{
|
||||||
switch (ul_reason_for_call)
|
switch (ul_reason_for_call)
|
||||||
{
|
{
|
||||||
@ -19,192 +18,178 @@ BOOL APIENTRY DllMain(HMODULE hModule,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HANDLE HostMessageSender;
|
typedef void (*ProcessEvent)(DWORD);
|
||||||
|
typedef void (*ThreadEvent)(wchar_t *, char *, ThreadParam);
|
||||||
struct messagelist{
|
typedef void (*OutputCallback)(wchar_t *, char *, ThreadParam, const wchar_t *);
|
||||||
bool read;
|
typedef void (*ConsoleHandler)(const wchar_t *);
|
||||||
int type;
|
typedef void (*HookInsertHandler)(uint64_t, const wchar_t *);
|
||||||
DWORD pid;
|
typedef void (*EmbedCallback)(const wchar_t *, ThreadParam);
|
||||||
char name[HOOK_NAME_SIZE];
|
#define XXXX char name[HOOK_NAME_SIZE];\
|
||||||
wchar_t hookcode[HOOKCODE_LEN];
|
wchar_t hookcode[HOOKCODE_LEN];\
|
||||||
ThreadParam tp;
|
wcscpy_s(hookcode, HOOKCODE_LEN, thread.hp.hookcode);\
|
||||||
wchar_t* stringptr;
|
strcpy_s(name, HOOK_NAME_SIZE, thread.hp.name);
|
||||||
uint64_t addr;
|
C_LUNA_API void Luna_Start(ProcessEvent Connect, ProcessEvent Disconnect, ThreadEvent Create, ThreadEvent Destroy, OutputCallback Output, ConsoleHandler console, HookInsertHandler hookinsert, EmbedCallback embed)
|
||||||
messagelist(int _t):read(false),type(_t),pid(0),tp({}),stringptr(nullptr),addr(0){};
|
{
|
||||||
void sethp(const HookParam& hp){
|
|
||||||
wcscpy_s(hookcode,HOOKCODE_LEN,hp.hookcode);
|
|
||||||
strcpy_s(name,HOOK_NAME_SIZE,hp.name);
|
|
||||||
}
|
|
||||||
void setstring(const std::wstring& s){
|
|
||||||
stringptr=new wchar_t[s.size()+1];
|
|
||||||
wcscpy(stringptr,s.c_str());
|
|
||||||
}
|
|
||||||
~messagelist(){
|
|
||||||
DWORD _;
|
|
||||||
WriteFile(HostMessageSender,this,sizeof(messagelist),&_,NULL);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
C_LUNA_API void Luna_Start( HANDLE* hRead ){
|
|
||||||
CreatePipe(hRead,&HostMessageSender,NULL,0);
|
|
||||||
Host::StartEx(
|
Host::StartEx(
|
||||||
[](DWORD pid){
|
Connect,
|
||||||
messagelist message(0);
|
Disconnect,
|
||||||
message.pid=pid;
|
[=](TextThread &thread)
|
||||||
},
|
{
|
||||||
[](DWORD pid){
|
XXXX
|
||||||
messagelist message(1);
|
Create(hookcode, name, thread.tp);
|
||||||
message.pid=pid;
|
},
|
||||||
},
|
[=](TextThread &thread)
|
||||||
[](TextThread& thread) {
|
{
|
||||||
messagelist message(2);
|
XXXX
|
||||||
message.sethp(thread.hp);
|
Destroy(hookcode, name, thread.tp);
|
||||||
message.tp=thread.tp;
|
},
|
||||||
},
|
[=](TextThread &thread, std::wstring &output)
|
||||||
[](TextThread& thread) {
|
{
|
||||||
messagelist message(3);
|
XXXX
|
||||||
message.sethp(thread.hp);
|
Output(hookcode, name, thread.tp, output.c_str());
|
||||||
message.tp=thread.tp;
|
return true;
|
||||||
},
|
},
|
||||||
[](TextThread& thread, std::wstring& output){
|
[=](std::wstring &output)
|
||||||
messagelist message(4);
|
{
|
||||||
message.sethp(thread.hp);
|
console(output.c_str());
|
||||||
message.tp=thread.tp;
|
},
|
||||||
message.setstring(output);
|
[=](uint64_t addr, std::wstring &output)
|
||||||
return true;
|
{
|
||||||
},
|
hookinsert(addr, output.c_str());
|
||||||
[](std::wstring& output){
|
},
|
||||||
messagelist message(5);
|
[=](std::wstring &output, ThreadParam &tp)
|
||||||
message.setstring(output);
|
{
|
||||||
},
|
embed(output.c_str(), tp);
|
||||||
[](uint64_t addr,std::wstring& output){
|
});
|
||||||
messagelist message(6);
|
|
||||||
message.setstring(output);
|
|
||||||
message.addr=addr;
|
|
||||||
},
|
|
||||||
[](std::wstring& output,ThreadParam& tp){
|
|
||||||
messagelist message(7);
|
|
||||||
message.setstring(output);
|
|
||||||
message.tp=tp;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
C_LUNA_API void Luna_Inject(DWORD pid,LPCWSTR basepath){
|
C_LUNA_API void Luna_Inject(DWORD pid, LPCWSTR basepath)
|
||||||
Host::InjectProcess(pid,basepath);
|
{
|
||||||
|
Host::InjectProcess(pid, basepath);
|
||||||
}
|
}
|
||||||
C_LUNA_API bool Luna_CreatePipeAndCheck(DWORD pid){
|
C_LUNA_API bool Luna_CreatePipeAndCheck(DWORD pid)
|
||||||
|
{
|
||||||
return Host::CreatePipeAndCheck(pid);
|
return Host::CreatePipeAndCheck(pid);
|
||||||
}
|
}
|
||||||
C_LUNA_API void Luna_Detach(DWORD pid){
|
C_LUNA_API void Luna_Detach(DWORD pid)
|
||||||
|
{
|
||||||
Host::DetachProcess(pid);
|
Host::DetachProcess(pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
C_LUNA_API void Luna_cfree(void* ptr){
|
C_LUNA_API void Luna_Settings(int flushDelay, bool filterRepetition, int defaultCodepage, int maxBufferSize)
|
||||||
delete ptr;
|
{
|
||||||
|
TextThread::flushDelay = flushDelay;
|
||||||
|
TextThread::filterRepetition = filterRepetition;
|
||||||
|
Host::defaultCodepage = defaultCodepage;
|
||||||
|
TextThread::maxBufferSize = maxBufferSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
C_LUNA_API void Luna_Settings(int flushDelay,bool filterRepetition,int defaultCodepage,int maxBufferSize){
|
C_LUNA_API bool Luna_InsertHookCode(DWORD pid, LPCWSTR hookcode)
|
||||||
TextThread::flushDelay=flushDelay;
|
{
|
||||||
TextThread::filterRepetition=filterRepetition;
|
|
||||||
Host::defaultCodepage=defaultCodepage;
|
|
||||||
TextThread::maxBufferSize=maxBufferSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
C_LUNA_API bool Luna_InsertHookCode(DWORD pid,LPCWSTR hookcode){
|
|
||||||
auto hp = HookCode::Parse(hookcode);
|
auto hp = HookCode::Parse(hookcode);
|
||||||
if(hp)
|
if (hp)
|
||||||
Host::InsertHook(pid, hp.value());
|
Host::InsertHook(pid, hp.value());
|
||||||
return hp.has_value();
|
return hp.has_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
C_LUNA_API void Luna_RemoveHook(DWORD pid,uint64_t addr){
|
C_LUNA_API void Luna_RemoveHook(DWORD pid, uint64_t addr)
|
||||||
Host::RemoveHook(pid,addr);
|
{
|
||||||
|
Host::RemoveHook(pid, addr);
|
||||||
}
|
}
|
||||||
struct simplehooks{
|
struct simplehooks
|
||||||
|
{
|
||||||
wchar_t hookcode[HOOKCODE_LEN];
|
wchar_t hookcode[HOOKCODE_LEN];
|
||||||
wchar_t *text;
|
wchar_t *text;
|
||||||
simplehooks():text(0){};
|
simplehooks() : text(0){};
|
||||||
};
|
};
|
||||||
C_LUNA_API void Luna_FindHooks(DWORD pid,SearchParam sp,HANDLE* hRead,int** pc){
|
typedef void (*findhookcallback_t)(wchar_t *hookcode, const wchar_t *text);
|
||||||
|
C_LUNA_API void Luna_FindHooks(DWORD pid, SearchParam sp, findhookcallback_t findhookcallback)
|
||||||
auto count=new int{0};
|
{
|
||||||
*pc=count;
|
Host::FindHooks(pid, sp, [=](HookParam hp, std::wstring text)
|
||||||
HANDLE hWrite;
|
{
|
||||||
CreatePipe(hRead,&hWrite,NULL,0);
|
wchar_t hookcode[HOOKCODE_LEN];
|
||||||
Host::FindHooks(pid,sp,[=](HookParam hp, std::wstring text) {
|
wcscpy_s(hookcode,HOOKCODE_LEN, hp.hookcode);
|
||||||
//if (std::regex_search(text, std::wregex(L"[\u3000-\ua000]"))) {
|
findhookcallback(hookcode,text.c_str()); });
|
||||||
simplehooks sh;
|
|
||||||
wcscpy_s(sh.hookcode,HOOKCODE_LEN, hp.hookcode);
|
|
||||||
sh.text=new wchar_t[text.size()+1];
|
|
||||||
wcscpy(sh.text, text.c_str());
|
|
||||||
*count+=1;
|
|
||||||
if(0==WriteFile(hWrite,&sh,sizeof(sh),NULL,NULL))
|
|
||||||
CloseHandle(hWrite);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
C_LUNA_API void Luna_FindHooks_waiting(int* count){
|
C_LUNA_API void Luna_EmbedSettings(DWORD pid, UINT32 waittime, UINT8 fontCharSet, bool fontCharSetEnabled, wchar_t *fontFamily, UINT32 spaceadjustpolicy, UINT32 keeprawtext, bool fastskipignore)
|
||||||
for (int lastSize = 0; *count == 0 || *count != lastSize; Sleep(2000)) lastSize = *count;
|
{
|
||||||
delete count;
|
auto sm = Host::GetEmbedSharedMem(pid);
|
||||||
|
if (!sm)
|
||||||
|
return;
|
||||||
|
sm->waittime = waittime;
|
||||||
|
sm->fontCharSet = fontCharSet;
|
||||||
|
sm->fontCharSetEnabled = fontCharSetEnabled;
|
||||||
|
wcscpy_s(sm->fontFamily, 100, fontFamily);
|
||||||
|
sm->spaceadjustpolicy = spaceadjustpolicy;
|
||||||
|
sm->keeprawtext = keeprawtext;
|
||||||
|
sm->fastskipignore = fastskipignore;
|
||||||
}
|
}
|
||||||
C_LUNA_API void Luna_EmbedSettings(DWORD pid,UINT32 waittime,UINT8 fontCharSet,bool fontCharSetEnabled,wchar_t *fontFamily,UINT32 spaceadjustpolicy,UINT32 keeprawtext,bool fastskipignore){
|
C_LUNA_API bool Luna_checkisusingembed(DWORD pid, uint64_t address, uint64_t ctx1, uint64_t ctx2)
|
||||||
auto sm=Host::GetEmbedSharedMem(pid);
|
{
|
||||||
if(!sm)return;
|
auto sm = Host::GetEmbedSharedMem(pid);
|
||||||
sm->waittime=waittime;
|
if (!sm)
|
||||||
sm->fontCharSet=fontCharSet;
|
return false;
|
||||||
sm->fontCharSetEnabled=fontCharSetEnabled;
|
for (int i = 0; i < 10; i++)
|
||||||
wcscpy_s(sm->fontFamily,100,fontFamily);
|
{
|
||||||
sm->spaceadjustpolicy=spaceadjustpolicy;
|
if (sm->use[i])
|
||||||
sm->keeprawtext=keeprawtext;
|
{
|
||||||
sm->fastskipignore=fastskipignore;
|
if ((sm->addr[i] == address) && (sm->ctx1[i] == ctx1) && (sm->ctx2[i] == ctx2))
|
||||||
}
|
return true;
|
||||||
C_LUNA_API bool Luna_checkisusingembed(DWORD pid,uint64_t address,uint64_t ctx1,uint64_t ctx2){
|
|
||||||
auto sm=Host::GetEmbedSharedMem(pid);
|
|
||||||
if(!sm)return false;
|
|
||||||
for(int i=0;i<10;i++){
|
|
||||||
if(sm->use[i]){
|
|
||||||
if((sm->addr[i]==address)&&(sm->ctx1[i]==ctx1)&&(sm->ctx2[i]==ctx2))return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
C_LUNA_API void Luna_useembed(DWORD pid,uint64_t address,uint64_t ctx1,uint64_t ctx2,bool use){
|
C_LUNA_API void Luna_useembed(DWORD pid, uint64_t address, uint64_t ctx1, uint64_t ctx2, bool use)
|
||||||
auto sm=Host::GetEmbedSharedMem(pid);
|
{
|
||||||
if(!sm)return ;
|
auto sm = Host::GetEmbedSharedMem(pid);
|
||||||
sm->codepage=Host::defaultCodepage;
|
if (!sm)
|
||||||
for(int i=0;i<10;i++){
|
return;
|
||||||
if(sm->use[i]){
|
sm->codepage = Host::defaultCodepage;
|
||||||
if((sm->addr[i]==address)&&(sm->ctx1[i]==ctx1)&&(sm->ctx2[i]==ctx2)){
|
for (int i = 0; i < 10; i++)
|
||||||
if(use==false){
|
{
|
||||||
sm->addr[i]=sm->ctx1[i]=sm->ctx2[i]=sm->use[i]=0;
|
if (sm->use[i])
|
||||||
|
{
|
||||||
|
if ((sm->addr[i] == address) && (sm->ctx1[i] == ctx1) && (sm->ctx2[i] == ctx2))
|
||||||
|
{
|
||||||
|
if (use == false)
|
||||||
|
{
|
||||||
|
sm->addr[i] = sm->ctx1[i] = sm->ctx2[i] = sm->use[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(use){
|
if (use)
|
||||||
for(int i=0;i<10;i++){
|
{
|
||||||
if(sm->use[i]==0){
|
for (int i = 0; i < 10; i++)
|
||||||
sm->use[i]=1;
|
{
|
||||||
sm->addr[i]=address;
|
if (sm->use[i] == 0)
|
||||||
sm->ctx1[i]=ctx1;
|
{
|
||||||
sm->ctx2[i]=ctx2;
|
sm->use[i] = 1;
|
||||||
|
sm->addr[i] = address;
|
||||||
|
sm->ctx1[i] = ctx1;
|
||||||
|
sm->ctx2[i] = ctx2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline UINT64 djb2_n2(const unsigned char * str, size_t len, UINT64 hash = 5381)
|
inline UINT64 djb2_n2(const unsigned char *str, size_t len, UINT64 hash = 5381)
|
||||||
{
|
{
|
||||||
int i=0;
|
int i = 0;
|
||||||
while (len--){
|
while (len--)
|
||||||
|
{
|
||||||
hash = ((hash << 5) + hash) + (*str++); // hash * 33 + c
|
hash = ((hash << 5) + hash) + (*str++); // hash * 33 + c
|
||||||
}
|
}
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
C_LUNA_API void Luna_embedcallback(DWORD pid,LPCWSTR text,LPCWSTR trans){
|
C_LUNA_API void Luna_embedcallback(DWORD pid, LPCWSTR text, LPCWSTR trans)
|
||||||
auto sm=Host::GetEmbedSharedMem(pid);
|
{
|
||||||
if(!sm)return;
|
auto sm = Host::GetEmbedSharedMem(pid);
|
||||||
wcscpy_s(sm->text,1000,trans);
|
if (!sm)
|
||||||
|
return;
|
||||||
|
wcscpy_s(sm->text, 1000, trans);
|
||||||
char eventname[1000];
|
char eventname[1000];
|
||||||
sprintf(eventname,LUNA_EMBED_notify_event,pid,djb2_n2((const unsigned char*)(text),wcslen(text)*2));
|
sprintf(eventname, LUNA_EMBED_notify_event, pid, djb2_n2((const unsigned char *)(text), wcslen(text) * 2));
|
||||||
win_event event1(eventname);
|
win_event event1(eventname);
|
||||||
event1.signal(true);
|
event1.signal(true);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user