2024-02-07 20:59:24 +08:00
|
|
|
|
|
|
|
#include <CommCtrl.h>
|
|
|
|
#include <TlHelp32.h>
|
|
|
|
#include"host.h"
|
2024-03-27 16:36:14 +08:00
|
|
|
#include"LunaHost.h"
|
2024-02-07 20:59:24 +08:00
|
|
|
#include"Lang/Lang.h"
|
2024-02-11 23:49:11 +08:00
|
|
|
#include<shellapi.h>
|
2024-02-07 20:59:24 +08:00
|
|
|
std::unordered_map<std::wstring,std::vector<int>> getprocesslist()
|
|
|
|
{
|
|
|
|
std::unordered_map<std::wstring,std::vector<int>>exe_pid;
|
|
|
|
AutoHandle<> hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
|
|
|
if (hSnapshot == INVALID_HANDLE_VALUE)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
PROCESSENTRY32 pe32;
|
|
|
|
pe32.dwSize = sizeof(PROCESSENTRY32);
|
|
|
|
wchar_t buff[65535];
|
2024-04-16 21:44:37 +08:00
|
|
|
auto currpid=GetCurrentProcessId();
|
2024-02-07 20:59:24 +08:00
|
|
|
if (Process32First(hSnapshot, &pe32))
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
auto PROCESS_INJECT_ACCESS = (
|
|
|
|
PROCESS_CREATE_THREAD |
|
|
|
|
PROCESS_QUERY_INFORMATION |
|
|
|
|
PROCESS_VM_OPERATION |
|
|
|
|
PROCESS_VM_WRITE |
|
|
|
|
PROCESS_VM_READ);
|
2024-04-16 21:44:37 +08:00
|
|
|
if(pe32.th32ProcessID==currpid)continue;
|
2024-02-07 20:59:24 +08:00
|
|
|
AutoHandle<> handle = OpenProcess(PROCESS_INJECT_ACCESS, 0, pe32.th32ProcessID);
|
|
|
|
if (handle == 0)continue;
|
|
|
|
DWORD sz = 65535;
|
|
|
|
QueryFullProcessImageNameW(handle, 0, buff, &sz);
|
|
|
|
|
|
|
|
auto buffs=std::wstring(buff);
|
2024-02-08 16:18:33 +08:00
|
|
|
auto str=stolower(buffs);
|
2024-02-13 18:57:28 +08:00
|
|
|
if(str.find(L":\\windows\\")!=str.npos || str.find(L"\\microsoft")!=str.npos|| str.find(L"\\windowsapps")!=str.npos)continue;
|
2024-02-07 20:59:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
if(exe_pid.find(buffs)==exe_pid.end()){
|
|
|
|
exe_pid.insert({buffs,{}});
|
|
|
|
}
|
|
|
|
exe_pid[buffs].push_back(pe32.th32ProcessID);
|
|
|
|
} while (Process32Next(hSnapshot, &pe32));
|
|
|
|
}
|
|
|
|
return exe_pid;
|
|
|
|
}
|
2024-02-11 23:49:11 +08:00
|
|
|
|
|
|
|
void processlistwindow::PopulateProcessList(listview* _listbox,std::unordered_map<std::wstring,std::vector<int>>&exe_pid){
|
2024-02-07 20:59:24 +08:00
|
|
|
_listbox->clear();
|
|
|
|
for(auto& exe:exe_pid){
|
2024-02-12 00:17:58 +08:00
|
|
|
auto hicon=GetExeIcon(exe.first);
|
|
|
|
_listbox->additem(exe.first,hicon);
|
2024-02-11 23:49:11 +08:00
|
|
|
DestroyIcon(hicon);
|
2024-02-07 20:59:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-09 09:25:26 +08:00
|
|
|
processlistwindow::processlistwindow(mainwindow* p):mainwindow(p){
|
2024-03-28 11:01:44 +08:00
|
|
|
g_hEdit = new lineedit(this);
|
|
|
|
g_hButton=new button(this,BtnAttach);
|
|
|
|
g_refreshbutton =new button(this,BtnRefresh);
|
2024-02-07 20:59:24 +08:00
|
|
|
g_hButton->onclick=[&](){
|
|
|
|
auto str=g_hEdit->text();
|
|
|
|
if(str.size()){
|
|
|
|
close();
|
2024-02-09 19:38:12 +08:00
|
|
|
|
2024-02-07 20:59:24 +08:00
|
|
|
for(auto _s:strSplit(str,L",")){
|
2024-02-09 19:38:12 +08:00
|
|
|
DWORD pid=0;
|
|
|
|
try{
|
|
|
|
pid=std::stoi(_s);
|
|
|
|
}catch(std::exception&){}
|
|
|
|
if(pid)
|
|
|
|
Host::InjectProcess(pid);
|
2024-02-07 20:59:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
g_refreshbutton->onclick=[&](){
|
|
|
|
g_exe_pid=getprocesslist();
|
|
|
|
PopulateProcessList(g_hListBox,g_exe_pid);
|
|
|
|
};
|
2024-04-18 16:19:52 +08:00
|
|
|
g_hListBox = new listview(this,true,true);
|
2024-02-11 23:49:11 +08:00
|
|
|
g_hListBox->setheader({L""});
|
2024-02-07 20:59:24 +08:00
|
|
|
g_hListBox->oncurrentchange=[&](int idx){
|
|
|
|
auto pids=g_exe_pid[g_hListBox->text(idx)];
|
|
|
|
|
|
|
|
std::wstring _;
|
|
|
|
bool _1=false;
|
|
|
|
for(auto &p:pids){
|
|
|
|
if(_1)_+=L",";
|
|
|
|
_+=std::to_wstring(p);
|
|
|
|
_1=true;
|
|
|
|
}
|
|
|
|
g_hEdit->settext(_);
|
|
|
|
};
|
2024-02-09 09:25:26 +08:00
|
|
|
settext(WndSelectProcess);
|
2024-03-28 11:01:44 +08:00
|
|
|
mainlayout=new gridlayout();
|
|
|
|
mainlayout->addcontrol(g_hEdit,0,0,1,2);
|
|
|
|
mainlayout->addcontrol(g_hButton,0,2);
|
|
|
|
mainlayout->addcontrol(g_refreshbutton,0,3);
|
|
|
|
mainlayout->addcontrol(g_hListBox,1,0,1,4);
|
|
|
|
mainlayout->setfixedheigth(0,30);
|
|
|
|
setlayout(mainlayout);
|
2024-02-09 09:25:26 +08:00
|
|
|
setcentral(800,400);
|
2024-02-07 20:59:24 +08:00
|
|
|
}
|
|
|
|
void processlistwindow::on_show(){
|
|
|
|
g_hEdit->settext(L"");
|
|
|
|
g_exe_pid=getprocesslist();
|
|
|
|
PopulateProcessList(g_hListBox,g_exe_pid);
|
|
|
|
}
|