2016-02-01 14:19:29 -05:00
|
|
|
require "vendor/macho/macho"
|
|
|
|
|
|
|
|
module RubyMachO
|
|
|
|
# @private
|
|
|
|
def macho
|
|
|
|
@macho ||= begin
|
|
|
|
MachO.open(to_s)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# @private
|
|
|
|
def mach_data
|
|
|
|
@mach_data ||= begin
|
|
|
|
machos = []
|
|
|
|
mach_data = []
|
|
|
|
|
2016-08-07 13:37:23 -04:00
|
|
|
if MachO::Utils.fat_magic?(macho.magic)
|
2016-02-01 14:19:29 -05:00
|
|
|
machos = macho.machos
|
|
|
|
else
|
|
|
|
machos << macho
|
|
|
|
end
|
|
|
|
|
|
|
|
machos.each do |m|
|
|
|
|
arch = case m.cputype
|
2016-06-17 20:41:08 -04:00
|
|
|
when :x86_64, :i386, :ppc64 then m.cputype
|
|
|
|
when :ppc then :ppc7400
|
2016-02-01 14:19:29 -05:00
|
|
|
else :dunno
|
|
|
|
end
|
|
|
|
|
|
|
|
type = case m.filetype
|
2016-08-07 13:37:23 -04:00
|
|
|
when :dylib, :bundle then m.filetype
|
|
|
|
when :execute then :executable
|
2016-02-01 14:19:29 -05:00
|
|
|
else :dunno
|
|
|
|
end
|
|
|
|
|
2016-09-17 15:32:44 +01:00
|
|
|
mach_data << { arch: arch, type: type }
|
2016-02-01 14:19:29 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
mach_data
|
2016-02-15 17:56:47 +01:00
|
|
|
rescue MachO::NotAMachOError
|
|
|
|
# Silently ignore errors that indicate the file is not a Mach-O binary ...
|
|
|
|
[]
|
2016-02-01 14:19:29 -05:00
|
|
|
rescue
|
2016-02-15 17:56:47 +01:00
|
|
|
# ... but complain about other (parse) errors for further investigation.
|
|
|
|
if ARGV.homebrew_developer?
|
|
|
|
onoe "Failed to read Mach-O binary: #{self}"
|
|
|
|
raise
|
|
|
|
end
|
2016-02-01 14:19:29 -05:00
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def dynamically_linked_libraries
|
|
|
|
macho.linked_dylibs
|
|
|
|
end
|
|
|
|
|
|
|
|
def dylib_id
|
|
|
|
macho.dylib_id
|
|
|
|
end
|
|
|
|
end
|