Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion PyMemoryEditor/linux/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 4 additions & 3 deletions PyMemoryEditor/util/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
7 changes: 6 additions & 1 deletion PyMemoryEditor/win32/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down