Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): bump ruby-macho from 2.2.0 to 2.5.0 in /Library/Homebrew #9115

Merged
merged 2 commits into from
Nov 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Library/Homebrew/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ GEM
rubocop-ast (>= 1.1.0)
rubocop-sorbet (0.5.1)
rubocop
ruby-macho (2.2.0)
ruby-macho (2.5.0)
ruby-progressbar (1.10.1)
simplecov (0.19.1)
docile (~> 1.1)
Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/vendor/bundle/bundler/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/parallel_tests-3.3.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/parser-2.7.2.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rainbow-3.0.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/sorbet-runtime-0.5.6036/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/sorbet-runtime-0.5.6040/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/parlour-4.0.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/patchelf-1.3.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/plist-3.5.0/lib"
Expand All @@ -76,9 +76,9 @@
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.8.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.0.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-sorbet-0.5.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-2.2.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/sorbet-static-0.5.6036-universal-darwin-19/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/sorbet-0.5.6036/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-2.5.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/sorbet-static-0.5.6042-universal-darwin-19/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/sorbet-0.5.6042/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/sorbet-runtime-stub-0.2.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/thor-1.0.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/spoom-1.0.4/lib"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# frozen_string_literal: true

require "open3"

require_relative "macho/structure"
require_relative "macho/view"
require_relative "macho/headers"
Expand All @@ -12,7 +16,7 @@
# The primary namespace for ruby-macho.
module MachO
# release version
VERSION = "2.2.0".freeze
VERSION = "2.5.0"

# Opens the given filename as a MachOFile or FatFile, depending on its magic.
# @param filename [String] the file being opened
Expand All @@ -25,7 +29,7 @@ def self.open(filename)
raise ArgumentError, "#{filename}: no such file" unless File.file?(filename)
raise TruncatedFileError unless File.stat(filename).size >= 4

magic = File.open(filename, "rb") { |f| f.read(4) }.unpack("N").first
magic = File.open(filename, "rb") { |f| f.read(4) }.unpack1("N")

if Utils.fat_magic?(magic)
file = FatFile.new(filename)
Expand All @@ -37,4 +41,21 @@ def self.open(filename)

file
end

# Signs the dylib using an ad-hoc identity.
# Necessary after making any changes to a dylib, since otherwise
# changing a signed file invalidates its signature.
# @param filename [String] the file being opened
# @return [void]
# @raise [ModificationError] if the operation fails
def self.codesign!(filename)
raise ArgumentError, "codesign binary is not available on Linux" if RUBY_PLATFORM !~ /darwin/
raise ArgumentError, "#{filename}: no such file" unless File.file?(filename)

_, _, status = Open3.capture3("codesign", "--sign", "-", "--force",
"--preserve-metadata=entitlements,requirements,flags,runtime",
filename)

raise CodeSigningError, "#{filename}: signing failed!" unless status.success?
end
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module MachO
# A generic Mach-O error in execution.
class MachOError < RuntimeError
Expand All @@ -7,6 +9,11 @@ class MachOError < RuntimeError
class ModificationError < MachOError
end

# Raised when codesigning fails. Certain environments
# may want to rescue this to treat it as non-fatal.
class CodeSigningError < MachOError
end

# Raised when a Mach-O file modification fails but can be recovered when
# operating on multiple Mach-O slices of a fat binary in non-strict mode.
class RecoverableModificationError < ModificationError
Expand All @@ -25,10 +32,6 @@ def to_s

# Raised when a file is not a Mach-O.
class NotAMachOError < MachOError
# @param error [String] the error in question
def initialize(error)
super error
end
end

# Raised when a file is too short to be a valid Mach-O file.
Expand All @@ -41,8 +44,8 @@ def initialize
# Raised when a file's magic bytes are not valid Mach-O magic.
class MagicError < NotAMachOError
# @param num [Integer] the unknown number
def initialize(num)
super "Unrecognized Mach-O magic: 0x#{"%02x" % num}"
def initialize(magic)
super "Unrecognized Mach-O magic: 0x%02<magic>x" % { :magic => magic }
end
end

Expand Down Expand Up @@ -71,7 +74,7 @@ def initialize
class CPUTypeError < MachOError
# @param cputype [Integer] the unknown CPU type
def initialize(cputype)
super "Unrecognized CPU type: 0x#{"%08x" % cputype}"
super "Unrecognized CPU type: 0x%08<cputype>x" % { :cputype => cputype }
end
end

Expand All @@ -80,24 +83,24 @@ class CPUSubtypeError < MachOError
# @param cputype [Integer] the CPU type of the unknown pair
# @param cpusubtype [Integer] the CPU sub-type of the unknown pair
def initialize(cputype, cpusubtype)
super "Unrecognized CPU sub-type: 0x#{"%08x" % cpusubtype}" \
" (for CPU type: 0x#{"%08x" % cputype})"
super "Unrecognized CPU sub-type: 0x%08<cpusubtype>x" \
" (for CPU type: 0x%08<cputype>x" % { :cputype => cputype, :cpusubtype => cpusubtype }
end
end

# Raised when a mach-o file's filetype field is unknown.
class FiletypeError < MachOError
# @param num [Integer] the unknown number
def initialize(num)
super "Unrecognized Mach-O filetype code: 0x#{"%02x" % num}"
super "Unrecognized Mach-O filetype code: 0x%02<num>x" % { :num => num }
end
end

# Raised when an unknown load command is encountered.
class LoadCommandError < MachOError
# @param num [Integer] the unknown number
def initialize(num)
super "Unrecognized Mach-O load command: 0x#{"%02x" % num}"
super "Unrecognized Mach-O load command: 0x%02<num>x" % { :num => num }
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "forwardable"

module MachO
Expand Down Expand Up @@ -64,7 +66,7 @@ def self.new_from_machos(*machos, fat64: false)
offset += (macho.serialize.bytesize + macho_pads[macho])
end

machos.each do |macho|
machos.each do |macho| # rubocop:disable Style/CombinableLoops
bin << Utils.nullpad(macho_pads[macho])
bin << macho.serialize
end
Expand Down Expand Up @@ -396,16 +398,14 @@ def each_macho(options = {})
errors = []

machos.each_with_index do |macho, index|
begin
yield macho
rescue RecoverableModificationError => error
error.macho_slice = index
yield macho
rescue RecoverableModificationError => e
e.macho_slice = index

# Strict mode: Immediately re-raise. Otherwise: Retain, check later.
raise error if strict
# Strict mode: Immediately re-raise. Otherwise: Retain, check later.
raise e if strict

errors << error
end
errors << e
end

# Non-strict mode: Raise first error if *all* Mach-O slices failed.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module MachO
# Classes and constants for parsing the headers of Mach-O binaries.
module Headers
Expand Down Expand Up @@ -490,14 +492,15 @@ class FatHeader < MachOStructure
# always big-endian
# @see MachOStructure::FORMAT
# @api private
FORMAT = "N2".freeze
FORMAT = "N2"

# @see MachOStructure::SIZEOF
# @api private
SIZEOF = 8

# @api private
def initialize(magic, nfat_arch)
super()
@magic = magic
@nfat_arch = nfat_arch
end
Expand Down Expand Up @@ -541,14 +544,15 @@ class FatArch < MachOStructure
# @note Always big endian.
# @see MachOStructure::FORMAT
# @api private
FORMAT = "L>5".freeze
FORMAT = "L>5"

# @see MachOStructure::SIZEOF
# @api private
SIZEOF = 20

# @api private
def initialize(cputype, cpusubtype, offset, size, align)
super()
@cputype = cputype
@cpusubtype = cpusubtype & ~CPU_SUBTYPE_MASK
@offset = offset
Expand Down Expand Up @@ -587,7 +591,7 @@ class FatArch64 < FatArch
# @note Always big endian.
# @see MachOStructure::FORMAT
# @api private
FORMAT = "L>2Q>2L>2".freeze
FORMAT = "L>2Q>2L>2"

# @see MachOStructure::SIZEOF
# @api private
Expand Down Expand Up @@ -637,7 +641,7 @@ class MachHeader < MachOStructure

# @see MachOStructure::FORMAT
# @api private
FORMAT = "L=7".freeze
FORMAT = "L=7"

# @see MachOStructure::SIZEOF
# @api private
Expand All @@ -646,6 +650,7 @@ class MachHeader < MachOStructure
# @api private
def initialize(magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds,
flags)
super()
@magic = magic
@cputype = cputype
# For now we're not interested in additional capability bits also to be
Expand Down Expand Up @@ -760,7 +765,7 @@ class MachHeader64 < MachHeader

# @see MachOStructure::FORMAT
# @api private
FORMAT = "L=8".freeze
FORMAT = "L=8"

# @see MachOStructure::SIZEOF
# @api private
Expand Down