Pymem
Pymem copied to clipboard
UnicodeDecodeError, when using read_string
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?
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'))
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
`
I think adding an encoding argument to read_string would fix this issue