Class: MachO::MachOFile
- Inherits:
-
Object
- Object
- MachO::MachOFile
- Extended by:
- Forwardable
- Defined in:
- lib/macho/macho_file.rb
Overview
Represents a Mach-O file, which contains a header and load commands as well as binary executable instructions. Mach-O binaries are architecture specific.
Instance Attribute Summary collapse
-
#endianness ⇒ Symbol
readonly
The endianness of the file, :big or :little.
-
#filename ⇒ String
The filename loaded from, or nil if loaded from a binary string.
- #header ⇒ Headers::MachHeader, Headers::MachHeader64 readonly
-
#load_commands ⇒ Array<LoadCommands::LoadCommand>
readonly
An array of the file's load commands.
Class Method Summary collapse
-
.new_from_bin(bin) ⇒ MachOFile
Creates a new instance from a binary string.
Instance Method Summary collapse
-
#add_command(lc, options = {}) ⇒ void
Appends a new load command to the Mach-O.
-
#add_rpath(path, _options = {}) ⇒ void
Add the given runtime path to the Mach-O.
-
#alignment ⇒ Integer
The file's internal alignment.
-
#bundle? ⇒ Boolean
Whether or not the file is of type
MH_BUNDLE. -
#change_dylib_id(new_id, _options = {}) ⇒ void
(also: #dylib_id=)
Changes the Mach-O's dylib ID to
new_id. -
#change_install_name(old_name, new_name, _options = {}) ⇒ void
(also: #change_dylib)
Changes the shared library
old_nametonew_name. -
#change_rpath(old_path, new_path, _options = {}) ⇒ void
Changes the runtime path
old_pathtonew_path. -
#command(name) ⇒ Array<LoadCommands::LoadCommand>
(also: #[])
All load commands of a given name.
-
#core? ⇒ Boolean
Whether or not the file is of type
MH_CORE. -
#cpusubtype ⇒ Symbol
A symbol representation of the Mach-O's CPU subtype.
-
#cputype ⇒ Symbol
A symbol representation of the Mach-O's CPU type.
-
#delete_command(lc, options = {}) ⇒ void
Delete a load command from the Mach-O.
-
#delete_rpath(path, _options = {}) ⇒ Object
Delete the given runtime path from the Mach-O.
-
#dsym? ⇒ Boolean
Whether or not the file is of type
MH_DSYM. -
#dylib? ⇒ Boolean
Whether or not the file is of type
MH_DYLIB. -
#dylib_id ⇒ String?
The Mach-O's dylib ID, or
nilif not a dylib. -
#dylib_load_commands ⇒ Array<LoadCommands::DylibCommand>
All load commands responsible for loading dylibs.
-
#dylinker? ⇒ Boolean
Whether or not the file is of type
MH_DYLINKER. -
#executable? ⇒ Boolean
Whether or not the file is of type
MH_EXECUTE. -
#filetype ⇒ Symbol
A string representation of the Mach-O's filetype.
-
#flags ⇒ Integer
The header flags associated with the Mach-O.
-
#fvmlib? ⇒ Boolean
Whether or not the file is of type
MH_FVMLIB. -
#initialize(filename) ⇒ MachOFile
constructor
Creates a new instance from data read from the given filename.
-
#initialize_from_bin(bin) ⇒ Object
private
Initializes a new MachOFile instance from a binary string.
-
#insert_command(offset, lc, options = {}) ⇒ Object
Inserts a load command at the given offset.
-
#kext? ⇒ Boolean
Whether or not the file is of type
MH_KEXT_BUNDLE. -
#linked_dylibs ⇒ Array<String>
All shared libraries linked to the Mach-O.
-
#magic ⇒ Integer
The magic number.
-
#magic32? ⇒ Boolean
True if the Mach-O has 32-bit magic, false otherwise.
-
#magic64? ⇒ Boolean
True if the Mach-O has 64-bit magic, false otherwise.
-
#magic_string ⇒ String
A string representation of the file's magic number.
-
#ncmds ⇒ Integer
The number of load commands in the Mach-O.
-
#object? ⇒ Boolean
Whether or not the file is of type
MH_OBJECT. -
#populate_fields ⇒ void
Populate the instance's fields with the raw Mach-O data.
-
#preload? ⇒ Boolean
Whether or not the file is of type
MH_PRELOAD. -
#replace_command(old_lc, new_lc) ⇒ void
Replace a load command with another command in the Mach-O, preserving location.
-
#rpaths ⇒ Array<String>
All runtime paths searched by the dynamic linker for the Mach-O.
-
#segment_alignment ⇒ Integer
The segment alignment for the Mach-O.
-
#segments ⇒ Array<LoadCommands::SegmentCommand>, Array<LoadCommands::SegmentCommand64>
All segment load commands in the Mach-O.
-
#serialize ⇒ String
The file's raw Mach-O data.
-
#sizeofcmds ⇒ Integer
The size of all load commands, in bytes, in the Mach-O.
-
#to_h ⇒ Hash
A hash representation of this MachOFile.
-
#write(filename) ⇒ void
Write all Mach-O data to the given filename.
-
#write! ⇒ void
Write all Mach-O data to the file used to initialize the instance.
Constructor Details
#initialize(filename) ⇒ MachOFile
Creates a new instance from data read from the given filename.
41 42 43 44 45 46 47 |
# File 'lib/macho/macho_file.rb', line 41 def initialize(filename) raise ArgumentError, "#{filename}: no such file" unless File.file?(filename) @filename = filename @raw_data = File.open(@filename, "rb", &:read) populate_fields end |
Instance Attribute Details
#endianness ⇒ Symbol (readonly)
Returns the endianness of the file, :big or :little.
17 18 19 |
# File 'lib/macho/macho_file.rb', line 17 def endianness @endianness end |
#filename ⇒ String
Returns the filename loaded from, or nil if loaded from a binary string.
14 15 16 |
# File 'lib/macho/macho_file.rb', line 14 def filename @filename end |
#header ⇒ Headers::MachHeader, Headers::MachHeader64 (readonly)
21 22 23 |
# File 'lib/macho/macho_file.rb', line 21 def header @header end |
#load_commands ⇒ Array<LoadCommands::LoadCommand> (readonly)
load commands are provided in order of ascending offset.
Returns an array of the file's load commands.
26 27 28 |
# File 'lib/macho/macho_file.rb', line 26 def load_commands @load_commands end |
Class Method Details
.new_from_bin(bin) ⇒ MachOFile
Creates a new instance from a binary string.
31 32 33 34 35 36 |
# File 'lib/macho/macho_file.rb', line 31 def self.new_from_bin(bin) instance = allocate instance.initialize_from_bin(bin) instance end |
Instance Method Details
#add_command(lc, options = {}) ⇒ void
This is public, but methods like #add_rpath should be preferred.
Setting repopulate to false will leave the instance in an
inconsistent state unless #populate_fields is called immediately
afterwards.
This method returns an undefined value.
Appends a new load command to the Mach-O.
200 201 202 |
# File 'lib/macho/macho_file.rb', line 200 def add_command(lc, = {}) insert_command(header.class.bytesize + sizeofcmds, lc, ) end |
#add_rpath(path, _options = {}) ⇒ void
_options is currently unused and is provided for signature
compatibility with FatFile#add_rpath
This method returns an undefined value.
Add the given runtime path to the Mach-O.
392 393 394 395 396 397 |
# File 'lib/macho/macho_file.rb', line 392 def add_rpath(path, = {}) raise RpathExistsError, path if rpaths.include?(path) rpath_cmd = LoadCommands::LoadCommand.create(:LC_RPATH, path) add_command(rpath_cmd) end |
#alignment ⇒ Integer
Returns the file's internal alignment.
98 99 100 101 |
# File 'lib/macho/macho_file.rb', line 98 def_delegators :header, :magic, :ncmds, :sizeofcmds, :flags, :object?, :executable?, :fvmlib?, :core?, :preload?, :dylib?, :dylinker?, :bundle?, :dsym?, :kext?, :magic32?, :magic64?, :alignment |
#bundle? ⇒ Boolean
Returns whether or not the file is of type MH_BUNDLE.
98 99 100 101 |
# File 'lib/macho/macho_file.rb', line 98 def_delegators :header, :magic, :ncmds, :sizeofcmds, :flags, :object?, :executable?, :fvmlib?, :core?, :preload?, :dylib?, :dylinker?, :bundle?, :dsym?, :kext?, :magic32?, :magic64?, :alignment |
#change_dylib_id(new_id, _options = {}) ⇒ void Also known as: dylib_id=
_options is currently unused and is provided for signature
compatibility with FatFile#change_dylib_id
This method returns an undefined value.
Changes the Mach-O's dylib ID to new_id. Does nothing if not a dylib.
302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/macho/macho_file.rb', line 302 def change_dylib_id(new_id, = {}) raise ArgumentError, "new ID must be a String" unless new_id.is_a?(String) return unless dylib? old_lc = command(:LC_ID_DYLIB).first raise DylibIdMissingError unless old_lc new_lc = LoadCommands::LoadCommand.create(:LC_ID_DYLIB, new_id, old_lc., old_lc.current_version, old_lc.compatibility_version) replace_command(old_lc, new_lc) end |
#change_install_name(old_name, new_name, _options = {}) ⇒ void Also known as: change_dylib
_options is currently unused and is provided for signature
compatibility with FatFile#change_install_name
This method returns an undefined value.
Changes the shared library old_name to new_name
339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/macho/macho_file.rb', line 339 def change_install_name(old_name, new_name, = {}) old_lc = dylib_load_commands.find { |d| d.name.to_s == old_name } raise DylibUnknownError, old_name if old_lc.nil? new_lc = LoadCommands::LoadCommand.create(old_lc.type, new_name, old_lc., old_lc.current_version, old_lc.compatibility_version) replace_command(old_lc, new_lc) end |
#change_rpath(old_path, new_path, _options = {}) ⇒ void
_options is currently unused and is provided for signature
compatibility with FatFile#change_rpath
This method returns an undefined value.
Changes the runtime path old_path to new_path
370 371 372 373 374 375 376 377 378 379 |
# File 'lib/macho/macho_file.rb', line 370 def change_rpath(old_path, new_path, = {}) old_lc = command(:LC_RPATH).find { |r| r.path.to_s == old_path } raise RpathUnknownError, old_path if old_lc.nil? raise RpathExistsError, new_path if rpaths.include?(new_path) new_lc = LoadCommands::LoadCommand.create(:LC_RPATH, new_path) delete_rpath(old_path) insert_command(old_lc.view.offset, new_lc) end |
#command(name) ⇒ Array<LoadCommands::LoadCommand> Also known as: []
All load commands of a given name.
130 131 132 |
# File 'lib/macho/macho_file.rb', line 130 def command(name) load_commands.select { |lc| lc.type == name.to_sym } end |
#core? ⇒ Boolean
Returns whether or not the file is of type MH_CORE.
98 99 100 101 |
# File 'lib/macho/macho_file.rb', line 98 def_delegators :header, :magic, :ncmds, :sizeofcmds, :flags, :object?, :executable?, :fvmlib?, :core?, :preload?, :dylib?, :dylinker?, :bundle?, :dsym?, :kext?, :magic32?, :magic64?, :alignment |
#cpusubtype ⇒ Symbol
Returns a symbol representation of the Mach-O's CPU subtype.
119 120 121 |
# File 'lib/macho/macho_file.rb', line 119 def cpusubtype Headers::CPU_SUBTYPES[header.cputype][header.cpusubtype] end |
#cputype ⇒ Symbol
Returns a symbol representation of the Mach-O's CPU type.
114 115 116 |
# File 'lib/macho/macho_file.rb', line 114 def cputype Headers::CPU_TYPES[header.cputype] end |
#delete_command(lc, options = {}) ⇒ void
This is public, but methods like #delete_rpath should be preferred.
Setting repopulate to false will leave the instance in an
inconsistent state unless #populate_fields is called immediately
afterwards.
This method returns an undefined value.
Delete a load command from the Mach-O.
214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/macho/macho_file.rb', line 214 def delete_command(lc, = {}) @raw_data.slice!(lc.view.offset, lc.cmdsize) # update Mach-O header fields to account for deleted load command update_ncmds(ncmds - 1) update_sizeofcmds(sizeofcmds - lc.cmdsize) # pad the space after the load commands to preserve offsets @raw_data.insert(header.class.bytesize + sizeofcmds - lc.cmdsize, Utils.nullpad(lc.cmdsize)) populate_fields if .fetch(:repopulate, true) end |
#delete_rpath(path, _options = {}) ⇒ Object
_options is currently unused and is provided for signature
compatibility with FatFile#delete_rpath
Delete the given runtime path from the Mach-O.
410 411 412 413 414 415 416 417 418 419 |
# File 'lib/macho/macho_file.rb', line 410 def delete_rpath(path, = {}) rpath_cmds = command(:LC_RPATH).select { |r| r.path.to_s == path } raise RpathUnknownError, path if rpath_cmds.empty? # delete the commands in reverse order, offset descending. this # allows us to defer (expensive) field population until the very end rpath_cmds.reverse_each { |cmd| delete_command(cmd, :repopulate => false) } populate_fields end |
#dsym? ⇒ Boolean
Returns whether or not the file is of type MH_DSYM.
98 99 100 101 |
# File 'lib/macho/macho_file.rb', line 98 def_delegators :header, :magic, :ncmds, :sizeofcmds, :flags, :object?, :executable?, :fvmlib?, :core?, :preload?, :dylib?, :dylinker?, :bundle?, :dsym?, :kext?, :magic32?, :magic64?, :alignment |
#dylib? ⇒ Boolean
Returns whether or not the file is of type MH_DYLIB.
98 99 100 101 |
# File 'lib/macho/macho_file.rb', line 98 def_delegators :header, :magic, :ncmds, :sizeofcmds, :flags, :object?, :executable?, :fvmlib?, :core?, :preload?, :dylib?, :dylinker?, :bundle?, :dsym?, :kext?, :magic32?, :magic64?, :alignment |
#dylib_id ⇒ String?
The Mach-O's dylib ID, or nil if not a dylib.
285 286 287 288 289 290 291 |
# File 'lib/macho/macho_file.rb', line 285 def dylib_id return unless dylib? dylib_id_cmd = command(:LC_ID_DYLIB).first dylib_id_cmd.name.to_s end |
#dylib_load_commands ⇒ Array<LoadCommands::DylibCommand>
All load commands responsible for loading dylibs.
239 240 241 |
# File 'lib/macho/macho_file.rb', line 239 def dylib_load_commands load_commands.select { |lc| LoadCommands::DYLIB_LOAD_COMMANDS.include?(lc.type) } end |
#dylinker? ⇒ Boolean
Returns whether or not the file is of type MH_DYLINKER.
98 99 100 101 |
# File 'lib/macho/macho_file.rb', line 98 def_delegators :header, :magic, :ncmds, :sizeofcmds, :flags, :object?, :executable?, :fvmlib?, :core?, :preload?, :dylib?, :dylinker?, :bundle?, :dsym?, :kext?, :magic32?, :magic64?, :alignment |
#executable? ⇒ Boolean
Returns whether or not the file is of type MH_EXECUTE.
98 99 100 101 |
# File 'lib/macho/macho_file.rb', line 98 def_delegators :header, :magic, :ncmds, :sizeofcmds, :flags, :object?, :executable?, :fvmlib?, :core?, :preload?, :dylib?, :dylinker?, :bundle?, :dsym?, :kext?, :magic32?, :magic64?, :alignment |
#filetype ⇒ Symbol
Returns a string representation of the Mach-O's filetype.
109 110 111 |
# File 'lib/macho/macho_file.rb', line 109 def filetype Headers::MH_FILETYPES[header.filetype] end |
#flags ⇒ Integer
Returns the header flags associated with the Mach-O.
98 99 100 101 |
# File 'lib/macho/macho_file.rb', line 98 def_delegators :header, :magic, :ncmds, :sizeofcmds, :flags, :object?, :executable?, :fvmlib?, :core?, :preload?, :dylib?, :dylinker?, :bundle?, :dsym?, :kext?, :magic32?, :magic64?, :alignment |
#fvmlib? ⇒ Boolean
Returns whether or not the file is of type MH_FVMLIB.
98 99 100 101 |
# File 'lib/macho/macho_file.rb', line 98 def_delegators :header, :magic, :ncmds, :sizeofcmds, :flags, :object?, :executable?, :fvmlib?, :core?, :preload?, :dylib?, :dylinker?, :bundle?, :dsym?, :kext?, :magic32?, :magic64?, :alignment |
#initialize_from_bin(bin) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes a new MachOFile instance from a binary string.
52 53 54 55 56 |
# File 'lib/macho/macho_file.rb', line 52 def initialize_from_bin(bin) @filename = nil @raw_data = bin populate_fields end |
#insert_command(offset, lc, options = {}) ⇒ Object
Calling this method with an arbitrary offset in the load command region will leave the object in an inconsistent state.
Inserts a load command at the given offset.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/macho/macho_file.rb', line 146 def insert_command(offset, lc, = {}) context = LoadCommands::LoadCommand::SerializationContext.context_for(self) cmd_raw = lc.serialize(context) if offset < header.class.bytesize || offset + cmd_raw.bytesize > low_fileoff raise OffsetInsertionError, offset end new_sizeofcmds = sizeofcmds + cmd_raw.bytesize if header.class.bytesize + new_sizeofcmds > low_fileoff raise HeaderPadError, @filename end # update Mach-O header fields to account for inserted load command update_ncmds(ncmds + 1) update_sizeofcmds(new_sizeofcmds) @raw_data.insert(offset, cmd_raw) @raw_data.slice!(header.class.bytesize + new_sizeofcmds, cmd_raw.bytesize) populate_fields if .fetch(:repopulate, true) end |
#kext? ⇒ Boolean
Returns whether or not the file is of type MH_KEXT_BUNDLE.
98 99 100 101 |
# File 'lib/macho/macho_file.rb', line 98 def_delegators :header, :magic, :ncmds, :sizeofcmds, :flags, :object?, :executable?, :fvmlib?, :core?, :preload?, :dylib?, :dylinker?, :bundle?, :dsym?, :kext?, :magic32?, :magic64?, :alignment |
#linked_dylibs ⇒ Array<String>
All shared libraries linked to the Mach-O.
321 322 323 324 325 326 327 |
# File 'lib/macho/macho_file.rb', line 321 def linked_dylibs # Some linkers produce multiple `LC_LOAD_DYLIB` load commands for the same # library, but at this point we're really only interested in a list of # unique libraries this Mach-O file links to, thus: `uniq`. (This is also # for consistency with `FatFile` that merges this list across all archs.) dylib_load_commands.map(&:name).map(&:to_s).uniq end |
#magic ⇒ Integer
Returns the magic number.
98 99 100 101 |
# File 'lib/macho/macho_file.rb', line 98 def_delegators :header, :magic, :ncmds, :sizeofcmds, :flags, :object?, :executable?, :fvmlib?, :core?, :preload?, :dylib?, :dylinker?, :bundle?, :dsym?, :kext?, :magic32?, :magic64?, :alignment |
#magic32? ⇒ Boolean
Returns true if the Mach-O has 32-bit magic, false otherwise.
98 99 100 101 |
# File 'lib/macho/macho_file.rb', line 98 def_delegators :header, :magic, :ncmds, :sizeofcmds, :flags, :object?, :executable?, :fvmlib?, :core?, :preload?, :dylib?, :dylinker?, :bundle?, :dsym?, :kext?, :magic32?, :magic64?, :alignment |
#magic64? ⇒ Boolean
Returns true if the Mach-O has 64-bit magic, false otherwise.
98 99 100 101 |
# File 'lib/macho/macho_file.rb', line 98 def_delegators :header, :magic, :ncmds, :sizeofcmds, :flags, :object?, :executable?, :fvmlib?, :core?, :preload?, :dylib?, :dylinker?, :bundle?, :dsym?, :kext?, :magic32?, :magic64?, :alignment |
#magic_string ⇒ String
Returns a string representation of the file's magic number.
104 105 106 |
# File 'lib/macho/macho_file.rb', line 104 def magic_string Headers::MH_MAGICS[magic] end |
#ncmds ⇒ Integer
Returns the number of load commands in the Mach-O.
98 99 100 101 |
# File 'lib/macho/macho_file.rb', line 98 def_delegators :header, :magic, :ncmds, :sizeofcmds, :flags, :object?, :executable?, :fvmlib?, :core?, :preload?, :dylib?, :dylinker?, :bundle?, :dsym?, :kext?, :magic32?, :magic64?, :alignment |
#object? ⇒ Boolean
Returns whether or not the file is of type MH_OBJECT.
98 99 100 101 |
# File 'lib/macho/macho_file.rb', line 98 def_delegators :header, :magic, :ncmds, :sizeofcmds, :flags, :object?, :executable?, :fvmlib?, :core?, :preload?, :dylib?, :dylinker?, :bundle?, :dsym?, :kext?, :magic32?, :magic64?, :alignment |
#populate_fields ⇒ void
This method is public, but should (almost) never need to be called.
The exception to this rule is when methods like #add_command and
#delete_command have been called with repopulate = false.
This method returns an undefined value.
Populate the instance's fields with the raw Mach-O data.
232 233 234 235 |
# File 'lib/macho/macho_file.rb', line 232 def populate_fields @header = populate_mach_header @load_commands = populate_load_commands end |
#preload? ⇒ Boolean
Returns whether or not the file is of type MH_PRELOAD.
98 99 100 101 |
# File 'lib/macho/macho_file.rb', line 98 def_delegators :header, :magic, :ncmds, :sizeofcmds, :flags, :object?, :executable?, :fvmlib?, :core?, :preload?, :dylib?, :dylinker?, :bundle?, :dsym?, :kext?, :magic32?, :magic64?, :alignment |
#replace_command(old_lc, new_lc) ⇒ void
This is public, but methods like #dylib_id= should be preferred.
This method returns an undefined value.
Replace a load command with another command in the Mach-O, preserving location.
177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/macho/macho_file.rb', line 177 def replace_command(old_lc, new_lc) context = LoadCommands::LoadCommand::SerializationContext.context_for(self) cmd_raw = new_lc.serialize(context) new_sizeofcmds = sizeofcmds + cmd_raw.bytesize - old_lc.cmdsize if header.class.bytesize + new_sizeofcmds > low_fileoff raise HeaderPadError, @filename end delete_command(old_lc) insert_command(old_lc.view.offset, new_lc) end |
#rpaths ⇒ Array<String>
All runtime paths searched by the dynamic linker for the Mach-O.
355 356 357 |
# File 'lib/macho/macho_file.rb', line 355 def rpaths command(:LC_RPATH).map(&:path).map(&:to_s) end |
#segment_alignment ⇒ Integer
This is not the same as #alignment!
See get_align and get_align_64 in cctools/misc/lipo.c
The segment alignment for the Mach-O. Guesses conservatively.
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/macho/macho_file.rb', line 258 def segment_alignment # special cases: 12 for x86/64/PPC/PP64, 14 for ARM/ARM64 return 12 if i[i386 x86_64 ppc ppc64].include?(cputype) return 14 if i[arm arm64].include?(cputype) cur_align = Sections::MAX_SECT_ALIGN segments.each do |segment| if filetype == :object # start with the smallest alignment, and work our way up align = magic32? ? 2 : 3 segment.sections.each do |section| align = section.align unless section.align <= align end else align = segment.guess_align end cur_align = align if align < cur_align end cur_align end |
#segments ⇒ Array<LoadCommands::SegmentCommand>, Array<LoadCommands::SegmentCommand64>
All segment load commands in the Mach-O.
246 247 248 249 250 251 252 |
# File 'lib/macho/macho_file.rb', line 246 def segments if magic32? command(:LC_SEGMENT) else command(:LC_SEGMENT_64) end end |
#serialize ⇒ String
The file's raw Mach-O data.
60 61 62 |
# File 'lib/macho/macho_file.rb', line 60 def serialize @raw_data end |
#sizeofcmds ⇒ Integer
Returns the size of all load commands, in bytes, in the Mach-O.
98 99 100 101 |
# File 'lib/macho/macho_file.rb', line 98 def_delegators :header, :magic, :ncmds, :sizeofcmds, :flags, :object?, :executable?, :fvmlib?, :core?, :preload?, :dylib?, :dylinker?, :bundle?, :dsym?, :kext?, :magic32?, :magic64?, :alignment |
#to_h ⇒ Hash
Returns a hash representation of this MachO::MachOFile.
439 440 441 442 443 444 |
# File 'lib/macho/macho_file.rb', line 439 def to_h { "header" => header.to_h, "load_commands" => load_commands.map(&:to_h), } end |
#write(filename) ⇒ void
This method returns an undefined value.
Write all Mach-O data to the given filename.
424 425 426 |
# File 'lib/macho/macho_file.rb', line 424 def write(filename) File.open(filename, "wb") { |f| f.write(@raw_data) } end |
#write! ⇒ void
Overwrites all data in the file!
This method returns an undefined value.
Write all Mach-O data to the file used to initialize the instance.
432 433 434 435 436 |
# File 'lib/macho/macho_file.rb', line 432 def write! raise MachOError, "no initial file to write to" if @filename.nil? File.open(@filename, "wb") { |f| f.write(@raw_data) } end |