Revert "Don't raise in mach_data so the debugger doesn't catch it"

This reverts commit 4f8a3e2113c2e7b88600ff6371f9f70579c55509.
This commit is contained in:
Jack Nagel 2014-10-11 01:45:41 -05:00
parent 977a2ceae3
commit 85a9156c6f

View File

@ -53,52 +53,51 @@ module MachO
# /usr/include/mach-o/fat.h # /usr/include/mach-o/fat.h
def mach_data def mach_data
@mach_data ||= _mach_data @mach_data ||= begin
end offsets = []
mach_data = []
def _mach_data header = read(8).unpack("N2")
offsets = [] case header[0]
mach_data = [] when 0xcafebabe # universal
header[1].times do |i|
header = read(8).unpack("N2") # header[1] is the number of struct fat_arch in the file.
case header[0] # Each struct fat_arch is 20 bytes, and the 'offset' member
when 0xcafebabe # universal # begins 8 bytes into the struct, with an additional 8 byte
header[1].times do |i| # offset due to the struct fat_header at the beginning of
# header[1] is the number of struct fat_arch in the file. # the file.
# Each struct fat_arch is 20 bytes, and the 'offset' member offsets << read(4, 20*i + 16).unpack("N")[0]
# begins 8 bytes into the struct, with an additional 8 byte end
# offset due to the struct fat_header at the beginning of when 0xcefaedfe, 0xcffaedfe, 0xfeedface, 0xfeedfacf # Single arch
# the file. offsets << 0
offsets << read(4, 20*i + 16).unpack("N")[0] when 0x7f454c46 # ELF
mach_data << { :arch => :x86_64, :type => :executable }
else
raise "Not a Mach-O binary."
end end
when 0xcefaedfe, 0xcffaedfe, 0xfeedface, 0xfeedfacf # Single arch
offsets << 0 offsets.each do |offset|
when 0x7f454c46 # ELF arch = case read(8, offset).unpack("N2")
mach_data << { :arch => :x86_64, :type => :executable } when [0xcefaedfe, 0x07000000] then :i386
else when [0xcffaedfe, 0x07000001] then :x86_64
return [] 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
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