idapython / src

IDAPython project for Hex-Ray's IDA Pro
http://www.hex-rays.com/
Other
1.4k stars 285 forks source link

Python3 str does not have .decode(), this will cause the idaapi.has_mbcs to always be False #49

Closed Harding-Stardust closed 1 year ago

Harding-Stardust commented 1 year ago

https://github.com/idapython/src/blob/d34bb4b45a4b862d9af992e30220e9c344834ce3/pywraps/py_idaapi.py#LL407C10-L407C10

There are some .decode() that will fail on Python 3.

williballenthin commented 1 year ago

might be fixed by using a bytes literal, like: b"".decode("UTF-8").encode("mbcs") (note leading "b").

Harding-Stardust commented 1 year ago

Unfortunately not. The first decode "".decode("UTF-8") will return a str and that will in turn fail on the .encode("mbcs")

williballenthin commented 1 year ago

in Python3 the str class has a method .encode(...) that returns the string as bytes using the specified encoding. So, I think this would work:

image
bytes.decode(encoding: str) -> str
str.encode(encoding: str) -> bytes
Harding-Stardust commented 1 year ago

You are correct, I read it as 2 decodes in a row. My bad!

aundro commented 1 year ago

Good catch, thank you! (will handle this soon)

0xeb commented 1 year ago

@aundro , this should have been fixed by now? want to close the issue?

aundro commented 1 year ago

Indeed. Thank you for the heads-up.