issues/735

Update v8.cpp
This commit is contained in:
恍兮惚兮 2024-05-12 16:48:32 +08:00
parent 8982616414
commit 8c2acca210
9 changed files with 44 additions and 35 deletions

View File

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

View File

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

View File

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

View File

@ -165,7 +165,7 @@ 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))
@ -173,7 +173,7 @@ inline std::optional<std::wstring> GetModuleFilename(DWORD processId, HMODULE mo
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();
@ -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;
}

View File

@ -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<std::wstring_view>{ L"|PROCESS|", L"|FILTER|" });

View File

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

View File

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

View File

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

View File

@ -78,8 +78,7 @@ 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))
@ -87,7 +86,7 @@ inline std::optional<std::wstring> GetModuleFilename(DWORD processId, HMODULE mo
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();