Class: PatchELF::Saver

Inherits:
Object
  • Object
show all
Defined in:
lib/patchelf/saver.rb

Overview

Internal use only.

For Patcher to do patching things and save to file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(in_file, out_file, set) ⇒ Saver

Instantiate a PatchELF::Saver object.

Parameters:

  • in_file (String)
  • out_file (String)
  • set ({Symbol => String, Array})


24
25
26
27
28
29
30
31
32
33
34
# File 'lib/patchelf/saver.rb', line 24

def initialize(in_file, out_file, set)
  @in_file = in_file
  @out_file = out_file
  @set = set
  # [{Integer => String}]
  @inline_patch = {}
  @elf = ELFTools::ELFFile.new(File.open(in_file))
  @mm = PatchELF::MM.new(@elf)
  @strtab_extend_requests = []
  @append_dyn = []
end

Instance Attribute Details

#in_fileString (readonly)

Returns Input filename.

Returns:

  • (String)

    Input filename.



17
18
19
# File 'lib/patchelf/saver.rb', line 17

def in_file
  @in_file
end

#out_fileString (readonly)

Returns Output filename.

Returns:

  • (String)

    Output filename.



18
19
20
# File 'lib/patchelf/saver.rb', line 18

def out_file
  @out_file
end

Instance Method Details

#save!void

This method returns an undefined value.



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/patchelf/saver.rb', line 37

def save!
  # In this method we assume all attributes that should exist do exist.
  # e.g. DT_INTERP, DT_DYNAMIC. These should have been checked in the patcher.
  patch_interpreter
  patch_dynamic

  @mm.dispatch!

  FileUtils.cp(in_file, out_file) if out_file != in_file
  patch_out(@out_file)
  # Let output file have the same permission as input.
  FileUtils.chmod(File.stat(in_file).mode, out_file)
end