From 42e2d2ed8ef08573927fca0fe9c4a61b26815836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Thu, 18 Apr 2024 16:19:52 +0800 Subject: [PATCH] new --- CMakeLists.txt | 6 +- Lang/en.h | 6 +- Lang/zh.h | 6 +- LunaHost/GUI/LunaHost.cpp | 65 ++++++++++++++------- LunaHost/GUI/LunaHost.h | 7 ++- LunaHost/GUI/controls.cpp | 91 ++++++++++++++++++++++++------ LunaHost/GUI/controls.h | 20 +++++-- LunaHost/GUI/processlistwindow.cpp | 2 +- LunaHost/host.cpp | 3 +- LunaHost/host.h | 2 +- 10 files changed, 158 insertions(+), 50 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7198080..fe4e4f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,9 +47,9 @@ include_directories(include) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/version) include(generate_product_version) -set(VERSION_MAJOR 2) -set(VERSION_MINOR 10) -set(VERSION_PATCH 1) +set(VERSION_MAJOR 3) +set(VERSION_MINOR 0) +set(VERSION_PATCH 0) set(VERSION_REVISION 0) add_subdirectory(include) diff --git a/Lang/en.h b/Lang/en.h index 9821427..c37ef80 100644 --- a/Lang/en.h +++ b/Lang/en.h @@ -91,4 +91,8 @@ #define HS_SEARCH_FOR_TEXT L"Search for specific text" #define VersionLatest L"Latest version" #define VersionCurrent L"Current version" -#define ProjectHomePage L"Project homepage: https://github.com/HIllya51/LunaHook" \ No newline at end of file +#define ProjectHomePage L"Project homepage: https://github.com/HIllya51/LunaHook" +#define LIST_HOOK L"Hook" +#define LIST_TEXT L"Text" +#define PROC_CONN L"process connected %d" +#define PROC_DISCONN L"process disconnected %d" \ No newline at end of file diff --git a/Lang/zh.h b/Lang/zh.h index 5b0fa17..7703b83 100644 --- a/Lang/zh.h +++ b/Lang/zh.h @@ -91,4 +91,8 @@ #define HS_SEARCH_FOR_TEXT L"搜索指定文本" #define VersionLatest L"最新版本" #define VersionCurrent L"当前版本" -#define ProjectHomePage L"项目主页: https://github.com/HIllya51/LunaHook" \ No newline at end of file +#define ProjectHomePage L"项目主页: https://github.com/HIllya51/LunaHook" +#define LIST_HOOK L"Hook" +#define LIST_TEXT L"文本" +#define PROC_CONN L"进程已连接 %d" +#define PROC_DISCONN L"进程已断开连接 %d" \ No newline at end of file diff --git a/LunaHost/GUI/LunaHost.cpp b/LunaHost/GUI/LunaHost.cpp index 210d410..b4beec3 100644 --- a/LunaHost/GUI/LunaHost.cpp +++ b/LunaHost/GUI/LunaHost.cpp @@ -93,6 +93,11 @@ void LunaHost::doautoattach() } +void LunaHost::on_proc_disconnect(DWORD pid) +{ + attachedprocess.erase(pid); +} + void LunaHost::on_proc_connect(DWORD pid) { attachedprocess.insert(pid); @@ -225,21 +230,21 @@ LunaHost::LunaHost(){ } } else{ - g_showtexts->appendtext(NotifyInvalidHookCode); + showtext(NotifyInvalidHookCode,false); } }; - g_hListBox_listtext = new listbox(this); + g_hListBox_listtext = new listview(this,false,false); + g_hListBox_listtext->setheader({LIST_HOOK,LIST_TEXT}); g_hListBox_listtext->oncurrentchange=[&](int idx){ uint64_t handle = g_hListBox_listtext->getdata(idx); std::wstring get; for(auto& _:savetext.at(handle)){ get+=_; - get+=L"\r\n"; + get+=L"\n"; } currentselect=handle; - g_showtexts->settext(get); - g_showtexts->scrolltoend(); + showtext(get,true); }; g_hListBox_listtext->on_menu=[&]()->maybehavemenu{ auto handle = g_hListBox_listtext->getdata(g_hListBox_listtext->currentidx()); @@ -282,9 +287,7 @@ LunaHost::LunaHost(){ Host::Start( std::bind(&LunaHost::on_proc_connect,this,std::placeholders::_1), - [&](DWORD pid) { - attachedprocess.erase(pid); - }, + std::bind(&LunaHost::on_proc_disconnect,this,std::placeholders::_1), 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) @@ -339,31 +342,55 @@ void LunaHost::on_text_recv_checkissaved(TextThread& thread) } } + +void LunaHost::showtext(const std::wstring&text,bool clear){ + auto output=text; + strReplace(output,L"\n",L"\r\n"); + if(clear) + { + g_showtexts->settext(output); + g_showtexts->scrolltoend(); + } + else{ + g_showtexts->scrolltoend(); + g_showtexts->appendtext(output); + } +} +void LunaHost::updatelisttext(const std::wstring&text,LONG_PTR data){ + auto idx=g_hListBox_listtext->querydataidx(data); + if(idx>=0){ + auto __output=text; + strReplace(__output,L"\n",L" "); + if(__output.size()>0x40){ + __output=__output.substr(0,0x40)+L"..."; + } + g_hListBox_listtext->settext(idx,1,__output); + } +} 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"); + + updatelisttext(output,thread.handle); + savetext.at(thread.handle).push_back(output); if(currentselect==thread.handle){ - g_showtexts->scrolltoend(); - g_showtexts->appendtext(output); + showtext(output,false); } return true; } void LunaHost::on_thread_create(TextThread& thread){ wchar_t buff[65535]; - swprintf_s(buff,L"[%I64X:%I32X:%I64X:%I64X:%I64X:%s:%s]", - thread.handle, - thread.tp.processId, - thread.tp.addr, - thread.tp.ctx, - thread.tp.ctx2, + swprintf_s(buff,L"%s:%s:%I32X:%I64X:%I64X", thread.name.c_str(), - thread.hp.hookcode + thread.hp.hookcode, + thread.tp.processId, + thread.tp.ctx, + thread.tp.ctx2 ); savetext.insert({thread.handle,{}}); - int index=g_hListBox_listtext->additem(buff); + int index=g_hListBox_listtext->additem(buff,NULL); g_hListBox_listtext->setdata(index,thread.handle); } void LunaHost::on_thread_delete(TextThread& thread){ diff --git a/LunaHost/GUI/LunaHost.h b/LunaHost/GUI/LunaHost.h index 45d6588..a966b8c 100644 --- a/LunaHost/GUI/LunaHost.h +++ b/LunaHost/GUI/LunaHost.h @@ -83,7 +83,8 @@ class LunaHost:public mainwindow{ gridlayout* mainlayout; button* g_hButton_insert; button* btnplugin; - listbox* g_hListBox_listtext; + //listbox* g_hListBox_listtext; + listview*g_hListBox_listtext; multilineedit* g_showtexts; button* g_selectprocessbutton; button* btndetachall; @@ -100,6 +101,10 @@ class LunaHost:public mainwindow{ void on_thread_create(TextThread& thread); void on_thread_delete(TextThread& thread); void on_proc_connect(DWORD pid); + void on_proc_disconnect(DWORD pid); + + void showtext(const std::wstring&text,bool clear); + void updatelisttext(const std::wstring&text,LONG_PTR data); public: confighelper* configs; int64_t currentselect=0; diff --git a/LunaHost/GUI/controls.cpp b/LunaHost/GUI/controls.cpp index a3d23f4..65363b8 100644 --- a/LunaHost/GUI/controls.cpp +++ b/LunaHost/GUI/controls.cpp @@ -166,13 +166,26 @@ int listbox::insertitem(int i,const std::wstring& t){ return SendMessage(winId, LB_INSERTSTRING, i, (LPARAM)t.c_str()); } -listview::listview(mainwindow* parent):control(parent){ - winId=CreateWindowEx(0, WC_LISTVIEW, NULL, WS_VISIBLE |WS_VSCROLL| WS_CHILD | LVS_REPORT |LVS_SINGLESEL|LVS_NOCOLUMNHEADER , 0,0,0,0, parent->winId, NULL,NULL, NULL); +void listview::deleteitem(int i){ + std::lock_guard _(lockdataidx); + assodata.erase(assodata.begin() + i); + for(auto& data:remapidx){ + if(data.second>=i) + data.second-=1; + } + ListView_DeleteItem(winId,i); +} +listview::listview(mainwindow* parent,bool _addicon,bool notheader):control(parent),addicon(_addicon){ + auto style=WS_VISIBLE |WS_VSCROLL| WS_CHILD | LVS_REPORT |LVS_SINGLESEL; + if(notheader)style|=LVS_NOCOLUMNHEADER; + winId=CreateWindowEx(0, WC_LISTVIEW, NULL, style , 0,0,0,0, parent->winId, NULL,NULL, NULL); ListView_SetExtendedListViewStyle(winId, LVS_EX_FULLROWSELECT); // Set extended styles setfont(22); - hImageList = ImageList_Create(22,22, //GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), - ILC_COLOR32, 1 ,1); - ListView_SetImageList(winId, hImageList, LVSIL_SMALL); + if(addicon){ + hImageList = ImageList_Create(22,22, //GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), + ILC_COLOR32, 1 ,1); + ListView_SetImageList(winId, hImageList, LVSIL_SMALL); + } } int listview::insertcol(int i,const std::wstring& text){ LVCOLUMN lvc; @@ -181,26 +194,63 @@ int listview::insertcol(int i,const std::wstring& text){ //lvc.cx = 100; return ListView_InsertColumn(winId, i, &lvc); } +void listview::settext(int row,int col,const std::wstring& text){ + ListView_SetItemText(winId,row,col,const_cast(text.c_str())); +} int listview::insertitem(int row,const std::wstring& text,HICON hicon){ LVITEM lvi; - lvi.mask = LVIF_TEXT | LVIF_IMAGE; lvi.pszText = const_cast(text.c_str()); lvi.iItem = row; lvi.iSubItem = 0; - lvi.iImage = ImageList_AddIcon(hImageList, hicon); + lvi.mask=LVIF_TEXT; + if(addicon && hicon && hImageList){ + lvi.mask |= LVIF_IMAGE; + lvi.iImage = ImageList_AddIcon(hImageList, hicon); + } + std::lock_guard _(lockdataidx); + assodata.resize(assodata.size()+1); + std::rotate(assodata.begin() + row, assodata.begin() + row + 1, assodata.end()); + for(auto& data:remapidx){ + if(data.second>=row) + data.second+=1; + } return ListView_InsertItem(winId, &lvi); } int listview::additem(const std::wstring& text,HICON hicon){ return insertitem(count(),text,hicon); } +LONG_PTR listview::getdata(int idx){ + std::lock_guard _(lockdataidx); + return assodata[idx]; +} +int listview::querydataidx(LONG_PTR data){ + std::lock_guard _(lockdataidx); + if(remapidx.find(data)==remapidx.end())return -1; + return remapidx[data]; +} + +void listview::setdata(int idx,LONG_PTR data){ + std::lock_guard _(lockdataidx); + assodata[idx]=data; + remapidx[data]=idx; +} void listview::clear(){ ListView_DeleteAllItems(winId); - ImageList_RemoveAll(hImageList); + if(addicon && hImageList) + ImageList_RemoveAll(hImageList); } int listview::count(){ return ListView_GetItemCount(winId); } +int listview::currentidx(){ + return ListView_GetNextItem(winId, -1, LVNI_SELECTED); + +} +void listview::setcurrent(int idx){ + ListView_SetItemState(winId,idx,LVIS_SELECTED,LVIS_SELECTED); + +} void listview::dispatch_2(WPARAM wParam, LPARAM lParam){ NMHDR* pnmhdr = (NMHDR*)lParam; switch (pnmhdr->code){ @@ -228,18 +278,24 @@ std::wstring listview::text(int row,int col){ void listview::setheader(const std::vector& headers){ for(int i=0;iassodata; + std::mapremapidx; + std::mutex lockdataidx; public: - listview(mainwindow*); - int insertitem(int,const std::wstring&,HICON hicon); + listview(mainwindow*,bool,bool); + int insertitem(int,const std::wstring&,HICON hicon=NULL); + void settext(int,int,const std::wstring&); int insertcol(int,const std::wstring& ); void clear(); int count(); + int currentidx(); + void setcurrent(int idx); + std::function oncurrentchange=[](int){}; std::wstring text(int,int=0); void setheader(const std::vector&); - void autosize(); - int additem(const std::wstring&,HICON hicon); + void deleteitem(int); + int additem(const std::wstring&,HICON hicon=NULL); + LONG_PTR getdata(int); + void setdata(int,LONG_PTR); + int querydataidx(LONG_PTR); void dispatch_2(WPARAM wParam, LPARAM lParam); void on_size(int,int); }; - class gridlayout:public control{ struct _c{ control* ctr; diff --git a/LunaHost/GUI/processlistwindow.cpp b/LunaHost/GUI/processlistwindow.cpp index 2e1f359..62b3545 100644 --- a/LunaHost/GUI/processlistwindow.cpp +++ b/LunaHost/GUI/processlistwindow.cpp @@ -78,7 +78,7 @@ processlistwindow::processlistwindow(mainwindow* p):mainwindow(p){ g_exe_pid=getprocesslist(); PopulateProcessList(g_hListBox,g_exe_pid); }; - g_hListBox = new listview(this); + g_hListBox = new listview(this,true,true); g_hListBox->setheader({L""}); g_hListBox->oncurrentchange=[&](int idx){ auto pids=g_exe_pid[g_hListBox->text(idx)]; diff --git a/LunaHost/host.cpp b/LunaHost/host.cpp index 92f4a7e..2dac4af 100644 --- a/LunaHost/host.cpp +++ b/LunaHost/host.cpp @@ -107,7 +107,7 @@ namespace ReadFile(hookPipe, &processId, sizeof(processId), &bytesRead, nullptr); processRecordsByIds->try_emplace(processId, processId, hostPipe); OnConnect(processId); - + Host::AddConsoleOutput(FormatString(PROC_CONN,processId)); //CreatePipe(); while (ReadFile(hookPipe, buffer, PIPE_BUFFER_SIZE, &bytesRead, nullptr)) @@ -190,6 +190,7 @@ namespace RemoveThreads([&](ThreadParam tp) { return tp.processId == processId; }); OnDisconnect(processId); + Host::AddConsoleOutput(FormatString(PROC_DISCONN,processId)); processRecordsByIds->erase(processId); }).detach(); } diff --git a/LunaHost/host.h b/LunaHost/host.h index a9ca963..428b5c3 100644 --- a/LunaHost/host.h +++ b/LunaHost/host.h @@ -28,5 +28,5 @@ namespace Host inline int defaultCodepage = SHIFT_JIS; - constexpr ThreadParam console{ 0, -1LL, -1LL, -1LL }; + constexpr ThreadParam console{ 0, 0, 0, 0 }; }