def zerome(string):
# find the header size with a dummy string
dummy = "header finder"
header = ctypes.string_at(id(dummy), sys.getsizeof(dummy)).find(dummy)
location = id(string) + header
size = sys.getsizeof(string) - header
if platform.system() == 'Windows':
memset = ctypes.cdll.msvcrt.memset
else:
libc = find_library('c')
memset = ctypes.CDLL(libc).memset
# For OS X, the above should work, but if it doesn't:
# memset = ctypes.CDLL('libc.dylib').memset
print "Clearing 0x%08x size %i bytes" % (location, size)
memset(location, 0, size)
#string still with us?
print ctypes.string_at(location, size)
评论列表
文章目录