Pymem icon indicating copy to clipboard operation
Pymem copied to clipboard

UnicodeDecodeError, when using read_string

Open VitalyTheGlitch opened this issue 3 years ago • 3 comments

When I read 4 bytes int, everything works fine, but when I try to read a string using read_string I get UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb4 in position 1: invalid start byte. How can I fix it? I have Windows 10 x64 and Python 3.9. Perhaps I have an unsupported version of Python?

VitalyTheGlitch avatar Jul 11 '21 17:07 VitalyTheGlitch

you can try this:

temp = b''
while pm.read_bytes(address, 1) != b'\x00':
    temp = temp + pm.read_bytes(address, 1)
    address += 1
print(temp.decode('utf-8'))

wkingnet avatar Jul 24 '21 07:07 wkingnet

I solved the problem,when u read chinese string,like “清润珍珠....”,will raise UnicodeDecodeError,you can try this: 1.Go into this method· ‘read_string’ 2.Go into this method 'pymem.memory.read_string(self.process_handle, address, byte)' 3.Modify the code `

buff = read_bytes(handle, address, byte)
i = buff.find(b'\x00')
if i != -1:
    buff = buff[:i]
try:
    buff = buff.decode()
except UnicodeDecodeError:
    buff=buff.decode('gb2312',errors='ignore')
return buff

`

LoseNine avatar Apr 09 '22 06:04 LoseNine

I think adding an encoding argument to read_string would fix this issue

StarrFox avatar Apr 09 '22 06:04 StarrFox