From ef90382bbb9af5680d33bafb39098c8b04d69873 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Sat, 15 Jun 2019 19:38:44 -0400 Subject: [PATCH] fixed hookstrlen seeing ascii char+unicode space as null terminator --- test/main.cpp | 2 +- texthook/texthook.cc | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/main.cpp b/test/main.cpp index 66b88a9..7fa2f31 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -43,7 +43,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) return FALSE; }, 0), SW_SHOW); - std::thread([] { while (true) Sleep(vars.at(0)), lstrlenW(L"こんにちは"); }).detach(); + std::thread([] { while (true) Sleep(vars.at(0)), lstrlenW(L"こんにちは\n (Hello)"); }).detach(); STARTUPINFOW info = { sizeof(info) }; wchar_t commandLine[] = { L"Textractor -p\"Test.exe\"" }; diff --git a/texthook/texthook.cc b/texthook/texthook.cc index c261062..2f70638 100644 --- a/texthook/texthook.cc +++ b/texthook/texthook.cc @@ -327,11 +327,11 @@ int TextHook::GetLength(uintptr_t base, uintptr_t in) int TextHook::HookStrlen(BYTE* data) { + if (!hp.null_length) return hp.type & USING_UNICODE ? wcslen((wchar_t*)data) * 2 : strlen((char*)data); BYTE* orig = data; - int nulls = hp.null_length ? hp.null_length : hp.type & USING_UNICODE ? 2 : 1; - for (int nullsRemaining = nulls; nullsRemaining > 0; ++data) + for (int nullsRemaining = hp.null_length; nullsRemaining > 0; ++data) if (*data == 0) nullsRemaining -= 1; - else nullsRemaining = nulls; + else nullsRemaining = hp.null_length; return data - orig; }