Class: Bwrap::Resolvers::Library Private

Inherits:
Object
  • Object
show all
Includes:
Execution, Output
Defined in:
lib/bwrap/resolvers/library/library.rb,
lib/bwrap/resolvers/library.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class to clean up namespace for implementation specific reasons.

Defined Under Namespace

Classes: Base, LLVMReadelf, Musl

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Output

debug?, debug_output, error_output, handle_output_options, info_output, quiet?, trace?, trace_output, verb_output, verbose?, warn_output

Methods included from Execution

do_execute, last_status, popen2e

Class Method Details

.clear_needed_libraries_cacheObject

Empties ‘@@needed_libraries_cache`.



18
19
20
# File 'lib/bwrap/resolvers/library/library.rb', line 18

def self.clear_needed_libraries_cache
  @@needed_libraries_cache.clear
end

.needed_libraries_cacheObject



23
24
25
# File 'lib/bwrap/resolvers/library/library.rb', line 23

def needed_libraries_cache
  @@needed_libraries_cache
end

Instance Method Details

#libraries_needed_by(executable) ⇒ Array

Otherwise similar to #needed_libraries, but checks used libc to handle musl executables.

Parameters:

  • executable (String)

    Path to the executable to find dependencies for

Returns:

  • (Array)

    Libraries the executable needs, if any



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/bwrap/resolvers/library/library.rb', line 32

def libraries_needed_by executable
  trace "Finding libraries needed by #{executable}"

  # %i == interpreter, the library used to load the executable by kernel.
  # %F == Path to given file.
  output_format = "%i::SEPARATOR::%F"
  scanelf_command = %W{ scanelf --nobanner --quiet --format #{output_format} }
  scanelf_command << executable

  data = execvalue scanelf_command

  # If data is empty, target probably is a script of some sort.
  if data.empty?
    return []
  end

  data = data.strip
  interpreter, _executable_path = data.split "::SEPARATOR::"
  interpreter = Pathname.new interpreter

  if interpreter.basename.to_s[0..6] == "ld-musl"
    trace "Resolved to musl interpreter: #{interpreter}"
    musl_needed_libraries executable
  else
    trace "Defaulting to glibc interpreter: #{interpreter}"
    # For glibc, scanelf can return full paths for us most of time.
    needed_libraries executable
  end
end

#musl_needed_libraries(binary_paths) ⇒ Object

Parameters:

  • binary_paths (String, Array)

    one or more paths to be resolved



63
64
65
66
# File 'lib/bwrap/resolvers/library/library.rb', line 63

def musl_needed_libraries binary_paths
  musl = Musl.new
  @needed_libraries = musl.needed_libraries binary_paths
end

#needed_libraries(binary_paths) ⇒ Object

Parameters:

  • binary_paths (String, Array)

    one or more paths to be resolved



69
70
71
72
# File 'lib/bwrap/resolvers/library/library.rb', line 69

def needed_libraries binary_paths
  llvm_readelf = LLVMReadelf.new
  @needed_libraries = llvm_readelf.needed_libraries binary_paths
end