加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

如何在python中将地址取消引用为整数?

发布时间:2020-12-20 13:50:25 所属栏目:Python 来源:网络整理
导读:参见英文答案 How to dereference a memory location from python ctypes?????????????????????????????????????1个 我有一个像0x6041f0的地址.我知道有一个整数坐在那里.在C中,我只需要完成*(int *)0x6041f0来获取该地址处的整数值. 如何在Python中实现相同
参见英文答案 > How to dereference a memory location from python ctypes?????????????????????????????????????1个
我有一个像0x6041f0的地址.我知道有一个整数坐在那里.在C中,我只需要完成*(int *)0x6041f0来获取该地址处的整数值.

如何在Python中实现相同的功能?

PS:我正在编写一个使用gdb模块的Python脚本.正在调试的实际程序是在C中.因此需要大量的低级操作.

解决方法

像这样的东西:

$python
Python 2.7.9 (default,Mar 19 2015,22:32:11) 
[GCC 4.8.4] on linux2
Type "help","copyright","credits" or "license" for more information.
>>> from ctypes import *
>>> c_int_p = POINTER(c_int)
>>> x = c_int(4)
>>> cast(addressof(x),c_int_p).contents
c_int(4)

随着那个artbitrary地址:)

>>> cast(0x6041f0,c_int_p)
<__main__.LP_c_int object at 0x7f44d06ce050>
>>> cast(0x6041f0,c_int_p).contents
Segmentation fault

见:ctypes供参考

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读