rs length changed

This commit is contained in:
恍兮惚兮 2024-05-23 16:29:46 +08:00
parent 06503ed972
commit 16852394ff
2 changed files with 15 additions and 9 deletions

View File

@ -154,11 +154,11 @@ int HookStrLen(HookParam* hp,BYTE* data){
if(data==0)return 0; if(data==0)return 0;
if(hp->type&CODEC_UTF16) if(hp->type&CODEC_UTF16)
return wcslen((wchar_t*)data)*2; return wcsnlen((wchar_t*)data,TEXT_BUFFER_SIZE)*2;
else if(hp->type&CODEC_UTF32) else if(hp->type&CODEC_UTF32)
return u32strlen((uint32_t*)data)*4; return u32strlen((uint32_t*)data)*4;
else else
return strlen((char*)data); return strnlen((char*)data,TEXT_BUFFER_SIZE);
} }
static std::mutex maplock; static std::mutex maplock;

View File

@ -413,7 +413,12 @@ void TextHook::Read()
} }
else else
{ {
while (WaitForSingleObject(readerEvent, 500) == WAIT_TIMEOUT) if (location&&(memcmp(pbData, location, dataLen) != 0)) if (int currentLen = HookStrlen((BYTE*)location)) while (WaitForSingleObject(readerEvent, 500) == WAIT_TIMEOUT)
{
if(!location)continue;
int currentLen = HookStrlen((BYTE*)location);
bool changed=memcmp(pbData, location, dataLen) != 0;
if(changed ||(currentLen!=dataLen))
{ {
dataLen = min(currentLen, TEXT_BUFFER_SIZE); dataLen = min(currentLen, TEXT_BUFFER_SIZE);
memcpy(pbData, location, dataLen); memcpy(pbData, location, dataLen);
@ -422,6 +427,7 @@ void TextHook::Read()
memcpy(pbData, location, dataLen); memcpy(pbData, location, dataLen);
} }
} }
}
} }
__except (EXCEPTION_EXECUTE_HANDLER) __except (EXCEPTION_EXECUTE_HANDLER)