This commit is contained in:
恍兮惚兮 2024-04-18 16:19:52 +08:00
parent 22472558c7
commit 42e2d2ed8e
10 changed files with 158 additions and 50 deletions

View File

@ -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)

View File

@ -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"
#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"

View File

@ -91,4 +91,8 @@
#define HS_SEARCH_FOR_TEXT L"搜索指定文本"
#define VersionLatest L"最新版本"
#define VersionCurrent L"当前版本"
#define ProjectHomePage L"项目主页: https://github.com/HIllya51/LunaHook"
#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"

View File

@ -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){

View File

@ -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;

View File

@ -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<LPWSTR>(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<LPWSTR>(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<std::wstring>& headers){
for(int i=0;i<headers.size();i++){
insertcol(i,headers[i]);
ListView_SetColumnWidth(winId, i, LVSCW_AUTOSIZE_USEHEADER);
}
headernum=headers.size();
}
void listview::on_size(int,int){
autosize();
}
void listview::autosize(){
for(int i=0;i<headernum;i++){
ListView_SetColumnWidth(winId, i, LVSCW_AUTOSIZE_USEHEADER);
if(headernum==1)
ListView_SetColumnWidth(winId, 0, LVSCW_AUTOSIZE_USEHEADER);
else if(headernum==2){
ListView_SetColumnWidth(winId, 0, 0x180);
}
}
void listview::on_size(int w,int){
if(headernum==1)
ListView_SetColumnWidth(winId, 0, LVSCW_AUTOSIZE_USEHEADER);
else if(headernum==2){
auto w0= ListView_GetColumnWidth(winId, 0);
ListView_SetColumnWidth(winId, 1, w-w0);
}
}
void gridlayout::setgeo(int x,int y,int w,int h){
auto dynarow=maxrow;
@ -334,4 +390,5 @@ void Menu::add_checkable(const std::wstring& str,bool check,std::function<void(b
}
void Menu::add_sep(){
menu_callbacks.push_back({MF_SEPARATOR});
}
}

View File

@ -95,22 +95,32 @@ public:
};
class listview:public control{
int headernum=1;
bool addicon;
HIMAGELIST hImageList;
std::vector<LONG_PTR>assodata;
std::map<LONG_PTR,int>remapidx;
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<void(int)> oncurrentchange=[](int){};
std::wstring text(int,int=0);
void setheader(const std::vector<std::wstring>&);
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;

View File

@ -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)];

View File

@ -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();
}

View File

@ -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 };
}