AtomCrafty / UniversalInjectorFramework

A framework to inject your own code into Windows applications.
46 stars 3 forks source link

Unable to hook when using character_substitution and replace_char #14

Closed dk000000000 closed 2 weeks ago

dk000000000 commented 2 weeks ago

Description It seems the game use PalFontDrawText from dll/Pal.dll, but Pal.dll is only loaded when first text box appear after the game started, I tried with both character substitution and textprocecssor replace char but failed. Is there a way to fix this?

UIF config uif_config.json

exe and dll folder [カノジョの親友にカラダで誘惑されるヒミツの関係 豪華版.zip](https://github.com/user-attachments/files/16814582/default.zip)
[injector] ======================================================
[injector] Injecting into module kanowaku_Claude-3-5-Sonnet.exe at address 009C0000
[injector] Loaded modules:
[injector] 00500000 
[injector] 009C0000 kanowaku_Claude-3-5-Sonnet.exe
[injector] 72370000 WINMM.dll
[injector] 72AD0000 SensApi.dll
[injector] 72AE0000 COMCTL32.dll
[injector] 73AB0000 MSVCP140.dll
[injector] 74740000 VCRUNTIME140.dll
[injector] 751B0000 VERSION.dll
[injector] 75440000 aswhook.dll
[injector] 75460000 RPCRT4.dll
[injector] 755A0000 ADVAPI32.dll
[injector] 75630000 combase.dll
[injector] 75920000 ucrtbase.dll
[injector] 75B40000 IMM32.dll
[injector] 75B70000 msvcrt.dll
[injector] 75C30000 bcrypt.dll
[injector] 75C50000 KERNELBASE.dll
[injector] 75E90000 KERNEL32.DLL
[injector] 76450000 COMDLG32.dll
[injector] 76560000 ole32.dll
[injector] 76650000 gdi32full.dll
[injector] 76740000 win32u.dll
[injector] 76760000 sechost.dll
[injector] 767E0000 SHLWAPI.dll
[injector] 76A90000 msvcp_win.dll
[injector] 76B10000 shcore.dll
[injector] 76C20000 USER32.dll
[injector] 76DC0000 GDI32.dll
[injector] 76DF0000 SHELL32.dll
[injector] 775D0000 
[injector] 775E0000 ntdll.dll
[injector] Error: Unable to locate dll dll/Pal.dll (5 - The specified module could not be found)
[injector] Error: Unable to locate additional module dll/Pal.dll (5 - The specified module could not be found)
[injector] Loading original library from C:\WINDOWS\system32\winmm.dll
[text_processor] Warning: unknown api: PalFontDrawText
[text_processor] Unable to hook import IsDBCSLeadByte because it does not exist
[text_processor] Unable to hook import IsDBCSLeadByteEx because it does not exist
[text_processor] Hooking import MultiByteToWideChar in kanowaku_Claude-3-5-Sonnet.exe at 00A791B0 --> 7239F6A0
[text_processor] Unable to hook import GetGlyphOutlineA because it does not exist
[text_processor] Unable to hook import GetGlyphOutlineW because it does not exist
[text_processor] Unable to hook import GetTextExtentExPointA because it does not exist
[text_processor] Unable to hook import GetTextExtentExPointW because it does not exist
[text_processor] Unable to hook import GetTextExtentPoint32A because it does not exist
[text_processor] Unable to hook import GetTextExtentPoint32W because it does not exist
[text_processor] Unable to hook import GetTextExtentPointA because it does not exist
[text_processor] Unable to hook import GetTextExtentPointW because it does not exist
[text_processor] Unable to hook import TextOutA because it does not exist
[text_processor] Unable to hook import TextOutW because it does not exist
[text_processor] Unable to hook import ExtTextOutA because it does not exist
[text_processor] Unable to hook import ExtTextOutW because it does not exist
[text_processor] Unable to hook import AppendMenuA because it does not exist
[text_processor] Unable to hook import AppendMenuW because it does not exist
[text_processor] Unable to hook import InsertMenuA because it does not exist
[text_processor] Unable to hook import InsertMenuW because it does not exist
[text_processor] Unable to hook import InsertMenuItemA because it does not exist
[text_processor] Unable to hook import InsertMenuItemW because it does not exist
[text_processor] Unable to hook import ModifyMenuA because it does not exist
[text_processor] Unable to hook import ModifyMenuW because it does not exist
[text_processor] Unable to hook import SetMenuItemInfoA because it does not exist
[text_processor] Unable to hook import SetMenuItemInfoW because it does not exist
[text_processor] Hooking import SetDlgItemTextA in kanowaku_Claude-3-5-Sonnet.exe at 00A792F8 --> 723A1390
[text_processor] Unable to hook import SetDlgItemTextW because it does not exist
[text_processor] Unable to hook import DrawTextA because it does not exist
[text_processor] Unable to hook import DrawTextW because it does not exist
[text_processor] Unable to hook import DrawTextExA because it does not exist
[text_processor] Unable to hook import DrawTextExW because it does not exist
[text_processor] Unable to hook import GrayStringA because it does not exist
[text_processor] Unable to hook import GrayStringW because it does not exist
[text_processor] Unable to hook import TabbedTextOutA because it does not exist
[text_processor] Unable to hook import TabbedTextOutW because it does not exist
[text_processor] Hooking import MessageBoxA in kanowaku_Claude-3-5-Sonnet.exe at 00A79318 --> 723A2550
[text_processor] Unable to hook import MessageBoxW because it does not exist
[text_processor] Unable to hook import MessageBoxExA because it does not exist
[text_processor] Unable to hook import MessageBoxExW because it does not exist
[text_processor] Unable to hook import MessageBoxIndirectA because it does not exist
[text_processor] Unable to hook import MessageBoxIndirectW because it does not exist
[text_processor] Unable to hook import DefWindowProcA because it does not exist
[text_processor] Unable to hook import DefWindowProcW because it does not exist
[text_processor] Hooking import DefDlgProcA in kanowaku_Claude-3-5-Sonnet.exe at 00A792B4 --> 723A2AD0
[text_processor] Unable to hook import DefDlgProcW because it does not exist
[text_processor] Unable to hook import DefWindowProcA because it does not exist
[text_processor] Unable to hook import DefWindowProcW because it does not exist
[text_processor] Unable to hook import DefDlgProcW because it does not exist
[character_substitution] Loaded 3019 substitution characters
[character_substitution] Unable to hook import TextOutA because it does not exist
[character_substitution] Unable to hook import TextOutW because it does not exist
[character_substitution] Unable to hook import GetGlyphOutlineA because it does not exist
[character_substitution] Unable to hook import GetGlyphOutlineW because it does not exist
[injector] Initialization complete
[injector] ======================================================
AtomCrafty commented 2 weeks ago

PalFontDrawText is not a Windows function and as such UIF does not natively support hooking it. Taking a look into Pal.dll reveals that PalFontDrawText itself uses the GetGlyphOutlineA function to determine a character's shape.

The log shows that UIF fails to load Pal.dll. What's supposed to happen is that UIF should load dll/Pal.dll on launch and hook the GetGlyphOutlineA import within the dll. The Microsoft documentation for LoadLibrary says to specify dll paths with backslashes (\) instead of forward slashes (/), so that may be why it can't be found. Note that since this is a json file, backslashes need to be escaped as \\.

Try this and see whether it works:

{
  "injector": {
    "enable": true,
    "print_loaded_modules": true,
    "load_modules": [
      "dll\\Pal.dll"
    ],
    "hook_modules": [
      "dll\\Pal.dll"
    ]
  },
  "allocate_console": true,
  "text_processor": {
    "enable": true,
    "enabled_apis": ["GetGlyphOutlineA"],
    "rules": [
      {
        "type": "replace_chars",
        "source_chars": "這説為凜們 ...",
        "target_chars": "这说为你们 ...",
        "apis": ["GetGlyphOutlineA"]
      }
    ]
  }
}
dk000000000 commented 2 weeks ago

still could't find dll\Pal.dll

[injector] ====================================================== [injector] Injecting into module kanowaku.log at address 00CE0000 [injector] Loaded modules: [injector] 00840000 [injector] 00CE0000 kanowaku.log [injector] 6DE40000 WINMM.dll [injector] 6DEA0000 COMCTL32.dll [injector] 72190000 SensApi.dll [injector] 73AB0000 MSVCP140.dll [injector] 74740000 VCRUNTIME140.dll [injector] 75260000 VERSION.dll [injector] 75440000 aswhook.dll [injector] 75460000 RPCRT4.dll [injector] 755A0000 ADVAPI32.dll [injector] 75630000 combase.dll [injector] 75920000 ucrtbase.dll [injector] 75B40000 IMM32.dll [injector] 75B70000 msvcrt.dll [injector] 75C30000 bcrypt.dll [injector] 75C50000 KERNELBASE.dll [injector] 75E90000 KERNEL32.DLL [injector] 76450000 COMDLG32.dll [injector] 76560000 ole32.dll [injector] 76650000 gdi32full.dll [injector] 76740000 win32u.dll [injector] 76760000 sechost.dll [injector] 767E0000 SHLWAPI.dll [injector] 76A90000 msvcp_win.dll [injector] 76B10000 shcore.dll [injector] 76C20000 USER32.dll [injector] 76DC0000 GDI32.dll [injector] 76DF0000 SHELL32.dll [injector] 775D0000 [injector] 775E0000 ntdll.dll [injector] Error: Unable to locate dll dll\Pal.dll (5 - The specified module could not be found) [injector] Error: Unable to locate additional module dll\Pal.dll (5 - The specified module could not be found) [injector] Loading original library from C:\WINDOWS\system32\winmm.dll [text_processor] Unable to hook import IsDBCSLeadByte because it does not exist [text_processor] Unable to hook import IsDBCSLeadByteEx because it does not exist [text_processor] Hooking import MultiByteToWideChar in kanowaku.log at 00D991B0 --> 6DE6F6A0 [text_processor] Unable to hook import GetGlyphOutlineA because it does not exist [text_processor] Unable to hook import GetGlyphOutlineW because it does not exist [text_processor] Unable to hook import GetTextExtentExPointA because it does not exist [text_processor] Unable to hook import GetTextExtentExPointW because it does not exist [text_processor] Unable to hook import GetTextExtentPoint32A because it does not exist [text_processor] Unable to hook import GetTextExtentPoint32W because it does not exist [text_processor] Unable to hook import GetTextExtentPointA because it does not exist [text_processor] Unable to hook import GetTextExtentPointW because it does not exist [text_processor] Unable to hook import TextOutA because it does not exist [text_processor] Unable to hook import TextOutW because it does not exist [text_processor] Unable to hook import ExtTextOutA because it does not exist [text_processor] Unable to hook import ExtTextOutW because it does not exist [text_processor] Unable to hook import AppendMenuA because it does not exist [text_processor] Unable to hook import AppendMenuW because it does not exist [text_processor] Unable to hook import InsertMenuA because it does not exist [text_processor] Unable to hook import InsertMenuW because it does not exist [text_processor] Unable to hook import InsertMenuItemA because it does not exist [text_processor] Unable to hook import InsertMenuItemW because it does not exist [text_processor] Unable to hook import ModifyMenuA because it does not exist [text_processor] Unable to hook import ModifyMenuW because it does not exist [text_processor] Unable to hook import SetMenuItemInfoA because it does not exist [text_processor] Unable to hook import SetMenuItemInfoW because it does not exist [text_processor] Hooking import SetDlgItemTextA in kanowaku.log at 00D992F8 --> 6DE71390 [text_processor] Unable to hook import SetDlgItemTextW because it does not exist [text_processor] Unable to hook import DrawTextA because it does not exist [text_processor] Unable to hook import DrawTextW because it does not exist [text_processor] Unable to hook import DrawTextExA because it does not exist [text_processor] Unable to hook import DrawTextExW because it does not exist [text_processor] Unable to hook import GrayStringA because it does not exist [text_processor] Unable to hook import GrayStringW because it does not exist [text_processor] Unable to hook import TabbedTextOutA because it does not exist [text_processor] Unable to hook import TabbedTextOutW because it does not exist [text_processor] Hooking import MessageBoxA in kanowaku.log at 00D99318 --> 6DE72550 [text_processor] Unable to hook import MessageBoxW because it does not exist [text_processor] Unable to hook import MessageBoxExA because it does not exist [text_processor] Unable to hook import MessageBoxExW because it does not exist [text_processor] Unable to hook import MessageBoxIndirectA because it does not exist [text_processor] Unable to hook import MessageBoxIndirectW because it does not exist [text_processor] Unable to hook import DefWindowProcA because it does not exist [text_processor] Unable to hook import DefWindowProcW because it does not exist [text_processor] Hooking import DefDlgProcA in kanowaku.log at 00D992B4 --> 6DE72AD0 [text_processor] Unable to hook import DefDlgProcW because it does not exist [text_processor] Unable to hook import DefWindowProcA because it does not exist [text_processor] Unable to hook import DefWindowProcW because it does not exist [text_processor] Unable to hook import DefDlgProcW because it does not exist [injector] Initialization complete [injector] ======================================================

AtomCrafty commented 2 weeks ago

Maybe the game changes the dll search path? Try just Pal.dll without the folder name.

dk000000000 commented 2 weeks ago

wouldn't work even with absolute path

[injector] Error: Unable to locate dll D:\a\dll\Pal.dll (5 - The specified module could not be found) [injector] Error: Unable to locate additional module D:\a\dll\Pal.dll (5 - The specified module could not be found)

dk000000000 commented 2 weeks ago

is it possible to deley the injector, let program load pal.dll first

AtomCrafty commented 2 weeks ago

Might be possible to do that by hooking LoadLibrary itself. But I don't really have the time to do that right now.

dk000000000 commented 2 weeks ago

it turns out Pal.dll is depend on other dll, character_subsitution is enough. "load_modules": [ "dll\\ogg.dll", "dll\\vorbis.dll", "dll\\vorbisfile.dll", "dll\\Pal.dll" ], "hook_modules": [ "dll\\ogg.dll", "dll\\vorbis.dll", "dll\\vorbisfile.dll", "dll\\Pal.dll" ]