lddwrap

Wrap ldd *nix utility to determine shared libraries required by a program.

class lddwrap.Dependency(found, soname=None, path=None, mem_address=None, unused=None)

Represent a shared library required by a program.

Variables:
  • found (bool) – True if ldd could resolve the library
  • soname (Optional[str]) – library name
  • path (Optional[pathlib.Path]) – path to the library
  • mem_address (Optional[str]) – hex memory location
  • unused (Optional[bool]) – library not used
Establishes:
  • not (self.mem_address is None and self.found) or (
    self.soname is not None and self.path is not None)
    
  • not (self.path is None and self.found) or (
    self.soname is not None and self.mem_address is not None)
    
  • not (self.soname is None and self.found) or (
    self.path is not None and self.mem_address is not None)
    
as_mapping()

Transform the dependency to a mapping.

Can be converted to JSON and similar formats.

Return type:Mapping[str, Any]
lddwrap.list_dependencies(path, unused=False, env=None)

Retrieve a list of dependencies of the given binary.

>>> import shutil
>>> ls = shutil.which("ls")
>>> path = pathlib.Path(ls)
>>> deps = list_dependencies(path=path)
>>> deps[0].soname
'linux-vdso.so.1'
Parameters:
  • path (Path) – path to a file
  • unused (bool) – if set, check if dependencies are actually used by the program
  • env (Optional[Dict[str, str]]) –

    the environment to use.

    If env is None, currently active env will be used. Otherwise specified env is used.

Return type:

List[Dependency]

Returns:

list of dependencies

Requires:
  • path.is_file()