Class: Bfd::Target
- Inherits:
-
Object
- Object
- Bfd::Target
- Defined in:
- lib/BFD.rb
Constant Summary collapse
- FORMAT_CORE =
core dump
'core'- FORMAT_OBJECT =
linkable (executable, shared library) or relocatable object file
'object'- FORMAT_ARCHIVE =
library archive (.ar)
'archive'- FORMAT_UNKNOWN =
unrecognized/unsupported file
'unknown'- FORMATS =
BFD object type
[ FORMAT_UNKNOWN, FORMAT_CORE, FORMAT_OBJECT, FORMAT_ARCHIVE ]
- FLAVOURS =
BFD file format. Defined in /usr/include/bfd.h : enum bfd_flavour
%w{ unknown aout coff ecoff xcoff elf ieee nlm oasys tekhex srec verilog ihex som os0k versados msdos ovax evax mmo mach_o pef pef_xlib sym }- ENDIAN =
Byte order. Defined in /usr/include/bfd.h : enum bfd_endian
%w{ big little unknown }- FLAG_EXEC =
'EXEC_P'- FLAG_DYNAMIC =
'DYNAMIC'- FLAGS =
File Format Flags. Defined in /usr/include/bfd.h : struct bfd
{ 0x0001 => 'HAS_RELOC', 0x0002 => FLAG_EXEC, 0x0004 => 'LINEN', 0x0008 => 'DEBUG', 0x0010 => 'SYMS', 0x0020 => 'LOCALS', 0x0040 => FLAG_DYNAMIC, 0x0080 => 'WP_TEXT', 0x0100 => 'D_PAGED', 0x0200 => 'IS_RELAXABLE', 0x0400 => 'TRADITIONAL_FORMAT', 0x0800 => 'IN_MEMORY', 0x1000 => 'HAS_LOAD_PAGE', 0x2000 => 'LINKER_CREATED', 0x4000 => 'DETERMINISTIC_OUTPUT' }
Instance Attribute Summary collapse
-
#temp_file ⇒ Object
Temporary file used if Target is instantiated from a buffer.
Class Method Summary collapse
-
.from_buffer(buf, args = {}) {|bfd| ... } ⇒ Object
Instantiate target from a buffer instead of from a file.
-
.new(target, args = {}) {|bfd| ... } ⇒ Object
Create a new Target from a path or IO object.
Instance Method Summary collapse
-
#close ⇒ Object
Free any resources used by BFD Target.
-
#endian ⇒ Object
Return the byte order of the target.
-
#flavour ⇒ Object
Return the target file format.
-
#format_flags ⇒ Object
Return an array of the names of the file format flags that are set.
- #inspect ⇒ Object
-
#is_executable? ⇒ Boolean
Is target a standalone executable.
-
#is_relocatable_object? ⇒ Boolean
Is target a relocatable object (not an executable or .so).
-
#is_shared_object? ⇒ Boolean
Is target a shared library file (.so).
-
#section_for_vma(vma) ⇒ Object
Return the Bfd::Section in the target that contains vma, or nil.
- #to_s ⇒ Object
-
#type_flags ⇒ Object
Return an array of the names of the target type flags that are set.
-
#valid? ⇒ Boolean
Is Target a valid BFD object (i.e. did BFD successfully parse it).
Instance Attribute Details
#temp_file ⇒ Object
Temporary file used if Target is instantiated from a buffer. BFD does not operate on memory locations and requires a file descriptor; a temporary file is therefore created on the filesystem when Target.from_buffer is called. The temp file is deleted when Target.close is called.
83 84 85 |
# File 'lib/BFD.rb', line 83 def temp_file @temp_file end |
Class Method Details
.from_buffer(buf, args = {}) {|bfd| ... } ⇒ Object
Instantiate target from a buffer instead of from a file. Note: this creates a temporary file which MUST be closed and unlinked by calling Target.close, or by passing a block to this method.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/BFD.rb', line 103 def self.from_buffer(buf, args={}) f = Tempfile.new( 'bfd_target' ) path = f.path f.close f = File.open(path, 'wb') f.write(buf) f.rewind bfd = ext_new(path, args) raise "Unable to construct BFD" if not bfd if not block_given? @temp_file = f return bfd end # yield bfd object, then close temp file yield bfd f.close File.unlink(path) nil end |
.new(target, args = {}) {|bfd| ... } ⇒ Object
Create a new Target from a path or IO object. This just wraps for ext_new and provides a default value for args. NOTE: target should either be the path to a file or an IO object with a valid read-only (i.e. opened with ‘rb’ flags) file descriptor returned by fileno(). File descriptors opened for write (‘wb’) will be rejected by libbfd.
92 93 94 95 96 |
# File 'lib/BFD.rb', line 92 def self.new(target, args={}) bfd = ext_new(target, args) yield bfd if (bfd and block_given?) return bfd end |
Instance Method Details
#close ⇒ Object
Free any resources used by BFD Target
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/BFD.rb', line 131 def close @temp_file ||= nil if @temp_file path = @temp_file.path @temp_file.close File.unlink(path) @temp_file = nil end end |
#endian ⇒ Object
Return the byte order of the target. See raw_endian.
204 205 206 |
# File 'lib/BFD.rb', line 204 def endian ENDIAN[@raw_endian] end |
#flavour ⇒ Object
Return the target file format. See raw_flavour.
196 197 198 |
# File 'lib/BFD.rb', line 196 def flavour FLAVOURS[@raw_flavour] end |
#format_flags ⇒ Object
Return an array of the names of the file format flags that are set. See raw_format_flags and type_flags.
146 147 148 |
# File 'lib/BFD.rb', line 146 def format_flags flag_strings(@raw_format_flags) end |
#inspect ⇒ Object
224 225 226 |
# File 'lib/BFD.rb', line 224 def inspect "#{self.to_s} : #{self.flavour} #{@format} (#{@type} #{endian}-endian)" end |
#is_executable? ⇒ Boolean
Is target a standalone executable
160 161 162 |
# File 'lib/BFD.rb', line 160 def is_executable? @format == FORMAT_OBJECT and format_flags.include? FLAG_EXEC end |
#is_relocatable_object? ⇒ Boolean
Is target a relocatable object (not an executable or .so)
175 176 177 178 |
# File 'lib/BFD.rb', line 175 def is_relocatable_object? @format == FORMAT_OBJECT and (not format_flags.include? FLAG_DYNAMIC) and (not format_flags.include? FLAG_EXEC) end |
#is_shared_object? ⇒ Boolean
Is target a shared library file (.so)
167 168 169 170 |
# File 'lib/BFD.rb', line 167 def is_shared_object? @format == FORMAT_OBJECT and format_flags.include? FLAG_DYNAMIC and (not format_flags.include? FLAG_EXEC) end |
#section_for_vma(vma) ⇒ Object
Return the Bfd::Section in the target that contains vma, or nil.
212 213 214 215 216 217 218 |
# File 'lib/BFD.rb', line 212 def section_for_vma(vma) @sections.values.each do |s| return s if (vma >= s.vma and vma < (s.vma + s.size)) end return nil end |
#to_s ⇒ Object
220 221 222 |
# File 'lib/BFD.rb', line 220 def to_s "[#{@id}] #{@filename}" end |
#type_flags ⇒ Object
Return an array of the names of the target type flags that are set. Note: These are the ‘backend’ flags for the BFD target type, and seem to be a list of the flags available for the target type, not the list of flags which are set. The format_flags field should always be used to determine the flags which are set for a BFD target. See raw_type_flags and format_flags.
188 189 190 |
# File 'lib/BFD.rb', line 188 def type_flags() flag_strings(@raw_type_flags) end |
#valid? ⇒ Boolean
Is Target a valid BFD object (i.e. did BFD successfully parse it)
153 154 155 |
# File 'lib/BFD.rb', line 153 def valid? @format != FORMAT_UNKNOWN end |