PyMemoryEditor 3.3.3__py3-none-any.whl → 3.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ Supported platforms: Windows, Linux and macOS (32-bit and 64-bit).
8
8
  """
9
9
 
10
10
  __author__ = "Jean Loui Bernard Silva de Jesus"
11
- __version__ = "3.3.3"
11
+ __version__ = "3.4.0"
12
12
 
13
13
  import logging
14
14
  import sys
@@ -196,12 +196,14 @@ class LinuxProcess(AbstractProcess):
196
196
  bufflength: Optional[int] = None,
197
197
  ) -> T:
198
198
  self.__require_target(hot_path=True)
199
+ self._require_address(address)
199
200
  return read_process_memory(
200
201
  self.pid, address, pytype, resolve_bufflength(pytype, bufflength)
201
202
  )
202
203
 
203
204
  def read_process_memory_into(self, address: int, buffer: object) -> int:
204
205
  self.__require_target(hot_path=True)
206
+ self._require_address(address)
205
207
  return read_process_memory_into(self.pid, address, buffer)
206
208
 
207
209
  def _scan_addresses(
@@ -270,6 +272,7 @@ class LinuxProcess(AbstractProcess):
270
272
  value: Union[bool, int, float, str, bytes] = UNSET,
271
273
  ) -> Union[bool, int, float, str, bytes]:
272
274
  self.__require_target()
275
+ self._require_address(address)
273
276
  w_pytype, w_length, w_value = prepare_write(pytype, bufflength, value)
274
277
  write_process_memory(self.pid, address, w_pytype, w_length, w_value)
275
278
  return value
@@ -255,12 +255,14 @@ class MacProcess(AbstractProcess):
255
255
  bufflength: Optional[int] = None,
256
256
  ) -> T:
257
257
  self._require_open()
258
+ self._require_address(address)
258
259
  return read_process_memory(
259
260
  self.__task, address, pytype, resolve_bufflength(pytype, bufflength)
260
261
  )
261
262
 
262
263
  def read_process_memory_into(self, address: int, buffer: object) -> int:
263
264
  self._require_open()
265
+ self._require_address(address)
264
266
  return read_process_memory_into(self.__task, address, buffer)
265
267
 
266
268
  def write_process_memory(
@@ -296,6 +298,7 @@ class MacProcess(AbstractProcess):
296
298
  :param value: value to be written.
297
299
  """
298
300
  self._require_open()
301
+ self._require_address(address)
299
302
  w_pytype, w_length, w_value = prepare_write(pytype, bufflength, value)
300
303
  write_process_memory(self.__task, address, w_pytype, w_length, w_value)
301
304
  return value
@@ -308,6 +311,7 @@ class MacProcess(AbstractProcess):
308
311
 
309
312
  def free_memory(self, address: int, size: int = 0) -> bool:
310
313
  self._require_open()
314
+ self._require_address(address)
311
315
  # mach_vm_deallocate needs the exact size. Reuse the tracked size when
312
316
  # the caller doesn't supply one.
313
317
  actual_size = size or self.__allocations.get(address, 0)
@@ -424,6 +424,10 @@ def _parse_signed_int(raw: Any, field: str) -> int:
424
424
  negative = text.startswith("-")
425
425
  body = text[1:] if negative else text
426
426
  try:
427
+ # int() accepts a sign of its own, so "--5" would strip to "-5" and
428
+ # the two minuses cancel: a write of "--5" stored +5. One sign only.
429
+ if negative and body.lstrip()[:1] in ("-", "+"):
430
+ raise ValueError(body)
427
431
  value = int(body, 16) if body[:2].lower() == "0x" else int(body, 10)
428
432
  except (ValueError, IndexError):
429
433
  raise ToolError(
@@ -53,15 +53,22 @@ _POINTER_SCAN_FORMAT = "pymemoryeditor-pointerscan"
53
53
  _POINTER_SCAN_VERSION = 1
54
54
 
55
55
 
56
- class _PointerOutOfRangeError(ValueError, OSError):
57
- """A pointer chain step landed outside the address space.
56
+ class _AddressOutOfRangeError(ValueError, OSError):
57
+ """An address (or a pointer chain step) lies outside the address space.
58
58
 
59
59
  A ``ValueError`` as documented, and also an ``OSError`` because the failed
60
60
  read of the wrapped address it replaces raised one: callers that guard a
61
- stale chain with ``except OSError`` keep working.
61
+ stale chain or a bad address with ``except OSError`` keep working.
62
62
  """
63
63
 
64
64
 
65
+ # One past the highest address this host can pass to the OS. ctypes masks an
66
+ # address argument to the width of the C type it is converted to instead of
67
+ # rejecting it, so a 32-bit Python would turn 0x1_0000_1000 into 0x1000 just as
68
+ # a 64-bit one turns 2**64 + 0x1000 into 0x1000.
69
+ _HOST_ADDRESS_END = min(ADDRESS_SPACE_END, 1 << (8 * ctypes.sizeof(ctypes.c_void_p)))
70
+
71
+
65
72
  class AbstractProcess(ABC):
66
73
  """
67
74
  Abstract class to represent a process.
@@ -205,6 +212,23 @@ class AbstractProcess(ABC):
205
212
  if not self._target_alive():
206
213
  raise ProcessIDNotExistsError(self.pid)
207
214
 
215
+ @staticmethod
216
+ def _require_address(address: int) -> None:
217
+ """
218
+ Refuse an address outside ``[0, host address space)`` before it
219
+ reaches ctypes, which would mask it to the C type's width and read,
220
+ write or free a *different*, wrapped address instead of failing.
221
+ """
222
+ if not 0 <= address < _HOST_ADDRESS_END:
223
+ raise _AddressOutOfRangeError(
224
+ "address %s is outside the %d-bit address space; it would "
225
+ "wrap around to a different address."
226
+ % (
227
+ ("-0x%X" % -address) if address < 0 else ("0x%X" % address),
228
+ _HOST_ADDRESS_END.bit_length() - 1,
229
+ )
230
+ )
231
+
208
232
  @abstractmethod
209
233
  def _detect_is_64bit(self) -> Optional[bool]:
210
234
  """
@@ -736,7 +760,9 @@ class AbstractProcess(ABC):
736
760
  and ``convert_from_byte_array``. Callers that need the original
737
761
  bytes verbatim (no decoding) should pass ``pytype=bytes``.
738
762
 
739
- :raises ValueError: if ``pytype`` is unsupported.
763
+ :raises ValueError: if ``pytype`` is unsupported, or ``address`` is
764
+ negative or past the end of the address space (also an
765
+ ``OSError``, so ``except OSError`` still catches it).
740
766
  :raises OSError: if the read fails, or returns fewer bytes than
741
767
  requested (e.g. the range crosses an unreadable/freed page).
742
768
  """
@@ -770,7 +796,9 @@ class AbstractProcess(ABC):
770
796
 
771
797
  :raises TypeError: if ``buffer`` is not a writable buffer (e.g. an
772
798
  immutable ``bytes`` object).
773
- :raises ValueError: if ``buffer`` is empty or not contiguous.
799
+ :raises ValueError: if ``buffer`` is empty or not contiguous, or
800
+ ``address`` is outside the address space (as in
801
+ :meth:`read_process_memory`).
774
802
  :raises OSError: if the read fails, or returns fewer bytes than
775
803
  requested (e.g. the range crosses an unreadable/freed page).
776
804
 
@@ -821,7 +849,8 @@ class AbstractProcess(ABC):
821
849
  (``write_process_memory(address, int, 4, 99)``).
822
850
  :raises ValueError: if ``pytype`` is unsupported, or if an ``int``
823
851
  ``value`` does not fit in ``bufflength`` bytes (rejected up front
824
- rather than silently truncated).
852
+ rather than silently truncated), or if ``address`` is outside the
853
+ address space (as in :meth:`read_process_memory`).
825
854
  :raises OSError: if the write fails, or fewer bytes than requested are
826
855
  written (e.g. the range crosses an unwritable/freed page).
827
856
  :return: the original ``value`` passed in.
@@ -1080,7 +1109,8 @@ class AbstractProcess(ABC):
1080
1109
  :return: ``True`` on success.
1081
1110
 
1082
1111
  :raises ValueError: on macOS and Windows, for a region this object did
1083
- not allocate when no ``size`` is given.
1112
+ not allocate when no ``size`` is given, or for an ``address``
1113
+ outside the address space.
1084
1114
  :raises NotImplementedError: on Linux (see :meth:`allocate_memory`).
1085
1115
  """
1086
1116
  raise NotImplementedError()
@@ -1190,7 +1220,7 @@ class AbstractProcess(ABC):
1190
1220
  # it, so `ptr + offset` below zero or past 2**64 would silently
1191
1221
  # read a *different*, wrapped address. Refuse it by name instead.
1192
1222
  if not 0 <= addr < ADDRESS_SPACE_END:
1193
- raise _PointerOutOfRangeError(
1223
+ raise _AddressOutOfRangeError(
1194
1224
  "pointer chain step produced address %s, outside the "
1195
1225
  "64-bit address space; the chain is stale (a hop read "
1196
1226
  "NULL or garbage) or an offset is wrong."
@@ -303,6 +303,7 @@ class WindowsProcess(AbstractProcess):
303
303
  ) -> T:
304
304
  self._require_open()
305
305
  self.__require_read()
306
+ self._require_address(address)
306
307
  return ReadProcessMemory(
307
308
  self.__process_handle,
308
309
  address,
@@ -313,6 +314,7 @@ class WindowsProcess(AbstractProcess):
313
314
  def read_process_memory_into(self, address: int, buffer: object) -> int:
314
315
  self._require_open()
315
316
  self.__require_read()
317
+ self._require_address(address)
316
318
  return ReadProcessMemoryInto(self.__process_handle, address, buffer)
317
319
 
318
320
  def write_process_memory(
@@ -324,6 +326,7 @@ class WindowsProcess(AbstractProcess):
324
326
  ) -> Union[bool, int, float, str, bytes]:
325
327
  self._require_open()
326
328
  self.__require_write()
329
+ self._require_address(address)
327
330
  w_pytype, w_length, w_value = prepare_write(pytype, bufflength, value)
328
331
  WriteProcessMemory(
329
332
  self.__process_handle,
@@ -344,6 +347,7 @@ class WindowsProcess(AbstractProcess):
344
347
  def free_memory(self, address: int, size: int = 0) -> bool:
345
348
  self._require_open()
346
349
  self.__require_operation()
350
+ self._require_address(address)
347
351
  # MEM_RELEASE tears down whatever VirtualAlloc'd block starts at
348
352
  # `address` -- a heap segment or a thread stack just as readily as one
349
353
  # of ours -- so an address this object did not allocate is refused
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: PyMemoryEditor
3
- Version: 3.3.3
3
+ Version: 3.4.0
4
4
  Summary: Read, write and scan process memory in a few lines of Python — Cheat Engine-style scans, pointer chains and AOB search on Windows, Linux and macOS.
5
5
  Project-URL: Homepage, https://github.com/JeanExtreme002/PyMemoryEditor
6
6
  Project-URL: Documentation, https://pymemoryeditor.readthedocs.io
@@ -1,4 +1,4 @@
1
- PyMemoryEditor/__init__.py,sha256=bwjUj-mN7Qc2d8r-9cSsNJr4SmKgq8tHIYAFauTtf9Y,3234
1
+ PyMemoryEditor/__init__.py,sha256=xLgUi2R-C4CS8imhiSFr5bOQrYjqc-P1amRkKBBXChQ,3234
2
2
  PyMemoryEditor/__main__.py,sha256=xukvvLjQ0BnYnnxMZda1cvyZ-BurSUk8dAGQybIqMD4,95
3
3
  PyMemoryEditor/enums.py,sha256=q_SWQYgh4F7yyAa7sZvNo2Sw91TSm3aTqPfTA7OqldM,322
4
4
  PyMemoryEditor/app/__init__.py,sha256=DGCYWpqGKPSeBa7cvzL7GmmhIfDDgF6vtim0VtLcfOo,357
@@ -26,12 +26,12 @@ PyMemoryEditor/app/threads_dialog.py,sha256=HnPS7Mte6CboM0DaoqkTqnEg8Ck65L1FKW-e
26
26
  PyMemoryEditor/app/value_types.py,sha256=Ya8_n8OTkvRqeG1Zwfzsh5y990PBsjcOOfF4ZPrzlhs,18388
27
27
  PyMemoryEditor/linux/functions.py,sha256=aNFgbTBzt3U9nIBhtyKHEvWdlCRQQJhhTAmFBsu0l5Q,31766
28
28
  PyMemoryEditor/linux/libc.py,sha256=kF2GCckU5lFEOQNis29tfKzBhvafFjhtiUIBotFScZg,1385
29
- PyMemoryEditor/linux/process.py,sha256=9H6o3Nx3S9Sg4uOt4u_L6hRz7nRzM888F5VEb7O59N0,11031
29
+ PyMemoryEditor/linux/process.py,sha256=TwKlzw5hJWIV_CirLndMJbW75tndgvqApTKgf1HLR1Y,11148
30
30
  PyMemoryEditor/linux/types.py,sha256=sOgO-s9oqKrKKCHMG4N-Pe7sNw49V06PeMENSNnNFl8,1924
31
31
  PyMemoryEditor/macos/__init__.py,sha256=85mOA4U5i9EW2r1ggKqRJkqRq0e9bV3I2HdfHIvox10,72
32
32
  PyMemoryEditor/macos/functions.py,sha256=eEawTDM3i_EocxU2ENvRm2XwdrecdZ5Uigt8UdFYxMc,61157
33
33
  PyMemoryEditor/macos/libsystem.py,sha256=1MDSrp3oC5Ay1CSDt7TGEEGcScBhHGbK3aZxNKj8qTM,9245
34
- PyMemoryEditor/macos/process.py,sha256=kd_k2ZPYRGTDLEIoppT8z3D4GjHTAc1lSklxh9ooKr0,12525
34
+ PyMemoryEditor/macos/process.py,sha256=fcOkFyolK9S3ebiG83MyMQ-dOae-E1vMNXDayI3MgQo,12681
35
35
  PyMemoryEditor/macos/types.py,sha256=pYVGpROHKt8-s1C-sFsG8xEk1vmBVdh5_5-BIqtsSak,7577
36
36
  PyMemoryEditor/mcp/__init__.py,sha256=g30FgXeR3_eHq5hsGSGsPEJQlMPQ3A0jstD-MAFbU2M,2393
37
37
  PyMemoryEditor/mcp/__main__.py,sha256=GXMMDJMMZfFMjzYnRcw20wRRb3v_IKxvv_-ZOyxkK1U,475
@@ -40,10 +40,10 @@ PyMemoryEditor/mcp/policy.py,sha256=cfG1A-IR1kTe_neLZFtd-JAqkZ_vcE4QYrPgNUv3yb0,
40
40
  PyMemoryEditor/mcp/procinfo.py,sha256=ufT07yoffyfA7KiBrdaQm7Hkf1WbpGveZMwcSmR8NQQ,10136
41
41
  PyMemoryEditor/mcp/server.py,sha256=YBJDMM2pXaavG_o-CnO8yL6aFecdsNfv6wEIqqard-o,33564
42
42
  PyMemoryEditor/mcp/session.py,sha256=0gy629j8lJrq4VxqUTMbxJ-D-D1IJo47T-UwtAIEzZE,31645
43
- PyMemoryEditor/mcp/toolset.py,sha256=kxkByx5YUowX7ldj1o1k0VXCPMoRNR4kxH1NHn3Z8ts,118338
43
+ PyMemoryEditor/mcp/toolset.py,sha256=Po_qLROe9WfACNHoyn1OvmHKkzEOvNhZeP8R89PDqYg,118583
44
44
  PyMemoryEditor/process/__init__.py,sha256=Xh5jngBqZyNIA9y3uwE49LxK8uH8YYsu6qotx1mP_WE,213
45
45
  PyMemoryEditor/process/_guard.py,sha256=91TKDEpFthFn99QNOioMD9hp2kzAOHA_qtkEgW9tJtI,1471
46
- PyMemoryEditor/process/abstract.py,sha256=JbgKqR6tBPb6aCyuI2onLH-_9g9pICGxrv-PI-Yi6mk,74035
46
+ PyMemoryEditor/process/abstract.py,sha256=1cmPkKqZgb4RCZGlvEgYbL4D_RJUq6PXrB9v5YCGgoQ,75572
47
47
  PyMemoryEditor/process/errors.py,sha256=485SXkidg9_E_KjuhuF6AsQNuFZlY-Ag-sG1C6NsGMw,2054
48
48
  PyMemoryEditor/process/info.py,sha256=yF7kE-wMEs_h3rpn2dPgBpuwn2EhhVq3lfl5u7GwCfY,1484
49
49
  PyMemoryEditor/process/module_info.py,sha256=D7qAoBymhe6vrL0IYc2R6ZhWE-OPmYQzf6hSp_f2KmA,2365
@@ -59,7 +59,7 @@ PyMemoryEditor/util/pattern.py,sha256=ONRljRxGYhiElQG1E5D5LusgyZR_YLLdFtZrHFjYYk
59
59
  PyMemoryEditor/util/scan.py,sha256=-VZdwrBeXB7CQ_DKePUWjb-h-ox6_ogwYrloGkw0v6A,28752
60
60
  PyMemoryEditor/util/scan_numpy.py,sha256=SRTuhrhYP5azSab3k8FBTPVCMK9_1vZHogSSofkFCAA,6940
61
61
  PyMemoryEditor/win32/functions.py,sha256=mzgo1DZDFGgK0gFFaw3Hc2ljPDWjeEBzfqmac4F233U,47972
62
- PyMemoryEditor/win32/process.py,sha256=9t9xtmW_rBIWh6-Jdr3CPLshmmuBNBonBgzQA3bZGc8,13562
62
+ PyMemoryEditor/win32/process.py,sha256=LzTcp439esldptdAht5ZPVo0QIVqzk4pcUfGm8ktdO0,13718
63
63
  PyMemoryEditor/win32/types.py,sha256=QkFRFKviS-7DNGgsK2eCTeiinYm2BZdxsPh_pw6I570,5177
64
64
  PyMemoryEditor/win32/enums/__init__.py,sha256=RZXhXb-yCGHVDEi0OxV27w0g2l6b68BIbKhHXyTM3cw,301
65
65
  PyMemoryEditor/win32/enums/memory_allocation_states.py,sha256=NTwC9XkUqlCjoSalwykEG2OZUiqXVylcLP2nYSd39zI,953
@@ -69,8 +69,8 @@ PyMemoryEditor/win32/enums/process_operations.py,sha256=wn-aMl01VVg-2rFavR9szBNR
69
69
  PyMemoryEditor/win32/enums/standard_access_rights.py,sha256=VGWlTagW4hvbm2AjZ4NK56ZrQwRmEl9Kz9GSCG8o-HI,738
70
70
  PyMemoryEditor/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
71
71
  PyMemoryEditor/app/assets/icon.svg,sha256=T7OqR7ldqC_dK2Ib2ntsH2rWO-Z5RzNK4WdD1wFwgM4,7132
72
- pymemoryeditor-3.3.3.dist-info/METADATA,sha256=6Pm1UqVnlDrzaK1VWVPqPvWAOLmwujsaw9iZlv56fps,11037
73
- pymemoryeditor-3.3.3.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
74
- pymemoryeditor-3.3.3.dist-info/entry_points.txt,sha256=qxto0CWCXsjLmE0jClEgz1Xriljr6IV6d3AySjIlw7E,127
75
- pymemoryeditor-3.3.3.dist-info/licenses/LICENSE,sha256=YkOx6Nvkavq36bgiAc3eF85SBG0Qu14KMAvxmv6Ssjc,1089
76
- pymemoryeditor-3.3.3.dist-info/RECORD,,
72
+ pymemoryeditor-3.4.0.dist-info/METADATA,sha256=ol6qiQvMO8L2cJBK-YAwXI1x6lwkvHnxxX8NzZeX6S4,11037
73
+ pymemoryeditor-3.4.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
74
+ pymemoryeditor-3.4.0.dist-info/entry_points.txt,sha256=qxto0CWCXsjLmE0jClEgz1Xriljr6IV6d3AySjIlw7E,127
75
+ pymemoryeditor-3.4.0.dist-info/licenses/LICENSE,sha256=YkOx6Nvkavq36bgiAc3eF85SBG0Qu14KMAvxmv6Ssjc,1089
76
+ pymemoryeditor-3.4.0.dist-info/RECORD,,