diff --git a/PyMemoryEditor/linux/functions.py b/PyMemoryEditor/linux/functions.py index d917296..93bbf4c 100644 --- a/PyMemoryEditor/linux/functions.py +++ b/PyMemoryEditor/linux/functions.py @@ -67,7 +67,13 @@ def read_process_memory( pid, (iovec * 1)(iovec(addressof(data), sizeof(data))), 1, (iovec * 1)(iovec(address, sizeof(data))), 1, 0 ) - return data.value.decode() if pytype is str else data.value + + if pytype is str: + return bytes(data).decode() + elif pytype is bytes: + return bytes(data) + else: + return data.value def search_addresses_by_value( diff --git a/PyMemoryEditor/util/convert.py b/PyMemoryEditor/util/convert.py index 224f884..3150fea 100644 --- a/PyMemoryEditor/util/convert.py +++ b/PyMemoryEditor/util/convert.py @@ -32,9 +32,10 @@ def get_c_type_of(pytype: Type, length) -> ctypes._SimpleCData: if length <= 4: return ctypes.c_int32() # 4 Bytes return ctypes.c_int64() # 8 Bytes - # Float values lose their precision when converted to c_float. For that reason, - # any float value will be converted to double. - elif pytype is float: return ctypes.c_double() # 8 Bytes + elif pytype is float: + + if length == 4: return ctypes.c_float() # 4 Bytes + return ctypes.c_double() # 8 Bytes elif pytype is bool: return ctypes.c_bool() diff --git a/PyMemoryEditor/win32/functions.py b/PyMemoryEditor/win32/functions.py index 4f6d860..6cdf0bc 100644 --- a/PyMemoryEditor/win32/functions.py +++ b/PyMemoryEditor/win32/functions.py @@ -127,7 +127,12 @@ def ReadProcessMemory( data = get_c_type_of(pytype, bufflength) kernel32.ReadProcessMemory(process_handle, ctypes.c_void_p(address), ctypes.byref(data), bufflength, None) - return data.value.decode() if pytype is str else data.value + if pytype is str: + return bytes(data).decode() + elif pytype is bytes: + return bytes(data) + else: + return data.value def SearchAddressesByValue(