From 72634e51e480bad13a4a56f32985da7fd5377fda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <1173718158@qq.com> Date: Fri, 3 Jan 2025 13:06:55 +0800 Subject: [PATCH] . --- .gitmodules | 3 -- cpp/exec/PyStand.cpp | 14 ++----- cpp/libs/Clipper2 | 2 +- cpp/libs/rapidfuzz-cpp | 2 +- cpp/libs/wechat-ocr | 1 - cpp/libs/wil | 2 +- cpp/version.cmake | 2 +- cpp/wcocr/CMakeLists.txt | 15 +++---- py/LunaTranslator/myutils/hwnd.py | 3 +- py/LunaTranslator/ocrengines/googlelens.py | 3 +- py/LunaTranslator/ocrengines/weixinocr.py | 46 ++++++++++++++-------- 11 files changed, 46 insertions(+), 47 deletions(-) delete mode 160000 cpp/libs/wechat-ocr diff --git a/.gitmodules b/.gitmodules index 87353623..521fefcd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,9 +4,6 @@ [submodule "src/plugins/libs/rapidfuzz-cpp"] path = cpp/libs/rapidfuzz-cpp url = https://github.com/rapidfuzz/rapidfuzz-cpp -[submodule "src/plugins/libs/wechat-ocr"] - path = cpp/libs/wechat-ocr - url = https://github.com/swigger/wechat-ocr [submodule "src/plugins/libs/Clipper2"] path = cpp/libs/Clipper2 url = https://github.com/AngusJohnson/Clipper2 diff --git a/cpp/exec/PyStand.cpp b/cpp/exec/PyStand.cpp index ab0e4597..16405454 100644 --- a/cpp/exec/PyStand.cpp +++ b/cpp/exec/PyStand.cpp @@ -95,16 +95,6 @@ bool PyStand::CheckEnviron(const wchar_t *rtp) SetEnvironmentVariableW(L"PYSTAND_HOME", _home.c_str()); SetEnvironmentVariableW(L"PYSTAND_RUNTIME", _runtime.c_str()); - // unnecessary to init PYSTAND_SCRIPT here. -#if 0 - SetEnvironmentVariableW(L"PYSTAND_SCRIPT", _script.c_str()); -#endif - -#if 0 - wprintf(L"%s - %s\n", _pystand.c_str(), path); - MessageBoxW(NULL, _pystand.c_str(), _home.c_str(), MB_OK); -#endif - return true; } @@ -223,7 +213,9 @@ int PyStand::DetectScript() return -1; } SetEnvironmentVariableW(L"PYSTAND_SCRIPT", _script.c_str()); - + std::vector buffer(MAX_PATH); + GetModuleFileNameW(GetModuleHandle(0), buffer.data(), MAX_PATH); + SetEnvironmentVariableW(L"LUNA_EXE_NAME", buffer.data()); return 0; } diff --git a/cpp/libs/Clipper2 b/cpp/libs/Clipper2 index ed98928c..7598be97 160000 --- a/cpp/libs/Clipper2 +++ b/cpp/libs/Clipper2 @@ -1 +1 @@ -Subproject commit ed98928c66707988d4eb2c49a31c41380a08931c +Subproject commit 7598be97d333837c460c778dd16ba8d945fefdba diff --git a/cpp/libs/rapidfuzz-cpp b/cpp/libs/rapidfuzz-cpp index cbdf8438..6ec7699e 160000 --- a/cpp/libs/rapidfuzz-cpp +++ b/cpp/libs/rapidfuzz-cpp @@ -1 +1 @@ -Subproject commit cbdf84388cea0f12d8a02d9bac28d806b178302a +Subproject commit 6ec7699ef20ddf87687c6b055be35ec6a034020c diff --git a/cpp/libs/wechat-ocr b/cpp/libs/wechat-ocr deleted file mode 160000 index 2faebdc1..00000000 --- a/cpp/libs/wechat-ocr +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2faebdc1ce91100acfaa550d83a8a470e98b9035 diff --git a/cpp/libs/wil b/cpp/libs/wil index 6f60a1b7..27d66a24 160000 --- a/cpp/libs/wil +++ b/cpp/libs/wil @@ -1 +1 @@ -Subproject commit 6f60a1b76fb812c6af5db1bc7abdec0001edd43f +Subproject commit 27d66a24b55a2f7baf91c06c196ba1a2d256c2db diff --git a/cpp/version.cmake b/cpp/version.cmake index f7caf03f..013f4457 100644 --- a/cpp/version.cmake +++ b/cpp/version.cmake @@ -1,7 +1,7 @@ set(VERSION_MAJOR 6) set(VERSION_MINOR 16) -set(VERSION_PATCH 16) +set(VERSION_PATCH 17) set(VERSION_REVISION 0) set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}") add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp) diff --git a/cpp/wcocr/CMakeLists.txt b/cpp/wcocr/CMakeLists.txt index 1a8df647..298cfc6d 100644 --- a/cpp/wcocr/CMakeLists.txt +++ b/cpp/wcocr/CMakeLists.txt @@ -1,20 +1,15 @@ project(wcocr) -set(wcocr_src wechat-ocr/src/mojocall.cpp wechat-ocr/src/ocr_protobuf.pb.cc wechat-ocr/src/wechatocr.cpp) -message(${wcocr_src}) -string(REPLACE ";" ";../libs/" wcocr_src "${wcocr_src}") -message(${wcocr_src}) -set(wcocr_src "../libs/${wcocr_src}") -message(${wcocr_src}) +set(wcocr_src wechat-ocr/src/mojocall.cpp wechat-ocr/src/ocr_common.pb.cc wechat-ocr/src/ocr_wx3.pb.cc wechat-ocr/src/ocr_wx4.pb.cc wechat-ocr/src/wechatocr.cpp) add_library(wcocr MODULE wcocr.cpp ${wcocr_src}) -target_include_directories(wcocr PUBLIC ../libs/wechat-ocr/vs.proj PUBLIC ../libs/wechat-ocr/src PRIVATE ../libs/wechat-ocr/spt) +target_include_directories(wcocr PUBLIC wechat-ocr/vs.proj PUBLIC wechat-ocr/src PRIVATE wechat-ocr/spt) target_compile_options(wcocr PUBLIC - /std:c++17 + /std:c++20 /MD /wd4018 /DUNICODE @@ -22,9 +17,9 @@ target_compile_options(wcocr ) if(${CMAKE_SIZEOF_VOID_P} EQUAL 8) - target_link_libraries(wcocr ${CMAKE_SOURCE_DIR}/libs/wechat-ocr/spt/x64/libprotobuf-lite.lib ${CMAKE_SOURCE_DIR}/libs/wechat-ocr/spt/x64/mmmojo_64.lib) + target_link_libraries(wcocr ${CMAKE_CURRENT_SOURCE_DIR}/wechat-ocr/spt/x64/libprotobuf-lite.lib ${CMAKE_CURRENT_SOURCE_DIR}/wechat-ocr/spt/x64/mmmojo_64.lib) target_link_options(wcocr PRIVATE "/DELAYLOAD:mmmojo_64.dll") else() - target_link_libraries(wcocr ${CMAKE_SOURCE_DIR}/libs/wechat-ocr/spt/x86/libprotobuf-lite.lib ${CMAKE_SOURCE_DIR}/libs/wechat-ocr/spt/x86/mmmojo.lib) + target_link_libraries(wcocr ${CMAKE_CURRENT_SOURCE_DIR}/wechat-ocr/spt/x86/libprotobuf-lite.lib ${CMAKE_CURRENT_SOURCE_DIR}/wechat-ocr/spt/x86/mmmojo.lib) target_link_options(wcocr PRIVATE "/DELAYLOAD:mmmojo.dll") endif() diff --git a/py/LunaTranslator/myutils/hwnd.py b/py/LunaTranslator/myutils/hwnd.py index 977deb7a..8bb9d3a4 100644 --- a/py/LunaTranslator/myutils/hwnd.py +++ b/py/LunaTranslator/myutils/hwnd.py @@ -124,7 +124,8 @@ def getpidexe(pid): def getcurrexe(): - return getpidexe(os.getpid()) + # getpidexe(os.getpid())谜之有人获取到的结果是None,无法理解,那就先回档吧。 + return os.environ.get("LUNA_EXE_NAME", getpidexe(os.getpid())) def test_injectable_1(pid): diff --git a/py/LunaTranslator/ocrengines/googlelens.py b/py/LunaTranslator/ocrengines/googlelens.py index 022eeb08..ff84729f 100644 --- a/py/LunaTranslator/ocrengines/googlelens.py +++ b/py/LunaTranslator/ocrengines/googlelens.py @@ -10,8 +10,9 @@ class OCR(baseocr): timestamp = int(time.time() * 1000) url = "https://lens.google.com/v3/upload?stcs={}".format(timestamp) + # https://github.com/AuroraWright/owocr/blob/master/owocr/ocr.py#L209C9-L209C204 headers = { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", + "User-Agent": "Mozilla/5.0 (SMART-TV; Linux; Tizen 6.0) AppleWebKit/538.1 (KHTML, like Gecko) Version/6.0 TV Safari/538.1 STvPlus/9e6462f14a056031e5b32ece2af7c3ca,gzip(gfe),gzip(gfe)" } cookies = {"SOCS": "CAESEwgDEgk0ODE3Nzk3MjQaAmVuIAEaBgiA_LyaBg"} files = {"encoded_image": ("screenshot.png", imagebinary, "image/png")} diff --git a/py/LunaTranslator/ocrengines/weixinocr.py b/py/LunaTranslator/ocrengines/weixinocr.py index c82461a5..64b33d6c 100644 --- a/py/LunaTranslator/ocrengines/weixinocr.py +++ b/py/LunaTranslator/ocrengines/weixinocr.py @@ -19,13 +19,13 @@ class wcocr: for function in [self.findwechat, self.findqqnt]: try: wechatocr_path, wechat_path = function() + if any([not os.path.exists(_) for _ in (wechatocr_path, wechat_path)]): + continue + self.pobj = wcocr_init(wechatocr_path, wechat_path) + if self.pobj: + break except: print_exc() - if any([not os.path.exists(_) for _ in (wechatocr_path, wechat_path)]): - continue - self.pobj = wcocr_init(wechatocr_path, wechat_path) - if self.pobj: - break if not self.pobj: raise Exception("找不到(微信和WeChatOCR)或(QQNT和TencentOCR)") @@ -52,20 +52,34 @@ class wcocr: base = winreg.QueryValueEx(k, "InstallPath")[0] winreg.CloseKey(k) WeChatexe = os.path.join(base, "WeChat.exe") + if not os.path.exists(WeChatexe): + # 4.x + WeChatexe = os.path.join(base, "Weixin.exe") version = winsharedutils.queryversion(WeChatexe) if not version: raise Exception - versionf = ".".join((str(_) for _ in version)) - wechat_path = os.path.join(base, "[" + versionf + "]") - wechatocr_path = ( - os.getenv("APPDATA") + r"\Tencent\WeChat\XPlugin\Plugins\WeChatOCR" - ) - wechatocr_path = os.path.join( - wechatocr_path, - os.listdir(wechatocr_path)[0], - r"extracted\WeChatOCR.exe", - ) + APPDATA = os.getenv("APPDATA") + if version[0] == 4: + wechat_path = os.path.join(base, versionf) + wechatocr_path = os.path.join( + APPDATA, r"Tencent\xwechat\XPlugin\plugins\WeChatOcr" + ) + wechatocr_path = os.path.join( + wechatocr_path, + os.listdir(wechatocr_path)[0], + r"extracted\wxocr.dll", + ) + elif version[0] == 3: + wechat_path = os.path.join(base, "[" + versionf + "]") + wechatocr_path = os.path.join( + APPDATA, r"Tencent\WeChat\XPlugin\Plugins\WeChatOCR" + ) + wechatocr_path = os.path.join( + wechatocr_path, + os.listdir(wechatocr_path)[0], + r"extracted\WeChatOCR.exe", + ) return wechatocr_path, wechat_path def __del__(self): @@ -89,9 +103,9 @@ class wcocr: fp = CFUNCTYPE(None, c_int, c_int, c_int, c_int, c_char_p)(cb) succ = wcocr_ocr(self.pobj, imgfile.encode("utf8"), fp) + os.remove(imgfile) if not succ: return - os.remove(imgfile) boxs = [] texts = [] for line in ret: