Skip to content
This repository has been archived by the owner on Nov 17, 2024. It is now read-only.

Commit

Permalink
issues/735
Browse files Browse the repository at this point in the history
Update v8.cpp
  • Loading branch information
HIllya51 committed May 12, 2024
1 parent 8982616 commit 8c2acca
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 35 deletions.
18 changes: 16 additions & 2 deletions LunaHook/engines/v8/v8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 12 additions & 10 deletions LunaHook/resource/lunajspatch.js
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 6 additions & 12 deletions LunaHost/GUI/LunaHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
#include"LunaHost.h"
#include"Lang/Lang.h"
#include"http.hpp"
auto gmf=[&](DWORD processId)->std::optional<std::wstring>{
//见鬼了,GetModuleFileName找不到标识符
std::vector<wchar_t> 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));
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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},
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -758,7 +752,7 @@ std::vector<BYTE> hexStringToBytes(const std::wstring& hexString_) {
void Hooksearchsetting::call(std::set<DWORD>pids,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);
Expand Down
6 changes: 3 additions & 3 deletions LunaHost/GUI/Plugin/extensions/extpch.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ void Localize();
#define TEST(...)
#endif

inline std::optional<std::wstring> GetModuleFilename(DWORD processId, HMODULE module = NULL)
inline std::optional<std::wstring> getModuleFilename(DWORD processId, HMODULE module = NULL)
{
std::vector<wchar_t> buffer(MAX_PATH);
if (AutoHandle<> process = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, FALSE, processId))
if (GetModuleFileNameExW(process, module, buffer.data(), MAX_PATH)) return buffer.data();
return {};
}

inline std::optional<std::wstring> GetModuleFilename(HMODULE module = NULL)
inline std::optional<std::wstring> getModuleFilename(HMODULE module = NULL)
{
std::vector<wchar_t> buffer(MAX_PATH);
if (GetModuleFileNameW(module, buffer.data(), MAX_PATH)) return buffer.data();
Expand All @@ -186,6 +186,6 @@ inline std::vector<std::pair<DWORD, std::optional<std::wstring>>> GetAllProcesse
DWORD spaceUsed = 0;
EnumProcesses(processIds.data(), 10000 * sizeof(DWORD), &spaceUsed);
std::vector<std::pair<DWORD, std::optional<std::wstring>>> 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;
}
4 changes: 2 additions & 2 deletions LunaHost/GUI/Plugin/extensions/regexfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Window : public QDialog, Localizer
{
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));
Expand All @@ -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<std::wstring_view>{ L"|PROCESS|", L"|FILTER|" });
Expand Down
2 changes: 1 addition & 1 deletion LunaHost/GUI/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion LunaHost/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion include/hookcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,15 @@ inline auto Swallow = [](auto&&...) {};
template <typename T> std::optional<std::remove_cv_t<T>> Copy(T* ptr) { if (ptr) return *ptr; return {}; }



inline std::optional<std::wstring> GetModuleFilename(DWORD processId, HMODULE module = NULL)
inline std::optional<std::wstring> getModuleFilename(DWORD processId, HMODULE module = NULL)
{
std::vector<wchar_t> buffer(MAX_PATH);
if (AutoHandle<> process = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, FALSE, processId))
if (GetModuleFileNameExW(process, module, buffer.data(), MAX_PATH)) return buffer.data();
return {};
}

inline std::optional<std::wstring> GetModuleFilename(HMODULE module = NULL)
inline std::optional<std::wstring> getModuleFilename(HMODULE module = NULL)
{
std::vector<wchar_t> buffer(MAX_PATH);
if (GetModuleFileNameW(module, buffer.data(), MAX_PATH)) return buffer.data();
Expand Down

0 comments on commit 8c2acca

Please sign in to comment.