Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Callback function for `dl_iterate_phdr` which is called for every
# module loaded in the current process until it returns 1.
def match_module_callback(info, size, data):
# Get the path of the current module
filepath = info.contents.dlpi_name
if filepath:
filepath = filepath.decode("utf-8")
# Store the module if it is supported and selected
self._make_module_from_path(filepath)
return 0
c_func_signature = ctypes.CFUNCTYPE(
ctypes.c_int, # Return type
ctypes.POINTER(_dl_phdr_info), ctypes.c_size_t, ctypes.c_char_p)
c_match_module_callback = c_func_signature(match_module_callback)
data = ctypes.c_char_p(b"")
libc.dl_iterate_phdr(c_match_module_callback, data)