mirror of
https://github.com/HIllya51/LunaHook.git
synced 2025-01-12 04:49:37 +08:00
fix bug
This commit is contained in:
parent
0265d2dd5b
commit
12963a053b
@ -1,7 +1,6 @@
|
||||
|
||||
#include <CommCtrl.h>
|
||||
#include <TlHelp32.h>
|
||||
#include <commdlg.h>
|
||||
#include<stdio.h>
|
||||
#include"host.h"
|
||||
#include"hookcode.h"
|
||||
@ -34,24 +33,7 @@ void LunaHost::on_size(int w,int h){
|
||||
g_hListBox_listtext->setgeo(10, 110, w - 20, height/2);
|
||||
g_showtexts->setgeo(10, 120+height/2, w - 20, height/2);
|
||||
}
|
||||
std::optional<std::wstring>SelectFile(HWND hwnd){
|
||||
OPENFILENAME ofn;
|
||||
wchar_t szFileName[MAX_PATH] = { 0 };
|
||||
|
||||
ZeroMemory(&ofn, sizeof(ofn));
|
||||
ofn.lStructSize = sizeof(ofn);
|
||||
ofn.hwndOwner = hwnd;
|
||||
ofn.lpstrFilter = L"Plugin Files\0*.dll;*.xdll\0";
|
||||
ofn.lpstrFile = szFileName;
|
||||
ofn.nMaxFile = sizeof(szFileName);
|
||||
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
|
||||
|
||||
if (GetOpenFileName(&ofn))
|
||||
{
|
||||
return szFileName;
|
||||
}
|
||||
else return {};
|
||||
}
|
||||
LunaHost::LunaHost(){
|
||||
settext(WndLunaHostGui);
|
||||
g_selectprocessbutton =new button(this,BtnSelectProcess,830, 10, 200, 40) ;
|
||||
@ -59,7 +41,7 @@ LunaHost::LunaHost(){
|
||||
g_hEdit_userhook = new textedit(this,L"",10, 60, 600, 40,ES_AUTOHSCROLL);
|
||||
btnaddplugin=new button(this,BtnAddPlugin,830,60,200,40);
|
||||
btnaddplugin->onclick=[&](){
|
||||
auto f=SelectFile(winId);
|
||||
auto f=plugins->selectpluginfile();
|
||||
if(f.has_value()){
|
||||
plugins->addplugin(f.value());
|
||||
}
|
||||
@ -147,7 +129,7 @@ LunaHost::LunaHost(){
|
||||
};
|
||||
g_showtexts = new textedit(this,L"",10, 330, 200, 200,ES_READONLY|ES_MULTILINE |ES_AUTOVSCROLL| WS_VSCROLL);
|
||||
|
||||
plugins=new pluginmanager;
|
||||
plugins=new pluginmanager(this);
|
||||
|
||||
Host::Start(
|
||||
[&](DWORD pid) {attachedprocess.push_back(pid);},
|
||||
@ -160,44 +142,10 @@ LunaHost::LunaHost(){
|
||||
);
|
||||
}
|
||||
|
||||
std::array<InfoForExtension, 20> LunaHost::GetSentenceInfo(TextThread& thread)
|
||||
{
|
||||
void (*AddText)(int64_t, const wchar_t*) = [](int64_t number, const wchar_t* text)
|
||||
{
|
||||
if (TextThread* thread = Host::GetThread(number)) thread->Push(text);
|
||||
};
|
||||
void (*AddSentence)(int64_t, const wchar_t*) = [](int64_t number, const wchar_t* sentence)
|
||||
{
|
||||
if (TextThread* thread = Host::GetThread(number)) thread->AddSentence(sentence);;
|
||||
};
|
||||
static DWORD SelectedProcessId;
|
||||
auto currthread=Host::GetThread(currentselect);
|
||||
SelectedProcessId=(currthread!=0)?currthread->tp.processId:0;
|
||||
DWORD (*GetSelectedProcessId)() = [] { return SelectedProcessId; };
|
||||
|
||||
return
|
||||
{ {
|
||||
{ "HostHWND",(int64_t)winId },
|
||||
{ "toclipboard", check_toclipboard },
|
||||
{ "current select", &thread == currthread },
|
||||
{ "text number", thread.handle },
|
||||
{ "process id", thread.tp.processId },
|
||||
{ "hook address", (int64_t)thread.tp.addr },
|
||||
{ "text handle", thread.handle },
|
||||
{ "text name", (int64_t)thread.name.c_str() },
|
||||
{ "add sentence", (int64_t)AddSentence },
|
||||
{ "add text", (int64_t)AddText },
|
||||
{ "get selected process id", (int64_t)GetSelectedProcessId },
|
||||
{ "void (*AddSentence)(int64_t number, const wchar_t* sentence)", (int64_t)AddSentence },
|
||||
{ "void (*AddText)(int64_t number, const wchar_t* text)", (int64_t)AddText },
|
||||
{ "DWORD (*GetSelectedProcessId)()", (int64_t)GetSelectedProcessId },
|
||||
{ nullptr, 0 } // nullptr marks end of info array
|
||||
} };
|
||||
}
|
||||
bool LunaHost::on_text_recv(TextThread& thread, std::wstring& output){
|
||||
std::lock_guard _(settextmutex);
|
||||
std::wstring lfoutput=output;
|
||||
if(!plugins->dispatch(GetSentenceInfo(thread).data(),output))return false;
|
||||
if(!plugins->dispatch(thread,output))return false;
|
||||
strReplace(lfoutput,L"\n",L"\r\n");
|
||||
savetext.at(thread.handle).push_back(lfoutput);
|
||||
if(currentselect==thread.handle){
|
||||
|
@ -3,13 +3,10 @@
|
||||
#include"processlistwindow.h"
|
||||
#include"textthread.h"
|
||||
#include"pluginmanager.h"
|
||||
#include"Plugin/plugindef.h"
|
||||
class LunaHost:public mainwindow{
|
||||
|
||||
int64_t currentselect=0;
|
||||
std::map<int64_t,std::vector<std::wstring>>savetext;
|
||||
std::vector<int>attachedprocess;
|
||||
bool check_toclipboard=false;
|
||||
std::mutex settextmutex;
|
||||
textedit* g_hEdit_userhook;
|
||||
button* g_hButton_insert;
|
||||
@ -26,8 +23,9 @@ class LunaHost:public mainwindow{
|
||||
bool on_text_recv(TextThread& thread, std::wstring& sentence);
|
||||
void on_thread_create(TextThread& thread);
|
||||
void on_thread_delete(TextThread& thread);
|
||||
std::array<InfoForExtension, 20> GetSentenceInfo(TextThread& thread);
|
||||
public:
|
||||
int64_t currentselect=0;
|
||||
bool check_toclipboard=false;
|
||||
void on_size(int w,int h);
|
||||
void on_close();
|
||||
LunaHost();
|
||||
|
@ -2,19 +2,49 @@
|
||||
#include<filesystem>
|
||||
#include"Plugin/plugindef.h"
|
||||
#include<fstream>
|
||||
#include <commdlg.h>
|
||||
#include"LunaHost.h"
|
||||
#include"Lang/Lang.h"
|
||||
std::vector<char> readfile(const wchar_t* fname) {
|
||||
#include"host.h"
|
||||
std::string readfile(const wchar_t* fname) {
|
||||
FILE* f;
|
||||
_wfopen_s(&f, fname, L"rb");
|
||||
if (f == 0)return {};
|
||||
fseek(f, 0, SEEK_END);
|
||||
auto len = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
auto buff = std::vector<char>(len);
|
||||
std::string buff;
|
||||
buff.resize(len);
|
||||
fread(buff.data(), 1, len, f);
|
||||
fclose(f);
|
||||
return buff;
|
||||
}
|
||||
void appendfile(const wchar_t* fname,const std::wstring& s){
|
||||
auto u8s=WideStringToString(s);
|
||||
FILE* f;
|
||||
_wfopen_s(&f, fname, L"a");
|
||||
fprintf(f,"\n%s",u8s.c_str());
|
||||
fclose(f);
|
||||
}
|
||||
std::optional<std::wstring>SelectFile(HWND hwnd,LPCWSTR lpstrFilter){
|
||||
OPENFILENAME ofn;
|
||||
wchar_t szFileName[MAX_PATH] = { 0 };
|
||||
|
||||
ZeroMemory(&ofn, sizeof(ofn));
|
||||
ofn.lStructSize = sizeof(ofn);
|
||||
ofn.hwndOwner = hwnd;
|
||||
ofn.lpstrFilter = lpstrFilter;
|
||||
ofn.lpstrFile = szFileName;
|
||||
ofn.nMaxFile = sizeof(szFileName);
|
||||
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
|
||||
|
||||
if (GetOpenFileName(&ofn))
|
||||
{
|
||||
return szFileName;
|
||||
}
|
||||
else return {};
|
||||
}
|
||||
|
||||
std::vector<std::wstring>pluginmanager::readpluginfile(){
|
||||
if(!std::filesystem::exists(pluginfilename))
|
||||
return{};
|
||||
@ -23,13 +53,9 @@ std::vector<std::wstring>pluginmanager::readpluginfile(){
|
||||
return pls;
|
||||
}
|
||||
void pluginmanager::writepluginfile(const std::wstring& plugf){
|
||||
auto u8s=WideStringToString(plugf);
|
||||
FILE* f;
|
||||
_wfopen_s(&f, pluginfilename.c_str(), L"a");
|
||||
fprintf(f,"\n%s",u8s.c_str());
|
||||
fclose(f);
|
||||
appendfile(pluginfilename.c_str(),plugf);
|
||||
}
|
||||
pluginmanager::pluginmanager(){
|
||||
pluginmanager::pluginmanager(LunaHost* _host):host(_host){
|
||||
try {
|
||||
std::scoped_lock lock(OnNewSentenceSLock);
|
||||
pluginfilename=std::filesystem::current_path()/(x64?"plugin64.txt":"plugin32.txt");
|
||||
@ -50,7 +76,8 @@ pluginmanager::pluginmanager(){
|
||||
}
|
||||
}
|
||||
|
||||
bool pluginmanager::dispatch(const InfoForExtension* sentenceInfo, std::wstring& sentence){
|
||||
bool pluginmanager::dispatch(TextThread& thread, std::wstring& sentence){
|
||||
auto sentenceInfo=GetSentenceInfo(thread).data();
|
||||
wchar_t* sentenceBuffer = (wchar_t*)HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, (sentence.size() + 1) * sizeof(wchar_t));
|
||||
wcscpy_s(sentenceBuffer, sentence.size() + 1, sentence.c_str());
|
||||
concurrency::reader_writer_lock::scoped_lock_read readLock(OnNewSentenceSLock);
|
||||
@ -83,6 +110,10 @@ bool pluginmanager::checkisdump(LPVOID ptr){
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::optional<std::wstring>pluginmanager::selectpluginfile(){
|
||||
return SelectFile(host->winId,L"Plugin Files\0*.dll;*.xdll\0");
|
||||
}
|
||||
bool pluginmanager::addplugin(const std::wstring& p){
|
||||
auto plugin=checkisvalidplugin(p);
|
||||
if(plugin.has_value()){
|
||||
@ -95,7 +126,43 @@ bool pluginmanager::addplugin(const std::wstring& p){
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
MessageBoxW(0,InVaildPlugin,L"Error",0);
|
||||
MessageBoxW(host->winId,InVaildPlugin,L"Error",0);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::array<InfoForExtension, 20> pluginmanager::GetSentenceInfo(TextThread& thread)
|
||||
{
|
||||
void (*AddText)(int64_t, const wchar_t*) = [](int64_t number, const wchar_t* text)
|
||||
{
|
||||
if (TextThread* thread = Host::GetThread(number)) thread->Push(text);
|
||||
};
|
||||
void (*AddSentence)(int64_t, const wchar_t*) = [](int64_t number, const wchar_t* sentence)
|
||||
{
|
||||
if (TextThread* thread = Host::GetThread(number)) thread->AddSentence(sentence);;
|
||||
};
|
||||
static DWORD SelectedProcessId;
|
||||
auto currthread=Host::GetThread(host->currentselect);
|
||||
SelectedProcessId=(currthread!=0)?currthread->tp.processId:0;
|
||||
DWORD (*GetSelectedProcessId)() = [] { return SelectedProcessId; };
|
||||
|
||||
return
|
||||
{ {
|
||||
{ "HostHWND",(int64_t)host->winId },
|
||||
{ "toclipboard", host->check_toclipboard },
|
||||
{ "current select", &thread == currthread },
|
||||
{ "text number", thread.handle },
|
||||
{ "process id", thread.tp.processId },
|
||||
{ "hook address", (int64_t)thread.tp.addr },
|
||||
{ "text handle", thread.handle },
|
||||
{ "text name", (int64_t)thread.name.c_str() },
|
||||
{ "add sentence", (int64_t)AddSentence },
|
||||
{ "add text", (int64_t)AddText },
|
||||
{ "get selected process id", (int64_t)GetSelectedProcessId },
|
||||
{ "void (*AddSentence)(int64_t number, const wchar_t* sentence)", (int64_t)AddSentence },
|
||||
{ "void (*AddText)(int64_t number, const wchar_t* text)", (int64_t)AddText },
|
||||
{ "DWORD (*GetSelectedProcessId)()", (int64_t)GetSelectedProcessId },
|
||||
{ nullptr, 0 } // nullptr marks end of info array
|
||||
} };
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
#ifndef LUNA_PLUGINMANAGER_H
|
||||
#define LUNA_PLUGINMANAGER_H
|
||||
#include"Plugin/plugindef.h"
|
||||
#include"textthread.h"
|
||||
class LunaHost;
|
||||
class pluginmanager{
|
||||
std::vector<std::pair<std::wstring,LPVOID>>OnNewSentenceS;
|
||||
std::optional<std::pair<std::wstring,LPVOID>> checkisvalidplugin(const std::wstring&);
|
||||
@ -8,9 +11,13 @@ class pluginmanager{
|
||||
std::wstring pluginfilename;
|
||||
concurrency::reader_writer_lock OnNewSentenceSLock;
|
||||
bool checkisdump(LPVOID);
|
||||
LunaHost* host;
|
||||
std::array<InfoForExtension, 20> GetSentenceInfo(TextThread& thread);
|
||||
public:
|
||||
pluginmanager();
|
||||
bool dispatch(const InfoForExtension*, std::wstring& sentence);
|
||||
pluginmanager(LunaHost*);
|
||||
bool dispatch(TextThread&, std::wstring& sentence);
|
||||
bool addplugin(const std::wstring&);
|
||||
std::optional<std::wstring>selectpluginfile();
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user