Class: PatchELF::Patcher
- Inherits:
-
Object
- Object
- PatchELF::Patcher
- Defined in:
- lib/patchelf/patcher.rb
Overview
Class to handle all patching things.
Instance Method Summary collapse
-
#add_needed(need) ⇒ void
Add the needed library.
-
#initialize(filename, logging: true) ⇒ Patcher
constructor
Instantiate a Patcher object.
-
#interpreter ⇒ String?
Get interpreter’s name.
-
#interpreter=(interp) ⇒ Object
Set interpreter’s name.
-
#needed ⇒ Array<String>
Get needed libraries.
-
#needed=(needs) ⇒ Object
Set needed libraries.
-
#remove_needed(need) ⇒ void
Remove the needed library.
-
#replace_needed(src, tar) ⇒ void
Replace needed library
srcwithtar. -
#runpath ⇒ String?
Get runpath.
-
#runpath=(runpath) ⇒ Object
Set runpath.
-
#save(out_file = nil) ⇒ void
Save the patched ELF as
out_file. -
#soname ⇒ String?
Get the soname of a shared library.
-
#soname=(name) ⇒ Object
Set soname.
-
#use_rpath! ⇒ self
Set all operations related to DT_RUNPATH to use DT_RPATH.
Constructor Details
#initialize(filename, logging: true) ⇒ Patcher
Instantiate a PatchELF::Patcher object.
21 22 23 24 25 26 27 |
# File 'lib/patchelf/patcher.rb', line 21 def initialize(filename, logging: true) @in_file = filename @elf = ELFTools::ELFFile.new(File.open(filename)) @set = {} @rpath_sym = :runpath @logging = logging end |
Instance Method Details
#add_needed(need) ⇒ void
This setting will be saved after #save being invoked.
This method returns an undefined value.
Add the needed library.
71 72 73 74 |
# File 'lib/patchelf/patcher.rb', line 71 def add_needed(need) @set[:needed] ||= needed_ @set[:needed] << need end |
#interpreter ⇒ String?
Returns Get interpreter’s name.
34 35 36 |
# File 'lib/patchelf/patcher.rb', line 34 def interpreter @set[:interpreter] || interpreter_ end |
#interpreter=(interp) ⇒ Object
This setting will be saved after #save being invoked.
Set interpreter’s name.
If the input ELF has no existent interpreter, this method will show a warning and has no effect.
44 45 46 47 48 |
# File 'lib/patchelf/patcher.rb', line 44 def interpreter=(interp) return if interpreter_.nil? # will also show warning if there's no interp segment. @set[:interpreter] = interp end |
#needed ⇒ Array<String>
Get needed libraries.
56 57 58 |
# File 'lib/patchelf/patcher.rb', line 56 def needed @set[:needed] || needed_ end |
#needed=(needs) ⇒ Object
This setting will be saved after #save being invoked.
Set needed libraries.
63 64 65 |
# File 'lib/patchelf/patcher.rb', line 63 def needed=(needs) @set[:needed] = needs end |
#remove_needed(need) ⇒ void
This setting will be saved after #save being invoked.
This method returns an undefined value.
Remove the needed library.
80 81 82 83 |
# File 'lib/patchelf/patcher.rb', line 80 def remove_needed(need) @set[:needed] ||= needed_ @set[:needed].delete(need) end |
#replace_needed(src, tar) ⇒ void
This setting will be saved after #save being invoked.
This method returns an undefined value.
Replace needed library src with tar.
93 94 95 96 |
# File 'lib/patchelf/patcher.rb', line 93 def replace_needed(src, tar) @set[:needed] ||= needed_ @set[:needed].map! { |v| v == src ? tar : v } end |
#runpath ⇒ String?
Get runpath.
126 127 128 |
# File 'lib/patchelf/patcher.rb', line 126 def runpath @set[@rpath_sym] || runpath_ end |
#runpath=(runpath) ⇒ Object
This setting will be saved after #save being invoked.
Set runpath.
If DT_RUNPATH is not presented in the input ELF, a new DT_RUNPATH attribute will be inserted into the DYNAMIC segment.
136 137 138 |
# File 'lib/patchelf/patcher.rb', line 136 def runpath=(runpath) @set[@rpath_sym] = runpath end |
#save(out_file = nil) ⇒ void
This method returns an undefined value.
Save the patched ELF as out_file.
151 152 153 154 155 156 157 158 159 |
# File 'lib/patchelf/patcher.rb', line 151 def save(out_file = nil) # If nothing is modified, return directly. return if out_file.nil? && !dirty? out_file ||= @in_file saver = PatchELF::Saver.new(@in_file, out_file, @set) saver.save! end |
#soname ⇒ String?
Get the soname of a shared library.
108 109 110 |
# File 'lib/patchelf/patcher.rb', line 108 def soname @set[:soname] || soname_ end |
#soname=(name) ⇒ Object
This setting will be saved after #save being invoked.
Set soname.
If the input ELF is not a shared library with a soname, this method will show a warning and has no effect.
118 119 120 121 122 |
# File 'lib/patchelf/patcher.rb', line 118 def soname=(name) return if soname_.nil? @set[:soname] = name end |
#use_rpath! ⇒ self
Set all operations related to DT_RUNPATH to use DT_RPATH.
142 143 144 145 |
# File 'lib/patchelf/patcher.rb', line 142 def use_rpath! @rpath_sym = :rpath self end |