首页 > 解决方案 > Python从RAM中获取变量的值

问题描述

是否有可能使用 Python 使用地址从 RAM 中获取变量的值,比如作弊引擎?

标签: python

解决方案


它真的依赖于实现,你可以在 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()返回对象的内存地址。


推荐阅读