typecast operator - How to dereference an address into an integer in python? -
this question has answer here:
i have address 0x6041f0
. know there's integer sitting out there. in c, have done *(int *)0x6041f0
integer value present @ address.
how achieve same in python?
ps: writing python script uses gdb
module. actual program being debugged in c++. such lot of low level manipulation required.
something this:
$ python python 2.7.9 (default, mar 19 2015, 22:32:11) [gcc 4.8.4] on linux2 type "help", "copyright", "credits" or "license" more information. >>> ctypes import * >>> c_int_p = pointer(c_int) >>> x = c_int(4) >>> cast(addressof(x), c_int_p).contents c_int(4)
with artbitrary address :)
>>> cast(0x6041f0, c_int_p) <__main__.lp_c_int object @ 0x7f44d06ce050> >>> cast(0x6041f0, c_int_p).contents segmentation fault
see: ctypes reference
Comments
Post a Comment