mirror of
https://github.com/HIllya51/LunaHook.git
synced 2024-12-24 20:24:13 +08:00
many update
This commit is contained in:
parent
bf6625ce97
commit
f1606d27a9
@ -40,6 +40,8 @@
|
||||
#define WndPlugins L"Plugins"
|
||||
#define NotifyInvalidHookCode L"Invalid HookCode"
|
||||
#define BtnSelectProcess L"Select Process"
|
||||
#define BtnDetach L"Detach"
|
||||
#define BtnSaveHook L"Save hook"
|
||||
#define BtnShowSettingWindow L"Settings"
|
||||
#define BtnAttach L"Attach"
|
||||
#define BtnRefresh L"Refresh"
|
||||
@ -52,9 +54,12 @@
|
||||
#define LblCodePage L"Default codepage"
|
||||
#define LblMaxBuff L"Max buffer size"
|
||||
#define LblAutoAttach L"Auto attach"
|
||||
#define LblAutoAttach_savedonly L"Auto attach (saved only)"
|
||||
#define MenuCopyHookCode L"CopyHookCode"
|
||||
#define MenuRemoveHook L"RemoveHook"
|
||||
#define MenuDetachProcess L"DetachProcess"
|
||||
#define MenuRemeberSelect L"Remeber Hook Selection"
|
||||
#define MenuForgetSelect L"Forget Hook Selection"
|
||||
#define MenuAddPlugin L"Add Plugin"
|
||||
#define MenuAddQtPlugin L"Add Qt Plugin"
|
||||
#define MenuRemovePlugin L"Remove Plugin"
|
||||
|
@ -40,6 +40,8 @@
|
||||
#define WndPlugins L"插件"
|
||||
#define NotifyInvalidHookCode L"特殊码无效"
|
||||
#define BtnSelectProcess L"选择进程"
|
||||
#define BtnDetach L"从游戏分离"
|
||||
#define BtnSaveHook L"保存钩子"
|
||||
#define BtnShowSettingWindow L"设置"
|
||||
#define BtnAttach L"注入进程"
|
||||
#define BtnRefresh L"刷新"
|
||||
@ -52,9 +54,12 @@
|
||||
#define LblCodePage L"默认代码页"
|
||||
#define LblMaxBuff L"最大缓冲区长度"
|
||||
#define LblAutoAttach L"自动附加"
|
||||
#define LblAutoAttach_savedonly L"自动附加 (仅限保存过配置的游戏)"
|
||||
#define MenuCopyHookCode L"复制特殊码"
|
||||
#define MenuRemoveHook L"移除钩子"
|
||||
#define MenuDetachProcess L"离开进程"
|
||||
#define MenuRemeberSelect L"记住选择的钩子"
|
||||
#define MenuForgetSelect L"忘掉选择的钩子"
|
||||
#define MenuAddPlugin L"添加插件"
|
||||
#define MenuAddQtPlugin L"添加依赖Qt的插件"
|
||||
#define MenuRemovePlugin L"移除插件"
|
||||
|
@ -2,12 +2,12 @@
|
||||
#include <CommCtrl.h>
|
||||
#include <TlHelp32.h>
|
||||
#include<stdio.h>
|
||||
#include<thread>
|
||||
#include<fstream>
|
||||
#include"host.h"
|
||||
#include"hookcode.h"
|
||||
#include"textthread.h"
|
||||
#include"LunaHost.h"
|
||||
#include"processlistwindow.h"
|
||||
#include"Lang/Lang.h"
|
||||
void LunaHost::toclipboard(std::wstring& sentence){
|
||||
|
||||
@ -31,45 +31,109 @@ void LunaHost::on_close(){
|
||||
Host::DetachProcess(pid);
|
||||
}
|
||||
if(attachedprocess.size())
|
||||
Sleep(100);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
void LunaHost::on_size(int w,int h){
|
||||
int height = h-110;
|
||||
w-=20;
|
||||
auto _w=w-20;
|
||||
g_selectprocessbutton->setgeo(10,10,_w/3,30);
|
||||
btnshowsettionwindow->setgeo(10+10+_w/3,10,_w/3,30);
|
||||
btnplugin->setgeo(10+20+_w*2/3,10,_w/3,30);
|
||||
|
||||
g_selectprocessbutton->setgeo(10,10,_w/4,30);
|
||||
btndetachall->setgeo(10+10+_w/4,10,_w/4,30);
|
||||
//btnsavehook->setgeo(10+20+_w*2/4,10,_w/4,30);
|
||||
btnshowsettionwindow->setgeo(10+30+_w*3/4,10,_w/4,30);
|
||||
g_hListBox_listtext->setgeo(10, 90, w , height/2);
|
||||
g_showtexts->setgeo(10, 100+height/2, w , height/2);
|
||||
g_hEdit_userhook->setgeo(10,50,_w*2/3+10,30);
|
||||
g_hButton_insert->setgeo(10+20+_w*2/3,50,_w/3,30);
|
||||
g_hEdit_userhook->setgeo(10,50,_w*2/4+10,30);
|
||||
g_hButton_insert->setgeo(10+20+_w*2/4,50,_w/4,30);
|
||||
btnplugin->setgeo(10+30+_w*3/4,50,_w/4,30);
|
||||
}
|
||||
void LunaHost::savesettings()
|
||||
{
|
||||
configs->set("ToClipboard",check_toclipboard);
|
||||
configs->set("AutoAttach",autoattach);
|
||||
configs->set("AutoAttach_SavedOnly",autoattach_savedonly);
|
||||
configs->set("flushDelay",TextThread::flushDelay);
|
||||
configs->set("filterRepetition",TextThread::filterRepetition);
|
||||
configs->set("maxBufferSize",TextThread::maxBufferSize);
|
||||
configs->set("defaultCodepage",Host::defaultCodepage);
|
||||
configs->set("autoattachexes",autoattachexes);
|
||||
configs->set("savedhookcontext",savedhookcontext);
|
||||
}
|
||||
void LunaHost::loadsettings(){
|
||||
check_toclipboard=configs->get("ToClipboard",false);
|
||||
autoattach=configs->get("AutoAttach",false);
|
||||
autoattach_savedonly=configs->get("AutoAttach_SavedOnly",true);
|
||||
TextThread::flushDelay=configs->get("flushDelay",TextThread::flushDelay);
|
||||
TextThread::filterRepetition=configs->get("filterRepetition",TextThread::filterRepetition);
|
||||
TextThread::maxBufferSize=configs->get("maxBufferSize",TextThread::maxBufferSize);
|
||||
Host::defaultCodepage=configs->get("defaultCodepage",Host::defaultCodepage);
|
||||
autoattachexes=configs->get("autoattachexes",std::set<std::string>{});
|
||||
savedhookcontext=configs->get("savedhookcontext",decltype(savedhookcontext){});
|
||||
}
|
||||
|
||||
std::unordered_map<std::wstring,std::vector<int>> getprocesslist();
|
||||
void LunaHost::doautoattach()
|
||||
{
|
||||
|
||||
if(autoattach==false&&autoattach_savedonly==false)return;
|
||||
|
||||
if(autoattachexes.empty())return;
|
||||
|
||||
for(auto [pexe,pids ]:getprocesslist())
|
||||
{
|
||||
auto&& u8procname=WideStringToString(pexe);
|
||||
if(autoattachexes.find(u8procname)==autoattachexes.end())continue;
|
||||
if(autoattach_savedonly && savedhookcontext.find(u8procname)==savedhookcontext.end())continue;
|
||||
for(auto pid:pids){
|
||||
if(userdetachedpids.find(pid)!=userdetachedpids.end())continue;
|
||||
|
||||
if(attachedprocess.find(pid)==attachedprocess.end())
|
||||
Host::InjectProcess(pid);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void LunaHost::on_proc_connect(DWORD pid)
|
||||
{
|
||||
attachedprocess.insert(pid);
|
||||
|
||||
if(auto pexe=GetModuleFilename(pid))
|
||||
{
|
||||
autoattachexes.insert(WideStringToString(pexe.value()));
|
||||
}
|
||||
}
|
||||
|
||||
LunaHost::LunaHost(){
|
||||
loadsettings();
|
||||
setfont(25);
|
||||
|
||||
configs=new confighelper;
|
||||
loadsettings();
|
||||
|
||||
std::thread([&]{
|
||||
while(1){
|
||||
doautoattach();
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
}
|
||||
}).detach();
|
||||
|
||||
setfont(25);
|
||||
settext(WndLunaHostGui);
|
||||
btnshowsettionwindow=new button(this, BtnShowSettingWindow,100,100,100,100);
|
||||
g_selectprocessbutton =new button(this,BtnSelectProcess,830, 10, 200, 40) ;
|
||||
|
||||
// btnsavehook=new button(this,BtnSaveHook,10,10,10,10);
|
||||
// btnsavehook->onclick=std::bind(&LunaHost::btnsavehookscallback,this);
|
||||
btndetachall=new button(this,BtnDetach,10,10,10,10);
|
||||
btndetachall->onclick=[&](){
|
||||
for(auto pid:attachedprocess){
|
||||
Host::DetachProcess(pid);
|
||||
userdetachedpids.insert(pid);
|
||||
}
|
||||
};
|
||||
|
||||
g_hEdit_userhook = new textedit(this,L"",10, 60, 600, 40,ES_AUTOHSCROLL);
|
||||
btnplugin=new button(this,BtnPlugin,830,60,200,40);
|
||||
|
||||
@ -115,11 +179,15 @@ LunaHost::LunaHost(){
|
||||
#define IDM_REMOVE_HOOK 1001
|
||||
#define IDM_DETACH_PROCESS 1002
|
||||
#define IDM_COPY_HOOKCODE 1003
|
||||
#define IDM_REMEMBER_SELECTION 1004
|
||||
#define IDM_FORGET_SELECTION 1005
|
||||
g_hListBox_listtext->oncontextmenu=[](){
|
||||
HMENU hMenu = CreatePopupMenu();
|
||||
AppendMenu(hMenu, MF_STRING, IDM_COPY_HOOKCODE, MenuCopyHookCode);
|
||||
AppendMenu(hMenu, MF_STRING, IDM_REMOVE_HOOK, MenuRemoveHook);
|
||||
AppendMenu(hMenu, MF_STRING, IDM_DETACH_PROCESS, MenuDetachProcess);
|
||||
AppendMenu(hMenu, MF_STRING, IDM_REMEMBER_SELECTION, MenuRemeberSelect);
|
||||
AppendMenu(hMenu, MF_STRING, IDM_FORGET_SELECTION, MenuForgetSelect);
|
||||
return hMenu;
|
||||
};
|
||||
g_hListBox_listtext->oncontextmenucallback=[&](WPARAM wparam){
|
||||
@ -134,30 +202,95 @@ LunaHost::LunaHost(){
|
||||
break;
|
||||
case IDM_DETACH_PROCESS:
|
||||
Host::DetachProcess(tt->tp.processId);
|
||||
userdetachedpids.insert(tt->tp.processId);
|
||||
break;
|
||||
case IDM_REMOVE_HOOK:
|
||||
Host::RemoveHook(tt->tp.processId,tt->tp.addr);
|
||||
break;
|
||||
case IDM_FORGET_SELECTION:
|
||||
case IDM_REMEMBER_SELECTION:
|
||||
{
|
||||
|
||||
std::vector<wchar_t> buffer(MAX_PATH);
|
||||
auto gmf=[&](DWORD processId)->std::optional<std::wstring>{
|
||||
std::vector<wchar_t> buffer(MAX_PATH);
|
||||
if (AutoHandle<> process = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, FALSE, processId))
|
||||
if (GetModuleFileNameExW(process, 0, buffer.data(), MAX_PATH)) return buffer.data();
|
||||
return {};
|
||||
};
|
||||
//见鬼了,GetModuleFileName找不到标识符
|
||||
|
||||
if(auto pexe=gmf(tt->tp.processId))
|
||||
{
|
||||
auto pexev=WideStringToString(pexe.value());
|
||||
if(LOWORD(wparam)==IDM_REMEMBER_SELECTION)
|
||||
{
|
||||
|
||||
savedhookcontext[pexev]={
|
||||
{"hookcode",WideStringToString(tt->hp.hookcode)},
|
||||
{"ctx1",tt->tp.ctx},
|
||||
{"ctx2",tt->tp.ctx2},
|
||||
};
|
||||
}
|
||||
else if(LOWORD(wparam)==IDM_FORGET_SELECTION)
|
||||
{
|
||||
savedhookcontext.erase(pexev);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
};
|
||||
g_showtexts = new textedit(this,L"",10, 330, 200, 200,ES_MULTILINE |ES_AUTOVSCROLL| WS_VSCROLL);
|
||||
g_showtexts->setreadonly(true);
|
||||
|
||||
Host::Start(
|
||||
[&](DWORD pid) {attachedprocess.push_back(pid);},
|
||||
std::bind(&LunaHost::on_proc_connect,this,std::placeholders::_1),
|
||||
[&](DWORD pid) {
|
||||
attachedprocess.erase(std::remove(attachedprocess.begin(), attachedprocess.end(), pid), attachedprocess.end());
|
||||
attachedprocess.erase(pid);
|
||||
},
|
||||
std::bind(&LunaHost::on_thread_create,this,std::placeholders::_1),
|
||||
std::bind(&LunaHost::on_thread_delete,this,std::placeholders::_1),
|
||||
std::bind(&LunaHost::on_text_recv,this,std::placeholders::_1,std::placeholders::_2)
|
||||
);
|
||||
|
||||
setcentral(1000,600);
|
||||
setcentral(1200,800);
|
||||
}
|
||||
void LunaHost::on_text_recv_checkissaved(TextThread& thread)
|
||||
{
|
||||
|
||||
if(onceautoselectthread.find(thread.handle)!=onceautoselectthread.end())return;
|
||||
|
||||
onceautoselectthread.insert(thread.handle);
|
||||
|
||||
if(auto exe=GetModuleFilename(thread.tp.processId))
|
||||
{
|
||||
auto exea=WideStringToString(exe.value());
|
||||
if(savedhookcontext.find(exea)==savedhookcontext.end())return;
|
||||
|
||||
std::string hc= savedhookcontext[exea]["hookcode"];
|
||||
uint64_t ctx1=savedhookcontext[exea]["ctx1"];
|
||||
uint64_t ctx2=savedhookcontext[exea]["ctx2"];
|
||||
if(((ctx1&0xffff)==(thread.tp.ctx&0xffff) )&& (ctx2==thread.tp.ctx2) && (hc==WideStringToString(thread.hp.hookcode)))
|
||||
{
|
||||
for(int i=0;i<g_hListBox_listtext->count();i++)
|
||||
{
|
||||
auto handle=g_hListBox_listtext->getdata(i);
|
||||
if(handle==thread.handle)
|
||||
{
|
||||
g_hListBox_listtext->setcurrent(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
bool LunaHost::on_text_recv(TextThread& thread, std::wstring& output){
|
||||
std::lock_guard _(settextmutex);
|
||||
on_text_recv_checkissaved(thread);
|
||||
if(!plugins->dispatch(thread,output))return false;
|
||||
strReplace(output,L"\n",L"\r\n");
|
||||
savetext.at(thread.handle).push_back(output);
|
||||
@ -196,7 +329,7 @@ void LunaHost::on_thread_delete(TextThread& thread){
|
||||
|
||||
Settingwindow::Settingwindow(LunaHost* host):mainwindow(host){
|
||||
int height=30;int curry=10;int space=10;
|
||||
int labelwidth=250;
|
||||
int labelwidth=300;
|
||||
g_timeout = new spinbox(this,std::to_wstring(TextThread::flushDelay),space+labelwidth, curry, 100, height) ;
|
||||
new label(this,LblFlushDelay,10, curry, labelwidth, height);curry+=height+space;
|
||||
|
||||
@ -207,7 +340,7 @@ Settingwindow::Settingwindow(LunaHost* host):mainwindow(host){
|
||||
new label(this,LblMaxBuff,10, curry, labelwidth, height);curry+=height+space;
|
||||
|
||||
spinmaxbuffsize->onvaluechange=[=](int v){
|
||||
TextThread::flushDelay=v;
|
||||
TextThread::maxBufferSize=v;
|
||||
};
|
||||
spinmaxbuffsize->setminmax(0,0x7fffffff);
|
||||
|
||||
@ -219,20 +352,26 @@ Settingwindow::Settingwindow(LunaHost* host):mainwindow(host){
|
||||
|
||||
g_check_clipboard =new checkbox(this,BtnToClipboard,10, curry, labelwidth, height) ;curry+=height+space;
|
||||
g_check_clipboard->onclick=[=](){
|
||||
((LunaHost*)parent)->check_toclipboard=g_check_clipboard->ischecked();
|
||||
host->check_toclipboard=g_check_clipboard->ischecked();
|
||||
};
|
||||
g_check_clipboard->setcheck(host->check_toclipboard);
|
||||
|
||||
autoattach =new checkbox(this,LblAutoAttach,10, curry, labelwidth, height) ;curry+=height+space;
|
||||
autoattach->onclick=[=](){
|
||||
((LunaHost*)parent)->autoattach=autoattach->ischecked();
|
||||
host->autoattach=autoattach->ischecked();
|
||||
};
|
||||
autoattach->setcheck(host->autoattach);
|
||||
|
||||
autoattach_so =new checkbox(this,LblAutoAttach_savedonly,10, curry, labelwidth, height) ;curry+=height+space;
|
||||
autoattach_so->onclick=[=](){
|
||||
host->autoattach_savedonly=autoattach_so->ischecked();
|
||||
};
|
||||
autoattach_so->setcheck(host->autoattach_savedonly);
|
||||
|
||||
|
||||
readonlycheck=new checkbox(this,BtnReadOnly,10,curry,labelwidth,height);curry+=height+space;
|
||||
readonlycheck->onclick=[=](){
|
||||
((LunaHost*)parent)->g_showtexts->setreadonly(readonlycheck->ischecked());
|
||||
host->g_showtexts->setreadonly(readonlycheck->ischecked());
|
||||
};
|
||||
readonlycheck->setcheck(true);
|
||||
|
||||
@ -246,7 +385,7 @@ Settingwindow::Settingwindow(LunaHost* host):mainwindow(host){
|
||||
}
|
||||
};
|
||||
g_codepage->setminmax(0,CP_UTF8);
|
||||
setcentral(300,300);
|
||||
setcentral(500,500);
|
||||
settext(WndSetting);
|
||||
}
|
||||
void Pluginwindow::on_size(int w,int h){
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include"window.h"
|
||||
#include"controls.h"
|
||||
#include"processlistwindow.h"
|
||||
#include"textthread.h"
|
||||
#include"pluginmanager.h"
|
||||
#include"confighelper.h"
|
||||
@ -19,14 +18,29 @@ class Settingwindow:public mainwindow{
|
||||
checkbox* g_check_clipboard;
|
||||
checkbox* readonlycheck;
|
||||
checkbox* autoattach;
|
||||
checkbox* autoattach_so;
|
||||
spinbox* spinmaxbuffsize;
|
||||
public:
|
||||
Settingwindow(LunaHost*);
|
||||
};
|
||||
|
||||
class processlistwindow:public mainwindow{
|
||||
textedit* g_hEdit;
|
||||
button* g_hButton;
|
||||
listview* g_hListBox;
|
||||
button* g_refreshbutton;
|
||||
std::unordered_map<std::wstring,std::vector<int>> g_exe_pid;
|
||||
void PopulateProcessList(listview*,std::unordered_map<std::wstring,std::vector<int>>&);
|
||||
public:
|
||||
processlistwindow(mainwindow* parent=0);
|
||||
void on_size(int w,int h);
|
||||
void on_show();
|
||||
};
|
||||
|
||||
class LunaHost:public mainwindow{
|
||||
Pluginwindow* pluginwindow=0;
|
||||
std::map<int64_t,std::vector<std::wstring>>savetext;
|
||||
std::vector<int>attachedprocess;
|
||||
std::set<int>attachedprocess;
|
||||
std::mutex settextmutex;
|
||||
textedit* g_hEdit_userhook;
|
||||
button* g_hButton_insert;
|
||||
@ -34,24 +48,37 @@ class LunaHost:public mainwindow{
|
||||
listbox* g_hListBox_listtext;
|
||||
textedit* g_showtexts;
|
||||
button* g_selectprocessbutton;
|
||||
button* btndetachall;
|
||||
button* btnshowsettionwindow;
|
||||
//button* btnsavehook;
|
||||
void toclipboard(std::wstring& sentence);
|
||||
processlistwindow *_processlistwindow=0;
|
||||
Settingwindow *settingwindow=0;
|
||||
Pluginmanager* plugins;
|
||||
bool on_text_recv(TextThread& thread, std::wstring& sentence);
|
||||
void on_text_recv_checkissaved(TextThread& thread);
|
||||
void on_thread_create(TextThread& thread);
|
||||
void on_thread_delete(TextThread& thread);
|
||||
void on_proc_connect(DWORD pid);
|
||||
public:
|
||||
confighelper* configs;
|
||||
int64_t currentselect=0;
|
||||
bool check_toclipboard=false;
|
||||
bool autoattach=false;
|
||||
bool check_toclipboard;
|
||||
bool autoattach;
|
||||
bool autoattach_savedonly;
|
||||
std::set<std::string>autoattachexes;
|
||||
std::unordered_map<std::string,nlohmann::json>savedhookcontext;
|
||||
std::set<int>userdetachedpids;
|
||||
std::set<int64_t>onceautoselectthread;
|
||||
void on_size(int w,int h);
|
||||
void on_close();
|
||||
LunaHost();
|
||||
friend class Settingwindow;
|
||||
friend class processlistwindow;
|
||||
private:
|
||||
void loadsettings();
|
||||
void savesettings();
|
||||
|
||||
void doautoattach();
|
||||
|
||||
};
|
||||
|
@ -112,7 +112,11 @@ void listbox::dispatch(WPARAM wparam){
|
||||
oncurrentchange(idx);
|
||||
}
|
||||
}
|
||||
|
||||
void listbox::setcurrent(int idx){
|
||||
SendMessage(winId, LB_SETCURSEL, idx, 0);
|
||||
if(idx!=-1)
|
||||
oncurrentchange(idx);
|
||||
}
|
||||
int listbox::currentidx(){
|
||||
return SendMessage(winId, LB_GETCURSEL, 0, 0);
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ public:
|
||||
int additem(const std::wstring&);
|
||||
void deleteitem(int);
|
||||
void setdata(int,LONG_PTR);
|
||||
void setcurrent(int idx);
|
||||
int insertitem(int,const std::wstring&);
|
||||
LONG_PTR getdata(int);
|
||||
int count();
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include <CommCtrl.h>
|
||||
#include <TlHelp32.h>
|
||||
#include"host.h"
|
||||
#include"processlistwindow.h"
|
||||
#include"LunaHost.h"
|
||||
#include"Lang/Lang.h"
|
||||
#include<shellapi.h>
|
||||
std::unordered_map<std::wstring,std::vector<int>> getprocesslist()
|
||||
|
@ -1,18 +0,0 @@
|
||||
#ifndef LUNA_PROCLIST_WIN_H
|
||||
#define LUNA_PROCLIST_WIN_H
|
||||
#include"window.h"
|
||||
#include"controls.h"
|
||||
class processlistwindow:public mainwindow{
|
||||
textedit* g_hEdit;
|
||||
button* g_hButton;
|
||||
listview* g_hListBox;
|
||||
button* g_refreshbutton;
|
||||
std::unordered_map<std::wstring,std::vector<int>> g_exe_pid;
|
||||
void PopulateProcessList(listview*,std::unordered_map<std::wstring,std::vector<int>>&);
|
||||
public:
|
||||
processlistwindow(mainwindow* parent=0);
|
||||
void on_size(int w,int h);
|
||||
void on_show();
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user