python - Python从RAM中获取变量的值
问题描述
是否有可能使用 Python 使用地址从 RAM 中获取变量的值,比如作弊引擎?
解决方案
它真的依赖于实现,你可以在 CPython 中尝试这个ctypes.string_at
函数(它转储整个 Python3 整数结构):
import ctypes
from sys import getsizeof
my_value_1 = int(1)
my_value_2 = int(2)
b1 = ctypes.string_at(id(my_value_1), getsizeof(my_value_1))
b2 = ctypes.string_at(id(my_value_2), getsizeof(my_value_2))
print(hex(id(b1)), ''.join(format(x, '02x') for x in b1))
print(hex(id(b2)), ''.join(format(x, '02x') for x in b2))
印刷:
0x7ffff670ffb0 4d0300000000000040b89d0000000000010000000000000001000000
0x7ffff670f5f0 740000000000000040b89d0000000000010000000000000002000000
在 Python 的其他实现(Jython、Iron Python 等)中,这可能不起作用。在 CPython 上id()
返回对象的内存地址。
推荐阅读
- javascript - react/javascript中的解构数组
- ruby-on-rails - Rails ActiveRecord 连接表,带有 id 数组,没有 n+1 请求
- drupal - 如何检查 TWIG 中字段的值?
- java - 调用对象存储库元素的最佳方法是什么
- powerbi - Power BI 无法建立一对一关系,基数问题
- php - 获取当前行和下一行并循环比较
- python - 根据另一个矩阵中的值移动一个矩阵中的值的有效方法
- regex - RegEX - 仅匹配大写字母,直到第一个符号出现
- multithreading - C# -Task.Run() 中线程池中的索引超出范围异常
- excel - 更改 PivotField Excel VBA 上的字体样式