fixed hookstrlen seeing ascii char+unicode space as null terminator

This commit is contained in:
Akash Mozumdar 2019-06-15 19:38:44 -04:00
parent b4c5b31482
commit ef90382bbb
2 changed files with 4 additions and 4 deletions

View File

@ -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\"" };

View File

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