srounet / Pymem

A python library for windows, providing the needed functions to start working on your own with memory editing.
MIT License
303 stars 45 forks source link

UnicodeDecodeError, when using read_string #61

Closed VitalijKo closed 7 months ago

VitalijKo commented 2 years ago

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?

wkingnet commented 2 years ago

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'))
LoseNine commented 2 years ago

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

`

StarrFox commented 2 years ago

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