From 984cffba82180138675369a52cdf2666589e3802 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, 20 Oct 2024 00:10:15 +0800 Subject: [PATCH] ... --- LunaHook/engines/v8/httpserver.cpp | 4 +- LunaHook/engines/v8/v8.cpp | 4 ++ LunaHook/resource/lunajspatch.js | 67 +++++++++++------------------- 3 files changed, 31 insertions(+), 44 deletions(-) diff --git a/LunaHook/engines/v8/httpserver.cpp b/LunaHook/engines/v8/httpserver.cpp index 3ba4dc9..95f93e8 100644 --- a/LunaHook/engines/v8/httpserver.cpp +++ b/LunaHook/engines/v8/httpserver.cpp @@ -293,7 +293,8 @@ int GetRandomAvailablePort() int makehttpgetserverinternal() { - while (1) + // 尝试1000次 + for (int i = 0; i < 1000; i++) { auto port = GetRandomAvailablePort(); auto [succ, hReqQueue, ssID, urlGroupId] = makeserveronce(port); @@ -310,6 +311,7 @@ int makehttpgetserverinternal() .detach(); return port; } + return 0; } // int main() // { diff --git a/LunaHook/engines/v8/v8.cpp b/LunaHook/engines/v8/v8.cpp index dc1b3ed..b57acc2 100644 --- a/LunaHook/engines/v8/v8.cpp +++ b/LunaHook/engines/v8/v8.cpp @@ -323,6 +323,10 @@ namespace }; hp.filter_fun = [](void *data, size_t *len, HookParam *hp) { + if (strstr((char *)data, R"(http://)") != 0) + return false; + if (strstr((char *)data, R"(https://)") != 0) + return false; if (strstr((char *)data, R"(\\?\)") != 0) return false; // 过滤路径 return true; diff --git a/LunaHook/resource/lunajspatch.js b/LunaHook/resource/lunajspatch.js index db0c890..fd01b13 100644 --- a/LunaHook/resource/lunajspatch.js +++ b/LunaHook/resource/lunajspatch.js @@ -25,76 +25,57 @@ function splitfonttext(transwithfont) { function syncquery(s) { if (internal_http_port == 0) { throw new Error('') } var xhr = new XMLHttpRequest(); - xhr.open('GET', 'http://127.0.0.1:' + internal_http_port + '/fuck?' + s, false); + var url = 'http://127.0.0.1:' + internal_http_port + '/fuck?' + s + xhr.open('GET', url, false); xhr.send(); if (xhr.status === 200) { - return xhr.responseText; + return xhr.responseText;//解析这个会导致v8::String::Length的v8StringUtf8Length出现错误,但不影响。 } else { throw new Error('') } } -function isEmptyString(str) { - return str === null || str === undefined || str.length == 0; +function makecomplexs(name, s_raw, lpsplit) { + return magicsend + name + '\x03' + lpsplit.toString() + '\x02' + s_raw; } -function clipboardsender(name, s_raw, lpsplit) { - //magic split \x02 text - if (isEmptyString(s_raw)) - return s_raw - s = magicsend + name + '\x03' + lpsplit.toString() + '\x02' + s_raw; +function cppjsio(s) { try { - if (!is_useclipboard) { throw new Error('') } - const _clipboard = require('nw.gui').Clipboard.get(); - _clipboard.set(s, 'text'); - transwithfont = _clipboard.get('text'); + return syncquery(s) } catch (err) { try { if (!is_useclipboard) { throw new Error('') } - const clipboard = require('electron').clipboard; - clipboard.writeText(s); - transwithfont = clipboard.readText(); + const _clipboard = require('nw.gui').Clipboard.get(); + _clipboard.set(s, 'text'); + return _clipboard.get('text'); } catch (err2) { - try { - - transwithfont = syncquery(s) + if (!is_useclipboard) { throw new Error('') } + const clipboard = require('electron').clipboard; + clipboard.writeText(s); + return clipboard.readText(); } catch (err3) { return s_raw; } } } +} +function clipboardsender(name, s_raw, lpsplit) { + //magic split \x02 text + if (!s_raw) + return s_raw + transwithfont = cppjsio(makecomplexs(name, s_raw, lpsplit)) if (transwithfont.length == 0) return s_raw; return splitfonttext(transwithfont) } function clipboardsender_only_send(name, s_raw, lpsplit) { //magic split \x02 text - if (isEmptyString(s_raw)) + if (!s_raw) return s_raw - s = magicsend + name + '\x03' + lpsplit.toString() + '\x02' + s_raw; - try { - if (!is_useclipboard) { throw new Error('') } - const _clipboard = require('nw.gui').Clipboard.get(); - _clipboard.set(s, 'text'); - } - catch (err) { - try { - if (!is_useclipboard) { throw new Error('') } - const clipboard = require('electron').clipboard; - clipboard.writeText(s); - } - catch (err2) { - try { - syncquery(s) - } - catch (err3) { - - } - } - } + cppjsio(makecomplexs(name, s_raw, lpsplit)) } function rpgmakerhook() { @@ -110,7 +91,7 @@ function rpgmakerhook() { Bitmap.prototype.origin_makeFontNameText = Bitmap.prototype._makeFontNameText; } Bitmap.prototype._makeFontNameText = function () { - if (fontface == '') return this.origin_makeFontNameText(); + if (!fontface) return this.origin_makeFontNameText(); return (this.fontItalic ? 'Italic ' : '') + this.fontSize + 'px ' + fontface; } @@ -170,7 +151,7 @@ function tyranohook() { tyrano.plugin.kag.tag.text.start = function (pm) { if (1 != this.kag.stat.is_script && 1 != this.kag.stat.is_html) { pm.val = clipboardsender('tyranoscript', pm.val, 0); - if (fontface != '') { + if (fontface) { this.kag.stat.font.face = fontface } }