How to change the value stored in the memory address?

Assume that the memory address 0A7F03E4stores the value 124. How to change it to 300using python? Is there a module supplied for this kind of task?

+5
source share
3 answers
>>> import ctypes
>>> memfield = (ctypes.c_char).from_address(0x0A7F03E4)

Now you can read memfield, assign it, do whatever you want. If you have access to this memory cell, of course.

you can also get memarray with

>>> memarray = (ctypes.c_char*memoryfieldlen).from_address(0x0A7F03E4)

which gives you a list of memfields.

Update: I just read that you want to get an integer. in this case, of course, use ctypes.c_int. In general: use the appropriate ctype type;)

+8
source

ctypes? memset, , .

+1

On UNIX, you can try a open()device /dev/memto access physical memory, and then use the seek()object method by filespecifying the file pointer in the right place. Then use the method write()to change the value. Remember to encode the number as a raw string!

As a rule, only the user roothas access to this device.

+1
source

All Articles