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

Fixed the problem which not search the pattern with re.search and re.… #77

Closed airvzxf closed 2 years ago

airvzxf commented 2 years ago

It fixes #76.

The problem is that the module re for the functions search and finditer is not matching with byte arrays (b'\x54\x98').

The solution that I purpose, and it is working in my computer. Convert the byte strings to hex string in the re functions.

My thoughts are that maybe it was working before because in PyCharm it marks as AnyString (def search(pattern: Pattern[AnyStr],) but in the official documentation https://docs.python.org/3.10/library/re.html#re.search, it is showing as a string but not specify the byte string.

Or maybe it is something that the official web page says:

Both patterns and strings to be searched can be Unicode strings (str) as well as 8-bit strings (bytes). However, Unicode strings and 8-bit strings cannot be mixed: that is, you cannot match a Unicode string with a byte pattern or vice-versa; similarly, when asking for a substitution, the replacement string must be of the same type as both the pattern and the search string.