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,14 +413,20 @@ 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)
{ {
dataLen = min(currentLen, TEXT_BUFFER_SIZE); if(!location)continue;
memcpy(pbData, location, dataLen); int currentLen = HookStrlen((BYTE*)location);
if (hp.filter_fun && !hp.filter_fun(pbData, &dataLen, &hp) || dataLen <= 0) continue; bool changed=memcmp(pbData, location, dataLen) != 0;
TextOutput({ GetCurrentProcessId(), address, 0, 0 },hp, buffer, dataLen); if(changed ||(currentLen!=dataLen))
memcpy(pbData, location, dataLen); {
} dataLen = min(currentLen, TEXT_BUFFER_SIZE);
memcpy(pbData, location, dataLen);
if (hp.filter_fun && !hp.filter_fun(pbData, &dataLen, &hp) || dataLen <= 0) continue;
TextOutput({ GetCurrentProcessId(), address, 0, 0 },hp, buffer, dataLen);
memcpy(pbData, location, dataLen);
}
}
} }
} }