Don't raise in mach_data so the debugger doesn't catch it
Closes Homebrew/homebrew#33088.
This commit is contained in:
parent
8cc5aabfcf
commit
01397d17f7
@ -53,51 +53,52 @@ module MachO
|
|||||||
# /usr/include/mach-o/fat.h
|
# /usr/include/mach-o/fat.h
|
||||||
|
|
||||||
def mach_data
|
def mach_data
|
||||||
@mach_data ||= begin
|
@mach_data ||= _mach_data
|
||||||
offsets = []
|
end
|
||||||
mach_data = []
|
|
||||||
|
|
||||||
header = read(8).unpack("N2")
|
def _mach_data
|
||||||
case header[0]
|
offsets = []
|
||||||
when 0xcafebabe # universal
|
mach_data = []
|
||||||
header[1].times do |i|
|
|
||||||
# header[1] is the number of struct fat_arch in the file.
|
header = read(8).unpack("N2")
|
||||||
# Each struct fat_arch is 20 bytes, and the 'offset' member
|
case header[0]
|
||||||
# begins 8 bytes into the struct, with an additional 8 byte
|
when 0xcafebabe # universal
|
||||||
# offset due to the struct fat_header at the beginning of
|
header[1].times do |i|
|
||||||
# the file.
|
# header[1] is the number of struct fat_arch in the file.
|
||||||
offsets << read(4, 20*i + 16).unpack("N")[0]
|
# Each struct fat_arch is 20 bytes, and the 'offset' member
|
||||||
end
|
# begins 8 bytes into the struct, with an additional 8 byte
|
||||||
when 0xcefaedfe, 0xcffaedfe, 0xfeedface, 0xfeedfacf # Single arch
|
# offset due to the struct fat_header at the beginning of
|
||||||
offsets << 0
|
# the file.
|
||||||
when 0x7f454c46 # ELF
|
offsets << read(4, 20*i + 16).unpack("N")[0]
|
||||||
mach_data << { :arch => :x86_64, :type => :executable }
|
|
||||||
else
|
|
||||||
raise "Not a Mach-O binary."
|
|
||||||
end
|
end
|
||||||
|
when 0xcefaedfe, 0xcffaedfe, 0xfeedface, 0xfeedfacf # Single arch
|
||||||
offsets.each do |offset|
|
offsets << 0
|
||||||
arch = case read(8, offset).unpack("N2")
|
when 0x7f454c46 # ELF
|
||||||
when [0xcefaedfe, 0x07000000] then :i386
|
mach_data << { :arch => :x86_64, :type => :executable }
|
||||||
when [0xcffaedfe, 0x07000001] then :x86_64
|
else
|
||||||
when [0xfeedface, 0x00000012] then :ppc7400
|
return []
|
||||||
when [0xfeedfacf, 0x01000012] then :ppc64
|
|
||||||
else :dunno
|
|
||||||
end
|
|
||||||
|
|
||||||
type = case read(4, offset + 12).unpack("N")[0]
|
|
||||||
when 0x00000002, 0x02000000 then :executable
|
|
||||||
when 0x00000006, 0x06000000 then :dylib
|
|
||||||
when 0x00000008, 0x08000000 then :bundle
|
|
||||||
else :dunno
|
|
||||||
end
|
|
||||||
|
|
||||||
mach_data << { :arch => arch, :type => type }
|
|
||||||
end
|
|
||||||
mach_data
|
|
||||||
rescue
|
|
||||||
[]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
offsets.each do |offset|
|
||||||
|
arch = case read(8, offset).unpack("N2")
|
||||||
|
when [0xcefaedfe, 0x07000000] then :i386
|
||||||
|
when [0xcffaedfe, 0x07000001] then :x86_64
|
||||||
|
when [0xfeedface, 0x00000012] then :ppc7400
|
||||||
|
when [0xfeedfacf, 0x01000012] then :ppc64
|
||||||
|
else :dunno
|
||||||
|
end
|
||||||
|
|
||||||
|
type = case read(4, offset + 12).unpack("N")[0]
|
||||||
|
when 0x00000002, 0x02000000 then :executable
|
||||||
|
when 0x00000006, 0x06000000 then :dylib
|
||||||
|
when 0x00000008, 0x08000000 then :bundle
|
||||||
|
else :dunno
|
||||||
|
end
|
||||||
|
|
||||||
|
mach_data << { :arch => arch, :type => type }
|
||||||
|
end
|
||||||
|
|
||||||
|
mach_data
|
||||||
end
|
end
|
||||||
|
|
||||||
def archs
|
def archs
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user