ruby-macho
A Ruby library for examining and modifying Mach-O files.
What is a Mach-O file?
The Mach-O file format is used by OS X and iOS (among others) as a general purpose binary format for object files, executables, dynamic libraries, and so forth.
Documentation
Full documentation is available on RubyDoc.
A quick example of what ruby-macho can do:
require 'macho'
file = MachO::MachOFile.open("/path/to/my/binary")
# get the file's type (MH_OBJECT, MH_DYLIB, MH_EXECUTE, etc)
file.filetype # => "MH_EXECUTE"
# get all load commands in the file and print their offsets:
file.load_commands.each do |lc|
puts "#{lc}: offset #{lc.offset}, size: #{lc.cmdsize}"
end
# access a specific load command
lc_vers = file['LC_VERSION_MIN_MACOSX'].first
puts lc_vers.version_string # => "10.10.0"
What works?
- Reading data from x86/x86_64 Mach-O files
- Changing the IDs of Mach-O dylibs
- Changing install names in Mach-O files
What might work?
- Reading some data from PPC Mach-O files.
- Reading data from "Fat" files.
What doesn't work yet?
- Reading data from any other architecure's Mach-O files (probably).
- Changing anything in "Fat" files (at least not correctly).
What needs to be done?
- Documentation.
- Rpath modification.
- Many, many things.
Attribution:
lib/macho/cstruct.rb
was taken from Sami Samhuri's compiler repository. (No license provided).- Constants were taken from Apple, Inc's
loader.h
incctools/include/mach-o
. (Apple Public Source License 2.0).
License
ruby-macho
is licensed under the MIT License.
For the exact terms, see the license file.