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

There was a problem converting the string to bytes #115

Open Pyer-At-Gh opened 7 months ago

Pyer-At-Gh commented 7 months ago

Input_ String1="E8 29 05 00 00 43"

Ex_ String=bytes. from hex (input_string1)

Output: b ' xe8) x05 x00 x00 , an error will appear below

If using ex_ String=rb "\xe8\x29\x05\x00\x00", there will be no errors.

Pm=pymem Pymem (" . exe")

ModelMem=pymem. process. module From Name (pm. process_handle, " . exe")

Temp=pm. pattern Scan All (ex_string)

An error occurred: unbalanced presentation at position 1

Python 3.11, the latest version of Pymem, Win10

Can you please tell me How should I solve it?

StarrFox commented 7 months ago

can you provide the original code and the full traceback?

Harding-Stardust commented 4 months ago

I had a similar problem and it seems you have the classical problem of number of \ in the code, try this:

raw_input_string = "E8 29 05 00 00 43"
mod_input_string = r"\x" + raw_input_string.replace(" ", r"\x") # Spaces --> \x. Notice the r before the strings with \ in them
# mod_input_string should now be r"\xE8\x29\x05\x00\x00\x43"
ex_string = mod_input_string.encode("UTF-8")
print(f"len of ex_string is {len(ex_string)} which should show 24 (6*4)")
temp = pm.pattern_scan_all(ex_string)