From 8c2acca21084920ac0326a8ebfad12ca807b256e 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: Sun, 12 May 2024 16:48:32 +0800 Subject: [PATCH] issues/735 Update v8.cpp --- LunaHook/engines/v8/v8.cpp | 18 +++++++++++++-- LunaHook/resource/lunajspatch.js | 22 ++++++++++--------- LunaHost/GUI/LunaHost.cpp | 18 +++++---------- LunaHost/GUI/Plugin/extensions/extpch.h | 6 ++--- .../GUI/Plugin/extensions/regexfilter.cpp | 4 ++-- LunaHost/GUI/window.cpp | 2 +- LunaHost/host.cpp | 2 +- include/hookcode.cpp | 2 +- include/utils.h | 5 ++--- 9 files changed, 44 insertions(+), 35 deletions(-) diff --git a/LunaHook/engines/v8/v8.cpp b/LunaHook/engines/v8/v8.cpp index be6e6aa..2e35916 100644 --- a/LunaHook/engines/v8/v8.cpp +++ b/LunaHook/engines/v8/v8.cpp @@ -111,7 +111,21 @@ bool v8runscript_isolate(void* isolate){ GetCurrentContext(isolate,&context); ConsoleOutput("context %p",context); if(context==0)return; - NewFromUtf8(&v8string,isolate,LoadResData(L"lunajspatch",L"JSSOURCE").c_str(),1,-1); + int is_packed=0; + if(auto moduleFileName=getModuleFilename()){ + + AutoHandle hFile = CreateFile(moduleFileName.value().c_str(), FILE_READ_ATTRIBUTES , FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if(hFile){ + LARGE_INTEGER fileSize; + if (GetFileSizeEx(hFile, &fileSize)) { + if(fileSize.QuadPart>1024*1024*200){ + //200mb + is_packed=1; + } + } + } + } + NewFromUtf8(&v8string,isolate,FormatString(LoadResData(L"lunajspatch",L"JSSOURCE").c_str(),is_packed).c_str(),1,-1); ConsoleOutput("v8string %p",v8string); if(v8string==0)return; if(NewFromUtf8v1) @@ -246,7 +260,7 @@ namespace{ } bool tryhookv8_internal(HMODULE hm){ auto succ=hookstring(hm); - if(!std::filesystem::exists(std::filesystem::path(GetModuleFilename().value()).replace_filename("disable.clipboard"))) + if(!std::filesystem::exists(std::filesystem::path(getModuleFilename().value()).replace_filename("disable.clipboard"))) if(v8script::v8runscript(hm)) succ|= hookClipboard(); return succ; diff --git a/LunaHook/resource/lunajspatch.js b/LunaHook/resource/lunajspatch.js index e7ae9e9..5b18e66 100644 --- a/LunaHook/resource/lunajspatch.js +++ b/LunaHook/resource/lunajspatch.js @@ -1,6 +1,7 @@ var fontface = ''; var magicsend = '\x01LUNAFROMJS\x01' var magicrecv = '\x01LUNAFROMHOST\x01' +var is_packed = %d function splitfonttext(transwithfont) { if (transwithfont.substr(0, magicsend.length) == magicsend) //not trans { @@ -75,17 +76,18 @@ function rpgmakerhook() { return (this.fontItalic ? 'Italic ' : '') + this.fontSize + 'px ' + fontface; } - Bitmap.prototype.drawText = function (text, x, y, maxWidth, lineHeight, align) { - //y>100的有重复;慢速是单字符,快速是多字符 - if (text && (y < 100)) { - extra = 5 + ((text.length == 1) ? 0 : 1); - if (y != Bitmap.prototype.last_y) - clipboardsender_only_send('\n', extra) - clipboardsender_only_send(text, extra) - Bitmap.prototype.last_y = y; + if(!is_packed) + Bitmap.prototype.drawText = function (text, x, y, maxWidth, lineHeight, align) { + //y>100的有重复;慢速是单字符,快速是多字符 + if (text && (y < 100)) { + extra = 5 + ((text.length == 1) ? 0 : 1); + if (y != Bitmap.prototype.last_y) + clipboardsender_only_send('\n', extra) + clipboardsender_only_send(text, extra) + Bitmap.prototype.last_y = y; + } + return this.drawText_ori(text, x, y, maxWidth, lineHeight, align); } - return this.drawText_ori(text, x, y, maxWidth, lineHeight, align); - } Window_Message.prototype.startMessage = function () { gametext = $gameMessage.allText(); resp = clipboardsender(gametext, 0); diff --git a/LunaHost/GUI/LunaHost.cpp b/LunaHost/GUI/LunaHost.cpp index 5ff1ee4..7582d27 100644 --- a/LunaHost/GUI/LunaHost.cpp +++ b/LunaHost/GUI/LunaHost.cpp @@ -9,13 +9,7 @@ #include"LunaHost.h" #include"Lang/Lang.h" #include"http.hpp" -auto gmf=[&](DWORD processId)->std::optional{ - //见鬼了,GetModuleFileName找不到标识符 - std::vector 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 {}; -}; + bool sendclipboarddata_i(const std::wstring&text,HWND hwnd){ if (!OpenClipboard((HWND)hwnd)) return false; HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, (text.size() + 1) * sizeof(wchar_t)); @@ -110,7 +104,7 @@ void LunaHost::on_proc_connect(DWORD pid) { attachedprocess.insert(pid); - if(auto pexe=GetModuleFilename(pid)) + if(auto pexe=getModuleFilename(pid)) { autoattachexes.insert(WideStringToString(pexe.value())); auto u8procname=WideStringToString(pexe.value()); @@ -235,7 +229,7 @@ LunaHost::LunaHost(){ }); menu.add_sep(); menu.add(MenuRemeberSelect,[&,tt](){ - if(auto pexe=gmf(tt->tp.processId)) + if(auto pexe=getModuleFilename(tt->tp.processId)) savedhookcontext[WideStringToString(pexe.value())]={ {"hookcode",WideStringToString(tt->hp.hookcode)}, {"ctx1",tt->tp.ctx}, @@ -244,7 +238,7 @@ LunaHost::LunaHost(){ }; }); menu.add(MenuForgetSelect,[&,tt](){ - if(auto pexe=gmf(tt->tp.processId)) + if(auto pexe=getModuleFilename(tt->tp.processId)) savedhookcontext.erase(WideStringToString(pexe.value())); }); return menu; @@ -343,7 +337,7 @@ void LunaHost::on_text_recv_checkissaved(TextThread& thread) onceautoselectthread.insert(thread.handle); - if(auto exe=GetModuleFilename(thread.tp.processId)) + if(auto exe=getModuleFilename(thread.tp.processId)) { auto exea=WideStringToString(exe.value()); if(savedhookcontext.find(exea)==savedhookcontext.end())return; @@ -758,7 +752,7 @@ std::vector hexStringToBytes(const std::wstring& hexString_) { void Hooksearchsetting::call(std::setpids,std::wstring reg){ if(pids.empty())return; - if(auto filename=gmf(*pids.begin())) + if(auto filename=getModuleFilename(*pids.begin())) editmodule->settext(std::filesystem::path(filename.value()).filename().wstring()); editregex->settext(reg); spincodepage->setcurr(Host::defaultCodepage); diff --git a/LunaHost/GUI/Plugin/extensions/extpch.h b/LunaHost/GUI/Plugin/extensions/extpch.h index 8f41959..289749c 100644 --- a/LunaHost/GUI/Plugin/extensions/extpch.h +++ b/LunaHost/GUI/Plugin/extensions/extpch.h @@ -165,7 +165,7 @@ void Localize(); #define TEST(...) #endif -inline std::optional GetModuleFilename(DWORD processId, HMODULE module = NULL) +inline std::optional getModuleFilename(DWORD processId, HMODULE module = NULL) { std::vector buffer(MAX_PATH); if (AutoHandle<> process = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, FALSE, processId)) @@ -173,7 +173,7 @@ inline std::optional GetModuleFilename(DWORD processId, HMODULE mo return {}; } -inline std::optional GetModuleFilename(HMODULE module = NULL) +inline std::optional getModuleFilename(HMODULE module = NULL) { std::vector buffer(MAX_PATH); if (GetModuleFileNameW(module, buffer.data(), MAX_PATH)) return buffer.data(); @@ -186,6 +186,6 @@ inline std::vector>> GetAllProcesse DWORD spaceUsed = 0; EnumProcesses(processIds.data(), 10000 * sizeof(DWORD), &spaceUsed); std::vector>> processes; - for (int i = 0; i < spaceUsed / sizeof(DWORD); ++i) processes.push_back({ processIds[i], GetModuleFilename(processIds[i]) }); + for (int i = 0; i < spaceUsed / sizeof(DWORD); ++i) processes.push_back({ processIds[i], getModuleFilename(processIds[i]) }); return processes; } diff --git a/LunaHost/GUI/Plugin/extensions/regexfilter.cpp b/LunaHost/GUI/Plugin/extensions/regexfilter.cpp index d21ff01..d214310 100644 --- a/LunaHost/GUI/Plugin/extensions/regexfilter.cpp +++ b/LunaHost/GUI/Plugin/extensions/regexfilter.cpp @@ -44,7 +44,7 @@ private: { auto formatted = FormatString( L"\xfeff|PROCESS|%s|FILTER|%s|END|\r\n", - GetModuleFilename(GetSelectedProcessId()).value_or(FormatString(L"Error getting name of process 0x%X", GetSelectedProcessId())), + getModuleFilename(GetSelectedProcessId()).value_or(FormatString(L"Error getting name of process 0x%X", GetSelectedProcessId())), S(ui.regexEdit->text()) ); std::ofstream(REGEX_SAVE_FILE, std::ios::binary | std::ios::app).write((const char*)formatted.c_str(), formatted.size() * sizeof(wchar_t)); @@ -57,7 +57,7 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo) { static auto _ = GetSelectedProcessId = (DWORD(*)())sentenceInfo["get selected process id"]; if (sentenceInfo["text number"] == 0) return false; - if (/*sentenceInfo["current select"] && */!regex) if (auto processName = GetModuleFilename(sentenceInfo["process id"])) + if (/*sentenceInfo["current select"] && */!regex) if (auto processName = getModuleFilename(sentenceInfo["process id"])) { std::ifstream stream(REGEX_SAVE_FILE, std::ios::binary); BlockMarkupIterator savedFilters(stream, Array{ L"|PROCESS|", L"|FILTER|" }); diff --git a/LunaHost/GUI/window.cpp b/LunaHost/GUI/window.cpp index 5e57c9c..3ce811f 100644 --- a/LunaHost/GUI/window.cpp +++ b/LunaHost/GUI/window.cpp @@ -166,7 +166,7 @@ mainwindow::mainwindow(mainwindow* _parent){ wc.hInstance = GetModuleHandle(0); wc.lpszClassName = CLASS_NAME; wc.hbrBackground = (HBRUSH)(COLOR_WINDOW ); - wc.hIcon= GetExeIcon(GetModuleFilename().value());//LoadIconW(GetModuleHandle(0),L"IDI_ICON1"); + wc.hIcon= GetExeIcon(getModuleFilename().value());//LoadIconW(GetModuleHandle(0),L"IDI_ICON1"); static auto _=RegisterClass(&wc); HWND hWnd = CreateWindowEx( diff --git a/LunaHost/host.cpp b/LunaHost/host.cpp index e3b668d..a60ba97 100644 --- a/LunaHost/host.cpp +++ b/LunaHost/host.cpp @@ -277,7 +277,7 @@ namespace Host if(!process)return false; bool proc64=Is64BitProcess(process); auto dllname=proc64?LUNA_HOOK_DLL_64:LUNA_HOOK_DLL_32; - std::wstring location =locationX.size()?(locationX+L"\\"+dllname): std::filesystem::path(GetModuleFilename().value()).replace_filename(dllname); + std::wstring location =locationX.size()?(locationX+L"\\"+dllname): std::filesystem::path(getModuleFilename().value()).replace_filename(dllname); AddConsoleOutput(location); if(proc64==x64){ return (SafeInject(process,location)); diff --git a/include/hookcode.cpp b/include/hookcode.cpp index d8dba43..5b54a7f 100644 --- a/include/hookcode.cpp +++ b/include/hookcode.cpp @@ -358,7 +358,7 @@ namespace if (processId && !(hp.type & MODULE_OFFSET)) if (AutoHandle<> process = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, FALSE, processId)) if (MEMORY_BASIC_INFORMATION info = {}; VirtualQueryEx(process, (LPCVOID)hp.address, &info, sizeof(info))) - if (auto moduleName = GetModuleFilename(processId, (HMODULE)info.AllocationBase)) + if (auto moduleName = getModuleFilename(processId, (HMODULE)info.AllocationBase)) { hp.type |= MODULE_OFFSET; hp.address -= (uint64_t)info.AllocationBase; diff --git a/include/utils.h b/include/utils.h index 9208811..18e9faa 100644 --- a/include/utils.h +++ b/include/utils.h @@ -78,8 +78,7 @@ inline auto Swallow = [](auto&&...) {}; template std::optional> Copy(T* ptr) { if (ptr) return *ptr; return {}; } - -inline std::optional GetModuleFilename(DWORD processId, HMODULE module = NULL) +inline std::optional getModuleFilename(DWORD processId, HMODULE module = NULL) { std::vector buffer(MAX_PATH); if (AutoHandle<> process = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, FALSE, processId)) @@ -87,7 +86,7 @@ inline std::optional GetModuleFilename(DWORD processId, HMODULE mo return {}; } -inline std::optional GetModuleFilename(HMODULE module = NULL) +inline std::optional getModuleFilename(HMODULE module = NULL) { std::vector buffer(MAX_PATH); if (GetModuleFileNameW(module, buffer.data(), MAX_PATH)) return buffer.data();