I am trying to memset a substring in python file using ctypes.memset
Here is the code I am using:
import ctypes
def memz(string):
buffsize = len(string)+1
size = sys.getsizeof(string)
offset = size - buffsize
start = string.find('{') -----------> 142
end = string.find('}') + 1 --------> 167
location = id(string)
ctypes.memset(location + offset + start, 0, end-start)
I see that this does not memset the substring, but writes some other part of memory. I suspect I am not passing the correct memory location to ctypes.memset. Do I need to change the format of the location(location + offset + start) that I am passing to ctypes.memset?
PS: The solution is derived from Mark data as sensitive in python. I tried that solution but using the memset from ctypes.CDLL('libc.so.6').memset results in a seg fault. I am using Python2.7.11.