language
stringclasses
1 value
owner
stringlengths
2
15
repo
stringlengths
2
21
sha
stringlengths
45
45
message
stringlengths
7
36.3k
path
stringlengths
1
199
patch
stringlengths
15
102k
is_multipart
bool
2 classes
Other
Homebrew
brew
2047dbd50e05cf03a7f7912011fd510cbc9172f5.json
Update all references to taps. - Remove taps that are (or will shortly be) deprecated. - Remove commands that are only relevant to the boneyard (which will shortly be removed).
Library/Homebrew/dev-cmd/boneyard-formula-pr.rb
@@ -1,166 +0,0 @@ -#: @hide_from_man_page -#: * `boneyard-formula-pr` [`--dry-run`] [`--local`] [`--reason=<reason>`] <formula> : -#: Creates a pull request to boneyard a formula. -#: -#: If `--dry-run` is passed, print what would be done rather than doing it. -#: -#: If `--local` is passed, perform only local operations (i.e. don't push or create PR). -#: -#: If `--reason=<reason>` is passed, append this to the commit/PR message. - -require "formula" -require "json" -require "fileutils" - -begin - require "json" -rescue LoadError - puts "Homebrew does not provide Ruby dependencies; install with:" - puts " gem install json" - odie "Dependency json is not installed." -end - -module Homebrew - module_function - - def boneyard_formula_pr - local_only = ARGV.include?("--local") - formula = ARGV.formulae.first - reason = ARGV.value("reason") - odie "No formula found!" unless formula - - formula_relpath = formula.path.relative_path_from(formula.tap.path) - formula_file = "#{formula.name}.rb" - bottle_block = File.read(formula.path).include? " bottle do" - boneyard_tap = Tap.fetch("homebrew", "boneyard") - tap_migrations_path = formula.tap.path/"tap_migrations.json" - if ARGV.dry_run? - ohai "brew update" - ohai "brew tap #{boneyard_tap.name}" - ohai "cd #{formula.tap.path}" - cd formula.tap.path - ohai "cp #{formula_relpath} #{boneyard_tap.path}" - ohai "git rm #{formula_relpath}" - unless File.exist? tap_migrations_path - ohai "Creating tap_migrations.json for #{formula.tap.name}" - ohai "git add #{tap_migrations_path}" - end - ohai "Loading tap_migrations.json" - ohai "Adding #{formula.name} to tap_migrations.json" - else - safe_system HOMEBREW_BREW_FILE, "update" - safe_system HOMEBREW_BREW_FILE, "tap", boneyard_tap.name - cd formula.tap.path - cp formula_relpath, boneyard_tap.formula_dir - safe_system "git", "rm", formula_relpath - unless File.exist? tap_migrations_path - tap_migrations_path.write <<-EOS.undent - { - } - EOS - safe_system "git", "add", tap_migrations_path - end - tap_migrations = JSON.parse(File.read(tap_migrations_path)) - tap_migrations[formula.name] = boneyard_tap.name - tap_migrations = tap_migrations.sort.inject({}) { |acc, elem| acc.merge!(elem[0] => elem[1]) } - tap_migrations_path.atomic_write(JSON.pretty_generate(tap_migrations) + "\n") - end - unless which("hub") || local_only - if ARGV.dry_run? - ohai "brew install hub" - else - safe_system HOMEBREW_BREW_FILE, "install", "hub" - end - end - branch = "#{formula.name}-boneyard" - - reason = " because #{reason}" if reason - - if ARGV.dry_run? - ohai "cd #{formula.tap.path}" - ohai "git checkout --no-track -b #{branch} origin/master" - ohai "git commit --no-edit --verbose --message=\"#{formula.name}: migrate to boneyard\" -- #{formula_relpath} #{tap_migrations_path.basename}" - - unless local_only - ohai "hub fork --no-remote" - ohai "hub fork" - ohai "hub fork (to read $HUB_REMOTE)" - ohai "git push $HUB_REMOTE #{branch}:#{branch}" - ohai "hub pull-request -m $'#{formula.name}: migrate to boneyard\\n\\nCreated with `brew boneyard-formula-pr`#{reason}.'" - end - - ohai "git checkout -" - else - cd formula.tap.path - safe_system "git", "checkout", "--no-track", "-b", branch, "origin/master" - safe_system "git", "commit", "--no-edit", "--verbose", - "--message=#{formula.name}: migrate to boneyard", - "--", formula_relpath, tap_migrations_path.basename - - unless local_only - safe_system "hub", "fork", "--no-remote" - quiet_system "hub", "fork" - remote = Utils.popen_read("hub fork 2>&1")[/fatal: remote (.+) already exists\./, 1] - odie "cannot get remote from 'hub'!" unless remote - safe_system "git", "push", remote, "#{branch}:#{branch}" - pr_message = <<-EOS.undent - #{formula.name}: migrate to boneyard - - Created with `brew boneyard-formula-pr`#{reason}. - EOS - pr_url = Utils.popen_read("hub", "pull-request", "-m", pr_message).chomp - end - - safe_system "git", "checkout", "-" - end - - if ARGV.dry_run? - ohai "cd #{boneyard_tap.path}" - ohai "git checkout --no-track -b #{branch} origin/master" - if bottle_block - ohai "Removing bottle block" - else - ohai "No bottle block to remove" - end - ohai "git add #{formula_file}" - ohai "git commit --no-edit --verbose --message=\"#{formula.name}: migrate from #{formula.tap.repo}\" -- #{formula_file}" - - unless local_only - ohai "hub fork --no-remote" - ohai "hub fork" - ohai "hub fork (to read $HUB_REMOTE)" - ohai "git push $HUB_REMOTE #{branch}:#{branch}" - ohai "hub pull-request --browse -m $'#{formula.name}: migrate from #{formula.tap.repo}\\n\\nGoes together with $PR_URL\\n\\nCreated with `brew boneyard-formula-pr`#{reason}.'" - end - - ohai "git checkout -" - else - cd boneyard_tap.formula_dir - safe_system "git", "checkout", "--no-track", "-b", branch, "origin/master" - if bottle_block - Utils::Inreplace.inreplace formula_file, / bottle do.+?end\n\n/m, "" - end - safe_system "git", "add", formula_file - safe_system "git", "commit", "--no-edit", "--verbose", - "--message=#{formula.name}: migrate from #{formula.tap.repo}", - "--", formula_file - - unless local_only - safe_system "hub", "fork", "--no-remote" - quiet_system "hub", "fork" - remote = Utils.popen_read("hub fork 2>&1")[/fatal: remote (.+) already exists\./, 1] - odie "cannot get remote from 'hub'!" unless remote - safe_system "git", "push", remote, "#{branch}:#{branch}" - safe_system "hub", "pull-request", "--browse", "-m", <<-EOS.undent - #{formula.name}: migrate from #{formula.tap.repo} - - Goes together with #{pr_url}. - - Created with `brew boneyard-formula-pr`#{reason}. - EOS - end - - safe_system "git", "checkout", "-" - end - end -end
true
Other
Homebrew
brew
2047dbd50e05cf03a7f7912011fd510cbc9172f5.json
Update all references to taps. - Remove taps that are (or will shortly be) deprecated. - Remove commands that are only relevant to the boneyard (which will shortly be removed).
Library/Homebrew/exceptions.rb
@@ -363,14 +363,6 @@ def dump end end - if formula.tap && formula.tap.name == "homebrew/boneyard" - onoe <<-EOS.undent - #{formula} was moved to homebrew-boneyard because it has unfixable issues. - Please do not file any issues about this. Sorry! - EOS - return - end - if formula.tap && defined?(OS::ISSUES_URL) if formula.tap.official? puts Formatter.error(Formatter.url(OS::ISSUES_URL), label: "READ THIS")
true
Other
Homebrew
brew
2047dbd50e05cf03a7f7912011fd510cbc9172f5.json
Update all references to taps. - Remove taps that are (or will shortly be) deprecated. - Remove commands that are only relevant to the boneyard (which will shortly be removed).
Library/Homebrew/official_taps.rb
@@ -1,11 +1,8 @@ OFFICIAL_TAPS = %w[ apache - dupes - fuse nginx php science - tex ].freeze OFFICIAL_CMD_TAPS = {
true
Other
Homebrew
brew
2047dbd50e05cf03a7f7912011fd510cbc9172f5.json
Update all references to taps. - Remove taps that are (or will shortly be) deprecated. - Remove commands that are only relevant to the boneyard (which will shortly be removed).
completions/zsh/_brew
@@ -205,14 +205,6 @@ _brew_audit() { '*:formula:__brew_formulae' } -# brew boneyard-formula-pr [--dry-run] [--local] formula-name -_brew_boneyard_formula_pr() { - _arguments \ - '--dry-run[print what would be done rather than doing it]' \ - '--local[perform only local operations(i.e. don''t push or create PR)]' \ - ':formula:__brew_formulae' -} - # brew bottle [--verbose] [--no-rebuild] [--keep-old] [--skip-relocation] [--root-url=root_url] # brew bottle --merge [--no-commit] [--keep-old] [--write] # TODO missing argument docs
true
Other
Homebrew
brew
2047dbd50e05cf03a7f7912011fd510cbc9172f5.json
Update all references to taps. - Remove taps that are (or will shortly be) deprecated. - Remove commands that are only relevant to the boneyard (which will shortly be removed).
docs/Interesting-Taps-&-Forks.md
@@ -1,37 +1,19 @@ # Interesting Taps & Forks A _tap_ is homebrew-speak for a Git repository containing extra formulae. -Homebrew has the capability to add (and remove) multiple taps to your local installation with the `brew tap` and `brew untap` commands. Type `man brew` in your Terminal. The main repository <https://github.com/Homebrew/homebrew-core>, often called `homebrew/core`, is always built-in. +Homebrew has the capability to add (and remove) multiple taps to your local installation with the `brew tap` and `brew untap` commands. Type `man brew` in your Terminal. The main repository [https://github.com/Homebrew/homebrew-core](https://github.com/Homebrew/homebrew-core), often called `homebrew/core`, is always built-in. ## Main taps * [homebrew/apache](https://github.com/Homebrew/homebrew-apache): A tap for Apache modules, extending macOS's built-in Apache. These brews may require unconventional additional setup, as explained in the caveats. -* [homebrew/boneyard](https://github.com/Homebrew/homebrew-boneyard): Formulae from other official taps, primarily `homebrew/core` are not deleted, they are moved here. - -* [homebrew/bundle](https://github.com/Homebrew/homebrew-bundle): Bundler for non-Ruby dependencies from Homebrew. - -* [homebrew/completions](https://github.com/Homebrew/homebrew-completions): Shell completion formulae. - -* [homebrew/dupes](https://github.com/Homebrew/homebrew-dupes): Need GDB or a newer Tk? System duplicates go here. - -* [homebrew/emacs](https://github.com/Homebrew/homebrew-emacs): A tap for Emacs packages. - -* [homebrew/games](https://github.com/Homebrew/homebrew-games): Game or gaming-emulation related formulae. - * [homebrew/nginx](https://github.com/Homebrew/homebrew-nginx): Feature rich Nginx tap for modules. * [homebrew/php](https://github.com/Homebrew/homebrew-php): Repository for php-related formulae. -* [homebrew/python](https://github.com/Homebrew/homebrew-python): A few Python formulae that do not build well with `pip` alone. - * [homebrew/science](https://github.com/Homebrew/homebrew-science): A collection of scientific libraries and tools. -* [homebrew/services](https://github.com/Homebrew/homebrew-services): A tool to start Homebrew formulae's plists with `launchctl`. - -* [homebrew/x11](https://github.com/Homebrew/homebrew-x11): Formulae with hard X11 dependencies. - -`brew search` looks in these main taps as well as in [homebrew/core](https://github.com/Homebrew/homebrew-core). So don't worry about missing stuff. We will add other taps to the search as they become well maintained and popular. +`brew search` looks in these taps as well as in [homebrew/core](https://github.com/Homebrew/homebrew-core) so don't worry about missing stuff. You can be added as a maintainer for one of the Homebrew organization taps and aid the project! If you are interested write to our list: homebrew-discuss@googlegroups.com. We want your help! @@ -47,6 +29,8 @@ You can be added as a maintainer for one of the Homebrew organization taps and a * [titanous/gnuradio](https://github.com/titanous/homebrew-gnuradio): GNU Radio and friends running on macOS. +* [dunn/emacs](https://github.com/dunn/homebrew-emacs): A tap for Emacs packages. + ## Interesting forks * [mistydemeo/tigerbrew](https://github.com/mistydemeo/tigerbrew): Experimental Tiger PowerPC version
true
Other
Homebrew
brew
024264c381a5dc02dea8680dea29e83bdce9d13b.json
vendor: Update ruby-macho to 1.1.0.
Library/Homebrew/vendor/README.md
@@ -3,7 +3,7 @@ Vendored Dependencies * [plist](https://github.com/bleything/plist), version 3.1.0 -* [ruby-macho](https://github.com/Homebrew/ruby-macho), version 0.2.6 +* [ruby-macho](https://github.com/Homebrew/ruby-macho), version 1.1.0 ## Licenses: @@ -33,7 +33,7 @@ Vendored Dependencies ### ruby-macho > The MIT License -> Copyright (c) 2015, 2016 William Woodruff <william @ tuffbizz.com> +> Copyright (c) 2015, 2016, 2017 William Woodruff <william @ tuffbizz.com> > > Permission is hereby granted, free of charge, to any person obtaining a copy > of this software and associated documentation files (the "Software"), to deal
true
Other
Homebrew
brew
024264c381a5dc02dea8680dea29e83bdce9d13b.json
vendor: Update ruby-macho to 1.1.0.
Library/Homebrew/vendor/macho/macho.rb
@@ -5,13 +5,36 @@ require "#{File.dirname(__FILE__)}/macho/sections" require "#{File.dirname(__FILE__)}/macho/macho_file" require "#{File.dirname(__FILE__)}/macho/fat_file" -require "#{File.dirname(__FILE__)}/macho/open" require "#{File.dirname(__FILE__)}/macho/exceptions" require "#{File.dirname(__FILE__)}/macho/utils" require "#{File.dirname(__FILE__)}/macho/tools" # The primary namespace for ruby-macho. module MachO # release version - VERSION = "0.2.6".freeze + VERSION = "1.1.0".freeze + + # Opens the given filename as a MachOFile or FatFile, depending on its magic. + # @param filename [String] the file being opened + # @return [MachOFile] if the file is a Mach-O + # @return [FatFile] if the file is a Fat file + # @raise [ArgumentError] if the given file does not exist + # @raise [TruncatedFileError] if the file is too small to have a valid header + # @raise [MagicError] if the file's magic is not valid Mach-O magic + 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 + + if Utils.fat_magic?(magic) + file = FatFile.new(filename) + elsif Utils.magic?(magic) + file = MachOFile.new(filename) + else + raise MagicError, magic + end + + file + end end
true
Other
Homebrew
brew
024264c381a5dc02dea8680dea29e83bdce9d13b.json
vendor: Update ruby-macho to 1.1.0.
Library/Homebrew/vendor/macho/macho/exceptions.rb
@@ -80,7 +80,8 @@ class CPUSubtypeError < MachOError # @param cputype [Fixnum] the CPU type of the unknown pair # @param cpusubtype [Fixnum] 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#{"%08x" % cpusubtype}" \ + " (for CPU type: 0x#{"%08x" % cputype})" end end @@ -108,13 +109,15 @@ def initialize(cmd_sym) end end - # Raised when the number of arguments used to create a load command manually is wrong. + # Raised when the number of arguments used to create a load command manually + # is wrong. class LoadCommandCreationArityError < MachOError # @param cmd_sym [Symbol] the load command's symbol # @param expected_arity [Fixnum] the number of arguments expected # @param actual_arity [Fixnum] the number of arguments received def initialize(cmd_sym, expected_arity, actual_arity) - super "Expected #{expected_arity} arguments for #{cmd_sym} creation, got #{actual_arity}" + super "Expected #{expected_arity} arguments for #{cmd_sym} creation," \ + " got #{actual_arity}" end end @@ -130,7 +133,8 @@ def initialize(cmd_sym) class LCStrMalformedError < MachOError # @param lc [MachO::LoadCommand] the load command containing the string def initialize(lc) - super "Load command #{lc.type} at offset #{lc.view.offset} contains a malformed string" + super "Load command #{lc.type} at offset #{lc.view.offset} contains a" \ + " malformed string" end end
true
Other
Homebrew
brew
024264c381a5dc02dea8680dea29e83bdce9d13b.json
vendor: Update ruby-macho to 1.1.0.
Library/Homebrew/vendor/macho/macho/fat_file.rb
@@ -1,24 +1,50 @@ +require "forwardable" + module MachO # Represents a "Fat" file, which contains a header, a listing of available # architectures, and one or more Mach-O binaries. # @see https://en.wikipedia.org/wiki/Mach-O#Multi-architecture_binaries - # @see MachO::MachOFile + # @see MachOFile class FatFile + extend Forwardable + # @return [String] the filename loaded from, or nil if loaded from a binary string attr_accessor :filename - # @return [MachO::FatHeader] the file's header + # @return [Headers::FatHeader] the file's header attr_reader :header - # @return [Array<MachO::FatArch>] an array of fat architectures + # @return [Array<Headers::FatArch>] an array of fat architectures attr_reader :fat_archs - # @return [Array<MachO::MachOFile>] an array of Mach-O binaries + # @return [Array<MachOFile>] an array of Mach-O binaries attr_reader :machos + # Creates a new FatFile from the given (single-arch) Mach-Os + # @param machos [Array<MachOFile>] the machos to combine + # @return [FatFile] a new FatFile containing the give machos + def self.new_from_machos(*machos) + header = Headers::FatHeader.new(Headers::FAT_MAGIC, machos.size) + offset = Headers::FatHeader.bytesize + (machos.size * Headers::FatArch.bytesize) + fat_archs = [] + machos.each do |macho| + fat_archs << Headers::FatArch.new(macho.header.cputype, + macho.header.cpusubtype, + offset, macho.serialize.bytesize, + macho.alignment) + offset += macho.serialize.bytesize + end + + bin = header.serialize + bin << fat_archs.map(&:serialize).join + bin << machos.map(&:serialize).join + + new_from_bin(bin) + end + # Creates a new FatFile instance from a binary string. # @param bin [String] a binary string containing raw Mach-O data - # @return [MachO::FatFile] a new FatFile + # @return [FatFile] a new FatFile def self.new_from_bin(bin) instance = allocate instance.initialize_from_bin(bin) @@ -38,7 +64,7 @@ def initialize(filename) end # Initializes a new FatFile instance from a binary string. - # @see MachO::FatFile.new_from_bin + # @see new_from_bin # @api private def initialize_from_bin(bin) @filename = nil @@ -52,70 +78,41 @@ def serialize @raw_data end - # @return [Boolean] true if the file is of type `MH_OBJECT`, false otherwise - def object? - machos.first.object? - end - - # @return [Boolean] true if the file is of type `MH_EXECUTE`, false otherwise - def executable? - machos.first.executable? - end - - # @return [Boolean] true if the file is of type `MH_FVMLIB`, false otherwise - def fvmlib? - machos.first.fvmlib? - end - - # @return [Boolean] true if the file is of type `MH_CORE`, false otherwise - def core? - machos.first.core? - end - - # @return [Boolean] true if the file is of type `MH_PRELOAD`, false otherwise - def preload? - machos.first.preload? - end - - # @return [Boolean] true if the file is of type `MH_DYLIB`, false otherwise - def dylib? - machos.first.dylib? - end - - # @return [Boolean] true if the file is of type `MH_DYLINKER`, false otherwise - def dylinker? - machos.first.dylinker? - end - - # @return [Boolean] true if the file is of type `MH_BUNDLE`, false otherwise - def bundle? - machos.first.bundle? - end - - # @return [Boolean] true if the file is of type `MH_DSYM`, false otherwise - def dsym? - machos.first.dsym? - end - - # @return [Boolean] true if the file is of type `MH_KEXT_BUNDLE`, false otherwise - def kext? - machos.first.kext? - end - - # @return [Fixnum] the file's magic number - def magic - header.magic - end + # @!method object? + # @return (see MachO::MachOFile#object?) + # @!method executable? + # @return (see MachO::MachOFile#executable?) + # @!method fvmlib? + # @return (see MachO::MachOFile#fvmlib?) + # @!method core? + # @return (see MachO::MachOFile#core?) + # @!method preload? + # @return (see MachO::MachOFile#preload?) + # @!method dylib? + # @return (see MachO::MachOFile#dylib?) + # @!method dylinker? + # @return (see MachO::MachOFile#dylinker?) + # @!method bundle? + # @return (see MachO::MachOFile#bundle?) + # @!method dsym? + # @return (see MachO::MachOFile#dsym?) + # @!method kext? + # @return (see MachO::MachOFile#kext?) + # @!method filetype + # @return (see MachO::MachOFile#filetype) + # @!method dylib_id + # @return (see MachO::MachOFile#dylib_id) + def_delegators :canonical_macho, :object?, :executable?, :fvmlib?, + :core?, :preload?, :dylib?, :dylinker?, :bundle?, + :dsym?, :kext?, :filetype, :dylib_id + + # @!method magic + # @return (see MachO::Headers::FatHeader#magic) + def_delegators :header, :magic # @return [String] a string representation of the file's magic number def magic_string - MH_MAGICS[magic] - end - - # The file's type. Assumed to be the same for every Mach-O within. - # @return [Symbol] the filetype - def filetype - machos.first.filetype + Headers::MH_MAGICS[magic] end # Populate the instance's fields with the raw Fat Mach-O data. @@ -128,21 +125,13 @@ def populate_fields end # All load commands responsible for loading dylibs in the file's Mach-O's. - # @return [Array<MachO::DylibCommand>] an array of DylibCommands + # @return [Array<LoadCommands::DylibCommand>] an array of DylibCommands def dylib_load_commands machos.map(&:dylib_load_commands).flatten end - # The file's dylib ID. If the file is not a dylib, returns `nil`. - # @example - # file.dylib_id # => 'libBar.dylib' - # @return [String, nil] the file's dylib ID - # @see MachO::MachOFile#linked_dylibs - def dylib_id - machos.first.dylib_id - end - - # Changes the file's dylib ID to `new_id`. If the file is not a dylib, does nothing. + # Changes the file's dylib ID to `new_id`. If the file is not a dylib, + # does nothing. # @example # file.change_dylib_id('libFoo.dylib') # @param new_id [String] the new dylib ID @@ -151,7 +140,7 @@ def dylib_id # if false, fail only if all slices fail. # @return [void] # @raise [ArgumentError] if `new_id` is not a String - # @see MachO::MachOFile#linked_dylibs + # @see MachOFile#linked_dylibs def change_dylib_id(new_id, options = {}) raise ArgumentError, "argument must be a String" unless new_id.is_a?(String) return unless machos.all?(&:dylib?) @@ -167,16 +156,17 @@ def change_dylib_id(new_id, options = {}) # All shared libraries linked to the file's Mach-Os. # @return [Array<String>] an array of all shared libraries - # @see MachO::MachOFile#linked_dylibs + # @see MachOFile#linked_dylibs def linked_dylibs # Individual architectures in a fat binary can link to different subsets # of libraries, but at this point we want to have the full picture, i.e. # the union of all libraries used by all architectures. machos.map(&:linked_dylibs).flatten.uniq end - # Changes all dependent shared library install names from `old_name` to `new_name`. - # In a fat file, this changes install names in all internal Mach-Os. + # Changes all dependent shared library install names from `old_name` to + # `new_name`. In a fat file, this changes install names in all internal + # Mach-Os. # @example # file.change_install_name('/usr/lib/libFoo.dylib', '/usr/lib/libBar.dylib') # @param old_name [String] the shared library name being changed @@ -185,7 +175,7 @@ def linked_dylibs # @option options [Boolean] :strict (true) if true, fail if one slice fails. # if false, fail only if all slices fail. # @return [void] - # @see MachO::MachOFile#change_install_name + # @see MachOFile#change_install_name def change_install_name(old_name, new_name, options = {}) each_macho(options) do |macho| macho.change_install_name(old_name, new_name, options) @@ -198,7 +188,7 @@ def change_install_name(old_name, new_name, options = {}) # All runtime paths associated with the file's Mach-Os. # @return [Array<String>] an array of all runtime paths - # @see MachO::MachOFile#rpaths + # @see MachOFile#rpaths def rpaths # Can individual architectures have different runtime paths? machos.map(&:rpaths).flatten.uniq @@ -211,7 +201,7 @@ def rpaths # @option options [Boolean] :strict (true) if true, fail if one slice fails. # if false, fail only if all slices fail. # @return [void] - # @see MachO::MachOFile#change_rpath + # @see MachOFile#change_rpath def change_rpath(old_path, new_path, options = {}) each_macho(options) do |macho| macho.change_rpath(old_path, new_path, options) @@ -226,7 +216,7 @@ def change_rpath(old_path, new_path, options = {}) # @option options [Boolean] :strict (true) if true, fail if one slice fails. # if false, fail only if all slices fail. # @return [void] - # @see MachO::MachOFile#add_rpath + # @see MachOFile#add_rpath def add_rpath(path, options = {}) each_macho(options) do |macho| macho.add_rpath(path, options) @@ -241,7 +231,7 @@ def add_rpath(path, options = {}) # @option options [Boolean] :strict (true) if true, fail if one slice fails. # if false, fail only if all slices fail. # @return void - # @see MachO::MachOFile#delete_rpath + # @see MachOFile#delete_rpath def delete_rpath(path, options = {}) each_macho(options) do |macho| macho.delete_rpath(path, options) @@ -254,20 +244,21 @@ def delete_rpath(path, options = {}) # @example # file.extract(:i386) # => MachO::MachOFile # @param cputype [Symbol] the CPU type of the Mach-O being extracted - # @return [MachO::MachOFile, nil] the extracted Mach-O or nil if no Mach-O has the given CPU type + # @return [MachOFile, nil] the extracted Mach-O or nil if no Mach-O has the given CPU type def extract(cputype) machos.select { |macho| macho.cputype == cputype }.first end # Write all (fat) data to the given filename. # @param filename [String] the file to write to + # @return [void] def write(filename) File.open(filename, "wb") { |f| f.write(@raw_data) } end # Write all (fat) data to the file used to initialize the instance. # @return [void] - # @raise [MachO::MachOError] if the instance was initialized without a file + # @raise [MachOError] if the instance was initialized without a file # @note Overwrites all data in the file! def write! if filename.nil? @@ -280,17 +271,18 @@ def write! private # Obtain the fat header from raw file data. - # @return [MachO::FatHeader] the fat header - # @raise [MachO::TruncatedFileError] if the file is too small to have a valid header - # @raise [MachO::MagicError] if the magic is not valid Mach-O magic - # @raise [MachO::MachOBinaryError] if the magic is for a non-fat Mach-O file - # @raise [MachO::JavaClassFileError] if the file is a Java classfile + # @return [Headers::FatHeader] the fat header + # @raise [TruncatedFileError] if the file is too small to have a + # valid header + # @raise [MagicError] if the magic is not valid Mach-O magic + # @raise [MachOBinaryError] if the magic is for a non-fat Mach-O file + # @raise [JavaClassFileError] if the file is a Java classfile # @api private def populate_fat_header # the smallest fat Mach-O header is 8 bytes raise TruncatedFileError if @raw_data.size < 8 - fh = FatHeader.new_from_bin(:big, @raw_data[0, FatHeader.bytesize]) + fh = Headers::FatHeader.new_from_bin(:big, @raw_data[0, Headers::FatHeader.bytesize]) raise MagicError, fh.magic unless Utils.magic?(fh.magic) raise MachOBinaryError unless Utils.fat_magic?(fh.magic) @@ -308,22 +300,22 @@ def populate_fat_header end # Obtain an array of fat architectures from raw file data. - # @return [Array<MachO::FatArch>] an array of fat architectures + # @return [Array<Headers::FatArch>] an array of fat architectures # @api private def populate_fat_archs archs = [] - fa_off = FatHeader.bytesize - fa_len = FatArch.bytesize + fa_off = Headers::FatHeader.bytesize + fa_len = Headers::FatArch.bytesize header.nfat_arch.times do |i| - archs << FatArch.new_from_bin(:big, @raw_data[fa_off + (fa_len * i), fa_len]) + archs << Headers::FatArch.new_from_bin(:big, @raw_data[fa_off + (fa_len * i), fa_len]) end archs end # Obtain an array of Mach-O blobs from raw file data. - # @return [Array<MachO::MachOFile>] an array of Mach-Os + # @return [Array<MachOFile>] an array of Mach-Os # @api private def populate_machos machos = [] @@ -351,7 +343,7 @@ def repopulate_raw_machos # @option options [Boolean] :strict (true) whether or not to fail loudly # with an exception if at least one Mach-O raises an exception. If false, # only raises an exception if *all* Mach-Os raise exceptions. - # @raise [MachO::RecoverableModificationError] under the conditions of + # @raise [RecoverableModificationError] under the conditions of # the `:strict` option above. # @api private def each_macho(options = {}) @@ -373,5 +365,13 @@ def each_macho(options = {}) # Non-strict mode: Raise first error if *all* Mach-O slices failed. raise errors.first if errors.size == machos.size end + + # Return a single-arch Mach-O that represents this fat Mach-O for purposes + # of delegation. + # @return [MachOFile] the Mach-O file + # @api private + def canonical_macho + machos.first + end end end
true
Other
Homebrew
brew
024264c381a5dc02dea8680dea29e83bdce9d13b.json
vendor: Update ruby-macho to 1.1.0.
Library/Homebrew/vendor/macho/macho/headers.rb
@@ -1,587 +1,665 @@ module MachO - # big-endian fat magic - # @api private - FAT_MAGIC = 0xcafebabe - - # little-endian fat magic - # this is defined, but should never appear in ruby-macho code because - # fat headers are always big-endian and therefore always unpacked as such. - # @api private - FAT_CIGAM = 0xbebafeca - - # 32-bit big-endian magic - # @api private - MH_MAGIC = 0xfeedface - - # 32-bit little-endian magic - # @api private - MH_CIGAM = 0xcefaedfe - - # 64-bit big-endian magic - # @api private - MH_MAGIC_64 = 0xfeedfacf - - # 64-bit little-endian magic - # @api private - MH_CIGAM_64 = 0xcffaedfe - - # association of magic numbers to string representations - # @api private - MH_MAGICS = { - FAT_MAGIC => "FAT_MAGIC", - MH_MAGIC => "MH_MAGIC", - MH_CIGAM => "MH_CIGAM", - MH_MAGIC_64 => "MH_MAGIC_64", - MH_CIGAM_64 => "MH_CIGAM_64", - }.freeze - - # mask for CPUs with 64-bit architectures (when running a 64-bit ABI?) - # @api private - CPU_ARCH_ABI64 = 0x01000000 - - # any CPU (unused?) - # @api private - CPU_TYPE_ANY = -1 - - # m68k compatible CPUs - # @api private - CPU_TYPE_MC680X0 = 0x06 - - # i386 and later compatible CPUs - # @api private - CPU_TYPE_I386 = 0x07 - - # x86_64 (AMD64) compatible CPUs - # @api private - CPU_TYPE_X86_64 = (CPU_TYPE_I386 | CPU_ARCH_ABI64) - - # 32-bit ARM compatible CPUs - # @api private - CPU_TYPE_ARM = 0x0c - - # m88k compatible CPUs - # @api private - CPU_TYPE_MC88000 = 0xd - - # 64-bit ARM compatible CPUs - # @api private - CPU_TYPE_ARM64 = (CPU_TYPE_ARM | CPU_ARCH_ABI64) - - # PowerPC compatible CPUs - # @api private - CPU_TYPE_POWERPC = 0x12 - - # PowerPC64 compatible CPUs - # @api private - CPU_TYPE_POWERPC64 = (CPU_TYPE_POWERPC | CPU_ARCH_ABI64) - - # association of cpu types to symbol representations - # @api private - CPU_TYPES = { - CPU_TYPE_ANY => :any, - CPU_TYPE_I386 => :i386, - CPU_TYPE_X86_64 => :x86_64, - CPU_TYPE_ARM => :arm, - CPU_TYPE_ARM64 => :arm64, - CPU_TYPE_POWERPC => :ppc, - CPU_TYPE_POWERPC64 => :ppc64, - }.freeze - - # mask for CPU subtype capabilities - # @api private - CPU_SUBTYPE_MASK = 0xff000000 - - # 64-bit libraries (undocumented!) - # @see http://llvm.org/docs/doxygen/html/Support_2MachO_8h_source.html - # @api private - CPU_SUBTYPE_LIB64 = 0x80000000 - - # the lowest common sub-type for `CPU_TYPE_I386` - # @api private - CPU_SUBTYPE_I386 = 3 - - # the i486 sub-type for `CPU_TYPE_I386` - # @api private - CPU_SUBTYPE_486 = 4 - - # the i486SX sub-type for `CPU_TYPE_I386` - # @api private - CPU_SUBTYPE_486SX = 132 - - # the i586 (P5, Pentium) sub-type for `CPU_TYPE_I386` - # @api private - CPU_SUBTYPE_586 = 5 - - # @see CPU_SUBTYPE_586 - # @api private - CPU_SUBTYPE_PENT = CPU_SUBTYPE_586 - - # the Pentium Pro (P6) sub-type for `CPU_TYPE_I386` - # @api private - CPU_SUBTYPE_PENTPRO = 22 - - # the Pentium II (P6, M3?) sub-type for `CPU_TYPE_I386` - # @api private - CPU_SUBTYPE_PENTII_M3 = 54 - - # the Pentium II (P6, M5?) sub-type for `CPU_TYPE_I386` - # @api private - CPU_SUBTYPE_PENTII_M5 = 86 - - # the Pentium 4 (Netburst) sub-type for `CPU_TYPE_I386` - # @api private - CPU_SUBTYPE_PENTIUM_4 = 10 - - # the lowest common sub-type for `CPU_TYPE_MC680X0` - # @api private - CPU_SUBTYPE_MC680X0_ALL = 1 - - # @see CPU_SUBTYPE_MC680X0_ALL - # @api private - CPU_SUBTYPE_MC68030 = CPU_SUBTYPE_MC680X0_ALL - - # the 040 subtype for `CPU_TYPE_MC680X0` - # @api private - CPU_SUBTYPE_MC68040 = 2 - - # the 030 subtype for `CPU_TYPE_MC680X0` - # @api private - CPU_SUBTYPE_MC68030_ONLY = 3 - - # the lowest common sub-type for `CPU_TYPE_X86_64` - # @api private - CPU_SUBTYPE_X86_64_ALL = CPU_SUBTYPE_I386 - - # the Haskell sub-type for `CPU_TYPE_X86_64` - # @api private - CPU_SUBTYPE_X86_64_H = 8 - - # the lowest common sub-type for `CPU_TYPE_ARM` - # @api private - CPU_SUBTYPE_ARM_ALL = 0 - - # the v4t sub-type for `CPU_TYPE_ARM` - # @api private - CPU_SUBTYPE_ARM_V4T = 5 - - # the v6 sub-type for `CPU_TYPE_ARM` - # @api private - CPU_SUBTYPE_ARM_V6 = 6 - - # the v5 sub-type for `CPU_TYPE_ARM` - # @api private - CPU_SUBTYPE_ARM_V5TEJ = 7 - - # the xscale (v5 family) sub-type for `CPU_TYPE_ARM` - # @api private - CPU_SUBTYPE_ARM_XSCALE = 8 - - # the v7 sub-type for `CPU_TYPE_ARM` - # @api private - CPU_SUBTYPE_ARM_V7 = 9 - - # the v7f (Cortex A9) sub-type for `CPU_TYPE_ARM` - # @api private - CPU_SUBTYPE_ARM_V7F = 10 + # Classes and constants for parsing the headers of Mach-O binaries. + module Headers + # big-endian fat magic + # @api private + FAT_MAGIC = 0xcafebabe - # the v7s ("Swift") sub-type for `CPU_TYPE_ARM` - # @api private - CPU_SUBTYPE_ARM_V7S = 11 + # little-endian fat magic + # this is defined, but should never appear in ruby-macho code because + # fat headers are always big-endian and therefore always unpacked as such. + # @api private + FAT_CIGAM = 0xbebafeca - # the v7k ("Kirkwood40") sub-type for `CPU_TYPE_ARM` - # @api private - CPU_SUBTYPE_ARM_V7K = 12 - - # the v6m sub-type for `CPU_TYPE_ARM` - # @api private - CPU_SUBTYPE_ARM_V6M = 14 - - # the v7m sub-type for `CPU_TYPE_ARM` - # @api private - CPU_SUBTYPE_ARM_V7M = 15 - - # the v7em sub-type for `CPU_TYPE_ARM` - # @api private - CPU_SUBTYPE_ARM_V7EM = 16 - - # the v8 sub-type for `CPU_TYPE_ARM` - # @api private - CPU_SUBTYPE_ARM_V8 = 13 - - # the lowest common sub-type for `CPU_TYPE_ARM64` - # @api private - CPU_SUBTYPE_ARM64_ALL = 0 - - # the v8 sub-type for `CPU_TYPE_ARM64` - # @api private - CPU_SUBTYPE_ARM64_V8 = 1 - - # the lowest common sub-type for `CPU_TYPE_MC88000` - # @api private - CPU_SUBTYPE_MC88000_ALL = 0 - - # @see CPU_SUBTYPE_MC88000_ALL - # @api private - CPU_SUBTYPE_MMAX_JPC = CPU_SUBTYPE_MC88000_ALL - - # the 100 sub-type for `CPU_TYPE_MC88000` - # @api private - CPU_SUBTYPE_MC88100 = 1 - - # the 110 sub-type for `CPU_TYPE_MC88000` - # @api private - CPU_SUBTYPE_MC88110 = 2 - - # the lowest common sub-type for `CPU_TYPE_POWERPC` - # @api private - CPU_SUBTYPE_POWERPC_ALL = 0 - - # the 601 sub-type for `CPU_TYPE_POWERPC` - # @api private - CPU_SUBTYPE_POWERPC_601 = 1 - - # the 602 sub-type for `CPU_TYPE_POWERPC` - # @api private - CPU_SUBTYPE_POWERPC_602 = 2 - - # the 603 sub-type for `CPU_TYPE_POWERPC` - # @api private - CPU_SUBTYPE_POWERPC_603 = 3 - - # the 603e (G2) sub-type for `CPU_TYPE_POWERPC` - # @api private - CPU_SUBTYPE_POWERPC_603E = 4 - - # the 603ev sub-type for `CPU_TYPE_POWERPC` - # @api private - CPU_SUBTYPE_POWERPC_603EV = 5 - - # the 604 sub-type for `CPU_TYPE_POWERPC` - # @api private - CPU_SUBTYPE_POWERPC_604 = 6 - - # the 604e sub-type for `CPU_TYPE_POWERPC` - # @api private - CPU_SUBTYPE_POWERPC_604E = 7 - - # the 620 sub-type for `CPU_TYPE_POWERPC` - # @api private - CPU_SUBTYPE_POWERPC_620 = 8 - - # the 750 (G3) sub-type for `CPU_TYPE_POWERPC` - # @api private - CPU_SUBTYPE_POWERPC_750 = 9 - - # the 7400 (G4) sub-type for `CPU_TYPE_POWERPC` - # @api private - CPU_SUBTYPE_POWERPC_7400 = 10 - - # the 7450 (G4 "Voyager") sub-type for `CPU_TYPE_POWERPC` - # @api private - CPU_SUBTYPE_POWERPC_7450 = 11 - - # the 970 (G5) sub-type for `CPU_TYPE_POWERPC` - # @api private - CPU_SUBTYPE_POWERPC_970 = 100 - - # any CPU sub-type for CPU type `CPU_TYPE_POWERPC64` - # @api private - CPU_SUBTYPE_POWERPC64_ALL = CPU_SUBTYPE_POWERPC_ALL - - # association of CPU types/subtype pairs to symbol representations in - # (very) roughly descending order of commonness - # @see https://opensource.apple.com/source/cctools/cctools-877.8/libstuff/arch.c - # @api private - CPU_SUBTYPES = { - CPU_TYPE_I386 => { - CPU_SUBTYPE_I386 => :i386, - CPU_SUBTYPE_486 => :i486, - CPU_SUBTYPE_486SX => :i486SX, - CPU_SUBTYPE_586 => :i586, # also "pentium" in arch(3) - CPU_SUBTYPE_PENTPRO => :i686, # also "pentpro" in arch(3) - CPU_SUBTYPE_PENTII_M3 => :pentIIm3, - CPU_SUBTYPE_PENTII_M5 => :pentIIm5, - CPU_SUBTYPE_PENTIUM_4 => :pentium4, - }.freeze, - CPU_TYPE_X86_64 => { - CPU_SUBTYPE_X86_64_ALL => :x86_64, - CPU_SUBTYPE_X86_64_H => :x86_64h, - }.freeze, - CPU_TYPE_ARM => { - CPU_SUBTYPE_ARM_ALL => :arm, - CPU_SUBTYPE_ARM_V4T => :armv4t, - CPU_SUBTYPE_ARM_V6 => :armv6, - CPU_SUBTYPE_ARM_V5TEJ => :armv5, - CPU_SUBTYPE_ARM_XSCALE => :xscale, - CPU_SUBTYPE_ARM_V7 => :armv7, - CPU_SUBTYPE_ARM_V7F => :armv7f, - CPU_SUBTYPE_ARM_V7S => :armv7s, - CPU_SUBTYPE_ARM_V7K => :armv7k, - CPU_SUBTYPE_ARM_V6M => :armv6m, - CPU_SUBTYPE_ARM_V7M => :armv7m, - CPU_SUBTYPE_ARM_V7EM => :armv7em, - CPU_SUBTYPE_ARM_V8 => :armv8, - }.freeze, - CPU_TYPE_ARM64 => { - CPU_SUBTYPE_ARM64_ALL => :arm64, - CPU_SUBTYPE_ARM64_V8 => :arm64v8, - }.freeze, - CPU_TYPE_POWERPC => { - CPU_SUBTYPE_POWERPC_ALL => :ppc, - CPU_SUBTYPE_POWERPC_601 => :ppc601, - CPU_SUBTYPE_POWERPC_603 => :ppc603, - CPU_SUBTYPE_POWERPC_603E => :ppc603e, - CPU_SUBTYPE_POWERPC_603EV => :ppc603ev, - CPU_SUBTYPE_POWERPC_604 => :ppc604, - CPU_SUBTYPE_POWERPC_604E => :ppc604e, - CPU_SUBTYPE_POWERPC_750 => :ppc750, - CPU_SUBTYPE_POWERPC_7400 => :ppc7400, - CPU_SUBTYPE_POWERPC_7450 => :ppc7450, - CPU_SUBTYPE_POWERPC_970 => :ppc970, - }.freeze, - CPU_TYPE_POWERPC64 => { - CPU_SUBTYPE_POWERPC64_ALL => :ppc64, - # apparently the only exception to the naming scheme - CPU_SUBTYPE_POWERPC_970 => :ppc970_64, - }.freeze, - CPU_TYPE_MC680X0 => { - CPU_SUBTYPE_MC680X0_ALL => :m68k, - CPU_SUBTYPE_MC68030 => :mc68030, - CPU_SUBTYPE_MC68040 => :mc68040, - }, - CPU_TYPE_MC88000 => { - CPU_SUBTYPE_MC88000_ALL => :m88k, - }, - }.freeze - - # relocatable object file - # @api private - MH_OBJECT = 0x1 - - # demand paged executable file - # @api private - MH_EXECUTE = 0x2 - - # fixed VM shared library file - # @api private - MH_FVMLIB = 0x3 - - # core dump file - # @api private - MH_CORE = 0x4 - - # preloaded executable file - # @api private - MH_PRELOAD = 0x5 - - # dynamically bound shared library - # @api private - MH_DYLIB = 0x6 - - # dynamic link editor - # @api private - MH_DYLINKER = 0x7 - - # dynamically bound bundle file - # @api private - MH_BUNDLE = 0x8 - - # shared library stub for static linking only, no section contents - # @api private - MH_DYLIB_STUB = 0x9 - - # companion file with only debug sections - # @api private - MH_DSYM = 0xa - - # x86_64 kexts - # @api private - MH_KEXT_BUNDLE = 0xb - - # association of filetypes to Symbol representations - # @api private - MH_FILETYPES = { - MH_OBJECT => :object, - MH_EXECUTE => :execute, - MH_FVMLIB => :fvmlib, - MH_CORE => :core, - MH_PRELOAD => :preload, - MH_DYLIB => :dylib, - MH_DYLINKER => :dylinker, - MH_BUNDLE => :bundle, - MH_DYLIB_STUB => :dylib_stub, - MH_DSYM => :dsym, - MH_KEXT_BUNDLE => :kext_bundle, - }.freeze - - # association of mach header flag symbols to values - # @api private - MH_FLAGS = { - :MH_NOUNDEFS => 0x1, - :MH_INCRLINK => 0x2, - :MH_DYLDLINK => 0x4, - :MH_BINDATLOAD => 0x8, - :MH_PREBOUND => 0x10, - :MH_SPLIT_SEGS => 0x20, - :MH_LAZY_INIT => 0x40, - :MH_TWOLEVEL => 0x80, - :MH_FORCE_FLAT => 0x100, - :MH_NOMULTIDEFS => 0x200, - :MH_NOPREFIXBINDING => 0x400, - :MH_PREBINDABLE => 0x800, - :MH_ALLMODSBOUND => 0x1000, - :MH_SUBSECTIONS_VIA_SYMBOLS => 0x2000, - :MH_CANONICAL => 0x4000, - :MH_WEAK_DEFINES => 0x8000, - :MH_BINDS_TO_WEAK => 0x10000, - :MH_ALLOW_STACK_EXECUTION => 0x20000, - :MH_ROOT_SAFE => 0x40000, - :MH_SETUID_SAFE => 0x80000, - :MH_NO_REEXPORTED_DYLIBS => 0x100000, - :MH_PIE => 0x200000, - :MH_DEAD_STRIPPABLE_DYLIB => 0x400000, - :MH_HAS_TLV_DESCRIPTORS => 0x800000, - :MH_NO_HEAP_EXECUTION => 0x1000000, - :MH_APP_EXTENSION_SAFE => 0x02000000, - }.freeze - - # Fat binary header structure - # @see MachO::FatArch - class FatHeader < MachOStructure - # @return [Fixnum] the magic number of the header (and file) - attr_reader :magic - - # @return [Fixnum] the number of fat architecture structures following the header - attr_reader :nfat_arch - - # always big-endian - # @see MachOStructure::FORMAT - # @api private - FORMAT = "N2".freeze - - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 8 - - # @api private - def initialize(magic, nfat_arch) - @magic = magic - @nfat_arch = nfat_arch - end - end + # 32-bit big-endian magic + # @api private + MH_MAGIC = 0xfeedface - # Fat binary header architecture structure. A Fat binary has one or more of - # these, representing one or more internal Mach-O blobs. - # @see MachO::FatHeader - class FatArch < MachOStructure - # @return [Fixnum] the CPU type of the Mach-O - attr_reader :cputype + # 32-bit little-endian magic + # @api private + MH_CIGAM = 0xcefaedfe - # @return [Fixnum] the CPU subtype of the Mach-O - attr_reader :cpusubtype + # 64-bit big-endian magic + # @api private + MH_MAGIC_64 = 0xfeedfacf - # @return [Fixnum] the file offset to the beginning of the Mach-O data - attr_reader :offset + # 64-bit little-endian magic + # @api private + MH_CIGAM_64 = 0xcffaedfe - # @return [Fixnum] the size, in bytes, of the Mach-O data - attr_reader :size + # association of magic numbers to string representations + # @api private + MH_MAGICS = { + FAT_MAGIC => "FAT_MAGIC", + MH_MAGIC => "MH_MAGIC", + MH_CIGAM => "MH_CIGAM", + MH_MAGIC_64 => "MH_MAGIC_64", + MH_CIGAM_64 => "MH_CIGAM_64", + }.freeze + + # mask for CPUs with 64-bit architectures (when running a 64-bit ABI?) + # @api private + CPU_ARCH_ABI64 = 0x01000000 - # @return [Fixnum] the alignment, as a power of 2 - attr_reader :align + # any CPU (unused?) + # @api private + CPU_TYPE_ANY = -1 - # always big-endian - # @see MachOStructure::FORMAT + # m68k compatible CPUs # @api private - FORMAT = "N5".freeze + CPU_TYPE_MC680X0 = 0x06 - # @see MachOStructure::SIZEOF + # i386 and later compatible CPUs # @api private - SIZEOF = 20 + CPU_TYPE_I386 = 0x07 + # x86_64 (AMD64) compatible CPUs # @api private - def initialize(cputype, cpusubtype, offset, size, align) - @cputype = cputype - @cpusubtype = cpusubtype - @offset = offset - @size = size - @align = align - end - end + CPU_TYPE_X86_64 = (CPU_TYPE_I386 | CPU_ARCH_ABI64) - # 32-bit Mach-O file header structure - class MachHeader < MachOStructure - # @return [Fixnum] the magic number - attr_reader :magic + # 32-bit ARM compatible CPUs + # @api private + CPU_TYPE_ARM = 0x0c - # @return [Fixnum] the CPU type of the Mach-O - attr_reader :cputype + # m88k compatible CPUs + # @api private + CPU_TYPE_MC88000 = 0xd - # @return [Fixnum] the CPU subtype of the Mach-O - attr_reader :cpusubtype + # 64-bit ARM compatible CPUs + # @api private + CPU_TYPE_ARM64 = (CPU_TYPE_ARM | CPU_ARCH_ABI64) - # @return [Fixnum] the file type of the Mach-O - attr_reader :filetype + # PowerPC compatible CPUs + # @api private + CPU_TYPE_POWERPC = 0x12 - # @return [Fixnum] the number of load commands in the Mach-O - attr_reader :ncmds + # PowerPC64 compatible CPUs + # @api private + CPU_TYPE_POWERPC64 = (CPU_TYPE_POWERPC | CPU_ARCH_ABI64) - # @return [Fixnum] the size of all load commands, in bytes, in the Mach-O - attr_reader :sizeofcmds + # association of cpu types to symbol representations + # @api private + CPU_TYPES = { + CPU_TYPE_ANY => :any, + CPU_TYPE_I386 => :i386, + CPU_TYPE_X86_64 => :x86_64, + CPU_TYPE_ARM => :arm, + CPU_TYPE_ARM64 => :arm64, + CPU_TYPE_POWERPC => :ppc, + CPU_TYPE_POWERPC64 => :ppc64, + }.freeze + + # mask for CPU subtype capabilities + # @api private + CPU_SUBTYPE_MASK = 0xff000000 - # @return [Fixnum] the header flags associated with the Mach-O - attr_reader :flags + # 64-bit libraries (undocumented!) + # @see http://llvm.org/docs/doxygen/html/Support_2MachO_8h_source.html + # @api private + CPU_SUBTYPE_LIB64 = 0x80000000 - # @see MachOStructure::FORMAT + # the lowest common sub-type for `CPU_TYPE_I386` # @api private - FORMAT = "L=7".freeze + CPU_SUBTYPE_I386 = 3 - # @see MachOStructure::SIZEOF + # the i486 sub-type for `CPU_TYPE_I386` # @api private - SIZEOF = 28 + CPU_SUBTYPE_486 = 4 + # the i486SX sub-type for `CPU_TYPE_I386` # @api private - def initialize(magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds, - flags) - @magic = magic - @cputype = cputype - # For now we're not interested in additional capability bits also to be - # found in the `cpusubtype` field. We only care about the CPU sub-type. - @cpusubtype = cpusubtype & ~CPU_SUBTYPE_MASK - @filetype = filetype - @ncmds = ncmds - @sizeofcmds = sizeofcmds - @flags = flags - end + CPU_SUBTYPE_486SX = 132 - # @example - # puts "this mach-o has position-independent execution" if header.flag?(:MH_PIE) - # @param flag [Symbol] a mach header flag symbol - # @return [Boolean] true if `flag` is present in the header's flag section - def flag?(flag) - flag = MH_FLAGS[flag] - return false if flag.nil? - flags & flag == flag - end - end + # the i586 (P5, Pentium) sub-type for `CPU_TYPE_I386` + # @api private + CPU_SUBTYPE_586 = 5 + + # @see CPU_SUBTYPE_586 + # @api private + CPU_SUBTYPE_PENT = CPU_SUBTYPE_586 + + # the Pentium Pro (P6) sub-type for `CPU_TYPE_I386` + # @api private + CPU_SUBTYPE_PENTPRO = 22 + + # the Pentium II (P6, M3?) sub-type for `CPU_TYPE_I386` + # @api private + CPU_SUBTYPE_PENTII_M3 = 54 + + # the Pentium II (P6, M5?) sub-type for `CPU_TYPE_I386` + # @api private + CPU_SUBTYPE_PENTII_M5 = 86 + + # the Pentium 4 (Netburst) sub-type for `CPU_TYPE_I386` + # @api private + CPU_SUBTYPE_PENTIUM_4 = 10 + + # the lowest common sub-type for `CPU_TYPE_MC680X0` + # @api private + CPU_SUBTYPE_MC680X0_ALL = 1 + + # @see CPU_SUBTYPE_MC680X0_ALL + # @api private + CPU_SUBTYPE_MC68030 = CPU_SUBTYPE_MC680X0_ALL + + # the 040 subtype for `CPU_TYPE_MC680X0` + # @api private + CPU_SUBTYPE_MC68040 = 2 + + # the 030 subtype for `CPU_TYPE_MC680X0` + # @api private + CPU_SUBTYPE_MC68030_ONLY = 3 + + # the lowest common sub-type for `CPU_TYPE_X86_64` + # @api private + CPU_SUBTYPE_X86_64_ALL = CPU_SUBTYPE_I386 + + # the Haskell sub-type for `CPU_TYPE_X86_64` + # @api private + CPU_SUBTYPE_X86_64_H = 8 + + # the lowest common sub-type for `CPU_TYPE_ARM` + # @api private + CPU_SUBTYPE_ARM_ALL = 0 + + # the v4t sub-type for `CPU_TYPE_ARM` + # @api private + CPU_SUBTYPE_ARM_V4T = 5 + + # the v6 sub-type for `CPU_TYPE_ARM` + # @api private + CPU_SUBTYPE_ARM_V6 = 6 + + # the v5 sub-type for `CPU_TYPE_ARM` + # @api private + CPU_SUBTYPE_ARM_V5TEJ = 7 + + # the xscale (v5 family) sub-type for `CPU_TYPE_ARM` + # @api private + CPU_SUBTYPE_ARM_XSCALE = 8 + + # the v7 sub-type for `CPU_TYPE_ARM` + # @api private + CPU_SUBTYPE_ARM_V7 = 9 + + # the v7f (Cortex A9) sub-type for `CPU_TYPE_ARM` + # @api private + CPU_SUBTYPE_ARM_V7F = 10 + + # the v7s ("Swift") sub-type for `CPU_TYPE_ARM` + # @api private + CPU_SUBTYPE_ARM_V7S = 11 + + # the v7k ("Kirkwood40") sub-type for `CPU_TYPE_ARM` + # @api private + CPU_SUBTYPE_ARM_V7K = 12 + + # the v6m sub-type for `CPU_TYPE_ARM` + # @api private + CPU_SUBTYPE_ARM_V6M = 14 + + # the v7m sub-type for `CPU_TYPE_ARM` + # @api private + CPU_SUBTYPE_ARM_V7M = 15 - # 64-bit Mach-O file header structure - class MachHeader64 < MachHeader - # @return [void] - attr_reader :reserved + # the v7em sub-type for `CPU_TYPE_ARM` + # @api private + CPU_SUBTYPE_ARM_V7EM = 16 + + # the v8 sub-type for `CPU_TYPE_ARM` + # @api private + CPU_SUBTYPE_ARM_V8 = 13 + + # the lowest common sub-type for `CPU_TYPE_ARM64` + # @api private + CPU_SUBTYPE_ARM64_ALL = 0 + + # the v8 sub-type for `CPU_TYPE_ARM64` + # @api private + CPU_SUBTYPE_ARM64_V8 = 1 + + # the lowest common sub-type for `CPU_TYPE_MC88000` + # @api private + CPU_SUBTYPE_MC88000_ALL = 0 + + # @see CPU_SUBTYPE_MC88000_ALL + # @api private + CPU_SUBTYPE_MMAX_JPC = CPU_SUBTYPE_MC88000_ALL + + # the 100 sub-type for `CPU_TYPE_MC88000` + # @api private + CPU_SUBTYPE_MC88100 = 1 + + # the 110 sub-type for `CPU_TYPE_MC88000` + # @api private + CPU_SUBTYPE_MC88110 = 2 + + # the lowest common sub-type for `CPU_TYPE_POWERPC` + # @api private + CPU_SUBTYPE_POWERPC_ALL = 0 + + # the 601 sub-type for `CPU_TYPE_POWERPC` + # @api private + CPU_SUBTYPE_POWERPC_601 = 1 + + # the 602 sub-type for `CPU_TYPE_POWERPC` + # @api private + CPU_SUBTYPE_POWERPC_602 = 2 + + # the 603 sub-type for `CPU_TYPE_POWERPC` + # @api private + CPU_SUBTYPE_POWERPC_603 = 3 + + # the 603e (G2) sub-type for `CPU_TYPE_POWERPC` + # @api private + CPU_SUBTYPE_POWERPC_603E = 4 + + # the 603ev sub-type for `CPU_TYPE_POWERPC` + # @api private + CPU_SUBTYPE_POWERPC_603EV = 5 + + # the 604 sub-type for `CPU_TYPE_POWERPC` + # @api private + CPU_SUBTYPE_POWERPC_604 = 6 + + # the 604e sub-type for `CPU_TYPE_POWERPC` + # @api private + CPU_SUBTYPE_POWERPC_604E = 7 + + # the 620 sub-type for `CPU_TYPE_POWERPC` + # @api private + CPU_SUBTYPE_POWERPC_620 = 8 + + # the 750 (G3) sub-type for `CPU_TYPE_POWERPC` + # @api private + CPU_SUBTYPE_POWERPC_750 = 9 - # @see MachOStructure::FORMAT + # the 7400 (G4) sub-type for `CPU_TYPE_POWERPC` # @api private - FORMAT = "L=8".freeze + CPU_SUBTYPE_POWERPC_7400 = 10 - # @see MachOStructure::SIZEOF + # the 7450 (G4 "Voyager") sub-type for `CPU_TYPE_POWERPC` # @api private - SIZEOF = 32 + CPU_SUBTYPE_POWERPC_7450 = 11 + # the 970 (G5) sub-type for `CPU_TYPE_POWERPC` # @api private - def initialize(magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds, - flags, reserved) - super(magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds, flags) - @reserved = reserved + CPU_SUBTYPE_POWERPC_970 = 100 + + # any CPU sub-type for CPU type `CPU_TYPE_POWERPC64` + # @api private + CPU_SUBTYPE_POWERPC64_ALL = CPU_SUBTYPE_POWERPC_ALL + + # association of CPU types/subtype pairs to symbol representations in + # (very) roughly descending order of commonness + # @see https://opensource.apple.com/source/cctools/cctools-877.8/libstuff/arch.c + # @api private + CPU_SUBTYPES = { + CPU_TYPE_I386 => { + CPU_SUBTYPE_I386 => :i386, + CPU_SUBTYPE_486 => :i486, + CPU_SUBTYPE_486SX => :i486SX, + CPU_SUBTYPE_586 => :i586, # also "pentium" in arch(3) + CPU_SUBTYPE_PENTPRO => :i686, # also "pentpro" in arch(3) + CPU_SUBTYPE_PENTII_M3 => :pentIIm3, + CPU_SUBTYPE_PENTII_M5 => :pentIIm5, + CPU_SUBTYPE_PENTIUM_4 => :pentium4, + }.freeze, + CPU_TYPE_X86_64 => { + CPU_SUBTYPE_X86_64_ALL => :x86_64, + CPU_SUBTYPE_X86_64_H => :x86_64h, + }.freeze, + CPU_TYPE_ARM => { + CPU_SUBTYPE_ARM_ALL => :arm, + CPU_SUBTYPE_ARM_V4T => :armv4t, + CPU_SUBTYPE_ARM_V6 => :armv6, + CPU_SUBTYPE_ARM_V5TEJ => :armv5, + CPU_SUBTYPE_ARM_XSCALE => :xscale, + CPU_SUBTYPE_ARM_V7 => :armv7, + CPU_SUBTYPE_ARM_V7F => :armv7f, + CPU_SUBTYPE_ARM_V7S => :armv7s, + CPU_SUBTYPE_ARM_V7K => :armv7k, + CPU_SUBTYPE_ARM_V6M => :armv6m, + CPU_SUBTYPE_ARM_V7M => :armv7m, + CPU_SUBTYPE_ARM_V7EM => :armv7em, + CPU_SUBTYPE_ARM_V8 => :armv8, + }.freeze, + CPU_TYPE_ARM64 => { + CPU_SUBTYPE_ARM64_ALL => :arm64, + CPU_SUBTYPE_ARM64_V8 => :arm64v8, + }.freeze, + CPU_TYPE_POWERPC => { + CPU_SUBTYPE_POWERPC_ALL => :ppc, + CPU_SUBTYPE_POWERPC_601 => :ppc601, + CPU_SUBTYPE_POWERPC_603 => :ppc603, + CPU_SUBTYPE_POWERPC_603E => :ppc603e, + CPU_SUBTYPE_POWERPC_603EV => :ppc603ev, + CPU_SUBTYPE_POWERPC_604 => :ppc604, + CPU_SUBTYPE_POWERPC_604E => :ppc604e, + CPU_SUBTYPE_POWERPC_750 => :ppc750, + CPU_SUBTYPE_POWERPC_7400 => :ppc7400, + CPU_SUBTYPE_POWERPC_7450 => :ppc7450, + CPU_SUBTYPE_POWERPC_970 => :ppc970, + }.freeze, + CPU_TYPE_POWERPC64 => { + CPU_SUBTYPE_POWERPC64_ALL => :ppc64, + # apparently the only exception to the naming scheme + CPU_SUBTYPE_POWERPC_970 => :ppc970_64, + }.freeze, + CPU_TYPE_MC680X0 => { + CPU_SUBTYPE_MC680X0_ALL => :m68k, + CPU_SUBTYPE_MC68030 => :mc68030, + CPU_SUBTYPE_MC68040 => :mc68040, + }, + CPU_TYPE_MC88000 => { + CPU_SUBTYPE_MC88000_ALL => :m88k, + }, + }.freeze + + # relocatable object file + # @api private + MH_OBJECT = 0x1 + + # demand paged executable file + # @api private + MH_EXECUTE = 0x2 + + # fixed VM shared library file + # @api private + MH_FVMLIB = 0x3 + + # core dump file + # @api private + MH_CORE = 0x4 + + # preloaded executable file + # @api private + MH_PRELOAD = 0x5 + + # dynamically bound shared library + # @api private + MH_DYLIB = 0x6 + + # dynamic link editor + # @api private + MH_DYLINKER = 0x7 + + # dynamically bound bundle file + # @api private + MH_BUNDLE = 0x8 + + # shared library stub for static linking only, no section contents + # @api private + MH_DYLIB_STUB = 0x9 + + # companion file with only debug sections + # @api private + MH_DSYM = 0xa + + # x86_64 kexts + # @api private + MH_KEXT_BUNDLE = 0xb + + # association of filetypes to Symbol representations + # @api private + MH_FILETYPES = { + MH_OBJECT => :object, + MH_EXECUTE => :execute, + MH_FVMLIB => :fvmlib, + MH_CORE => :core, + MH_PRELOAD => :preload, + MH_DYLIB => :dylib, + MH_DYLINKER => :dylinker, + MH_BUNDLE => :bundle, + MH_DYLIB_STUB => :dylib_stub, + MH_DSYM => :dsym, + MH_KEXT_BUNDLE => :kext_bundle, + }.freeze + + # association of mach header flag symbols to values + # @api private + MH_FLAGS = { + :MH_NOUNDEFS => 0x1, + :MH_INCRLINK => 0x2, + :MH_DYLDLINK => 0x4, + :MH_BINDATLOAD => 0x8, + :MH_PREBOUND => 0x10, + :MH_SPLIT_SEGS => 0x20, + :MH_LAZY_INIT => 0x40, + :MH_TWOLEVEL => 0x80, + :MH_FORCE_FLAT => 0x100, + :MH_NOMULTIDEFS => 0x200, + :MH_NOPREFIXBINDING => 0x400, + :MH_PREBINDABLE => 0x800, + :MH_ALLMODSBOUND => 0x1000, + :MH_SUBSECTIONS_VIA_SYMBOLS => 0x2000, + :MH_CANONICAL => 0x4000, + :MH_WEAK_DEFINES => 0x8000, + :MH_BINDS_TO_WEAK => 0x10000, + :MH_ALLOW_STACK_EXECUTION => 0x20000, + :MH_ROOT_SAFE => 0x40000, + :MH_SETUID_SAFE => 0x80000, + :MH_NO_REEXPORTED_DYLIBS => 0x100000, + :MH_PIE => 0x200000, + :MH_DEAD_STRIPPABLE_DYLIB => 0x400000, + :MH_HAS_TLV_DESCRIPTORS => 0x800000, + :MH_NO_HEAP_EXECUTION => 0x1000000, + :MH_APP_EXTENSION_SAFE => 0x02000000, + }.freeze + + # Fat binary header structure + # @see MachO::FatArch + class FatHeader < MachOStructure + # @return [Fixnum] the magic number of the header (and file) + attr_reader :magic + + # @return [Fixnum] the number of fat architecture structures following the header + attr_reader :nfat_arch + + # always big-endian + # @see MachOStructure::FORMAT + # @api private + FORMAT = "N2".freeze + + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 8 + + # @api private + def initialize(magic, nfat_arch) + @magic = magic + @nfat_arch = nfat_arch + end + + # @return [String] the serialized fields of the fat header + def serialize + [magic, nfat_arch].pack(FORMAT) + end + end + + # Fat binary header architecture structure. A Fat binary has one or more of + # these, representing one or more internal Mach-O blobs. + # @see MachO::Headers::FatHeader + class FatArch < MachOStructure + # @return [Fixnum] the CPU type of the Mach-O + attr_reader :cputype + + # @return [Fixnum] the CPU subtype of the Mach-O + attr_reader :cpusubtype + + # @return [Fixnum] the file offset to the beginning of the Mach-O data + attr_reader :offset + + # @return [Fixnum] the size, in bytes, of the Mach-O data + attr_reader :size + + # @return [Fixnum] the alignment, as a power of 2 + attr_reader :align + + # always big-endian + # @see MachOStructure::FORMAT + # @api private + FORMAT = "N5".freeze + + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 20 + + # @api private + def initialize(cputype, cpusubtype, offset, size, align) + @cputype = cputype + @cpusubtype = cpusubtype + @offset = offset + @size = size + @align = align + end + + # @return [String] the serialized fields of the fat arch + def serialize + [cputype, cpusubtype, offset, size, align].pack(FORMAT) + end + end + + # 32-bit Mach-O file header structure + class MachHeader < MachOStructure + # @return [Fixnum] the magic number + attr_reader :magic + + # @return [Fixnum] the CPU type of the Mach-O + attr_reader :cputype + + # @return [Fixnum] the CPU subtype of the Mach-O + attr_reader :cpusubtype + + # @return [Fixnum] the file type of the Mach-O + attr_reader :filetype + + # @return [Fixnum] the number of load commands in the Mach-O + attr_reader :ncmds + + # @return [Fixnum] the size of all load commands, in bytes, in the Mach-O + attr_reader :sizeofcmds + + # @return [Fixnum] the header flags associated with the Mach-O + attr_reader :flags + + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=7".freeze + + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 28 + + # @api private + def initialize(magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds, + flags) + @magic = magic + @cputype = cputype + # For now we're not interested in additional capability bits also to be + # found in the `cpusubtype` field. We only care about the CPU sub-type. + @cpusubtype = cpusubtype & ~CPU_SUBTYPE_MASK + @filetype = filetype + @ncmds = ncmds + @sizeofcmds = sizeofcmds + @flags = flags + end + + # @example + # puts "this mach-o has position-independent execution" if header.flag?(:MH_PIE) + # @param flag [Symbol] a mach header flag symbol + # @return [Boolean] true if `flag` is present in the header's flag section + def flag?(flag) + flag = MH_FLAGS[flag] + return false if flag.nil? + flags & flag == flag + end + + # @return [Boolean] whether or not the file is of type `MH_OBJECT` + def object? + filetype == Headers::MH_OBJECT + end + + # @return [Boolean] whether or not the file is of type `MH_EXECUTE` + def executable? + filetype == Headers::MH_EXECUTE + end + + # @return [Boolean] whether or not the file is of type `MH_FVMLIB` + def fvmlib? + filetype == Headers::MH_FVMLIB + end + + # @return [Boolean] whether or not the file is of type `MH_CORE` + def core? + filetype == Headers::MH_CORE + end + + # @return [Boolean] whether or not the file is of type `MH_PRELOAD` + def preload? + filetype == Headers::MH_PRELOAD + end + + # @return [Boolean] whether or not the file is of type `MH_DYLIB` + def dylib? + filetype == Headers::MH_DYLIB + end + + # @return [Boolean] whether or not the file is of type `MH_DYLINKER` + def dylinker? + filetype == Headers::MH_DYLINKER + end + + # @return [Boolean] whether or not the file is of type `MH_BUNDLE` + def bundle? + filetype == Headers::MH_BUNDLE + end + + # @return [Boolean] whether or not the file is of type `MH_DSYM` + def dsym? + filetype == Headers::MH_DSYM + end + + # @return [Boolean] whether or not the file is of type `MH_KEXT_BUNDLE` + def kext? + filetype == Headers::MH_KEXT_BUNDLE + end + + # @return [Boolean] true if the Mach-O has 32-bit magic, false otherwise + def magic32? + Utils.magic32?(magic) + end + + # @return [Boolean] true if the Mach-O has 64-bit magic, false otherwise + def magic64? + Utils.magic64?(magic) + end + + # @return [Fixnum] the file's internal alignment + def alignment + magic32? ? 4 : 8 + end + end + + # 64-bit Mach-O file header structure + class MachHeader64 < MachHeader + # @return [void] + attr_reader :reserved + + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=8".freeze + + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 32 + + # @api private + def initialize(magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds, + flags, reserved) + super(magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds, flags) + @reserved = reserved + end end end end
true
Other
Homebrew
brew
024264c381a5dc02dea8680dea29e83bdce9d13b.json
vendor: Update ruby-macho to 1.1.0.
Library/Homebrew/vendor/macho/macho/load_commands.rb
@@ -1,1314 +1,1350 @@ module MachO - # load commands added after OS X 10.1 need to be bitwise ORed with - # LC_REQ_DYLD to be recognized by the dynamic linder (dyld) - # @api private - LC_REQ_DYLD = 0x80000000 - - # association of load commands to symbol representations - # @api private - LOAD_COMMANDS = { - 0x1 => :LC_SEGMENT, - 0x2 => :LC_SYMTAB, - 0x3 => :LC_SYMSEG, - 0x4 => :LC_THREAD, - 0x5 => :LC_UNIXTHREAD, - 0x6 => :LC_LOADFVMLIB, - 0x7 => :LC_IDFVMLIB, - 0x8 => :LC_IDENT, - 0x9 => :LC_FVMFILE, - 0xa => :LC_PREPAGE, - 0xb => :LC_DYSYMTAB, - 0xc => :LC_LOAD_DYLIB, - 0xd => :LC_ID_DYLIB, - 0xe => :LC_LOAD_DYLINKER, - 0xf => :LC_ID_DYLINKER, - 0x10 => :LC_PREBOUND_DYLIB, - 0x11 => :LC_ROUTINES, - 0x12 => :LC_SUB_FRAMEWORK, - 0x13 => :LC_SUB_UMBRELLA, - 0x14 => :LC_SUB_CLIENT, - 0x15 => :LC_SUB_LIBRARY, - 0x16 => :LC_TWOLEVEL_HINTS, - 0x17 => :LC_PREBIND_CKSUM, - (0x18 | LC_REQ_DYLD) => :LC_LOAD_WEAK_DYLIB, - 0x19 => :LC_SEGMENT_64, - 0x1a => :LC_ROUTINES_64, - 0x1b => :LC_UUID, - (0x1c | LC_REQ_DYLD) => :LC_RPATH, - 0x1d => :LC_CODE_SIGNATURE, - 0x1e => :LC_SEGMENT_SPLIT_INFO, - (0x1f | LC_REQ_DYLD) => :LC_REEXPORT_DYLIB, - 0x20 => :LC_LAZY_LOAD_DYLIB, - 0x21 => :LC_ENCRYPTION_INFO, - 0x22 => :LC_DYLD_INFO, - (0x22 | LC_REQ_DYLD) => :LC_DYLD_INFO_ONLY, - (0x23 | LC_REQ_DYLD) => :LC_LOAD_UPWARD_DYLIB, - 0x24 => :LC_VERSION_MIN_MACOSX, - 0x25 => :LC_VERSION_MIN_IPHONEOS, - 0x26 => :LC_FUNCTION_STARTS, - 0x27 => :LC_DYLD_ENVIRONMENT, - (0x28 | LC_REQ_DYLD) => :LC_MAIN, - 0x29 => :LC_DATA_IN_CODE, - 0x2a => :LC_SOURCE_VERSION, - 0x2b => :LC_DYLIB_CODE_SIGN_DRS, - 0x2c => :LC_ENCRYPTION_INFO_64, - 0x2d => :LC_LINKER_OPTION, - 0x2e => :LC_LINKER_OPTIMIZATION_HINT, - 0x2f => :LC_VERSION_MIN_TVOS, - 0x30 => :LC_VERSION_MIN_WATCHOS, - }.freeze - - # association of symbol representations to load command constants - # @api private - LOAD_COMMAND_CONSTANTS = LOAD_COMMANDS.invert.freeze - - # load commands responsible for loading dylibs - # @api private - DYLIB_LOAD_COMMANDS = [ - :LC_LOAD_DYLIB, - :LC_LOAD_WEAK_DYLIB, - :LC_REEXPORT_DYLIB, - :LC_LAZY_LOAD_DYLIB, - :LC_LOAD_UPWARD_DYLIB, - ].freeze - - # load commands that can be created manually via {LoadCommand.create} - # @api private - CREATABLE_LOAD_COMMANDS = DYLIB_LOAD_COMMANDS + [ - :LC_ID_DYLIB, - :LC_RPATH, - :LC_LOAD_DYLINKER, - ].freeze - - # association of load command symbols to string representations of classes - # @api private - LC_STRUCTURES = { - :LC_SEGMENT => "SegmentCommand", - :LC_SYMTAB => "SymtabCommand", - :LC_SYMSEG => "SymsegCommand", # obsolete - :LC_THREAD => "ThreadCommand", # seems obsolete, but not documented as such - :LC_UNIXTHREAD => "ThreadCommand", - :LC_LOADFVMLIB => "FvmlibCommand", # obsolete - :LC_IDFVMLIB => "FvmlibCommand", # obsolete - :LC_IDENT => "IdentCommand", # obsolete - :LC_FVMFILE => "FvmfileCommand", # reserved for internal use only - :LC_PREPAGE => "LoadCommand", # reserved for internal use only, no public struct - :LC_DYSYMTAB => "DysymtabCommand", - :LC_LOAD_DYLIB => "DylibCommand", - :LC_ID_DYLIB => "DylibCommand", - :LC_LOAD_DYLINKER => "DylinkerCommand", - :LC_ID_DYLINKER => "DylinkerCommand", - :LC_PREBOUND_DYLIB => "PreboundDylibCommand", - :LC_ROUTINES => "RoutinesCommand", - :LC_SUB_FRAMEWORK => "SubFrameworkCommand", - :LC_SUB_UMBRELLA => "SubUmbrellaCommand", - :LC_SUB_CLIENT => "SubClientCommand", - :LC_SUB_LIBRARY => "SubLibraryCommand", - :LC_TWOLEVEL_HINTS => "TwolevelHintsCommand", - :LC_PREBIND_CKSUM => "PrebindCksumCommand", - :LC_LOAD_WEAK_DYLIB => "DylibCommand", - :LC_SEGMENT_64 => "SegmentCommand64", - :LC_ROUTINES_64 => "RoutinesCommand64", - :LC_UUID => "UUIDCommand", - :LC_RPATH => "RpathCommand", - :LC_CODE_SIGNATURE => "LinkeditDataCommand", - :LC_SEGMENT_SPLIT_INFO => "LinkeditDataCommand", - :LC_REEXPORT_DYLIB => "DylibCommand", - :LC_LAZY_LOAD_DYLIB => "DylibCommand", - :LC_ENCRYPTION_INFO => "EncryptionInfoCommand", - :LC_DYLD_INFO => "DyldInfoCommand", - :LC_DYLD_INFO_ONLY => "DyldInfoCommand", - :LC_LOAD_UPWARD_DYLIB => "DylibCommand", - :LC_VERSION_MIN_MACOSX => "VersionMinCommand", - :LC_VERSION_MIN_IPHONEOS => "VersionMinCommand", - :LC_FUNCTION_STARTS => "LinkeditDataCommand", - :LC_DYLD_ENVIRONMENT => "DylinkerCommand", - :LC_MAIN => "EntryPointCommand", - :LC_DATA_IN_CODE => "LinkeditDataCommand", - :LC_SOURCE_VERSION => "SourceVersionCommand", - :LC_DYLIB_CODE_SIGN_DRS => "LinkeditDataCommand", - :LC_ENCRYPTION_INFO_64 => "EncryptionInfoCommand64", - :LC_LINKER_OPTION => "LinkerOptionCommand", - :LC_LINKER_OPTIMIZATION_HINT => "LinkeditDataCommand", - :LC_VERSION_MIN_TVOS => "VersionMinCommand", - :LC_VERSION_MIN_WATCHOS => "VersionMinCommand", - }.freeze - - # association of segment name symbols to names - # @api private - SEGMENT_NAMES = { - :SEG_PAGEZERO => "__PAGEZERO", - :SEG_TEXT => "__TEXT", - :SEG_DATA => "__DATA", - :SEG_OBJC => "__OBJC", - :SEG_ICON => "__ICON", - :SEG_LINKEDIT => "__LINKEDIT", - :SEG_UNIXSTACK => "__UNIXSTACK", - :SEG_IMPORT => "__IMPORT", - }.freeze - - # association of segment flag symbols to values - # @api private - SEGMENT_FLAGS = { - :SG_HIGHVM => 0x1, - :SG_FVMLIB => 0x2, - :SG_NORELOC => 0x4, - :SG_PROTECTED_VERSION_1 => 0x8, - }.freeze - - # Mach-O load command structure - # This is the most generic load command - only cmd ID and size are - # represented, and no actual data. Used when a more specific class - # isn't available/implemented. - class LoadCommand < MachOStructure - # @return [MachO::MachOView] the raw view associated with the load command - attr_reader :view - - # @return [Fixnum] the load command's identifying number - attr_reader :cmd - - # @return [Fixnum] the size of the load command, in bytes - attr_reader :cmdsize - - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=2".freeze + # Classes and constants for parsing load commands in Mach-O binaries. + module LoadCommands + # load commands added after OS X 10.1 need to be bitwise ORed with + # LC_REQ_DYLD to be recognized by the dynamic linker (dyld) + # @api private + LC_REQ_DYLD = 0x80000000 + + # association of load commands to symbol representations + # @api private + LOAD_COMMANDS = { + 0x1 => :LC_SEGMENT, + 0x2 => :LC_SYMTAB, + 0x3 => :LC_SYMSEG, + 0x4 => :LC_THREAD, + 0x5 => :LC_UNIXTHREAD, + 0x6 => :LC_LOADFVMLIB, + 0x7 => :LC_IDFVMLIB, + 0x8 => :LC_IDENT, + 0x9 => :LC_FVMFILE, + 0xa => :LC_PREPAGE, + 0xb => :LC_DYSYMTAB, + 0xc => :LC_LOAD_DYLIB, + 0xd => :LC_ID_DYLIB, + 0xe => :LC_LOAD_DYLINKER, + 0xf => :LC_ID_DYLINKER, + 0x10 => :LC_PREBOUND_DYLIB, + 0x11 => :LC_ROUTINES, + 0x12 => :LC_SUB_FRAMEWORK, + 0x13 => :LC_SUB_UMBRELLA, + 0x14 => :LC_SUB_CLIENT, + 0x15 => :LC_SUB_LIBRARY, + 0x16 => :LC_TWOLEVEL_HINTS, + 0x17 => :LC_PREBIND_CKSUM, + (0x18 | LC_REQ_DYLD) => :LC_LOAD_WEAK_DYLIB, + 0x19 => :LC_SEGMENT_64, + 0x1a => :LC_ROUTINES_64, + 0x1b => :LC_UUID, + (0x1c | LC_REQ_DYLD) => :LC_RPATH, + 0x1d => :LC_CODE_SIGNATURE, + 0x1e => :LC_SEGMENT_SPLIT_INFO, + (0x1f | LC_REQ_DYLD) => :LC_REEXPORT_DYLIB, + 0x20 => :LC_LAZY_LOAD_DYLIB, + 0x21 => :LC_ENCRYPTION_INFO, + 0x22 => :LC_DYLD_INFO, + (0x22 | LC_REQ_DYLD) => :LC_DYLD_INFO_ONLY, + (0x23 | LC_REQ_DYLD) => :LC_LOAD_UPWARD_DYLIB, + 0x24 => :LC_VERSION_MIN_MACOSX, + 0x25 => :LC_VERSION_MIN_IPHONEOS, + 0x26 => :LC_FUNCTION_STARTS, + 0x27 => :LC_DYLD_ENVIRONMENT, + (0x28 | LC_REQ_DYLD) => :LC_MAIN, + 0x29 => :LC_DATA_IN_CODE, + 0x2a => :LC_SOURCE_VERSION, + 0x2b => :LC_DYLIB_CODE_SIGN_DRS, + 0x2c => :LC_ENCRYPTION_INFO_64, + 0x2d => :LC_LINKER_OPTION, + 0x2e => :LC_LINKER_OPTIMIZATION_HINT, + 0x2f => :LC_VERSION_MIN_TVOS, + 0x30 => :LC_VERSION_MIN_WATCHOS, + }.freeze + + # association of symbol representations to load command constants + # @api private + LOAD_COMMAND_CONSTANTS = LOAD_COMMANDS.invert.freeze + + # load commands responsible for loading dylibs + # @api private + DYLIB_LOAD_COMMANDS = [ + :LC_LOAD_DYLIB, + :LC_LOAD_WEAK_DYLIB, + :LC_REEXPORT_DYLIB, + :LC_LAZY_LOAD_DYLIB, + :LC_LOAD_UPWARD_DYLIB, + ].freeze + + # load commands that can be created manually via {LoadCommand.create} + # @api private + CREATABLE_LOAD_COMMANDS = DYLIB_LOAD_COMMANDS + [ + :LC_ID_DYLIB, + :LC_RPATH, + :LC_LOAD_DYLINKER, + ].freeze + + # association of load command symbols to string representations of classes + # @api private + LC_STRUCTURES = { + :LC_SEGMENT => "SegmentCommand", + :LC_SYMTAB => "SymtabCommand", + # "obsolete" + :LC_SYMSEG => "SymsegCommand", + # seems obsolete, but not documented as such + :LC_THREAD => "ThreadCommand", + :LC_UNIXTHREAD => "ThreadCommand", + # "obsolete" + :LC_LOADFVMLIB => "FvmlibCommand", + # "obsolete" + :LC_IDFVMLIB => "FvmlibCommand", + # "obsolete" + :LC_IDENT => "IdentCommand", + # "reserved for internal use only" + :LC_FVMFILE => "FvmfileCommand", + # "reserved for internal use only", no public struct + :LC_PREPAGE => "LoadCommand", + :LC_DYSYMTAB => "DysymtabCommand", + :LC_LOAD_DYLIB => "DylibCommand", + :LC_ID_DYLIB => "DylibCommand", + :LC_LOAD_DYLINKER => "DylinkerCommand", + :LC_ID_DYLINKER => "DylinkerCommand", + :LC_PREBOUND_DYLIB => "PreboundDylibCommand", + :LC_ROUTINES => "RoutinesCommand", + :LC_SUB_FRAMEWORK => "SubFrameworkCommand", + :LC_SUB_UMBRELLA => "SubUmbrellaCommand", + :LC_SUB_CLIENT => "SubClientCommand", + :LC_SUB_LIBRARY => "SubLibraryCommand", + :LC_TWOLEVEL_HINTS => "TwolevelHintsCommand", + :LC_PREBIND_CKSUM => "PrebindCksumCommand", + :LC_LOAD_WEAK_DYLIB => "DylibCommand", + :LC_SEGMENT_64 => "SegmentCommand64", + :LC_ROUTINES_64 => "RoutinesCommand64", + :LC_UUID => "UUIDCommand", + :LC_RPATH => "RpathCommand", + :LC_CODE_SIGNATURE => "LinkeditDataCommand", + :LC_SEGMENT_SPLIT_INFO => "LinkeditDataCommand", + :LC_REEXPORT_DYLIB => "DylibCommand", + :LC_LAZY_LOAD_DYLIB => "DylibCommand", + :LC_ENCRYPTION_INFO => "EncryptionInfoCommand", + :LC_DYLD_INFO => "DyldInfoCommand", + :LC_DYLD_INFO_ONLY => "DyldInfoCommand", + :LC_LOAD_UPWARD_DYLIB => "DylibCommand", + :LC_VERSION_MIN_MACOSX => "VersionMinCommand", + :LC_VERSION_MIN_IPHONEOS => "VersionMinCommand", + :LC_FUNCTION_STARTS => "LinkeditDataCommand", + :LC_DYLD_ENVIRONMENT => "DylinkerCommand", + :LC_MAIN => "EntryPointCommand", + :LC_DATA_IN_CODE => "LinkeditDataCommand", + :LC_SOURCE_VERSION => "SourceVersionCommand", + :LC_DYLIB_CODE_SIGN_DRS => "LinkeditDataCommand", + :LC_ENCRYPTION_INFO_64 => "EncryptionInfoCommand64", + :LC_LINKER_OPTION => "LinkerOptionCommand", + :LC_LINKER_OPTIMIZATION_HINT => "LinkeditDataCommand", + :LC_VERSION_MIN_TVOS => "VersionMinCommand", + :LC_VERSION_MIN_WATCHOS => "VersionMinCommand", + }.freeze + + # association of segment name symbols to names + # @api private + SEGMENT_NAMES = { + :SEG_PAGEZERO => "__PAGEZERO", + :SEG_TEXT => "__TEXT", + :SEG_DATA => "__DATA", + :SEG_OBJC => "__OBJC", + :SEG_ICON => "__ICON", + :SEG_LINKEDIT => "__LINKEDIT", + :SEG_UNIXSTACK => "__UNIXSTACK", + :SEG_IMPORT => "__IMPORT", + }.freeze + + # association of segment flag symbols to values + # @api private + SEGMENT_FLAGS = { + :SG_HIGHVM => 0x1, + :SG_FVMLIB => 0x2, + :SG_NORELOC => 0x4, + :SG_PROTECTED_VERSION_1 => 0x8, + }.freeze + + # Mach-O load command structure + # This is the most generic load command - only cmd ID and size are + # represented, and no actual data. Used when a more specific class + # isn't available/implemented. + class LoadCommand < MachOStructure + # @return [MachO::MachOView] the raw view associated with the load command + attr_reader :view + + # @return [Fixnum] the load command's identifying number + attr_reader :cmd + + # @return [Fixnum] the size of the load command, in bytes + attr_reader :cmdsize + + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=2".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 8 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 8 - # Instantiates a new LoadCommand given a view into its origin Mach-O - # @param view [MachO::MachOView] the load command's raw view - # @return [MachO::LoadCommand] the new load command - # @api private - def self.new_from_bin(view) - bin = view.raw_data.slice(view.offset, bytesize) - format = Utils.specialize_format(self::FORMAT, view.endianness) + # Instantiates a new LoadCommand given a view into its origin Mach-O + # @param view [MachO::MachOView] the load command's raw view + # @return [LoadCommand] the new load command + # @api private + def self.new_from_bin(view) + bin = view.raw_data.slice(view.offset, bytesize) + format = Utils.specialize_format(self::FORMAT, view.endianness) - new(view, *bin.unpack(format)) - end + new(view, *bin.unpack(format)) + end - # Creates a new (viewless) command corresponding to the symbol provided - # @param cmd_sym [Symbol] the symbol of the load command being created - # @param args [Array] the arguments for the load command being created - def self.create(cmd_sym, *args) - raise LoadCommandNotCreatableError, cmd_sym unless CREATABLE_LOAD_COMMANDS.include?(cmd_sym) + # Creates a new (viewless) command corresponding to the symbol provided + # @param cmd_sym [Symbol] the symbol of the load command being created + # @param args [Array] the arguments for the load command being created + def self.create(cmd_sym, *args) + raise LoadCommandNotCreatableError, cmd_sym unless CREATABLE_LOAD_COMMANDS.include?(cmd_sym) - klass = MachO.const_get LC_STRUCTURES[cmd_sym] - cmd = LOAD_COMMAND_CONSTANTS[cmd_sym] + klass = LoadCommands.const_get LC_STRUCTURES[cmd_sym] + cmd = LOAD_COMMAND_CONSTANTS[cmd_sym] - # cmd will be filled in, view and cmdsize will be left unpopulated - klass_arity = klass.instance_method(:initialize).arity - 3 + # cmd will be filled in, view and cmdsize will be left unpopulated + klass_arity = klass.instance_method(:initialize).arity - 3 - raise LoadCommandCreationArityError.new(cmd_sym, klass_arity, args.size) if klass_arity != args.size + raise LoadCommandCreationArityError.new(cmd_sym, klass_arity, args.size) if klass_arity != args.size - klass.new(nil, cmd, nil, *args) - end + klass.new(nil, cmd, nil, *args) + end - # @param view [MachO::MachOView] the load command's raw view - # @param cmd [Fixnum] the load command's identifying number - # @param cmdsize [Fixnum] the size of the load command in bytes - # @api private - def initialize(view, cmd, cmdsize) - @view = view - @cmd = cmd - @cmdsize = cmdsize - end + # @param view [MachO::MachOView] the load command's raw view + # @param cmd [Fixnum] the load command's identifying number + # @param cmdsize [Fixnum] the size of the load command in bytes + # @api private + def initialize(view, cmd, cmdsize) + @view = view + @cmd = cmd + @cmdsize = cmdsize + end - # @return [Boolean] true if the load command can be serialized, false otherwise - def serializable? - CREATABLE_LOAD_COMMANDS.include?(LOAD_COMMANDS[cmd]) - end + # @return [Boolean] whether the load command can be serialized + def serializable? + CREATABLE_LOAD_COMMANDS.include?(LOAD_COMMANDS[cmd]) + end - # @param context [MachO::LoadCommand::SerializationContext] the context - # to serialize into - # @return [String, nil] the serialized fields of the load command, or nil - # if the load command can't be serialized - # @api private - def serialize(context) - raise LoadCommandNotSerializableError, LOAD_COMMANDS[cmd] unless serializable? - format = Utils.specialize_format(FORMAT, context.endianness) - [cmd, SIZEOF].pack(format) - end + # @param context [SerializationContext] the context + # to serialize into + # @return [String, nil] the serialized fields of the load command, or nil + # if the load command can't be serialized + # @api private + def serialize(context) + raise LoadCommandNotSerializableError, LOAD_COMMANDS[cmd] unless serializable? + format = Utils.specialize_format(FORMAT, context.endianness) + [cmd, SIZEOF].pack(format) + end - # @return [Fixnum] the load command's offset in the source file - # @deprecated use {#view} instead - def offset - view.offset - end + # @return [Fixnum] the load command's offset in the source file + # @deprecated use {#view} instead + def offset + view.offset + end - # @return [Symbol] a symbol representation of the load command's identifying number - def type - LOAD_COMMANDS[cmd] - end + # @return [Symbol] a symbol representation of the load command's + # identifying number + def type + LOAD_COMMANDS[cmd] + end - alias to_sym type + alias to_sym type - # @return [String] a string representation of the load command's identifying number - def to_s - type.to_s - end + # @return [String] a string representation of the load command's + # identifying number + def to_s + type.to_s + end - # Represents a Load Command string. A rough analogue to the lc_str - # struct used internally by OS X. This class allows ruby-macho to - # pretend that strings stored in LCs are immediately available without - # explicit operations on the raw Mach-O data. - class LCStr - # @param lc [MachO::LoadCommand] the load command - # @param lc_str [Fixnum, String] the offset to the beginning of the string, - # or the string itself if not being initialized with a view. - # @raise [MachO::LCStrMalformedError] if the string is malformed - # @todo devise a solution such that the `lc_str` parameter is not - # interpreted differently depending on `lc.view`. The current behavior - # is a hack to allow viewless load command creation. - # @api private - def initialize(lc, lc_str) - view = lc.view - - if view - lc_str_abs = view.offset + lc_str - lc_end = view.offset + lc.cmdsize - 1 - raw_string = view.raw_data.slice(lc_str_abs..lc_end) - @string, null_byte, _padding = raw_string.partition("\x00") - raise LCStrMalformedError, lc if null_byte.empty? - @string_offset = lc_str - else - @string = lc_str - @string_offset = 0 + # Represents a Load Command string. A rough analogue to the lc_str + # struct used internally by OS X. This class allows ruby-macho to + # pretend that strings stored in LCs are immediately available without + # explicit operations on the raw Mach-O data. + class LCStr + # @param lc [LoadCommand] the load command + # @param lc_str [Fixnum, String] the offset to the beginning of the + # string, or the string itself if not being initialized with a view. + # @raise [MachO::LCStrMalformedError] if the string is malformed + # @todo devise a solution such that the `lc_str` parameter is not + # interpreted differently depending on `lc.view`. The current behavior + # is a hack to allow viewless load command creation. + # @api private + def initialize(lc, lc_str) + view = lc.view + + if view + lc_str_abs = view.offset + lc_str + lc_end = view.offset + lc.cmdsize - 1 + raw_string = view.raw_data.slice(lc_str_abs..lc_end) + @string, null_byte, _padding = raw_string.partition("\x00") + raise LCStrMalformedError, lc if null_byte.empty? + @string_offset = lc_str + else + @string = lc_str + @string_offset = 0 + end end - end - # @return [String] a string representation of the LCStr - def to_s - @string + # @return [String] a string representation of the LCStr + def to_s + @string + end + + # @return [Fixnum] the offset to the beginning of the string in the + # load command + def to_i + @string_offset + end end - # @return [Fixnum] the offset to the beginning of the string in the load command - def to_i - @string_offset + # Represents the contextual information needed by a load command to + # serialize itself correctly into a binary string. + class SerializationContext + # @return [Symbol] the endianness of the serialized load command + attr_reader :endianness + + # @return [Fixnum] the constant alignment value used to pad the + # serialized load command + attr_reader :alignment + + # @param macho [MachO::MachOFile] the file to contextualize + # @return [SerializationContext] the + # resulting context + def self.context_for(macho) + new(macho.endianness, macho.alignment) + end + + # @param endianness [Symbol] the endianness of the context + # @param alignment [Fixnum] the alignment of the context + # @api private + def initialize(endianness, alignment) + @endianness = endianness + @alignment = alignment + end end end - # Represents the contextual information needed by a load command to - # serialize itself correctly into a binary string. - class SerializationContext - # @return [Symbol] the endianness of the serialized load command - attr_reader :endianness + # A load command containing a single 128-bit unique random number + # identifying an object produced by static link editor. Corresponds to + # LC_UUID. + class UUIDCommand < LoadCommand + # @return [Array<Fixnum>] the UUID + attr_reader :uuid - # @return [Fixnum] the constant alignment value used to pad the serialized load command - attr_reader :alignment + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=2a16".freeze - # @param macho [MachO::MachOFile] the file to contextualize - # @return [MachO::LoadCommand::SerializationContext] the resulting context - def self.context_for(macho) - new(macho.endianness, macho.alignment) - end + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 24 - # @param endianness [Symbol] the endianness of the context - # @param alignment [Fixnum] the alignment of the context # @api private - def initialize(endianness, alignment) - @endianness = endianness - @alignment = alignment + def initialize(view, cmd, cmdsize, uuid) + super(view, cmd, cmdsize) + @uuid = uuid.unpack("C16") # re-unpack for the actual UUID array end - end - end - - # A load command containing a single 128-bit unique random number identifying - # an object produced by static link editor. Corresponds to LC_UUID. - class UUIDCommand < LoadCommand - # @return [Array<Fixnum>] the UUID - attr_reader :uuid - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=2a16".freeze - - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 24 + # @return [String] a string representation of the UUID + def uuid_string + hexes = uuid.map { |e| "%02x" % e } + segs = [ + hexes[0..3].join, hexes[4..5].join, hexes[6..7].join, + hexes[8..9].join, hexes[10..15].join + ] - # @api private - def initialize(view, cmd, cmdsize, uuid) - super(view, cmd, cmdsize) - @uuid = uuid.unpack("C16") # re-unpack for the actual UUID array + segs.join("-") + end end - # @return [String] a string representation of the UUID - def uuid_string - hexes = uuid.map { |e| "%02x" % e } - segs = [ - hexes[0..3].join, hexes[4..5].join, hexes[6..7].join, - hexes[8..9].join, hexes[10..15].join - ] + # A load command indicating that part of this file is to be mapped into + # the task's address space. Corresponds to LC_SEGMENT. + class SegmentCommand < LoadCommand + # @return [String] the name of the segment + attr_reader :segname - segs.join("-") - end - end + # @return [Fixnum] the memory address of the segment + attr_reader :vmaddr - # A load command indicating that part of this file is to be mapped into - # the task's address space. Corresponds to LC_SEGMENT. - class SegmentCommand < LoadCommand - # @return [String] the name of the segment - attr_reader :segname + # @return [Fixnum] the memory size of the segment + attr_reader :vmsize - # @return [Fixnum] the memory address of the segment - attr_reader :vmaddr + # @return [Fixnum] the file offset of the segment + attr_reader :fileoff - # @return [Fixnum] the memory size of the segment - attr_reader :vmsize + # @return [Fixnum] the amount to map from the file + attr_reader :filesize - # @return [Fixnum] the file offset of the segment - attr_reader :fileoff + # @return [Fixnum] the maximum VM protection + attr_reader :maxprot - # @return [Fixnum] the amount to map from the file - attr_reader :filesize + # @return [Fixnum] the initial VM protection + attr_reader :initprot - # @return [Fixnum] the maximum VM protection - attr_reader :maxprot + # @return [Fixnum] the number of sections in the segment + attr_reader :nsects - # @return [Fixnum] the initial VM protection - attr_reader :initprot + # @return [Fixnum] any flags associated with the segment + attr_reader :flags - # @return [Fixnum] the number of sections in the segment - attr_reader :nsects + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=2a16L=4l=2L=2".freeze - # @return [Fixnum] any flags associated with the segment - attr_reader :flags + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 56 - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=2a16L=4l=2L=2".freeze + # @api private + def initialize(view, cmd, cmdsize, segname, vmaddr, vmsize, fileoff, + filesize, maxprot, initprot, nsects, flags) + super(view, cmd, cmdsize) + @segname = segname.delete("\x00") + @vmaddr = vmaddr + @vmsize = vmsize + @fileoff = fileoff + @filesize = filesize + @maxprot = maxprot + @initprot = initprot + @nsects = nsects + @flags = flags + end - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 56 + # All sections referenced within this segment. + # @return [Array<MachO::Sections::Section>] if the Mach-O is 32-bit + # @return [Array<MachO::Sections::Section64>] if the Mach-O is 64-bit + def sections + klass = case self + when SegmentCommand64 + MachO::Sections::Section64 + when SegmentCommand + MachO::Sections::Section + end - # @api private - def initialize(view, cmd, cmdsize, segname, vmaddr, vmsize, fileoff, - filesize, maxprot, initprot, nsects, flags) - super(view, cmd, cmdsize) - @segname = segname.delete("\x00") - @vmaddr = vmaddr - @vmsize = vmsize - @fileoff = fileoff - @filesize = filesize - @maxprot = maxprot - @initprot = initprot - @nsects = nsects - @flags = flags - end + offset = view.offset + self.class.bytesize + length = nsects * klass.bytesize - # All sections referenced within this segment. - # @return [Array<MachO::Section>] if the Mach-O is 32-bit - # @return [Array<MachO::Section64>] if the Mach-O is 64-bit - def sections - klass = case self - when MachO::SegmentCommand64 - MachO::Section64 - when MachO::SegmentCommand - MachO::Section + bins = view.raw_data[offset, length] + bins.unpack("a#{klass.bytesize}" * nsects).map do |bin| + klass.new_from_bin(view.endianness, bin) + end end - bins = view.raw_data[view.offset + self.class.bytesize, nsects * klass.bytesize] - bins.unpack("a#{klass.bytesize}" * nsects).map do |bin| - klass.new_from_bin(view.endianness, bin) + # @example + # puts "this segment relocated in/to it" if sect.flag?(:SG_NORELOC) + # @param flag [Symbol] a segment flag symbol + # @return [Boolean] true if `flag` is present in the segment's flag field + def flag?(flag) + flag = SEGMENT_FLAGS[flag] + return false if flag.nil? + flags & flag == flag end end - # @example - # puts "this segment relocated in/to it" if sect.flag?(:SG_NORELOC) - # @param flag [Symbol] a segment flag symbol - # @return [Boolean] true if `flag` is present in the segment's flag field - def flag?(flag) - flag = SEGMENT_FLAGS[flag] - return false if flag.nil? - flags & flag == flag - end - end - - # A load command indicating that part of this file is to be mapped into - # the task's address space. Corresponds to LC_SEGMENT_64. - class SegmentCommand64 < SegmentCommand - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=2a16Q=4l=2L=2".freeze + # A load command indicating that part of this file is to be mapped into + # the task's address space. Corresponds to LC_SEGMENT_64. + class SegmentCommand64 < SegmentCommand + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=2a16Q=4l=2L=2".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 72 - end + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 72 + end - # A load command representing some aspect of shared libraries, depending - # on filetype. Corresponds to LC_ID_DYLIB, LC_LOAD_DYLIB, LC_LOAD_WEAK_DYLIB, - # and LC_REEXPORT_DYLIB. - class DylibCommand < LoadCommand - # @return [MachO::LoadCommand::LCStr] the library's path name as an LCStr - attr_reader :name + # A load command representing some aspect of shared libraries, depending + # on filetype. Corresponds to LC_ID_DYLIB, LC_LOAD_DYLIB, + # LC_LOAD_WEAK_DYLIB, and LC_REEXPORT_DYLIB. + class DylibCommand < LoadCommand + # @return [LCStr] the library's path + # name as an LCStr + attr_reader :name - # @return [Fixnum] the library's build time stamp - attr_reader :timestamp + # @return [Fixnum] the library's build time stamp + attr_reader :timestamp - # @return [Fixnum] the library's current version number - attr_reader :current_version + # @return [Fixnum] the library's current version number + attr_reader :current_version - # @return [Fixnum] the library's compatibility version number - attr_reader :compatibility_version + # @return [Fixnum] the library's compatibility version number + attr_reader :compatibility_version - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=6".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=6".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 24 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 24 - # @api private - def initialize(view, cmd, cmdsize, name, timestamp, current_version, compatibility_version) - super(view, cmd, cmdsize) - @name = LCStr.new(self, name) - @timestamp = timestamp - @current_version = current_version - @compatibility_version = compatibility_version - end + # @api private + def initialize(view, cmd, cmdsize, name, timestamp, current_version, + compatibility_version) + super(view, cmd, cmdsize) + @name = LCStr.new(self, name) + @timestamp = timestamp + @current_version = current_version + @compatibility_version = compatibility_version + end - # @param context [MachO::LoadCcommand::SerializationContext] the context - # @return [String] the serialized fields of the load command - # @api private - def serialize(context) - format = Utils.specialize_format(FORMAT, context.endianness) - string_payload, string_offsets = Utils.pack_strings(SIZEOF, context.alignment, :name => name.to_s) - cmdsize = SIZEOF + string_payload.bytesize - [cmd, cmdsize, string_offsets[:name], timestamp, current_version, - compatibility_version].pack(format) + string_payload + # @param context [SerializationContext] + # the context + # @return [String] the serialized fields of the load command + # @api private + def serialize(context) + format = Utils.specialize_format(FORMAT, context.endianness) + string_payload, string_offsets = Utils.pack_strings(SIZEOF, + context.alignment, + :name => name.to_s) + cmdsize = SIZEOF + string_payload.bytesize + [cmd, cmdsize, string_offsets[:name], timestamp, current_version, + compatibility_version].pack(format) + string_payload + end end - end - # A load command representing some aspect of the dynamic linker, depending - # on filetype. Corresponds to LC_ID_DYLINKER, LC_LOAD_DYLINKER, and - # LC_DYLD_ENVIRONMENT. - class DylinkerCommand < LoadCommand - # @return [MachO::LoadCommand::LCStr] the dynamic linker's path name as an LCStr - attr_reader :name + # A load command representing some aspect of the dynamic linker, depending + # on filetype. Corresponds to LC_ID_DYLINKER, LC_LOAD_DYLINKER, and + # LC_DYLD_ENVIRONMENT. + class DylinkerCommand < LoadCommand + # @return [LCStr] the dynamic linker's + # path name as an LCStr + attr_reader :name - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=3".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=3".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 12 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 12 - # @api private - def initialize(view, cmd, cmdsize, name) - super(view, cmd, cmdsize) - @name = LCStr.new(self, name) - end + # @api private + def initialize(view, cmd, cmdsize, name) + super(view, cmd, cmdsize) + @name = LCStr.new(self, name) + end - # @param context [MachO::LoadCcommand::SerializationContext] the context - # @return [String] the serialized fields of the load command - # @api private - def serialize(context) - format = Utils.specialize_format(FORMAT, context.endianness) - string_payload, string_offsets = Utils.pack_strings(SIZEOF, context.alignment, :name => name.to_s) - cmdsize = SIZEOF + string_payload.bytesize - [cmd, cmdsize, string_offsets[:name]].pack(format) + string_payload + # @param context [SerializationContext] + # the context + # @return [String] the serialized fields of the load command + # @api private + def serialize(context) + format = Utils.specialize_format(FORMAT, context.endianness) + string_payload, string_offsets = Utils.pack_strings(SIZEOF, + context.alignment, + :name => name.to_s) + cmdsize = SIZEOF + string_payload.bytesize + [cmd, cmdsize, string_offsets[:name]].pack(format) + string_payload + end end - end - # A load command used to indicate dynamic libraries used in prebinding. - # Corresponds to LC_PREBOUND_DYLIB. - class PreboundDylibCommand < LoadCommand - # @return [MachO::LoadCommand::LCStr] the library's path name as an LCStr - attr_reader :name + # A load command used to indicate dynamic libraries used in prebinding. + # Corresponds to LC_PREBOUND_DYLIB. + class PreboundDylibCommand < LoadCommand + # @return [LCStr] the library's path + # name as an LCStr + attr_reader :name - # @return [Fixnum] the number of modules in the library - attr_reader :nmodules + # @return [Fixnum] the number of modules in the library + attr_reader :nmodules - # @return [Fixnum] a bit vector of linked modules - attr_reader :linked_modules + # @return [Fixnum] a bit vector of linked modules + attr_reader :linked_modules - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=5".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=5".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 20 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 20 - # @api private - def initialize(view, cmd, cmdsize, name, nmodules, linked_modules) - super(view, cmd, cmdsize) - @name = LCStr.new(self, name) - @nmodules = nmodules - @linked_modules = linked_modules + # @api private + def initialize(view, cmd, cmdsize, name, nmodules, linked_modules) + super(view, cmd, cmdsize) + @name = LCStr.new(self, name) + @nmodules = nmodules + @linked_modules = linked_modules + end end - end - # A load command used to represent threads. - # @note cctools-870 has all fields of thread_command commented out except common ones (cmd, cmdsize) - class ThreadCommand < LoadCommand - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=2".freeze + # A load command used to represent threads. + # @note cctools-870 and onwards have all fields of thread_command commented + # out except the common ones (cmd, cmdsize) + class ThreadCommand < LoadCommand + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=2".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 8 - end + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 8 + end - # A load command containing the address of the dynamic shared library - # initialization routine and an index into the module table for the module - # that defines the routine. Corresponds to LC_ROUTINES. - class RoutinesCommand < LoadCommand - # @return [Fixnum] the address of the initialization routine - attr_reader :init_address + # A load command containing the address of the dynamic shared library + # initialization routine and an index into the module table for the module + # that defines the routine. Corresponds to LC_ROUTINES. + class RoutinesCommand < LoadCommand + # @return [Fixnum] the address of the initialization routine + attr_reader :init_address - # @return [Fixnum] the index into the module table that the init routine is defined in - attr_reader :init_module + # @return [Fixnum] the index into the module table that the init routine + # is defined in + attr_reader :init_module - # @return [void] - attr_reader :reserved1 + # @return [void] + attr_reader :reserved1 - # @return [void] - attr_reader :reserved2 + # @return [void] + attr_reader :reserved2 - # @return [void] - attr_reader :reserved3 + # @return [void] + attr_reader :reserved3 - # @return [void] - attr_reader :reserved4 + # @return [void] + attr_reader :reserved4 - # @return [void] - attr_reader :reserved5 + # @return [void] + attr_reader :reserved5 - # @return [void] - attr_reader :reserved6 + # @return [void] + attr_reader :reserved6 - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=10".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=10".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 40 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 40 - # @api private - def initialize(view, cmd, cmdsize, init_address, init_module, reserved1, - reserved2, reserved3, reserved4, reserved5, reserved6) - super(view, cmd, cmdsize) - @init_address = init_address - @init_module = init_module - @reserved1 = reserved1 - @reserved2 = reserved2 - @reserved3 = reserved3 - @reserved4 = reserved4 - @reserved5 = reserved5 - @reserved6 = reserved6 + # @api private + def initialize(view, cmd, cmdsize, init_address, init_module, reserved1, + reserved2, reserved3, reserved4, reserved5, reserved6) + super(view, cmd, cmdsize) + @init_address = init_address + @init_module = init_module + @reserved1 = reserved1 + @reserved2 = reserved2 + @reserved3 = reserved3 + @reserved4 = reserved4 + @reserved5 = reserved5 + @reserved6 = reserved6 + end end - end - # A load command containing the address of the dynamic shared library - # initialization routine and an index into the module table for the module - # that defines the routine. Corresponds to LC_ROUTINES_64. - class RoutinesCommand64 < RoutinesCommand - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=2Q=8".freeze + # A load command containing the address of the dynamic shared library + # initialization routine and an index into the module table for the module + # that defines the routine. Corresponds to LC_ROUTINES_64. + class RoutinesCommand64 < RoutinesCommand + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=2Q=8".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 72 - end + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 72 + end - # A load command signifying membership of a subframework containing the name - # of an umbrella framework. Corresponds to LC_SUB_FRAMEWORK. - class SubFrameworkCommand < LoadCommand - # @return [MachO::LoadCommand::LCStr] the umbrella framework name as an LCStr - attr_reader :umbrella + # A load command signifying membership of a subframework containing the name + # of an umbrella framework. Corresponds to LC_SUB_FRAMEWORK. + class SubFrameworkCommand < LoadCommand + # @return [LCStr] the umbrella framework name as an LCStr + attr_reader :umbrella - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=3".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=3".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 12 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 12 - # @api private - def initialize(view, cmd, cmdsize, umbrella) - super(view, cmd, cmdsize) - @umbrella = LCStr.new(self, umbrella) + # @api private + def initialize(view, cmd, cmdsize, umbrella) + super(view, cmd, cmdsize) + @umbrella = LCStr.new(self, umbrella) + end end - end - # A load command signifying membership of a subumbrella containing the name - # of an umbrella framework. Corresponds to LC_SUB_UMBRELLA. - class SubUmbrellaCommand < LoadCommand - # @return [MachO::LoadCommand::LCStr] the subumbrella framework name as an LCStr - attr_reader :sub_umbrella + # A load command signifying membership of a subumbrella containing the name + # of an umbrella framework. Corresponds to LC_SUB_UMBRELLA. + class SubUmbrellaCommand < LoadCommand + # @return [LCStr] the subumbrella framework name as an LCStr + attr_reader :sub_umbrella - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=3".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=3".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 12 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 12 - # @api private - def initialize(view, cmd, cmdsize, sub_umbrella) - super(view, cmd, cmdsize) - @sub_umbrella = LCStr.new(self, sub_umbrella) + # @api private + def initialize(view, cmd, cmdsize, sub_umbrella) + super(view, cmd, cmdsize) + @sub_umbrella = LCStr.new(self, sub_umbrella) + end end - end - # A load command signifying a sublibrary of a shared library. Corresponds - # to LC_SUB_LIBRARY. - class SubLibraryCommand < LoadCommand - # @return [MachO::LoadCommand::LCStr] the sublibrary name as an LCStr - attr_reader :sub_library + # A load command signifying a sublibrary of a shared library. Corresponds + # to LC_SUB_LIBRARY. + class SubLibraryCommand < LoadCommand + # @return [LCStr] the sublibrary name as an LCStr + attr_reader :sub_library - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=3".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=3".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 12 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 12 - # @api private - def initialize(view, cmd, cmdsize, sub_library) - super(view, cmd, cmdsize) - @sub_library = LCStr.new(self, sub_library) + # @api private + def initialize(view, cmd, cmdsize, sub_library) + super(view, cmd, cmdsize) + @sub_library = LCStr.new(self, sub_library) + end end - end - # A load command signifying a shared library that is a subframework of - # an umbrella framework. Corresponds to LC_SUB_CLIENT. - class SubClientCommand < LoadCommand - # @return [MachO::LoadCommand::LCStr] the subclient name as an LCStr - attr_reader :sub_client + # A load command signifying a shared library that is a subframework of + # an umbrella framework. Corresponds to LC_SUB_CLIENT. + class SubClientCommand < LoadCommand + # @return [LCStr] the subclient name as an LCStr + attr_reader :sub_client - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=3".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=3".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 12 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 12 - # @api private - def initialize(view, cmd, cmdsize, sub_client) - super(view, cmd, cmdsize) - @sub_client = LCStr.new(self, sub_client) + # @api private + def initialize(view, cmd, cmdsize, sub_client) + super(view, cmd, cmdsize) + @sub_client = LCStr.new(self, sub_client) + end end - end - # A load command containing the offsets and sizes of the link-edit 4.3BSD - # "stab" style symbol table information. Corresponds to LC_SYMTAB. - class SymtabCommand < LoadCommand - # @return [Fixnum] the symbol table's offset - attr_reader :symoff + # A load command containing the offsets and sizes of the link-edit 4.3BSD + # "stab" style symbol table information. Corresponds to LC_SYMTAB. + class SymtabCommand < LoadCommand + # @return [Fixnum] the symbol table's offset + attr_reader :symoff - # @return [Fixnum] the number of symbol table entries - attr_reader :nsyms + # @return [Fixnum] the number of symbol table entries + attr_reader :nsyms - # @return the string table's offset - attr_reader :stroff + # @return the string table's offset + attr_reader :stroff - # @return the string table size in bytes - attr_reader :strsize + # @return the string table size in bytes + attr_reader :strsize - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=6".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=6".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 24 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 24 - # @api private - def initialize(view, cmd, cmdsize, symoff, nsyms, stroff, strsize) - super(view, cmd, cmdsize) - @symoff = symoff - @nsyms = nsyms - @stroff = stroff - @strsize = strsize + # @api private + def initialize(view, cmd, cmdsize, symoff, nsyms, stroff, strsize) + super(view, cmd, cmdsize) + @symoff = symoff + @nsyms = nsyms + @stroff = stroff + @strsize = strsize + end end - end - # A load command containing symbolic information needed to support data - # structures used by the dynamic link editor. Corresponds to LC_DYSYMTAB. - class DysymtabCommand < LoadCommand - # @return [Fixnum] the index to local symbols - attr_reader :ilocalsym + # A load command containing symbolic information needed to support data + # structures used by the dynamic link editor. Corresponds to LC_DYSYMTAB. + class DysymtabCommand < LoadCommand + # @return [Fixnum] the index to local symbols + attr_reader :ilocalsym - # @return [Fixnum] the number of local symbols - attr_reader :nlocalsym + # @return [Fixnum] the number of local symbols + attr_reader :nlocalsym - # @return [Fixnum] the index to externally defined symbols - attr_reader :iextdefsym + # @return [Fixnum] the index to externally defined symbols + attr_reader :iextdefsym - # @return [Fixnum] the number of externally defined symbols - attr_reader :nextdefsym + # @return [Fixnum] the number of externally defined symbols + attr_reader :nextdefsym - # @return [Fixnum] the index to undefined symbols - attr_reader :iundefsym + # @return [Fixnum] the index to undefined symbols + attr_reader :iundefsym - # @return [Fixnum] the number of undefined symbols - attr_reader :nundefsym + # @return [Fixnum] the number of undefined symbols + attr_reader :nundefsym - # @return [Fixnum] the file offset to the table of contents - attr_reader :tocoff + # @return [Fixnum] the file offset to the table of contents + attr_reader :tocoff - # @return [Fixnum] the number of entries in the table of contents - attr_reader :ntoc + # @return [Fixnum] the number of entries in the table of contents + attr_reader :ntoc - # @return [Fixnum] the file offset to the module table - attr_reader :modtaboff + # @return [Fixnum] the file offset to the module table + attr_reader :modtaboff - # @return [Fixnum] the number of entries in the module table - attr_reader :nmodtab + # @return [Fixnum] the number of entries in the module table + attr_reader :nmodtab - # @return [Fixnum] the file offset to the referenced symbol table - attr_reader :extrefsymoff + # @return [Fixnum] the file offset to the referenced symbol table + attr_reader :extrefsymoff - # @return [Fixnum] the number of entries in the referenced symbol table - attr_reader :nextrefsyms + # @return [Fixnum] the number of entries in the referenced symbol table + attr_reader :nextrefsyms - # @return [Fixnum] the file offset to the indirect symbol table - attr_reader :indirectsymoff + # @return [Fixnum] the file offset to the indirect symbol table + attr_reader :indirectsymoff - # @return [Fixnum] the number of entries in the indirect symbol table - attr_reader :nindirectsyms + # @return [Fixnum] the number of entries in the indirect symbol table + attr_reader :nindirectsyms - # @return [Fixnum] the file offset to the external relocation entries - attr_reader :extreloff + # @return [Fixnum] the file offset to the external relocation entries + attr_reader :extreloff - # @return [Fixnum] the number of external relocation entries - attr_reader :nextrel + # @return [Fixnum] the number of external relocation entries + attr_reader :nextrel - # @return [Fixnum] the file offset to the local relocation entries - attr_reader :locreloff + # @return [Fixnum] the file offset to the local relocation entries + attr_reader :locreloff - # @return [Fixnum] the number of local relocation entries - attr_reader :nlocrel + # @return [Fixnum] the number of local relocation entries + attr_reader :nlocrel - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=20".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=20".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 80 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 80 - # ugh - # @api private - def initialize(view, cmd, cmdsize, ilocalsym, nlocalsym, iextdefsym, - nextdefsym, iundefsym, nundefsym, tocoff, ntoc, modtaboff, - nmodtab, extrefsymoff, nextrefsyms, indirectsymoff, - nindirectsyms, extreloff, nextrel, locreloff, nlocrel) - super(view, cmd, cmdsize) - @ilocalsym = ilocalsym - @nlocalsym = nlocalsym - @iextdefsym = iextdefsym - @nextdefsym = nextdefsym - @iundefsym = iundefsym - @nundefsym = nundefsym - @tocoff = tocoff - @ntoc = ntoc - @modtaboff = modtaboff - @nmodtab = nmodtab - @extrefsymoff = extrefsymoff - @nextrefsyms = nextrefsyms - @indirectsymoff = indirectsymoff - @nindirectsyms = nindirectsyms - @extreloff = extreloff - @nextrel = nextrel - @locreloff = locreloff - @nlocrel = nlocrel + # ugh + # @api private + def initialize(view, cmd, cmdsize, ilocalsym, nlocalsym, iextdefsym, + nextdefsym, iundefsym, nundefsym, tocoff, ntoc, modtaboff, + nmodtab, extrefsymoff, nextrefsyms, indirectsymoff, + nindirectsyms, extreloff, nextrel, locreloff, nlocrel) + super(view, cmd, cmdsize) + @ilocalsym = ilocalsym + @nlocalsym = nlocalsym + @iextdefsym = iextdefsym + @nextdefsym = nextdefsym + @iundefsym = iundefsym + @nundefsym = nundefsym + @tocoff = tocoff + @ntoc = ntoc + @modtaboff = modtaboff + @nmodtab = nmodtab + @extrefsymoff = extrefsymoff + @nextrefsyms = nextrefsyms + @indirectsymoff = indirectsymoff + @nindirectsyms = nindirectsyms + @extreloff = extreloff + @nextrel = nextrel + @locreloff = locreloff + @nlocrel = nlocrel + end end - end - # A load command containing the offset and number of hints in the two-level - # namespace lookup hints table. Corresponds to LC_TWOLEVEL_HINTS. - class TwolevelHintsCommand < LoadCommand - # @return [Fixnum] the offset to the hint table - attr_reader :htoffset + # A load command containing the offset and number of hints in the two-level + # namespace lookup hints table. Corresponds to LC_TWOLEVEL_HINTS. + class TwolevelHintsCommand < LoadCommand + # @return [Fixnum] the offset to the hint table + attr_reader :htoffset - # @return [Fixnum] the number of hints in the hint table - attr_reader :nhints + # @return [Fixnum] the number of hints in the hint table + attr_reader :nhints - # @return [MachO::TwolevelHintsCommand::TwolevelHintTable] the hint table - attr_reader :table + # @return [TwolevelHintsTable] + # the hint table + attr_reader :table - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=4".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=4".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 16 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 16 - # @api private - def initialize(view, cmd, cmdsize, htoffset, nhints) - super(view, cmd, cmdsize) - @htoffset = htoffset - @nhints = nhints - @table = TwolevelHintsTable.new(view, htoffset, nhints) - end + # @api private + def initialize(view, cmd, cmdsize, htoffset, nhints) + super(view, cmd, cmdsize) + @htoffset = htoffset + @nhints = nhints + @table = TwolevelHintsTable.new(view, htoffset, nhints) + end - # A representation of the two-level namespace lookup hints table exposed - # by a {TwolevelHintsCommand} (`LC_TWOLEVEL_HINTS`). - class TwolevelHintsTable - # @return [Array<MachO::TwoLevelHintsTable::TwoLevelHint>] all hints in the table - attr_reader :hints + # A representation of the two-level namespace lookup hints table exposed + # by a {TwolevelHintsCommand} (`LC_TWOLEVEL_HINTS`). + class TwolevelHintsTable + # @return [Array<TwolevelHint>] all hints in the table + attr_reader :hints - # @param view [MachO::MachOView] the view into the current Mach-O - # @param htoffset [Fixnum] the offset of the hints table - # @param nhints [Fixnum] the number of two-level hints in the table - # @api private - def initialize(view, htoffset, nhints) - format = Utils.specialize_format("L=#{nhints}", view.endianness) - raw_table = view.raw_data[htoffset, nhints * 4] - blobs = raw_table.unpack(format) + # @param view [MachO::MachOView] the view into the current Mach-O + # @param htoffset [Fixnum] the offset of the hints table + # @param nhints [Fixnum] the number of two-level hints in the table + # @api private + def initialize(view, htoffset, nhints) + format = Utils.specialize_format("L=#{nhints}", view.endianness) + raw_table = view.raw_data[htoffset, nhints * 4] + blobs = raw_table.unpack(format) - @hints = blobs.map { |b| TwolevelHint.new(b) } - end + @hints = blobs.map { |b| TwolevelHint.new(b) } + end - # An individual two-level namespace lookup hint. - class TwolevelHint - # @return [Fixnum] the index into the sub-images - attr_reader :isub_image + # An individual two-level namespace lookup hint. + class TwolevelHint + # @return [Fixnum] the index into the sub-images + attr_reader :isub_image - # @return [Fixnum] the index into the table of contents - attr_reader :itoc + # @return [Fixnum] the index into the table of contents + attr_reader :itoc - # @param blob [Fixnum] the 32-bit number containing the lookup hint - # @api private - def initialize(blob) - @isub_image = blob >> 24 - @itoc = blob & 0x00FFFFFF + # @param blob [Fixnum] the 32-bit number containing the lookup hint + # @api private + def initialize(blob) + @isub_image = blob >> 24 + @itoc = blob & 0x00FFFFFF + end end end end - end - # A load command containing the value of the original checksum for prebound - # files, or zero. Corresponds to LC_PREBIND_CKSUM. - class PrebindCksumCommand < LoadCommand - # @return [Fixnum] the checksum or 0 - attr_reader :cksum + # A load command containing the value of the original checksum for prebound + # files, or zero. Corresponds to LC_PREBIND_CKSUM. + class PrebindCksumCommand < LoadCommand + # @return [Fixnum] the checksum or 0 + attr_reader :cksum - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=3".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=3".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 12 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 12 - # @api private - def initialize(view, cmd, cmdsize, cksum) - super(view, cmd, cmdsize) - @cksum = cksum + # @api private + def initialize(view, cmd, cmdsize, cksum) + super(view, cmd, cmdsize) + @cksum = cksum + end end - end - # A load command representing an rpath, which specifies a path that should - # be added to the current run path used to find @rpath prefixed dylibs. - # Corresponds to LC_RPATH. - class RpathCommand < LoadCommand - # @return [MachO::LoadCommand::LCStr] the path to add to the run path as an LCStr - attr_reader :path + # A load command representing an rpath, which specifies a path that should + # be added to the current run path used to find @rpath prefixed dylibs. + # Corresponds to LC_RPATH. + class RpathCommand < LoadCommand + # @return [LCStr] the path to add to the run path as an LCStr + attr_reader :path - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=3".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=3".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 12 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 12 - # @api private - def initialize(view, cmd, cmdsize, path) - super(view, cmd, cmdsize) - @path = LCStr.new(self, path) - end + # @api private + def initialize(view, cmd, cmdsize, path) + super(view, cmd, cmdsize) + @path = LCStr.new(self, path) + end - # @param context [MachO::LoadCcommand::SerializationContext] the context - # @return [String] the serialized fields of the load command - # @api private - def serialize(context) - format = Utils.specialize_format(FORMAT, context.endianness) - string_payload, string_offsets = Utils.pack_strings(SIZEOF, context.alignment, :path => path.to_s) - cmdsize = SIZEOF + string_payload.bytesize - [cmd, cmdsize, string_offsets[:path]].pack(format) + string_payload + # @param context [SerializationContext] the context + # @return [String] the serialized fields of the load command + # @api private + def serialize(context) + format = Utils.specialize_format(FORMAT, context.endianness) + string_payload, string_offsets = Utils.pack_strings(SIZEOF, + context.alignment, + :path => path.to_s) + cmdsize = SIZEOF + string_payload.bytesize + [cmd, cmdsize, string_offsets[:path]].pack(format) + string_payload + end end - end - # A load command representing the offsets and sizes of a blob of data in - # the __LINKEDIT segment. Corresponds to LC_CODE_SIGNATURE, LC_SEGMENT_SPLIT_INFO, - # LC_FUNCTION_STARTS, LC_DATA_IN_CODE, LC_DYLIB_CODE_SIGN_DRS, and LC_LINKER_OPTIMIZATION_HINT. - class LinkeditDataCommand < LoadCommand - # @return [Fixnum] offset to the data in the __LINKEDIT segment - attr_reader :dataoff + # A load command representing the offsets and sizes of a blob of data in + # the __LINKEDIT segment. Corresponds to LC_CODE_SIGNATURE, + # LC_SEGMENT_SPLIT_INFO, LC_FUNCTION_STARTS, LC_DATA_IN_CODE, + # LC_DYLIB_CODE_SIGN_DRS, and LC_LINKER_OPTIMIZATION_HINT. + class LinkeditDataCommand < LoadCommand + # @return [Fixnum] offset to the data in the __LINKEDIT segment + attr_reader :dataoff - # @return [Fixnum] size of the data in the __LINKEDIT segment - attr_reader :datasize + # @return [Fixnum] size of the data in the __LINKEDIT segment + attr_reader :datasize - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=4".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=4".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 16 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 16 - # @api private - def initialize(view, cmd, cmdsize, dataoff, datasize) - super(view, cmd, cmdsize) - @dataoff = dataoff - @datasize = datasize + # @api private + def initialize(view, cmd, cmdsize, dataoff, datasize) + super(view, cmd, cmdsize) + @dataoff = dataoff + @datasize = datasize + end end - end - # A load command representing the offset to and size of an encrypted - # segment. Corresponds to LC_ENCRYPTION_INFO. - class EncryptionInfoCommand < LoadCommand - # @return [Fixnum] the offset to the encrypted segment - attr_reader :cryptoff + # A load command representing the offset to and size of an encrypted + # segment. Corresponds to LC_ENCRYPTION_INFO. + class EncryptionInfoCommand < LoadCommand + # @return [Fixnum] the offset to the encrypted segment + attr_reader :cryptoff - # @return [Fixnum] the size of the encrypted segment - attr_reader :cryptsize + # @return [Fixnum] the size of the encrypted segment + attr_reader :cryptsize - # @return [Fixnum] the encryption system, or 0 if not encrypted yet - attr_reader :cryptid + # @return [Fixnum] the encryption system, or 0 if not encrypted yet + attr_reader :cryptid - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=5".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=5".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 20 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 20 - # @api private - def initialize(view, cmd, cmdsize, cryptoff, cryptsize, cryptid) - super(view, cmd, cmdsize) - @cryptoff = cryptoff - @cryptsize = cryptsize - @cryptid = cryptid + # @api private + def initialize(view, cmd, cmdsize, cryptoff, cryptsize, cryptid) + super(view, cmd, cmdsize) + @cryptoff = cryptoff + @cryptsize = cryptsize + @cryptid = cryptid + end end - end - # A load command representing the offset to and size of an encrypted - # segment. Corresponds to LC_ENCRYPTION_INFO_64. - class EncryptionInfoCommand64 < LoadCommand - # @return [Fixnum] the offset to the encrypted segment - attr_reader :cryptoff + # A load command representing the offset to and size of an encrypted + # segment. Corresponds to LC_ENCRYPTION_INFO_64. + class EncryptionInfoCommand64 < LoadCommand + # @return [Fixnum] the offset to the encrypted segment + attr_reader :cryptoff - # @return [Fixnum] the size of the encrypted segment - attr_reader :cryptsize + # @return [Fixnum] the size of the encrypted segment + attr_reader :cryptsize - # @return [Fixnum] the encryption system, or 0 if not encrypted yet - attr_reader :cryptid + # @return [Fixnum] the encryption system, or 0 if not encrypted yet + attr_reader :cryptid - # @return [Fixnum] 64-bit padding value - attr_reader :pad + # @return [Fixnum] 64-bit padding value + attr_reader :pad - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=6".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=6".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 24 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 24 - # @api private - def initialize(view, cmd, cmdsize, cryptoff, cryptsize, cryptid, pad) - super(view, cmd, cmdsize) - @cryptoff = cryptoff - @cryptsize = cryptsize - @cryptid = cryptid - @pad = pad + # @api private + def initialize(view, cmd, cmdsize, cryptoff, cryptsize, cryptid, pad) + super(view, cmd, cmdsize) + @cryptoff = cryptoff + @cryptsize = cryptsize + @cryptid = cryptid + @pad = pad + end end - end - # A load command containing the minimum OS version on which the binary - # was built to run. Corresponds to LC_VERSION_MIN_MACOSX and LC_VERSION_MIN_IPHONEOS. - class VersionMinCommand < LoadCommand - # @return [Fixnum] the version X.Y.Z packed as x16.y8.z8 - attr_reader :version + # A load command containing the minimum OS version on which the binary + # was built to run. Corresponds to LC_VERSION_MIN_MACOSX and + # LC_VERSION_MIN_IPHONEOS. + class VersionMinCommand < LoadCommand + # @return [Fixnum] the version X.Y.Z packed as x16.y8.z8 + attr_reader :version - # @return [Fixnum] the SDK version X.Y.Z packed as x16.y8.z8 - attr_reader :sdk + # @return [Fixnum] the SDK version X.Y.Z packed as x16.y8.z8 + attr_reader :sdk - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=4".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=4".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 16 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 16 - # @api private - def initialize(view, cmd, cmdsize, version, sdk) - super(view, cmd, cmdsize) - @version = version - @sdk = sdk - end + # @api private + def initialize(view, cmd, cmdsize, version, sdk) + super(view, cmd, cmdsize) + @version = version + @sdk = sdk + end - # A string representation of the binary's minimum OS version. - # @return [String] a string representing the minimum OS version. - def version_string - binary = "%032b" % version - segs = [ - binary[0..15], binary[16..23], binary[24..31] - ].map { |s| s.to_i(2) } + # A string representation of the binary's minimum OS version. + # @return [String] a string representing the minimum OS version. + def version_string + binary = "%032b" % version + segs = [ + binary[0..15], binary[16..23], binary[24..31] + ].map { |s| s.to_i(2) } - segs.join(".") - end + segs.join(".") + end - # A string representation of the binary's SDK version. - # @return [String] a string representing the SDK version. - def sdk_string - binary = "%032b" % sdk - segs = [ - binary[0..15], binary[16..23], binary[24..31] - ].map { |s| s.to_i(2) } + # A string representation of the binary's SDK version. + # @return [String] a string representing the SDK version. + def sdk_string + binary = "%032b" % sdk + segs = [ + binary[0..15], binary[16..23], binary[24..31] + ].map { |s| s.to_i(2) } - segs.join(".") + segs.join(".") + end end - end - # A load command containing the file offsets and sizes of the new - # compressed form of the information dyld needs to load the image. - # Corresponds to LC_DYLD_INFO and LC_DYLD_INFO_ONLY. - class DyldInfoCommand < LoadCommand - # @return [Fixnum] the file offset to the rebase information - attr_reader :rebase_off + # A load command containing the file offsets and sizes of the new + # compressed form of the information dyld needs to load the image. + # Corresponds to LC_DYLD_INFO and LC_DYLD_INFO_ONLY. + class DyldInfoCommand < LoadCommand + # @return [Fixnum] the file offset to the rebase information + attr_reader :rebase_off - # @return [Fixnum] the size of the rebase information - attr_reader :rebase_size + # @return [Fixnum] the size of the rebase information + attr_reader :rebase_size - # @return [Fixnum] the file offset to the binding information - attr_reader :bind_off + # @return [Fixnum] the file offset to the binding information + attr_reader :bind_off - # @return [Fixnum] the size of the binding information - attr_reader :bind_size + # @return [Fixnum] the size of the binding information + attr_reader :bind_size - # @return [Fixnum] the file offset to the weak binding information - attr_reader :weak_bind_off + # @return [Fixnum] the file offset to the weak binding information + attr_reader :weak_bind_off - # @return [Fixnum] the size of the weak binding information - attr_reader :weak_bind_size + # @return [Fixnum] the size of the weak binding information + attr_reader :weak_bind_size - # @return [Fixnum] the file offset to the lazy binding information - attr_reader :lazy_bind_off + # @return [Fixnum] the file offset to the lazy binding information + attr_reader :lazy_bind_off - # @return [Fixnum] the size of the lazy binding information - attr_reader :lazy_bind_size + # @return [Fixnum] the size of the lazy binding information + attr_reader :lazy_bind_size - # @return [Fixnum] the file offset to the export information - attr_reader :export_off + # @return [Fixnum] the file offset to the export information + attr_reader :export_off - # @return [Fixnum] the size of the export information - attr_reader :export_size + # @return [Fixnum] the size of the export information + attr_reader :export_size - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=12".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=12".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 48 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 48 - # @api private - def initialize(view, cmd, cmdsize, rebase_off, rebase_size, bind_off, - bind_size, weak_bind_off, weak_bind_size, lazy_bind_off, - lazy_bind_size, export_off, export_size) - super(view, cmd, cmdsize) - @rebase_off = rebase_off - @rebase_size = rebase_size - @bind_off = bind_off - @bind_size = bind_size - @weak_bind_off = weak_bind_off - @weak_bind_size = weak_bind_size - @lazy_bind_off = lazy_bind_off - @lazy_bind_size = lazy_bind_size - @export_off = export_off - @export_size = export_size + # @api private + def initialize(view, cmd, cmdsize, rebase_off, rebase_size, bind_off, + bind_size, weak_bind_off, weak_bind_size, lazy_bind_off, + lazy_bind_size, export_off, export_size) + super(view, cmd, cmdsize) + @rebase_off = rebase_off + @rebase_size = rebase_size + @bind_off = bind_off + @bind_size = bind_size + @weak_bind_off = weak_bind_off + @weak_bind_size = weak_bind_size + @lazy_bind_off = lazy_bind_off + @lazy_bind_size = lazy_bind_size + @export_off = export_off + @export_size = export_size + end end - end - # A load command containing linker options embedded in object files. - # Corresponds to LC_LINKER_OPTION. - class LinkerOptionCommand < LoadCommand - # @return [Fixnum] the number of strings - attr_reader :count + # A load command containing linker options embedded in object files. + # Corresponds to LC_LINKER_OPTION. + class LinkerOptionCommand < LoadCommand + # @return [Fixnum] the number of strings + attr_reader :count - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=3".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=3".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 12 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 12 - # @api private - def initialize(view, cmd, cmdsize, count) - super(view, cmd, cmdsize) - @count = count + # @api private + def initialize(view, cmd, cmdsize, count) + super(view, cmd, cmdsize) + @count = count + end end - end - # A load command specifying the offset of main(). Corresponds to LC_MAIN. - class EntryPointCommand < LoadCommand - # @return [Fixnum] the file (__TEXT) offset of main() - attr_reader :entryoff + # A load command specifying the offset of main(). Corresponds to LC_MAIN. + class EntryPointCommand < LoadCommand + # @return [Fixnum] the file (__TEXT) offset of main() + attr_reader :entryoff - # @return [Fixnum] if not 0, the initial stack size. - attr_reader :stacksize + # @return [Fixnum] if not 0, the initial stack size. + attr_reader :stacksize - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=2Q=2".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=2Q=2".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 24 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 24 - # @api private - def initialize(view, cmd, cmdsize, entryoff, stacksize) - super(view, cmd, cmdsize) - @entryoff = entryoff - @stacksize = stacksize + # @api private + def initialize(view, cmd, cmdsize, entryoff, stacksize) + super(view, cmd, cmdsize) + @entryoff = entryoff + @stacksize = stacksize + end end - end - # A load command specifying the version of the sources used to build the - # binary. Corresponds to LC_SOURCE_VERSION. - class SourceVersionCommand < LoadCommand - # @return [Fixnum] the version packed as a24.b10.c10.d10.e10 - attr_reader :version + # A load command specifying the version of the sources used to build the + # binary. Corresponds to LC_SOURCE_VERSION. + class SourceVersionCommand < LoadCommand + # @return [Fixnum] the version packed as a24.b10.c10.d10.e10 + attr_reader :version - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=2Q=1".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=2Q=1".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 16 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 16 - # @api private - def initialize(view, cmd, cmdsize, version) - super(view, cmd, cmdsize) - @version = version - end + # @api private + def initialize(view, cmd, cmdsize, version) + super(view, cmd, cmdsize) + @version = version + end - # A string representation of the sources used to build the binary. - # @return [String] a string representation of the version - def version_string - binary = "%064b" % version - segs = [ - binary[0..23], binary[24..33], binary[34..43], binary[44..53], - binary[54..63] - ].map { |s| s.to_i(2) } + # A string representation of the sources used to build the binary. + # @return [String] a string representation of the version + def version_string + binary = "%064b" % version + segs = [ + binary[0..23], binary[24..33], binary[34..43], binary[44..53], + binary[54..63] + ].map { |s| s.to_i(2) } - segs.join(".") + segs.join(".") + end end - end - # An obsolete load command containing the offset and size of the (GNU style) - # symbol table information. Corresponds to LC_SYMSEG. - class SymsegCommand < LoadCommand - # @return [Fixnum] the offset to the symbol segment - attr_reader :offset + # An obsolete load command containing the offset and size of the (GNU style) + # symbol table information. Corresponds to LC_SYMSEG. + class SymsegCommand < LoadCommand + # @return [Fixnum] the offset to the symbol segment + attr_reader :offset - # @return [Fixnum] the size of the symbol segment in bytes - attr_reader :size + # @return [Fixnum] the size of the symbol segment in bytes + attr_reader :size - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=4".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=4".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 16 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 16 - # @api private - def initialize(view, cmd, cmdsize, offset, size) - super(view, cmd, cmdsize) - @offset = offset - @size = size + # @api private + def initialize(view, cmd, cmdsize, offset, size) + super(view, cmd, cmdsize) + @offset = offset + @size = size + end end - end - # An obsolete load command containing a free format string table. Each string - # is null-terminated and the command is zero-padded to a multiple of 4. - # Corresponds to LC_IDENT. - class IdentCommand < LoadCommand - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=2".freeze + # An obsolete load command containing a free format string table. Each + # string is null-terminated and the command is zero-padded to a multiple of + # 4. Corresponds to LC_IDENT. + class IdentCommand < LoadCommand + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=2".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 8 - end + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 8 + end - # An obsolete load command containing the path to a file to be loaded into - # memory. Corresponds to LC_FVMFILE. - class FvmfileCommand < LoadCommand - # @return [MachO::LoadCommand::LCStr] the pathname of the file being loaded - attr_reader :name + # An obsolete load command containing the path to a file to be loaded into + # memory. Corresponds to LC_FVMFILE. + class FvmfileCommand < LoadCommand + # @return [LCStr] the pathname of the file being loaded + attr_reader :name - # @return [Fixnum] the virtual address being loaded at - attr_reader :header_addr + # @return [Fixnum] the virtual address being loaded at + attr_reader :header_addr - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=4".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=4".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 16 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 16 - def initialize(view, cmd, cmdsize, name, header_addr) - super(view, cmd, cmdsize) - @name = LCStr.new(self, name) - @header_addr = header_addr + def initialize(view, cmd, cmdsize, name, header_addr) + super(view, cmd, cmdsize) + @name = LCStr.new(self, name) + @header_addr = header_addr + end end - end - # An obsolete load command containing the path to a library to be loaded into - # memory. Corresponds to LC_LOADFVMLIB and LC_IDFVMLIB. - class FvmlibCommand < LoadCommand - # @return [MachO::LoadCommand::LCStr] the library's target pathname - attr_reader :name + # An obsolete load command containing the path to a library to be loaded + # into memory. Corresponds to LC_LOADFVMLIB and LC_IDFVMLIB. + class FvmlibCommand < LoadCommand + # @return [LCStr] the library's target pathname + attr_reader :name - # @return [Fixnum] the library's minor version number - attr_reader :minor_version + # @return [Fixnum] the library's minor version number + attr_reader :minor_version - # @return [Fixnum] the library's header address - attr_reader :header_addr + # @return [Fixnum] the library's header address + attr_reader :header_addr - # @see MachOStructure::FORMAT - # @api private - FORMAT = "L=5".freeze + # @see MachOStructure::FORMAT + # @api private + FORMAT = "L=5".freeze - # @see MachOStructure::SIZEOF - # @api private - SIZEOF = 20 + # @see MachOStructure::SIZEOF + # @api private + SIZEOF = 20 - def initialize(view, cmd, cmdsize, name, minor_version, header_addr) - super(view, cmd, cmdsize) - @name = LCStr.new(self, name) - @minor_version = minor_version - @header_addr = header_addr + def initialize(view, cmd, cmdsize, name, minor_version, header_addr) + super(view, cmd, cmdsize) + @name = LCStr.new(self, name) + @minor_version = minor_version + @header_addr = header_addr + end end end end
true
Other
Homebrew
brew
024264c381a5dc02dea8680dea29e83bdce9d13b.json
vendor: Update ruby-macho to 1.1.0.
Library/Homebrew/vendor/macho/macho/macho_file.rb
@@ -1,27 +1,33 @@ +require "forwardable" + module MachO # Represents a Mach-O file, which contains a header and load commands # as well as binary executable instructions. Mach-O binaries are # architecture specific. # @see https://en.wikipedia.org/wiki/Mach-O - # @see MachO::FatFile + # @see FatFile class MachOFile - # @return [String] the filename loaded from, or nil if loaded from a binary string + extend Forwardable + + # @return [String] the filename loaded from, or nil if loaded from a binary + # string attr_accessor :filename # @return [Symbol] the endianness of the file, :big or :little attr_reader :endianness - # @return [MachO::MachHeader] if the Mach-O is 32-bit - # @return [MachO::MachHeader64] if the Mach-O is 64-bit + # @return [Headers::MachHeader] if the Mach-O is 32-bit + # @return [Headers::MachHeader64] if the Mach-O is 64-bit attr_reader :header - # @return [Array<MachO::LoadCommand>] an array of the file's load commands + # @return [Array<LoadCommands::LoadCommand>] an array of the file's load + # commands # @note load commands are provided in order of ascending offset. attr_reader :load_commands # Creates a new MachOFile instance from a binary string. # @param bin [String] a binary string containing raw Mach-O data - # @return [MachO::MachOFile] a new MachOFile + # @return [MachOFile] a new MachOFile def self.new_from_bin(bin) instance = allocate instance.initialize_from_bin(bin) @@ -55,117 +61,72 @@ def serialize @raw_data end - # @return [Boolean] true if the Mach-O has 32-bit magic, false otherwise - def magic32? - Utils.magic32?(header.magic) - end - - # @return [Boolean] true if the Mach-O has 64-bit magic, false otherwise - def magic64? - Utils.magic64?(header.magic) - end - - # @return [Fixnum] the file's internal alignment - def alignment - magic32? ? 4 : 8 - end - - # @return [Boolean] true if the file is of type `MH_OBJECT`, false otherwise - def object? - header.filetype == MH_OBJECT - end - - # @return [Boolean] true if the file is of type `MH_EXECUTE`, false otherwise - def executable? - header.filetype == MH_EXECUTE - end - - # @return [Boolean] true if the file is of type `MH_FVMLIB`, false otherwise - def fvmlib? - header.filetype == MH_FVMLIB - end - - # @return [Boolean] true if the file is of type `MH_CORE`, false otherwise - def core? - header.filetype == MH_CORE - end - - # @return [Boolean] true if the file is of type `MH_PRELOAD`, false otherwise - def preload? - header.filetype == MH_PRELOAD - end - - # @return [Boolean] true if the file is of type `MH_DYLIB`, false otherwise - def dylib? - header.filetype == MH_DYLIB - end - - # @return [Boolean] true if the file is of type `MH_DYLINKER`, false otherwise - def dylinker? - header.filetype == MH_DYLINKER - end - - # @return [Boolean] true if the file is of type `MH_BUNDLE`, false otherwise - def bundle? - header.filetype == MH_BUNDLE - end - - # @return [Boolean] true if the file is of type `MH_DSYM`, false otherwise - def dsym? - header.filetype == MH_DSYM - end - - # @return [Boolean] true if the file is of type `MH_KEXT_BUNDLE`, false otherwise - def kext? - header.filetype == MH_KEXT_BUNDLE - end - - # @return [Fixnum] the file's magic number - def magic - header.magic - end + # @!method magic + # @return (see MachO::Headers::MachHeader#magic) + # @!method ncmds + # @return (see MachO::Headers::MachHeader#ncmds) + # @!method sizeofcmds + # @return (see MachO::Headers::MachHeader#sizeofcmds) + # @!method flags + # @return (see MachO::Headers::MachHeader#flags) + # @!method object? + # @return (see MachO::Headers::MachHeader#object?) + # @!method executable? + # @return (see MachO::Headers::MachHeader#executable?) + # @!method fvmlib? + # @return (see MachO::Headers::MachHeader#fvmlib?) + # @!method core? + # @return (see MachO::Headers::MachHeader#core?) + # @!method preload? + # @return (see MachO::Headers::MachHeader#preload?) + # @!method dylib? + # @return (see MachO::Headers::MachHeader#dylib?) + # @!method dylinker? + # @return (see MachO::Headers::MachHeader#dylinker?) + # @!method bundle? + # @return (see MachO::Headers::MachHeader#bundle?) + # @!method dsym? + # @return (see MachO::Headers::MachHeader#dsym?) + # @!method kext? + # @return (see MachO::Headers::MachHeader#kext?) + # @!method magic32? + # @return (see MachO::Headers::MachHeader#magic32?) + # @!method magic64? + # @return (see MachO::Headers::MachHeader#magic64?) + # @!method alignment + # @return (see MachO::Headers::MachHeader#alignment) + def_delegators :header, :magic, :ncmds, :sizeofcmds, :flags, :object?, + :executable?, :fvmlib?, :core?, :preload?, :dylib?, + :dylinker?, :bundle?, :dsym?, :kext?, :magic32?, :magic64?, + :alignment # @return [String] a string representation of the file's magic number def magic_string - MH_MAGICS[magic] + Headers::MH_MAGICS[magic] end # @return [Symbol] a string representation of the Mach-O's filetype def filetype - MH_FILETYPES[header.filetype] + Headers::MH_FILETYPES[header.filetype] end # @return [Symbol] a symbol representation of the Mach-O's CPU type def cputype - CPU_TYPES[header.cputype] + Headers::CPU_TYPES[header.cputype] end # @return [Symbol] a symbol representation of the Mach-O's CPU subtype def cpusubtype - CPU_SUBTYPES[header.cputype][header.cpusubtype] - end - - # @return [Fixnum] the number of load commands in the Mach-O's header - def ncmds - header.ncmds - end - - # @return [Fixnum] the size of all load commands, in bytes - def sizeofcmds - header.sizeofcmds - end - - # @return [Fixnum] execution flags set by the linker - def flags - header.flags + Headers::CPU_SUBTYPES[header.cputype][header.cpusubtype] end # All load commands of a given name. # @example # file.command("LC_LOAD_DYLIB") # file[:LC_LOAD_DYLIB] # @param [String, Symbol] name the load command ID - # @return [Array<MachO::LoadCommand>] an array of LoadCommands corresponding to `name` + # @return [Array<LoadCommands::LoadCommand>] an array of load commands + # corresponding to `name` def command(name) load_commands.select { |lc| lc.type == name.to_sym } end @@ -174,16 +135,16 @@ def command(name) # Inserts a load command at the given offset. # @param offset [Fixnum] the offset to insert at - # @param lc [MachO::LoadCommand] the load command to insert + # @param lc [LoadCommands::LoadCommand] the load command to insert # @param options [Hash] # @option options [Boolean] :repopulate (true) whether or not to repopulate # the instance fields - # @raise [MachO::OffsetInsertionError] if the offset is not in the load command region - # @raise [MachO::HeaderPadError] if the new command exceeds the header pad buffer + # @raise [OffsetInsertionError] if the offset is not in the load command region + # @raise [HeaderPadError] if the new command exceeds the header pad buffer # @note Calling this method with an arbitrary offset in the load command # region **will leave the object in an inconsistent state**. def insert_command(offset, lc, options = {}) - context = LoadCommand::SerializationContext.context_for(self) + context = LoadCommands::LoadCommand::SerializationContext.context_for(self) cmd_raw = lc.serialize(context) if offset < header.class.bytesize || offset + cmd_raw.bytesize > low_fileoff @@ -207,14 +168,14 @@ def insert_command(offset, lc, options = {}) end # Replace a load command with another command in the Mach-O, preserving location. - # @param old_lc [MachO::LoadCommand] the load command being replaced - # @param new_lc [MachO::LoadCommand] the load command being added + # @param old_lc [LoadCommands::LoadCommand] the load command being replaced + # @param new_lc [LoadCommands::LoadCommand] the load command being added # @return [void] - # @raise [MachO::HeaderPadError] if the new command exceeds the header pad buffer - # @see {#insert_command} + # @raise [HeaderPadError] if the new command exceeds the header pad buffer + # @see #insert_command # @note This is public, but methods like {#dylib_id=} should be preferred. def replace_command(old_lc, new_lc) - context = LoadCommand::SerializationContext.context_for(self) + context = LoadCommands::LoadCommand::SerializationContext.context_for(self) cmd_raw = new_lc.serialize(context) new_sizeofcmds = sizeofcmds + cmd_raw.bytesize - old_lc.cmdsize if header.class.bytesize + new_sizeofcmds > low_fileoff @@ -226,12 +187,12 @@ def replace_command(old_lc, new_lc) end # Appends a new load command to the Mach-O. - # @param lc [MachO::LoadCommand] the load command being added + # @param lc [LoadCommands::LoadCommand] the load command being added # @param options [Hash] # @option options [Boolean] :repopulate (true) whether or not to repopulate # the instance fields # @return [void] - # @see {#insert_command} + # @see #insert_command # @note This is public, but methods like {#add_rpath} should be preferred. # Setting `repopulate` to false **will leave the instance in an # inconsistent state** unless {#populate_fields} is called **immediately** @@ -241,7 +202,7 @@ def add_command(lc, options = {}) end # Delete a load command from the Mach-O. - # @param lc [MachO::LoadCommand] the load command being deleted + # @param lc [LoadCommands::LoadCommand] the load command being deleted # @param options [Hash] # @option options [Boolean] :repopulate (true) whether or not to repopulate # the instance fields @@ -275,14 +236,14 @@ def populate_fields end # All load commands responsible for loading dylibs. - # @return [Array<MachO::DylibCommand>] an array of DylibCommands + # @return [Array<LoadCommands::DylibCommand>] an array of DylibCommands def dylib_load_commands - load_commands.select { |lc| DYLIB_LOAD_COMMANDS.include?(lc.type) } + load_commands.select { |lc| LoadCommands::DYLIB_LOAD_COMMANDS.include?(lc.type) } end # All segment load commands in the Mach-O. - # @return [Array<MachO::SegmentCommand>] if the Mach-O is 32-bit - # @return [Array<MachO::SegmentCommand64>] if the Mach-O is 64-bit + # @return [Array<LoadCommands::SegmentCommand>] if the Mach-O is 32-bit + # @return [Array<LoadCommands::SegmentCommand64>] if the Mach-O is 64-bit def segments if magic32? command(:LC_SEGMENT) @@ -319,10 +280,10 @@ def change_dylib_id(new_id, _options = {}) old_lc = command(:LC_ID_DYLIB).first raise DylibIdMissingError unless old_lc - new_lc = LoadCommand.create(:LC_ID_DYLIB, new_id, - old_lc.timestamp, - old_lc.current_version, - old_lc.compatibility_version) + new_lc = LoadCommands::LoadCommand.create(:LC_ID_DYLIB, new_id, + old_lc.timestamp, + old_lc.current_version, + old_lc.compatibility_version) replace_command(old_lc, new_lc) end @@ -341,22 +302,22 @@ def linked_dylibs # Changes the shared library `old_name` to `new_name` # @example - # file.change_install_name("/usr/lib/libWhatever.dylib", "/usr/local/lib/libWhatever2.dylib") + # file.change_install_name("abc.dylib", "def.dylib") # @param old_name [String] the shared library's old name # @param new_name [String] the shared library's new name # @param _options [Hash] # @return [void] - # @raise [MachO::DylibUnknownError] if no shared library has the old name + # @raise [DylibUnknownError] if no shared library has the old name # @note `_options` is currently unused and is provided for signature # compatibility with {MachO::FatFile#change_install_name} def change_install_name(old_name, new_name, _options = {}) old_lc = dylib_load_commands.find { |d| d.name.to_s == old_name } raise DylibUnknownError, old_name if old_lc.nil? - new_lc = LoadCommand.create(old_lc.type, new_name, - old_lc.timestamp, - old_lc.current_version, - old_lc.compatibility_version) + new_lc = LoadCommands::LoadCommand.create(old_lc.type, new_name, + old_lc.timestamp, + old_lc.current_version, + old_lc.compatibility_version) replace_command(old_lc, new_lc) end @@ -376,16 +337,16 @@ def rpaths # @param new_path [String] the new runtime path # @param _options [Hash] # @return [void] - # @raise [MachO::RpathUnknownError] if no such old runtime path exists - # @raise [MachO::RpathExistsError] if the new runtime path already exists + # @raise [RpathUnknownError] if no such old runtime path exists + # @raise [RpathExistsError] if the new runtime path already exists # @note `_options` is currently unused and is provided for signature # compatibility with {MachO::FatFile#change_rpath} def change_rpath(old_path, new_path, _options = {}) old_lc = command(:LC_RPATH).find { |r| r.path.to_s == old_path } raise RpathUnknownError, old_path if old_lc.nil? raise RpathExistsError, new_path if rpaths.include?(new_path) - new_lc = LoadCommand.create(:LC_RPATH, new_path) + new_lc = LoadCommands::LoadCommand.create(:LC_RPATH, new_path) delete_rpath(old_path) insert_command(old_lc.view.offset, new_lc) @@ -399,13 +360,13 @@ def change_rpath(old_path, new_path, _options = {}) # @param path [String] the new runtime path # @param _options [Hash] # @return [void] - # @raise [MachO::RpathExistsError] if the runtime path already exists + # @raise [RpathExistsError] if the runtime path already exists # @note `_options` is currently unused and is provided for signature # compatibility with {MachO::FatFile#add_rpath} def add_rpath(path, _options = {}) raise RpathExistsError, path if rpaths.include?(path) - rpath_cmd = LoadCommand.create(:LC_RPATH, path) + rpath_cmd = LoadCommands::LoadCommand.create(:LC_RPATH, path) add_command(rpath_cmd) end @@ -417,7 +378,7 @@ def add_rpath(path, _options = {}) # @param path [String] the runtime path to delete # @param _options [Hash] # @return void - # @raise [MachO::RpathUnknownError] if no such runtime path exists + # @raise [RpathUnknownError] if no such runtime path exists # @note `_options` is currently unused and is provided for signature # compatibility with {MachO::FatFile#delete_rpath} def delete_rpath(path, _options = {}) @@ -431,15 +392,6 @@ def delete_rpath(path, _options = {}) populate_fields end - # All sections of the segment `segment`. - # @param segment [MachO::SegmentCommand, MachO::SegmentCommand64] the segment being inspected - # @return [Array<MachO::Section>] if the Mach-O is 32-bit - # @return [Array<MachO::Section64>] if the Mach-O is 64-bit - # @deprecated use {MachO::SegmentCommand#sections} instead - def sections(segment) - segment.sections - end - # Write all Mach-O data to the given filename. # @param filename [String] the file to write to # @return [void] @@ -449,7 +401,7 @@ def write(filename) # Write all Mach-O data to the file used to initialize the instance. # @return [void] - # @raise [MachO::MachOError] if the instance was initialized without a file + # @raise [MachOError] if the instance was initialized without a file # @note Overwrites all data in the file! def write! if @filename.nil? @@ -462,16 +414,16 @@ def write! private # The file's Mach-O header structure. - # @return [MachO::MachHeader] if the Mach-O is 32-bit - # @return [MachO::MachHeader64] if the Mach-O is 64-bit - # @raise [MachO::TruncatedFileError] if the file is too small to have a valid header + # @return [Headers::MachHeader] if the Mach-O is 32-bit + # @return [Headers::MachHeader64] if the Mach-O is 64-bit + # @raise [TruncatedFileError] if the file is too small to have a valid header # @api private def populate_mach_header # the smallest Mach-O header is 28 bytes raise TruncatedFileError if @raw_data.size < 28 magic = populate_and_check_magic - mh_klass = Utils.magic32?(magic) ? MachHeader : MachHeader64 + mh_klass = Utils.magic32?(magic) ? Headers::MachHeader : Headers::MachHeader64 mh = mh_klass.new_from_bin(endianness, @raw_data[0, mh_klass.bytesize]) check_cputype(mh.cputype) @@ -483,8 +435,8 @@ def populate_mach_header # Read just the file's magic number and check its validity. # @return [Fixnum] the magic - # @raise [MachO::MagicError] if the magic is not valid Mach-O magic - # @raise [MachO::FatBinaryError] if the magic is for a Fat file + # @raise [MagicError] if the magic is not valid Mach-O magic + # @raise [FatBinaryError] if the magic is for a Fat file # @api private def populate_and_check_magic magic = @raw_data[0..3].unpack("N").first @@ -499,32 +451,32 @@ def populate_and_check_magic # Check the file's CPU type. # @param cputype [Fixnum] the CPU type - # @raise [MachO::CPUTypeError] if the CPU type is unknown + # @raise [CPUTypeError] if the CPU type is unknown # @api private def check_cputype(cputype) - raise CPUTypeError, cputype unless CPU_TYPES.key?(cputype) + raise CPUTypeError, cputype unless Headers::CPU_TYPES.key?(cputype) end # Check the file's CPU type/subtype pair. # @param cpusubtype [Fixnum] the CPU subtype - # @raise [MachO::CPUSubtypeError] if the CPU sub-type is unknown + # @raise [CPUSubtypeError] if the CPU sub-type is unknown # @api private def check_cpusubtype(cputype, cpusubtype) # Only check sub-type w/o capability bits (see `populate_mach_header`). - raise CPUSubtypeError.new(cputype, cpusubtype) unless CPU_SUBTYPES[cputype].key?(cpusubtype) + raise CPUSubtypeError.new(cputype, cpusubtype) unless Headers::CPU_SUBTYPES[cputype].key?(cpusubtype) end # Check the file's type. # @param filetype [Fixnum] the file type - # @raise [MachO::FiletypeError] if the file type is unknown + # @raise [FiletypeError] if the file type is unknown # @api private def check_filetype(filetype) - raise FiletypeError, filetype unless MH_FILETYPES.key?(filetype) + raise FiletypeError, filetype unless Headers::MH_FILETYPES.key?(filetype) end # All load commands in the file. - # @return [Array<MachO::LoadCommand>] an array of load commands - # @raise [MachO::LoadCommandError] if an unknown load command is encountered + # @return [Array<LoadCommands::LoadCommand>] an array of load commands + # @raise [LoadCommandError] if an unknown load command is encountered # @api private def populate_load_commands offset = header.class.bytesize @@ -533,13 +485,13 @@ def populate_load_commands header.ncmds.times do fmt = Utils.specialize_format("L=", endianness) cmd = @raw_data.slice(offset, 4).unpack(fmt).first - cmd_sym = LOAD_COMMANDS[cmd] + cmd_sym = LoadCommands::LOAD_COMMANDS[cmd] raise LoadCommandError, cmd if cmd_sym.nil? # why do I do this? i don't like declaring constants below # classes, and i need them to resolve... - klass = MachO.const_get LC_STRUCTURES[cmd_sym] + klass = LoadCommands.const_get LoadCommands::LC_STRUCTURES[cmd_sym] view = MachOView.new(@raw_data, endianness, offset) command = klass.new_from_bin(view)
true
Other
Homebrew
brew
024264c381a5dc02dea8680dea29e83bdce9d13b.json
vendor: Update ruby-macho to 1.1.0.
Library/Homebrew/vendor/macho/macho/open.rb
@@ -1,25 +0,0 @@ -module MachO - # Opens the given filename as a MachOFile or FatFile, depending on its magic. - # @param filename [String] the file being opened - # @return [MachO::MachOFile] if the file is a Mach-O - # @return [MachO::FatFile] if the file is a Fat file - # @raise [ArgumentError] if the given file does not exist - # @raise [MachO::TruncatedFileError] if the file is too small to have a valid header - # @raise [MachO::MagicError] if the file's magic is not valid Mach-O magic - 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 - - if Utils.fat_magic?(magic) - file = FatFile.new(filename) - elsif Utils.magic?(magic) - file = MachOFile.new(filename) - else - raise MagicError, magic - end - - file - end -end
true
Other
Homebrew
brew
024264c381a5dc02dea8680dea29e83bdce9d13b.json
vendor: Update ruby-macho to 1.1.0.
Library/Homebrew/vendor/macho/macho/sections.rb
@@ -1,170 +1,176 @@ module MachO - # type mask - SECTION_TYPE = 0x000000ff - - # attributes mask - SECTION_ATTRIBUTES = 0xffffff00 - - # user settable attributes mask - SECTION_ATTRIBUTES_USR = 0xff000000 - - # system settable attributes mask - SECTION_ATTRIBUTES_SYS = 0x00ffff00 - - # association of section flag symbols to values - # @api private - SECTION_FLAGS = { - :S_REGULAR => 0x0, - :S_ZEROFILL => 0x1, - :S_CSTRING_LITERALS => 0x2, - :S_4BYTE_LITERALS => 0x3, - :S_8BYTE_LITERALS => 0x4, - :S_LITERAL_POINTERS => 0x5, - :S_NON_LAZY_SYMBOL_POINTERS => 0x6, - :S_LAZY_SYMBOL_POINTERS => 0x7, - :S_SYMBOL_STUBS => 0x8, - :S_MOD_INIT_FUNC_POINTERS => 0x9, - :S_MOD_TERM_FUNC_POINTERS => 0xa, - :S_COALESCED => 0xb, - :S_GB_ZEROFILE => 0xc, - :S_INTERPOSING => 0xd, - :S_16BYTE_LITERALS => 0xe, - :S_DTRACE_DOF => 0xf, - :S_LAZY_DYLIB_SYMBOL_POINTERS => 0x10, - :S_THREAD_LOCAL_REGULAR => 0x11, - :S_THREAD_LOCAL_ZEROFILL => 0x12, - :S_THREAD_LOCAL_VARIABLES => 0x13, - :S_THREAD_LOCAL_VARIABLE_POINTERS => 0x14, - :S_THREAD_LOCAL_INIT_FUNCTION_POINTERS => 0x15, - :S_ATTR_PURE_INSTRUCTIONS => 0x80000000, - :S_ATTR_NO_TOC => 0x40000000, - :S_ATTR_STRIP_STATIC_SYMS => 0x20000000, - :S_ATTR_NO_DEAD_STRIP => 0x10000000, - :S_ATTR_LIVE_SUPPORT => 0x08000000, - :S_ATTR_SELF_MODIFYING_CODE => 0x04000000, - :S_ATTR_DEBUG => 0x02000000, - :S_ATTR_SOME_INSTRUCTIONS => 0x00000400, - :S_ATTR_EXT_RELOC => 0x00000200, - :S_ATTR_LOC_RELOC => 0x00000100, - }.freeze - - # association of section name symbols to names - # @api private - SECTION_NAMES = { - :SECT_TEXT => "__text", - :SECT_FVMLIB_INIT0 => "__fvmlib_init0", - :SECT_FVMLIB_INIT1 => "__fvmlib_init1", - :SECT_DATA => "__data", - :SECT_BSS => "__bss", - :SECT_COMMON => "__common", - :SECT_OBJC_SYMBOLS => "__symbol_table", - :SECT_OBJC_MODULES => "__module_info", - :SECT_OBJC_STRINGS => "__selector_strs", - :SECT_OBJC_REFS => "__selector_refs", - :SECT_ICON_HEADER => "__header", - :SECT_ICON_TIFF => "__tiff", - }.freeze - - # Represents a section of a segment for 32-bit architectures. - class Section < MachOStructure - # @return [String] the name of the section, including null pad bytes - attr_reader :sectname - - # @return [String] the name of the segment's section, including null pad bytes - attr_reader :segname - - # @return [Fixnum] the memory address of the section - attr_reader :addr - - # @return [Fixnum] the size, in bytes, of the section - attr_reader :size - - # @return [Fixnum] the file offset of the section - attr_reader :offset - - # @return [Fixnum] the section alignment (power of 2) of the section - attr_reader :align - - # @return [Fixnum] the file offset of the section's relocation entries - attr_reader :reloff - - # @return [Fixnum] the number of relocation entries - attr_reader :nreloc - - # @return [Fixnum] flags for type and attributes of the section - attr_reader :flags - - # @return [void] reserved (for offset or index) - attr_reader :reserved1 - - # @return [void] reserved (for count or sizeof) - attr_reader :reserved2 - - # @see MachOStructure::FORMAT - FORMAT = "a16a16L=9".freeze - - # @see MachOStructure::SIZEOF - SIZEOF = 68 + # Classes and constants for parsing sections in Mach-O binaries. + module Sections + # type mask + SECTION_TYPE = 0x000000ff - # @api private - def initialize(sectname, segname, addr, size, offset, align, reloff, - nreloc, flags, reserved1, reserved2) - @sectname = sectname - @segname = segname - @addr = addr - @size = size - @offset = offset - @align = align - @reloff = reloff - @nreloc = nreloc - @flags = flags - @reserved1 = reserved1 - @reserved2 = reserved2 - end + # attributes mask + SECTION_ATTRIBUTES = 0xffffff00 - # @return [String] the section's name, with any trailing NULL characters removed - def section_name - sectname.delete("\x00") - end - - # @return [String] the parent segment's name, with any trailing NULL characters removed - def segment_name - segname.delete("\x00") - end + # user settable attributes mask + SECTION_ATTRIBUTES_USR = 0xff000000 - # @return [Boolean] true if the section has no contents (i.e, `size` is 0) - def empty? - size.zero? - end + # system settable attributes mask + SECTION_ATTRIBUTES_SYS = 0x00ffff00 - # @example - # puts "this section is regular" if sect.flag?(:S_REGULAR) - # @param flag [Symbol] a section flag symbol - # @return [Boolean] true if `flag` is present in the section's flag field - def flag?(flag) - flag = SECTION_FLAGS[flag] - return false if flag.nil? - flags & flag == flag + # association of section flag symbols to values + # @api private + SECTION_FLAGS = { + :S_REGULAR => 0x0, + :S_ZEROFILL => 0x1, + :S_CSTRING_LITERALS => 0x2, + :S_4BYTE_LITERALS => 0x3, + :S_8BYTE_LITERALS => 0x4, + :S_LITERAL_POINTERS => 0x5, + :S_NON_LAZY_SYMBOL_POINTERS => 0x6, + :S_LAZY_SYMBOL_POINTERS => 0x7, + :S_SYMBOL_STUBS => 0x8, + :S_MOD_INIT_FUNC_POINTERS => 0x9, + :S_MOD_TERM_FUNC_POINTERS => 0xa, + :S_COALESCED => 0xb, + :S_GB_ZEROFILE => 0xc, + :S_INTERPOSING => 0xd, + :S_16BYTE_LITERALS => 0xe, + :S_DTRACE_DOF => 0xf, + :S_LAZY_DYLIB_SYMBOL_POINTERS => 0x10, + :S_THREAD_LOCAL_REGULAR => 0x11, + :S_THREAD_LOCAL_ZEROFILL => 0x12, + :S_THREAD_LOCAL_VARIABLES => 0x13, + :S_THREAD_LOCAL_VARIABLE_POINTERS => 0x14, + :S_THREAD_LOCAL_INIT_FUNCTION_POINTERS => 0x15, + :S_ATTR_PURE_INSTRUCTIONS => 0x80000000, + :S_ATTR_NO_TOC => 0x40000000, + :S_ATTR_STRIP_STATIC_SYMS => 0x20000000, + :S_ATTR_NO_DEAD_STRIP => 0x10000000, + :S_ATTR_LIVE_SUPPORT => 0x08000000, + :S_ATTR_SELF_MODIFYING_CODE => 0x04000000, + :S_ATTR_DEBUG => 0x02000000, + :S_ATTR_SOME_INSTRUCTIONS => 0x00000400, + :S_ATTR_EXT_RELOC => 0x00000200, + :S_ATTR_LOC_RELOC => 0x00000100, + }.freeze + + # association of section name symbols to names + # @api private + SECTION_NAMES = { + :SECT_TEXT => "__text", + :SECT_FVMLIB_INIT0 => "__fvmlib_init0", + :SECT_FVMLIB_INIT1 => "__fvmlib_init1", + :SECT_DATA => "__data", + :SECT_BSS => "__bss", + :SECT_COMMON => "__common", + :SECT_OBJC_SYMBOLS => "__symbol_table", + :SECT_OBJC_MODULES => "__module_info", + :SECT_OBJC_STRINGS => "__selector_strs", + :SECT_OBJC_REFS => "__selector_refs", + :SECT_ICON_HEADER => "__header", + :SECT_ICON_TIFF => "__tiff", + }.freeze + + # Represents a section of a segment for 32-bit architectures. + class Section < MachOStructure + # @return [String] the name of the section, including null pad bytes + attr_reader :sectname + + # @return [String] the name of the segment's section, including null + # pad bytes + attr_reader :segname + + # @return [Fixnum] the memory address of the section + attr_reader :addr + + # @return [Fixnum] the size, in bytes, of the section + attr_reader :size + + # @return [Fixnum] the file offset of the section + attr_reader :offset + + # @return [Fixnum] the section alignment (power of 2) of the section + attr_reader :align + + # @return [Fixnum] the file offset of the section's relocation entries + attr_reader :reloff + + # @return [Fixnum] the number of relocation entries + attr_reader :nreloc + + # @return [Fixnum] flags for type and attributes of the section + attr_reader :flags + + # @return [void] reserved (for offset or index) + attr_reader :reserved1 + + # @return [void] reserved (for count or sizeof) + attr_reader :reserved2 + + # @see MachOStructure::FORMAT + FORMAT = "a16a16L=9".freeze + + # @see MachOStructure::SIZEOF + SIZEOF = 68 + + # @api private + def initialize(sectname, segname, addr, size, offset, align, reloff, + nreloc, flags, reserved1, reserved2) + @sectname = sectname + @segname = segname + @addr = addr + @size = size + @offset = offset + @align = align + @reloff = reloff + @nreloc = nreloc + @flags = flags + @reserved1 = reserved1 + @reserved2 = reserved2 + end + + # @return [String] the section's name, with any trailing NULL characters + # removed + def section_name + sectname.delete("\x00") + end + + # @return [String] the parent segment's name, with any trailing NULL + # characters removed + def segment_name + segname.delete("\x00") + end + + # @return [Boolean] whether the section is empty (i.e, {size} is 0) + def empty? + size.zero? + end + + # @example + # puts "this section is regular" if sect.flag?(:S_REGULAR) + # @param flag [Symbol] a section flag symbol + # @return [Boolean] whether the flag is present in the section's {flags} + def flag?(flag) + flag = SECTION_FLAGS[flag] + return false if flag.nil? + flags & flag == flag + end end - end - # Represents a section of a segment for 64-bit architectures. - class Section64 < Section - # @return [void] reserved - attr_reader :reserved3 + # Represents a section of a segment for 64-bit architectures. + class Section64 < Section + # @return [void] reserved + attr_reader :reserved3 - # @see MachOStructure::FORMAT - FORMAT = "a16a16Q=2L=8".freeze + # @see MachOStructure::FORMAT + FORMAT = "a16a16Q=2L=8".freeze - # @see MachOStructure::SIZEOF - SIZEOF = 80 + # @see MachOStructure::SIZEOF + SIZEOF = 80 - # @api private - def initialize(sectname, segname, addr, size, offset, align, reloff, - nreloc, flags, reserved1, reserved2, reserved3) - super(sectname, segname, addr, size, offset, align, reloff, - nreloc, flags, reserved1, reserved2) - @reserved3 = reserved3 + # @api private + def initialize(sectname, segname, addr, size, offset, align, reloff, + nreloc, flags, reserved1, reserved2, reserved3) + super(sectname, segname, addr, size, offset, align, reloff, + nreloc, flags, reserved1, reserved2) + @reserved3 = reserved3 + end end end end
true
Other
Homebrew
brew
024264c381a5dc02dea8680dea29e83bdce9d13b.json
vendor: Update ruby-macho to 1.1.0.
Library/Homebrew/vendor/macho/macho/structure.rb
@@ -19,7 +19,7 @@ def self.bytesize # @param endianness [Symbol] either `:big` or `:little` # @param bin [String] the string to be unpacked into the new structure - # @return [MachO::MachOStructure] a new MachOStructure initialized with `bin` + # @return [MachO::MachOStructure] the resulting structure # @api private def self.new_from_bin(endianness, bin) format = Utils.specialize_format(self::FORMAT, endianness)
true
Other
Homebrew
brew
024264c381a5dc02dea8680dea29e83bdce9d13b.json
vendor: Update ruby-macho to 1.1.0.
Library/Homebrew/vendor/macho/macho/tools.rb
@@ -1,5 +1,6 @@ module MachO - # A collection of convenient methods for common operations on Mach-O and Fat binaries. + # A collection of convenient methods for common operations on Mach-O and Fat + # binaries. module Tools # @param filename [String] the Mach-O or Fat binary being read # @return [Array<String>] an array of all dylibs linked to the binary @@ -9,7 +10,8 @@ def self.dylibs(filename) file.linked_dylibs end - # Changes the dylib ID of a Mach-O or Fat binary, overwriting the source file. + # Changes the dylib ID of a Mach-O or Fat binary, overwriting the source + # file. # @param filename [String] the Mach-O or Fat binary being modified # @param new_id [String] the new dylib ID for the binary # @param options [Hash] @@ -23,7 +25,8 @@ def self.change_dylib_id(filename, new_id, options = {}) file.write! end - # Changes a shared library install name in a Mach-O or Fat binary, overwriting the source file. + # Changes a shared library install name in a Mach-O or Fat binary, + # overwriting the source file. # @param filename [String] the Mach-O or Fat binary being modified # @param old_name [String] the old shared library name # @param new_name [String] the new shared library name @@ -38,7 +41,8 @@ def self.change_install_name(filename, old_name, new_name, options = {}) file.write! end - # Changes a runtime path in a Mach-O or Fat binary, overwriting the source file. + # Changes a runtime path in a Mach-O or Fat binary, overwriting the source + # file. # @param filename [String] the Mach-O or Fat binary being modified # @param old_path [String] the old runtime path # @param new_path [String] the new runtime path @@ -67,7 +71,8 @@ def self.add_rpath(filename, new_path, options = {}) file.write! end - # Delete a runtime path from a Mach-O or Fat binary, overwriting the source file. + # Delete a runtime path from a Mach-O or Fat binary, overwriting the source + # file. # @param filename [String] the Mach-O or Fat binary being modified # @param old_path [String] the old runtime path # @param options [Hash] @@ -80,5 +85,24 @@ def self.delete_rpath(filename, old_path, options = {}) file.delete_rpath(old_path, options) file.write! end + + # Merge multiple Mach-Os into one universal (Fat) binary. + # @param filename [String] the fat binary to create + # @param files [Array<MachO::MachOFile, MachO::FatFile>] the files to merge + # @return [void] + def self.merge_machos(filename, *files) + machos = files.map do |file| + macho = MachO.open(file) + case macho + when MachO::MachOFile + macho + else + macho.machos + end + end.flatten + + fat_macho = MachO::FatFile.new_from_machos(*machos) + fat_macho.write(filename) + end end end
true
Other
Homebrew
brew
024264c381a5dc02dea8680dea29e83bdce9d13b.json
vendor: Update ruby-macho to 1.1.0.
Library/Homebrew/vendor/macho/macho/utils.rb
@@ -5,23 +5,25 @@ module Utils # @param value [Fixnum] the number being rounded # @param round [Fixnum] the number being rounded with # @return [Fixnum] the rounded value - # @see https://www.opensource.apple.com/source/cctools/cctools-870/libstuff/rnd.c + # @see http://www.opensource.apple.com/source/cctools/cctools-870/libstuff/rnd.c def self.round(value, round) round -= 1 value += round value &= ~round value end - # Returns the number of bytes needed to pad the given size to the given alignment. + # Returns the number of bytes needed to pad the given size to the given + # alignment. # @param size [Fixnum] the unpadded size # @param alignment [Fixnum] the number to alignment the size with # @return [Fixnum] the number of pad bytes required def self.padding_for(size, alignment) round(size, alignment) - size end - # Converts an abstract (native-endian) String#unpack format to big or little. + # Converts an abstract (native-endian) String#unpack format to big or + # little. # @param format [String] the format string being converted # @param endianness [Symbol] either `:big` or `:little` # @return [String] the converted string @@ -31,7 +33,8 @@ def self.specialize_format(format, endianness) end # Packs tagged strings into an aligned payload. - # @param fixed_offset [Fixnum] the baseline offset for the first packed string + # @param fixed_offset [Fixnum] the baseline offset for the first packed + # string # @param alignment [Fixnum] the alignment value to use for packing # @param strings [Hash] the labeled strings to pack # @return [Array<String, Hash>] the packed string and labeled offsets @@ -53,44 +56,44 @@ def self.pack_strings(fixed_offset, alignment, strings = {}) # Compares the given number to valid Mach-O magic numbers. # @param num [Fixnum] the number being checked - # @return [Boolean] true if `num` is a valid Mach-O magic number, false otherwise + # @return [Boolean] whether `num` is a valid Mach-O magic number def self.magic?(num) - MH_MAGICS.key?(num) + Headers::MH_MAGICS.key?(num) end # Compares the given number to valid Fat magic numbers. # @param num [Fixnum] the number being checked - # @return [Boolean] true if `num` is a valid Fat magic number, false otherwise + # @return [Boolean] whether `num` is a valid Fat magic number def self.fat_magic?(num) - num == FAT_MAGIC + num == Headers::FAT_MAGIC end # Compares the given number to valid 32-bit Mach-O magic numbers. # @param num [Fixnum] the number being checked - # @return [Boolean] true if `num` is a valid 32-bit magic number, false otherwise + # @return [Boolean] whether `num` is a valid 32-bit magic number def self.magic32?(num) - num == MH_MAGIC || num == MH_CIGAM + num == Headers::MH_MAGIC || num == Headers::MH_CIGAM end # Compares the given number to valid 64-bit Mach-O magic numbers. # @param num [Fixnum] the number being checked - # @return [Boolean] true if `num` is a valid 64-bit magic number, false otherwise + # @return [Boolean] whether `num` is a valid 64-bit magic number def self.magic64?(num) - num == MH_MAGIC_64 || num == MH_CIGAM_64 + num == Headers::MH_MAGIC_64 || num == Headers::MH_CIGAM_64 end # Compares the given number to valid little-endian magic numbers. # @param num [Fixnum] the number being checked - # @return [Boolean] true if `num` is a valid little-endian magic number, false otherwise + # @return [Boolean] whether `num` is a valid little-endian magic number def self.little_magic?(num) - num == MH_CIGAM || num == MH_CIGAM_64 + num == Headers::MH_CIGAM || num == Headers::MH_CIGAM_64 end # Compares the given number to valid big-endian magic numbers. # @param num [Fixnum] the number being checked - # @return [Boolean] true if `num` is a valid big-endian magic number, false otherwise + # @return [Boolean] whether `num` is a valid big-endian magic number def self.big_magic?(num) - num == MH_CIGAM || num == MH_CIGAM_64 + num == Headers::MH_CIGAM || num == Headers::MH_CIGAM_64 end end end
true
Other
Homebrew
brew
59fab56afdf6129c37ff30eb842bf7bff41348e0.json
docs: update sample formula Also works around bug in Jekyll where a URL with a "#" will cause links in the same paragraph to not have their extensions replaced by using "&num;" instead.
docs/Formula-Cookbook.md
@@ -59,10 +59,18 @@ class Foo < Formula # depends_on "cmake" => :build def install - system "./configure", "--prefix=#{prefix}", "--disable-debug", "--disable-dependency-tracking" + # ENV.deparallelize + system "./configure", "--disable-debug", + "--disable-dependency-tracking", + "--disable-silent-rules", + "--prefix=#{prefix}" # system "cmake", ".", *std_cmake_args system "make", "install" end + + test do + system "false" + end end ``` @@ -259,7 +267,7 @@ Check the top of the e.g. `./configure` output. Some configure scripts do not re ### Add a test to the formula -Please add a [`test do`](http://www.rubydoc.info/github/Homebrew/brew/master/Formula#test-class_method) block to the formula. This will be run by `brew test foo` and the [Brew Test Bot](Brew-Test-Bot.md). +Add a valid test to the [`test do`](http://www.rubydoc.info/github/Homebrew/brew/master/Formula&num;test-class_method) block of the formula. This will be run by `brew test foo` and the [Brew Test Bot](Brew-Test-Bot.md). The [`test do`](http://www.rubydoc.info/github/Homebrew/brew/master/Formula#test-class_method)
false
Other
Homebrew
brew
689e35a1e7eed6e499f90866a768be1260558bbc.json
README: add some more shields. For the current release, Travis CI and Coveralls status.
README.md
@@ -1,4 +1,6 @@ # Homebrew +[![GitHub release](https://img.shields.io/github/release/Homebrew/brew.svg)](https://github.com/Homebrew/brew/releases) + Features, usage and installation instructions are [summarised on the homepage](https://brew.sh). Terminology (e.g. the difference between a Cellar, Tap, Cask and so forth) is [explained here](docs/Formula-Cookbook.md#homebrew-terminology). ## Update Bug @@ -23,6 +25,9 @@ Second, read the [Troubleshooting Checklist](http://docs.brew.sh/Troubleshooting **If you don't read these it will take us far longer to help you with your problem.** ## Contributing +[![Travis](https://img.shields.io/travis/Homebrew/brew.svg)](https://travis-ci.org/Homebrew/brew) +[![Codecov](https://img.shields.io/codecov/c/github/Homebrew/brew.svg)](https://codecov.io/gh/Homebrew/brew) + We'd love you to contribute to Homebrew. First, please read our [Contribution Guide](https://github.com/Homebrew/brew/blob/master/CONTRIBUTING.md) and [Code of Conduct](https://github.com/Homebrew/brew/blob/master/CODEOFCONDUCT.md#code-of-conduct). We explicitly welcome contributions from people who have never contributed to open-source before: we were all beginners once! We can help build on a partially working pull request with the aim of getting it merged. We are also actively seeking to diversify our contributors and especially welcome contributions from women from all backgrounds and people of colour.
false
Other
Homebrew
brew
4cae6a724e6d684eb157dd6d7328755694f228b2.json
link: tell users of `brew link --force` about opt. If people are force-linking keg-only things they should probably be told that they can add the opt prefix to their PATH instead.
Library/Homebrew/cmd/link.rb
@@ -44,6 +44,7 @@ def link elsif keg_only && !ARGV.force? opoo "#{keg.name} is keg-only and must be linked with --force" puts "Note that doing so can interfere with building software." + puts_keg_only_path_message(keg) next elsif mode.dry_run && mode.overwrite puts "Would remove:" @@ -53,6 +54,7 @@ def link elsif mode.dry_run puts "Would link:" keg.link(mode) + puts_keg_only_path_message(keg) if keg_only next end @@ -69,10 +71,25 @@ def link else puts "#{n} symlinks created" end + + if keg_only && !ARGV.homebrew_developer? + puts_keg_only_path_message(keg) + end end end end + def puts_keg_only_path_message(keg) + bin = keg/"bin" + sbin = keg/"sbin" + return if !bin.directory? && !sbin.directory? + + opt = HOMEBREW_PREFIX/"opt/#{keg.name}" + puts "\nIf you need to have this software first in your PATH instead consider running:" + puts " #{Utils::Shell.prepend_path_in_shell_profile(opt)}/bin" if bin.directory? + puts " #{Utils::Shell.prepend_path_in_shell_profile(opt)}/sbin" if sbin.directory? + end + def keg_only?(rack) Formulary.from_rack(rack).keg_only? rescue FormulaUnavailableError, TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError
false
Other
Homebrew
brew
5fc4cabdeb37d47b59bddfa41f28dc3ff92d17ad.json
tap-new: fix symlink creation. Ensure the full HOMEBREW_TAP_DIR path is created before deleting and creating the symlink for it. This ensures that non-`homebrew` taps will have the necessary username/organisation folder created. Fixes #2378.
Library/Homebrew/dev-cmd/tap-new.rb
@@ -60,6 +60,7 @@ def tap_new - git -C "$HOMEBREW_REPOSITORY" reset --hard origin/master - brew update || brew update - HOMEBREW_TAP_DIR="$(brew --repo "$TRAVIS_REPO_SLUG")" + - mkdir -p "$HOMEBREW_TAP_DIR" - rm -rf "$HOMEBREW_TAP_DIR" - ln -s "$PWD" "$HOMEBREW_TAP_DIR" - export HOMEBREW_DEVELOPER="1"
false
Other
Homebrew
brew
b41a88eac4a1fe75af18d115d40c8821bcd2a160.json
update-report: check migration symlinks. Check if `HOMEBREW_CELLAR/old_name` is a symlink. If so, it's already been migrated so can be skipped.
Library/Homebrew/cmd/update-report.rb
@@ -503,7 +503,9 @@ def migrate_tap_migration def migrate_formula_rename Formula.installed.map(&:oldname).compact.each do |old_name| - next unless (dir = HOMEBREW_CELLAR/old_name).directory? && !dir.subdirs.empty? + old_name_dir = HOMEBREW_CELLAR/old_name + next if old_name_dir.symlink? + next unless old_name_dir.directory? && !old_name_dir.subdirs.empty? new_name = tap.formula_renames[old_name] next unless new_name
false
Other
Homebrew
brew
f59eb358c29c5f40601a99e3f1bf7e8e891f10ba.json
missing_formula: subsume historic logic. These methods belong together so combine them in a single class to provide a simpler API.
Library/Homebrew/cmd/info.rb
@@ -23,7 +23,6 @@ require "keg" require "tab" require "json" -require "historic" module Homebrew module_function @@ -57,22 +56,10 @@ def print_info end rescue FormulaUnavailableError => e # No formula with this name, try a missing formula lookup - if (missing_formula = Homebrew::MissingFormula.missing_formula(f)) - ofail "#{e.message}\n#{missing_formula}" + if (reason = Homebrew::MissingFormula.reason(f)) + ofail "#{e.message}\n#{reason}" else ofail e.message - - # No point in searching if the specified tap isn't tapped yet - next if e.instance_of?(TapFormulaUnavailableError) && !e.tap.installed? - - migrations = search_for_migrated_formula(f) - next unless migrations.empty? - ohai "Searching among deleted formulae..." - begin - search_for_deleted_formula(f) - rescue - nil - end end end end
true
Other
Homebrew
brew
f59eb358c29c5f40601a99e3f1bf7e8e891f10ba.json
missing_formula: subsume historic logic. These methods belong together so combine them in a single class to provide a simpler API.
Library/Homebrew/cmd/install.rb
@@ -62,7 +62,6 @@ require "tap" require "hardware" require "development_tools" -require "historic" module Homebrew module_function @@ -207,24 +206,13 @@ def install # formula was found, but there's a problem with its implementation). ofail e.message rescue FormulaUnavailableError => e - if (missing_formula = Homebrew::MissingFormula.missing_formula(e.name)) - ofail "#{e.message}\n#{missing_formula}" + if (reason = Homebrew::MissingFormula.reason(e.name)) + ofail "#{e.message}\n#{reason}" elsif e.name == "updog" ofail "What's updog?" else ofail e.message - migrations = search_for_migrated_formula(e.name) - return unless migrations.empty? - - ohai "Searching among deleted formulae..." - begin - search_for_deleted_formula(e.name) - return - rescue - nil - end - query = query_regexp(e.name) ohai "Searching for similarly named formulae..."
true
Other
Homebrew
brew
f59eb358c29c5f40601a99e3f1bf7e8e891f10ba.json
missing_formula: subsume historic logic. These methods belong together so combine them in a single class to provide a simpler API.
Library/Homebrew/cmd/search.rb
@@ -67,12 +67,12 @@ def search if $stdout.tty? count = local_results.length + tap_results.length - if msg = Homebrew::MissingFormula.missing_formula(query) + if reason = Homebrew::MissingFormula.reason(query) if count > 0 puts puts "If you meant #{query.inspect} specifically:" end - puts msg + puts reason elsif count.zero? puts "No formula found for #{query.inspect}." begin
true
Other
Homebrew
brew
f59eb358c29c5f40601a99e3f1bf7e8e891f10ba.json
missing_formula: subsume historic logic. These methods belong together so combine them in a single class to provide a simpler API.
Library/Homebrew/exceptions.rb
@@ -94,19 +94,6 @@ def to_s end end -class FormulaExistsError < RuntimeError - attr_reader :name, :path - - def initialize(name, path) - @name = name - @path = path - end - - def to_s - "Formula #{name} exists in #{path}" - end -end - class FormulaClassUnavailableError < FormulaUnavailableError attr_reader :path attr_reader :class_name
true
Other
Homebrew
brew
f59eb358c29c5f40601a99e3f1bf7e8e891f10ba.json
missing_formula: subsume historic logic. These methods belong together so combine them in a single class to provide a simpler API.
Library/Homebrew/historic.rb
@@ -1,57 +0,0 @@ -require "formulary" -require "tap" - -module Homebrew - module_function - - # name should not be qualified, since migration of qualified names is already - # handled in Formulary::TapLoader.formula_name_path. - def search_for_migrated_formula(name, options = {}) - print_messages = options.fetch(:print_messages, true) - migrations = [] - Tap.each do |old_tap| - new_tap_name = old_tap.tap_migrations[name] - next unless new_tap_name - migrations << [old_tap, new_tap_name] - next unless print_messages - deprecation = (new_tap_name == "homebrew/boneyard") ? "deprecated " : "" - puts "A #{deprecation}formula named \"#{name}\" has been migrated from #{old_tap} to #{new_tap_name}." - end - migrations - end - - # name may be qualified. - def search_for_deleted_formula(name, options = {}) - print_messages = options.fetch(:print_messages, true) - warn_shallow = options.fetch(:warn_shallow, false) - - path = Formulary.path name - raise FormulaExistsError.new(name, path) if File.exist? path - path.to_s =~ HOMEBREW_TAP_PATH_REGEX - tap = Tap.new ($1 == "Homebrew" ? "homebrew" : $1), $2.strip_prefix("homebrew-") - raise TapUnavailableError, tap.name unless File.exist? tap.path - relpath = path.relative_path_from tap.path - - cd tap.path - - if warn_shallow && File.exist?(".git/shallow") - opoo <<-EOS.undend - The git repository is a shallow clone therefore the output may be incomplete. - Use `git fetch -C #{tap.path} --unshallow` to get the full repository. - EOS - end - - log_cmd = "git log --name-only --max-count=1 --format=$'format:%H\\n%h' -- #{relpath}" - hash, hash_abbrev, relpath = Utils.popen_read(log_cmd).lines.map(&:chomp) - if hash.to_s.empty? || hash_abbrev.to_s.empty? || relpath.to_s.empty? - raise FormulaUnavailableError, name - end - - if print_messages - puts "#{name} was deleted from #{tap.name} in commit #{hash_abbrev}." - puts "Run `brew boneyard #{name}` to show the formula's content prior to its removal." - end - - [tap, relpath, hash, hash_abbrev] - end -end
true
Other
Homebrew
brew
f59eb358c29c5f40601a99e3f1bf7e8e891f10ba.json
missing_formula: subsume historic logic. These methods belong together so combine them in a single class to provide a simpler API.
Library/Homebrew/missing_formula.rb
@@ -6,7 +6,7 @@ module Homebrew module MissingFormula class << self def reason(name) - blacklisted_reason(name) + blacklisted_reason(name) || tap_migration_reason(name) || deleted_reason(name) end def blacklisted_reason(name) @@ -100,6 +100,59 @@ def blacklisted_reason(name) end alias generic_blacklisted_reason blacklisted_reason + def tap_migration_reason(name) + message = nil + + Tap.each do |old_tap| + new_tap_name = old_tap.tap_migrations[name] + next unless new_tap_name + message = <<-EOS.undent + It was migrated from #{old_tap} to #{new_tap_name}. + You can access it again by running: + brew tap #{new_tap_name} + EOS + break + end + + message + end + + def deleted_reason(name) + path = Formulary.path name + return if File.exist? path + tap = Tap.from_path(path) + return unless File.exist? tap.path + relative_path = path.relative_path_from tap.path + + tap.path.cd do + # We know this may return incomplete results for shallow clones but + # we don't want to nag everyone with a shallow clone to unshallow it. + log_command = "git log --name-only --max-count=1 --format=%H\\\\n%h\\\\n%B -- #{relative_path}" + hash, short_hash, *commit_message, relative_path = + Utils.popen_read(log_command).gsub("\\n", "\n").lines.map(&:chomp) + if hash.to_s.empty? || short_hash.to_s.empty? || + relative_path.to_s.empty? + return + end + + commit_message = commit_message.reject(&:empty?).join("\n ") + + commit_message.sub!(/ \(#(\d+)\)$/, " (#{tap.issues_url}/\\1)") + commit_message.gsub!(/(Closes|Fixes) #(\d+)/, "\\1 #{tap.issues_url}/\\2") + + <<-EOS.undent + #{name} was deleted from #{tap.name} in commit #{short_hash}: + #{commit_message} + + To show the formula before removal run: + git -C "$(brew --repo #{tap})" show #{short_hash}^:#{relative_path} + + If you still use this formula consider creating your own tap: + http://docs.brew.sh/How-to-Create-and-Maintain-a-Tap.html + EOS + end + end + require "extend/os/missing_formula" end end
true
Other
Homebrew
brew
f59eb358c29c5f40601a99e3f1bf7e8e891f10ba.json
missing_formula: subsume historic logic. These methods belong together so combine them in a single class to provide a simpler API.
Library/Homebrew/test/historic_test.rb
@@ -1,46 +0,0 @@ -require "testing_env" -require "historic" - -class HistoricTest < Homebrew::TestCase - def setup - super - - @path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" - @path.mkpath - @tap = Tap.new("Homebrew", "foo") - - (@path/"tap_migrations.json").write <<-EOS.undent - { "migrated-formula": "homebrew/bar" } - EOS - (@path/"Formula/to-delete.rb").write "placeholder" - - @path.cd do - shutup do - system "git", "init" - system "git", "add", "--all" - system "git", "commit", "-m", "initial state" - system "git", "rm", "Formula/to-delete.rb" - system "git", "commit", "-m", "delete formula 'to-delete'" - end - end - end - - def teardown - @path.rmtree - - super - end - - def test_search_for_migrated_formula - migrations = Homebrew.search_for_migrated_formula("migrated-formula", print_messages: false) - assert_equal [[@tap, "homebrew/bar"]], migrations - end - - def test_search_for_deleted_formula - tap, relpath, hash, = Homebrew.search_for_deleted_formula("homebrew/foo/to-delete", - print_messages: false) - assert_equal tap, @tap - assert_equal relpath, "Formula/to-delete.rb" - assert_equal `git rev-parse HEAD`.chomp, hash - end -end
true
Other
Homebrew
brew
f59eb358c29c5f40601a99e3f1bf7e8e891f10ba.json
missing_formula: subsume historic logic. These methods belong together so combine them in a single class to provide a simpler API.
Library/Homebrew/test/missing_formula_spec.rb
@@ -1,13 +1,13 @@ require "missing_formula" describe Homebrew::MissingFormula do - context ".reason" do + context "::reason" do subject { described_class.reason("gem") } it { is_expected.to_not be_nil } end - context ".blacklisted_reason" do + context "::blacklisted_reason" do matcher(:be_blacklisted) do match(&Homebrew::MissingFormula.method(:blacklisted_reason)) end @@ -122,4 +122,58 @@ end end end + + context "::tap_migration_reason" do + subject { described_class.tap_migration_reason(formula) } + + before do + Tap.clear_cache + tap_path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" + tap_path.mkpath + (tap_path/"tap_migrations.json").write <<-EOS.undent + { "migrated-formula": "homebrew/bar" } + EOS + end + + context "with a migrated formula" do + let(:formula) { "migrated-formula" } + it { is_expected.to_not be_nil } + end + + context "with a missing formula" do + let(:formula) { "missing-formula" } + it { is_expected.to be_nil } + end + end + + context "::deleted_reason" do + subject { described_class.deleted_reason(formula) } + + before do + Tap.clear_cache + tap_path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" + tap_path.mkpath + (tap_path/"deleted-formula.rb").write "placeholder" + + tap_path.cd do + shutup do + system "git", "init" + system "git", "add", "--all" + system "git", "commit", "-m", "initial state" + system "git", "rm", "deleted-formula.rb" + system "git", "commit", "-m", "delete formula 'deleted-formula'" + end + end + end + + context "with a deleted formula" do + let(:formula) { "homebrew/foo/deleted-formula" } + it { is_expected.to_not be_nil } + end + + context "with a formula that never existed" do + let(:formula) { "homebrew/foo/missing-formula" } + it { is_expected.to be_nil } + end + end end
true
Other
Homebrew
brew
623c95b3f8660d5c77936483ec9b9a4db16aff00.json
cmd/log: improve output messaging. This wasn’t adapted to the new, multiple repository world.
Library/Homebrew/cmd/log.rb
@@ -9,20 +9,32 @@ module Homebrew def log if ARGV.named.empty? - cd HOMEBREW_REPOSITORY - git_log + git_log HOMEBREW_REPOSITORY else path = Formulary.path(ARGV.named.first) - cd path.dirname # supports taps - git_log path + tap = Tap.from_path(path) + git_log path.dirname, path, tap end end - def git_log(path = nil) - if File.exist? "#{`git rev-parse --show-toplevel`.chomp}/.git/shallow" + def git_log(cd_dir, path = nil, tap = nil) + cd cd_dir + repo = Utils.popen_read("git rev-parse --show-toplevel").chomp + if tap + name = tap.to_s + git_cd = "$(brew --repo #{tap})" + elsif cd_dir == HOMEBREW_REPOSITORY + name = "Homebrew/brew" + git_cd = "$(brew --repo)" + else + name, git_cd = cd_dir + end + + if File.exist? "#{repo}/.git/shallow" opoo <<-EOS.undent - The git repository is a shallow clone therefore the filtering may be incorrect. - Use `git fetch --unshallow` to get the full repository. + #{name} is a shallow clone so only partial output will be shown. + To get a full clone run: + git -C "#{git_cd}" fetch --unshallow EOS end args = ARGV.options_only
true
Other
Homebrew
brew
623c95b3f8660d5c77936483ec9b9a4db16aff00.json
cmd/log: improve output messaging. This wasn’t adapted to the new, multiple repository world.
Library/Homebrew/test/cmd/log_spec.rb
@@ -33,7 +33,7 @@ expect { brew "log", "#{shallow_tap}/testball" } .to output(/This is a test commit for Testball/).to_stdout - .and output(/Warning: The git repository is a shallow clone/).to_stderr + .and output(%r{Warning: homebrew/shallow is a shallow clone}).to_stderr .and be_a_success expect(shallow_tap.path/".git/shallow").to exist, "A shallow clone should have been created."
true
Other
Homebrew
brew
ac10b2ab50e987858b9fa5514785b12b7600787f.json
Tap: add from_path helper method. This makes it easier to turn an arbitrary path into a tap path.
Library/Homebrew/tap.rb
@@ -41,6 +41,15 @@ def self.fetch(*args) CACHE.fetch(cache_key) { |key| CACHE[key] = Tap.new(user, repo) } end + def self.from_path(path) + path.to_s =~ HOMEBREW_TAP_PATH_REGEX + raise "Invalid tap path '#{path}'" unless $1 + fetch($1, $2) + rescue + # No need to error as a nil tap is sufficient to show failure. + nil + end + extend Enumerable # The user name of this {Tap}. Usually, it's the Github username of
false
Other
Homebrew
brew
d11e417105c04a1c21edfb4481bc26e21f1c94f9.json
Hide output from brew cask uninstall test This test showed extraneous info in the test output
Library/Homebrew/test/cask/cli/uninstall_spec.rb
@@ -30,7 +30,9 @@ it "tries anyway on a non-present Cask when --force is given" do expect { - Hbc::CLI::Uninstall.run("local-caffeine", "--force") + shutup do + Hbc::CLI::Uninstall.run("local-caffeine", "--force") + end }.not_to raise_error end
false
Other
Homebrew
brew
3703ef1885ba4afce1ed4ae531dcb7ddc573b3c2.json
Show messages when (un)installing Casks Addresses an issue where it can be unclear at times exactly which part of the (un|re)installation processes is reporting an error. See https://github.com/caskroom/homebrew-cask/issues/30968
Library/Homebrew/cask/lib/hbc/installer.rb
@@ -85,6 +85,8 @@ def install print_caveats fetch uninstall_if_neccessary + + oh1 "Installing Cask #{@cask}" stage install_artifacts enable_accessibility_access @@ -322,7 +324,7 @@ def save_caskfile end def uninstall - odebug "Hbc::Installer#uninstall" + oh1 "Uninstalling Cask #{@cask}" disable_accessibility_access uninstall_artifacts purge_versioned_files
true
Other
Homebrew
brew
3703ef1885ba4afce1ed4ae531dcb7ddc573b3c2.json
Show messages when (un)installing Casks Addresses an issue where it can be unclear at times exactly which part of the (un|re)installation processes is reporting an error. See https://github.com/caskroom/homebrew-cask/issues/30968
Library/Homebrew/test/cask/cli/install_spec.rb
@@ -1,4 +1,18 @@ describe Hbc::CLI::Install, :cask do + it "displays the installation progress" do + output = Regexp.new <<-EOS.undent + ==> Downloading file:.*/caffeine.zip + ==> Verifying checksum for Cask local-caffeine + ==> Installing Cask local-caffeine + ==> Moving App 'Caffeine.app' to '.*/Caffeine.app'. + 🍺 local-caffeine was successfully installed! + EOS + + expect { + Hbc::CLI::Install.run("local-caffeine") + }.to output(output).to_stdout + end + it "allows staging and activation of multiple Casks at once" do shutup do Hbc::CLI::Install.run("local-transmission", "local-caffeine")
true
Other
Homebrew
brew
3703ef1885ba4afce1ed4ae531dcb7ddc573b3c2.json
Show messages when (un)installing Casks Addresses an issue where it can be unclear at times exactly which part of the (un|re)installation processes is reporting an error. See https://github.com/caskroom/homebrew-cask/issues/30968
Library/Homebrew/test/cask/cli/reinstall_spec.rb
@@ -1,4 +1,27 @@ describe Hbc::CLI::Reinstall, :cask do + it "displays the reinstallation progress" do + caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") + + shutup do + Hbc::Installer.new(caffeine).install + end + + output = Regexp.new <<-EOS.undent + ==> Downloading file:.*/caffeine.zip + Already downloaded: .*/local-caffeine--1.2.3.zip + ==> Verifying checksum for Cask local-caffeine + ==> Uninstalling Cask local-caffeine + ==> Removing App '.*/Caffeine.app'. + ==> Installing Cask local-caffeine + ==> Moving App 'Caffeine.app' to '.*/Caffeine.app'. + 🍺 local-caffeine was successfully installed! + EOS + + expect { + Hbc::CLI::Reinstall.run("local-caffeine") + }.to output(output).to_stdout + end + it "allows reinstalling a Cask" do shutup do Hbc::CLI::Install.run("local-transmission")
true
Other
Homebrew
brew
3703ef1885ba4afce1ed4ae531dcb7ddc573b3c2.json
Show messages when (un)installing Casks Addresses an issue where it can be unclear at times exactly which part of the (un|re)installation processes is reporting an error. See https://github.com/caskroom/homebrew-cask/issues/30968
Library/Homebrew/test/cask/cli/uninstall_spec.rb
@@ -1,4 +1,21 @@ describe Hbc::CLI::Uninstall, :cask do + it "displays the uninstallation progress" do + caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") + + shutup do + Hbc::Installer.new(caffeine).install + end + + output = Regexp.new <<-EOS.undent + ==> Uninstalling Cask local-caffeine + ==> Removing App '.*/Caffeine.app'. + EOS + + expect { + Hbc::CLI::Uninstall.run("local-caffeine") + }.to output(output).to_stdout + end + it "shows an error when a bad Cask is provided" do expect { Hbc::CLI::Uninstall.run("notacask")
true
Other
Homebrew
brew
1206e9e3f296b2876238da0ce1e5248d94df9002.json
Remove double space.
docs/How-to-Create-and-Maintain-a-Tap.md
@@ -42,7 +42,7 @@ avoid conflicts. ## Maintaining a tap A tap is just a git repository so you don’t have to do anything specific when -making modifications,  apart from committing and pushing your changes. +making modifications, apart from committing and pushing your changes. ### Updating Once your tap is installed, Homebrew will update it each time a user runs
false
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/cask/lib/hbc.rb
@@ -42,8 +42,4 @@ def self.init Cache.ensure_cache_exists Caskroom.ensure_caskroom_exists end - - def self.load(ref) - CaskLoader.load(ref) - end end
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/cask/lib/hbc/cask_dependencies.rb
@@ -15,7 +15,7 @@ def graph_dependencies walk = lambda do |acc, deps| deps.each do |dep| next if acc.key?(dep) - succs = deps_in.call Hbc.load(dep) + succs = deps_in.call CaskLoader.load(dep) acc[dep] = succs walk.call(acc, succs) end
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/cask/lib/hbc/cli/audit.rb
@@ -40,7 +40,7 @@ def casks_to_audit if cask_tokens.empty? Hbc.all else - cask_tokens.map { |token| Hbc.load(token) } + cask_tokens.map { |token| CaskLoader.load(token) } end end
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/cask/lib/hbc/cli/fetch.rb
@@ -8,7 +8,7 @@ def self.run(*args) cask_tokens.each do |cask_token| ohai "Downloading external files for Cask #{cask_token}" - cask = Hbc.load(cask_token) + cask = CaskLoader.load(cask_token) downloaded_path = Download.new(cask, force: force).perform Verify.all(cask, downloaded_path) ohai "Success! Downloaded to -> #{downloaded_path}"
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/cask/lib/hbc/cli/home.rb
@@ -8,7 +8,7 @@ def self.run(*cask_tokens) else cask_tokens.each do |cask_token| odebug "Opening homepage for Cask #{cask_token}" - cask = Hbc.load(cask_token) + cask = CaskLoader.load(cask_token) system "/usr/bin/open", "--", cask.homepage end end
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/cask/lib/hbc/cli/info.rb
@@ -6,7 +6,7 @@ def self.run(*args) raise CaskUnspecifiedError if cask_tokens.empty? cask_tokens.each do |cask_token| odebug "Getting info for Cask #{cask_token}" - cask = Hbc.load(cask_token) + cask = CaskLoader.load(cask_token) info(cask) end
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/cask/lib/hbc/cli/install.rb
@@ -18,7 +18,7 @@ def self.install_casks(cask_tokens, force, skip_cask_deps, require_sha) count = 0 cask_tokens.each do |cask_token| begin - cask = Hbc.load(cask_token) + cask = CaskLoader.load(cask_token) Installer.new(cask, force: force, skip_cask_deps: skip_cask_deps,
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb
@@ -24,7 +24,7 @@ def self.appcask_checkpoint(cask_tokens, calculate) count = 0 cask_tokens.each do |cask_token| - cask = Hbc.load(cask_token) + cask = CaskLoader.load(cask_token) if cask.appcast.nil? opoo "Cask '#{cask}' is missing an `appcast` stanza."
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb
@@ -84,7 +84,7 @@ def git_filter_cask_files(filter) def modified_casks return @modified_casks if defined? @modified_casks - @modified_casks = modified_cask_files.map { |f| Hbc.load(f) } + @modified_casks = modified_cask_files.map { |f| CaskLoader.load(f) } if @modified_casks.any? num_modified = @modified_casks.size ohai "#{Formatter.pluralize(num_modified, "modified cask")}: " \
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/cask/lib/hbc/cli/internal_checkurl.rb
@@ -2,7 +2,7 @@ module Hbc class CLI class InternalCheckurl < InternalUseBase def self.run(*args) - casks_to_check = args.empty? ? Hbc.all : args.map { |arg| Hbc.load(arg) } + casks_to_check = args.empty? ? Hbc.all : args.map { |arg| CaskLoader.load(arg) } casks_to_check.each do |cask| odebug "Checking URL for Cask #{cask}" checker = UrlChecker.new(cask)
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb
@@ -16,7 +16,7 @@ def self.dump_casks(*cask_tokens) count = 0 cask_tokens.each do |cask_token| begin - cask = Hbc.load(cask_token) + cask = CaskLoader.load(cask_token) count += 1 cask.dumpcask rescue StandardError => e
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb
@@ -84,7 +84,7 @@ def self.print_stanzas(stanza, format = nil, table = nil, quiet = nil, *cask_tok print "#{cask_token}\t" if table begin - cask = Hbc.load(cask_token) + cask = CaskLoader.load(cask_token) rescue StandardError opoo "Cask '#{cask_token}' was not found" unless quiet puts ""
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/cask/lib/hbc/cli/list.rb
@@ -28,7 +28,7 @@ def self.list(*cask_tokens) cask_tokens.each do |cask_token| odebug "Listing files for Cask #{cask_token}" begin - cask = Hbc.load(cask_token) + cask = CaskLoader.load(cask_token) if cask.installed? if @options[:one]
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/cask/lib/hbc/cli/outdated.rb
@@ -9,7 +9,7 @@ def self.run(*args) casks_to_check = if cask_tokens.empty? Hbc.installed else - cask_tokens.map { |token| Hbc.load(token) } + cask_tokens.map { |token| CaskLoader.load(token) } end casks_to_check.each do |cask|
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/cask/lib/hbc/cli/reinstall.rb
@@ -5,7 +5,7 @@ def self.install_casks(cask_tokens, force, skip_cask_deps, require_sha) count = 0 cask_tokens.each do |cask_token| begin - cask = Hbc.load(cask_token) + cask = CaskLoader.load(cask_token) installer = Installer.new(cask, force: force,
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/cask/lib/hbc/cli/uninstall.rb
@@ -8,7 +8,7 @@ def self.run(*args) cask_tokens.each do |cask_token| odebug "Uninstalling Cask #{cask_token}" - cask = Hbc.load(cask_token) + cask = CaskLoader.load(cask_token) raise CaskNotInstalledError, cask unless cask.installed? || force
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/cask/lib/hbc/cli/zap.rb
@@ -6,7 +6,7 @@ def self.run(*args) raise CaskUnspecifiedError if cask_tokens.empty? cask_tokens.each do |cask_token| odebug "Zapping Cask #{cask_token}" - cask = Hbc.load(cask_token) + cask = CaskLoader.load(cask_token) Installer.new(cask).zap end end
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/cask/lib/hbc/installer.rb
@@ -229,7 +229,7 @@ def cask_dependencies deps = CaskDependencies.new(@cask) deps.sorted.each do |dep_token| puts "#{dep_token} ..." - dep = Hbc.load(dep_token) + dep = CaskLoader.load(dep_token) if dep.installed? puts "already installed" else
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/cask/lib/hbc/scopes.rb
@@ -23,10 +23,10 @@ def all_tokens end def installed - # Hbc.load has some DWIM which is slow. Optimize here - # by spoon-feeding Hbc.load fully-qualified paths. + # CaskLoader.load has some DWIM which is slow. Optimize here + # by spoon-feeding CaskLoader.load fully-qualified paths. # TODO: speed up Hbc::Source::Tapped (main perf drag is calling Hbc.all_tokens repeatedly) - # TODO: ability to specify expected source when calling Hbc.load (minor perf benefit) + # TODO: ability to specify expected source when calling CaskLoader.load (minor perf benefit) Pathname.glob(caskroom.join("*")) .map do |caskroom_path| token = caskroom_path.basename.to_s @@ -36,9 +36,9 @@ def installed end if path_to_cask - Hbc.load(path_to_cask.join("#{token}.rb")) + CaskLoader.load(path_to_cask.join("#{token}.rb")) else - Hbc.load(token) + CaskLoader.load(token) end end end
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/test/cask/audit_spec.rb
@@ -79,7 +79,7 @@ def include_msg?(messages, msg) end describe "#run!" do - let(:cask) { Hbc.load(cask_token) } + let(:cask) { Hbc::CaskLoader.load(cask_token) } subject { audit.run! } describe "required stanzas" do @@ -320,7 +320,7 @@ def include_msg?(messages, msg) describe "audit of downloads" do let(:cask_token) { "with-binary" } - let(:cask) { Hbc.load(cask_token) } + let(:cask) { Hbc::CaskLoader.load(cask_token) } let(:download) { instance_double(Hbc::Download) } let(:verify) { class_double(Hbc::Verify).as_stubbed_const } let(:error_msg) { "Download Failed" }
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/test/cask/cask_spec.rb
@@ -27,20 +27,20 @@ let(:relative_tap_path) { tap_path.relative_path_from(file_dirname) } it "returns an instance of the Cask for the given token" do - c = Hbc.load("local-caffeine") + c = Hbc::CaskLoader.load("local-caffeine") expect(c).to be_kind_of(Hbc::Cask) expect(c.token).to eq("local-caffeine") end it "returns an instance of the Cask from a specific file location" do - c = Hbc.load("#{tap_path}/Casks/local-caffeine.rb") + c = Hbc::CaskLoader.load("#{tap_path}/Casks/local-caffeine.rb") expect(c).to be_kind_of(Hbc::Cask) expect(c.token).to eq("local-caffeine") end it "returns an instance of the Cask from a url" do c = shutup do - Hbc.load("file://#{tap_path}/Casks/local-caffeine.rb") + Hbc::CaskLoader.load("file://#{tap_path}/Casks/local-caffeine.rb") end expect(c).to be_kind_of(Hbc::Cask) expect(c.token).to eq("local-caffeine") @@ -50,25 +50,25 @@ expect { url = "file://#{tap_path}/Casks/notacask.rb" shutup do - Hbc.load(url) + Hbc::CaskLoader.load(url) end }.to raise_error(Hbc::CaskUnavailableError) end it "returns an instance of the Cask from a relative file location" do - c = Hbc.load(relative_tap_path/"Casks/local-caffeine.rb") + c = Hbc::CaskLoader.load(relative_tap_path/"Casks/local-caffeine.rb") expect(c).to be_kind_of(Hbc::Cask) expect(c.token).to eq("local-caffeine") end it "uses exact match when loading by token" do - expect(Hbc.load("test-opera").token).to eq("test-opera") - expect(Hbc.load("test-opera-mail").token).to eq("test-opera-mail") + expect(Hbc::CaskLoader.load("test-opera").token).to eq("test-opera") + expect(Hbc::CaskLoader.load("test-opera-mail").token).to eq("test-opera-mail") end it "raises an error when attempting to load a Cask that doesn't exist" do expect { - Hbc.load("notacask") + Hbc::CaskLoader.load("notacask") }.to raise_error(Hbc::CaskUnavailableError) end end @@ -84,21 +84,21 @@ describe "metadata" do it "proposes a versioned metadata directory name for each instance" do cask_token = "local-caffeine" - c = Hbc.load(cask_token) + c = Hbc::CaskLoader.load(cask_token) metadata_path = Hbc.caskroom.join(cask_token, ".metadata", c.version) expect(c.metadata_versioned_container_path.to_s).to eq(metadata_path.to_s) end end describe "outdated" do it "ignores the Casks that have auto_updates true (without --greedy)" do - c = Hbc.load("auto-updates") + c = Hbc::CaskLoader.load("auto-updates") expect(c).not_to be_outdated expect(c.outdated_versions).to be_empty end it "ignores the Casks that have version :latest (without --greedy)" do - c = Hbc.load("version-latest-string") + c = Hbc::CaskLoader.load("version-latest-string") expect(c).not_to be_outdated expect(c.outdated_versions).to be_empty end
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/test/cask/cli/audit_spec.rb
@@ -13,7 +13,7 @@ it "audits specified Casks if tokens are given" do cask_token = "nice-app" - expect(Hbc).to receive(:load).with(cask_token).and_return(cask) + expect(Hbc::CaskLoader).to receive(:load).with(cask_token).and_return(cask) expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: false) @@ -23,14 +23,14 @@ describe "rules for downloading a Cask" do it "does not download the Cask per default" do - allow(Hbc).to receive(:load).and_return(cask) + allow(Hbc::CaskLoader).to receive(:load).and_return(cask) expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: false) run_audit(["casktoken"], auditor) end it "download a Cask if --download flag is set" do - allow(Hbc).to receive(:load).and_return(cask) + allow(Hbc::CaskLoader).to receive(:load).and_return(cask) expect(auditor).to receive(:audit).with(cask, audit_download: true, check_token_conflicts: false) run_audit(["casktoken", "--download"], auditor) @@ -39,14 +39,14 @@ describe "rules for checking token conflicts" do it "does not check for token conflicts per default" do - allow(Hbc).to receive(:load).and_return(cask) + allow(Hbc::CaskLoader).to receive(:load).and_return(cask) expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: false) run_audit(["casktoken"], auditor) end it "checks for token conflicts if --token-conflicts flag is set" do - allow(Hbc).to receive(:load).and_return(cask) + allow(Hbc::CaskLoader).to receive(:load).and_return(cask) expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: true) run_audit(["casktoken", "--token-conflicts"], auditor)
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/test/cask/cli/list_spec.rb
@@ -1,6 +1,6 @@ describe Hbc::CLI::List, :cask do it "lists the installed Casks in a pretty fashion" do - casks = %w[local-caffeine local-transmission].map { |c| Hbc.load(c) } + casks = %w[local-caffeine local-transmission].map { |c| Hbc::CaskLoader.load(c) } casks.each do |c| InstallHelper.install_with_caskfile(c) @@ -24,7 +24,7 @@ } before(:each) do - casks.map(&Hbc.method(:load)).each(&InstallHelper.method(:install_with_caskfile)) + casks.map(&Hbc::CaskLoader.method(:load)).each(&InstallHelper.method(:install_with_caskfile)) end it "of all installed Casks" do
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/test/cask/cli/zap_spec.rb
@@ -32,7 +32,7 @@ # The above tests that implicitly. # # it "dispatches both uninstall and zap stanzas" do - # with_zap = Hbc.load('with-zap') + # with_zap = Hbc::CaskLoader.load('with-zap') # # shutup do # Hbc::Installer.new(with_zap).install
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/test/cask/depends_on_spec.rb
@@ -17,7 +17,7 @@ context do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask.rb") } - let(:dependency) { Hbc.load(cask.depends_on.cask.first) } + let(:dependency) { Hbc::CaskLoader.load(cask.depends_on.cask.first) } it "installs the dependency of a Cask and the Cask itself" do expect(subject).not_to raise_error
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/test/cask/download_strategy_spec.rb
@@ -291,7 +291,7 @@ # does not work yet, because (for unknown reasons), the tar command # returns an error code when running under the test suite # it 'creates a tarball matching the expected checksum' do - # cask = Hbc.load('svn-download-check-cask') + # cask = Hbc::CaskLoader.load('svn-download-check-cask') # downloader = Hbc::SubversionDownloadStrategy.new(cask) # # special mocking required for tar to have something to work with # def downloader.fetch_repo(target, url, revision = nil, ignore_externals=false)
true
Other
Homebrew
brew
ed10135da4fbabca2798afe949b6f5af9544ec9f.json
Replace `Hbc.load` with `CaskLoader.load`.
Library/Homebrew/test/cask/scopes_spec.rb
@@ -1,15 +1,15 @@ describe Hbc::Scopes, :cask do describe "installed" do it "returns a list installed Casks by loading Casks for all the dirs that exist in the caskroom" do - allow(Hbc).to receive(:load) { |token| "loaded-#{token}" } + allow(Hbc::CaskLoader).to receive(:load) { |token| "loaded-#{token}" } Hbc.caskroom.join("cask-bar").mkpath Hbc.caskroom.join("cask-foo").mkpath installed_casks = Hbc.installed - expect(Hbc).to have_received(:load).with("cask-bar") - expect(Hbc).to have_received(:load).with("cask-foo") + expect(Hbc::CaskLoader).to have_received(:load).with("cask-bar") + expect(Hbc::CaskLoader).to have_received(:load).with("cask-foo") expect(installed_casks).to eq( %w[ loaded-cask-bar @@ -18,11 +18,11 @@ ) end - it "optimizes performance by resolving to a fully qualified path before calling Hbc.load" do + it "optimizes performance by resolving to a fully qualified path before calling Hbc::CaskLoader.load" do fake_tapped_cask_dir = Pathname.new(Dir.mktmpdir).join("Casks") absolute_path_to_cask = fake_tapped_cask_dir.join("some-cask.rb") - allow(Hbc).to receive(:load) + allow(Hbc::CaskLoader).to receive(:load) allow(Hbc).to receive(:all_tapped_cask_dirs) { [fake_tapped_cask_dir] } Hbc.caskroom.join("some-cask").mkdir @@ -31,7 +31,7 @@ Hbc.installed - expect(Hbc).to have_received(:load).with(absolute_path_to_cask) + expect(Hbc::CaskLoader).to have_received(:load).with(absolute_path_to_cask) end end end
true
Other
Homebrew
brew
d1995dad4bf76b447d9c97f1c2db99c6b3854b51.json
Use a `Formulary`-like approach to load Casks.
Library/Homebrew/cask/lib/hbc.rb
@@ -7,7 +7,6 @@ require "hbc/cache" require "hbc/cask" require "hbc/cask_loader" -require "hbc/without_source" require "hbc/caskroom" require "hbc/checkable" require "hbc/cli" @@ -24,7 +23,6 @@ require "hbc/pkg" require "hbc/qualified_token" require "hbc/scopes" -require "hbc/source" require "hbc/staged" require "hbc/system_command" require "hbc/topological_hash" @@ -45,10 +43,7 @@ def self.init Caskroom.ensure_caskroom_exists end - def self.load(query) - odebug "Loading Cask definitions" - cask = Source.for_query(query).load - cask.dumpcask - cask + def self.load(ref) + CaskLoader.load(ref) end end
true
Other
Homebrew
brew
d1995dad4bf76b447d9c97f1c2db99c6b3854b51.json
Use a `Formulary`-like approach to load Casks.
Library/Homebrew/cask/lib/hbc/cask_loader.rb
@@ -1,44 +1,167 @@ module Hbc - class CaskLoader - def self.load_from_file(path) - raise CaskError, "File '#{path}' does not exist" unless path.exist? - raise CaskError, "File '#{path}' is not readable" unless path.readable? - raise CaskError, "File '#{path}' is not a plain file" unless path.file? + module CaskLoader + class FromContentLoader + def initialize(content) + @content = content + end + + def load + instance_eval(@content.force_encoding("UTF-8"), __FILE__, __LINE__) + end - token = path.basename(".rb").to_s - content = IO.read(path).force_encoding("UTF-8") + private - new(token, content, path).load + def cask(header_token, &block) + Cask.new(header_token, &block) + end end - def self.load_from_string(token, content) - new(token, content).load + class FromPathLoader < FromContentLoader + def self.can_load?(ref) + path = Pathname.new(ref) + path.extname == ".rb" && path.expand_path.exist? + end + + attr_reader :token, :path + + def initialize(path) + path = Pathname.new(path).expand_path + + @token = path.basename(".rb").to_s + @path = path + end + + def load + raise CaskError, "'#{@path}' does not exist." unless @path.exist? + raise CaskError, "'#{@path}' is not readable." unless @path.readable? + raise CaskError, "'#{@path}' is not a file." unless @path.file? + + @content = IO.read(@path) + + super + end + + private + + def cask(header_token, &block) + if @token != header_token + raise CaskTokenDoesNotMatchError.new(@token, header_token) + end + + Cask.new(header_token, sourcefile_path: @path, &block) + end end - def load - instance_eval(@content, __FILE__, __LINE__) - rescue CaskError, StandardError, ScriptError => e - e.message.concat(" while loading '#{@token}'") - e.message.concat(" from '#{@path}'") unless @path.nil? - raise e, e.message + class FromURILoader < FromPathLoader + def self.can_load?(ref) + !(ref.to_s !~ ::URI.regexp) + end + + def initialize(url) + @url = url + uri = URI(url) + super Hbc.cache/File.basename(uri.path) + end + + def load + Hbc.cache.mkpath + FileUtils.rm_f @path + + begin + ohai "Downloading #{@url}." + curl @url, "-o", @path + rescue ErrorDuringExecution + raise CaskUnavailableError, @url + end + + super + end end - private + class FromTapLoader < FromPathLoader + def self.can_load?(ref) + !(ref.to_s !~ HOMEBREW_TAP_CASK_REGEX) + end + + def initialize(tapped_name) + user, repo, token = tapped_name.split("/", 3).map(&:downcase) + @tap = Tap.fetch(user, repo) + + super @tap.cask_dir/"#{token}.rb" + end - def initialize(token, content, path = nil) - @token = token - @content = content - @path = path unless path.nil? + def load + @tap.install unless @tap.installed? + + super + end + end + + class NullLoader < FromPathLoader + def self.can_load?(*) + true + end + + def initialize(ref) + @token = File.basename(ref, ".rb") + super CaskLoader.default_path(@token) + end + + def load + raise CaskUnavailableError, @token + end + end + + def self.load_from_file(path) + FromPathLoader.new(path).load + end + + def self.load_from_string(content) + FromContentLoader.new(content).load end - def cask(header_token, &block) - raise CaskTokenDoesNotMatchError.new(@token, header_token) unless @token == header_token + def self.path(ref) + self.for(ref).path + end + + def self.load(ref) + self.for(ref).load + end + + def self.for(ref) + [ + FromURILoader, + FromTapLoader, + FromPathLoader, + ].each do |loader_class| + return loader_class.new(ref) if loader_class.can_load?(ref) + end + + if FromPathLoader.can_load?(default_path(ref)) + return FromPathLoader.new(default_path(ref)) + end - if @path.nil? - Cask.new(@token, &block) - else - Cask.new(@token, sourcefile_path: @path, &block) + possible_tap_casks = tap_paths(ref) + if possible_tap_casks.count == 1 + possible_tap_cask = possible_tap_casks.first + return FromPathLoader.new(possible_tap_cask) end + + possible_installed_cask = Cask.new(ref) + if possible_installed_cask.installed? + return FromPathLoader.new(possible_installed_cask.installed_caskfile) + end + + NullLoader.new(ref) + end + + def self.default_path(token) + Hbc.default_tap.cask_dir/"#{token.to_s.downcase}.rb" + end + + def self.tap_paths(token) + Tap.map { |t| t.cask_dir/"#{token.to_s.downcase}.rb" } + .select(&:exist?) end end end
true
Other
Homebrew
brew
d1995dad4bf76b447d9c97f1c2db99c6b3854b51.json
Use a `Formulary`-like approach to load Casks.
Library/Homebrew/cask/lib/hbc/locations.rb
@@ -126,15 +126,14 @@ def path(query) end if token_with_tap - user, repo, token = token_with_tap.split("/") + user, repo, token = token_with_tap.split("/", 3) tap = Tap.fetch(user, repo) else token = query_without_extension tap = Hbc.default_tap end - return query_path if tap.cask_dir.nil? - tap.cask_dir.join("#{token}.rb") + CaskLoader.default_path(token) end def tcc_db
true
Other
Homebrew
brew
d1995dad4bf76b447d9c97f1c2db99c6b3854b51.json
Use a `Formulary`-like approach to load Casks.
Library/Homebrew/cask/lib/hbc/scopes.rb
@@ -11,15 +11,15 @@ def all end def all_tapped_cask_dirs - Tap.map(&:cask_dir).compact + Tap.map(&:cask_dir).select(&:directory?) end def all_tokens - Tap.map do |t| + Tap.flat_map do |t| t.cask_files.map do |p| "#{t.name}/#{File.basename(p, ".rb")}" end - end.flatten + end end def installed
true
Other
Homebrew
brew
d1995dad4bf76b447d9c97f1c2db99c6b3854b51.json
Use a `Formulary`-like approach to load Casks.
Library/Homebrew/cask/lib/hbc/source.rb
@@ -1,37 +0,0 @@ -require "hbc/source/gone" -require "hbc/source/path_slash_required" -require "hbc/source/path_slash_optional" -require "hbc/source/tapped_qualified" -require "hbc/source/untapped_qualified" -require "hbc/source/tapped" -require "hbc/source/uri" - -module Hbc - module Source - def self.sources - [ - URI, - PathSlashRequired, - TappedQualified, - UntappedQualified, - Tapped, - PathSlashOptional, - Gone, - ] - end - - def self.for_query(query) - odebug "Translating '#{query}' into a valid Cask source" - raise CaskUnavailableError, query if query.to_s =~ /^\s*$/ - source = sources.find do |s| - odebug "Testing source class #{s}" - s.me?(query) - end - raise CaskUnavailableError, query unless source - odebug "Success! Using source class #{source}" - resolved_cask_source = source.new(query) - odebug "Resolved Cask URI or file source to '#{resolved_cask_source}'" - resolved_cask_source - end - end -end
true
Other
Homebrew
brew
d1995dad4bf76b447d9c97f1c2db99c6b3854b51.json
Use a `Formulary`-like approach to load Casks.
Library/Homebrew/cask/lib/hbc/source/gone.rb
@@ -1,23 +0,0 @@ -module Hbc - module Source - class Gone - def self.me?(query) - WithoutSource.new(query).installed? - end - - attr_reader :query - - def initialize(query) - @query = query - end - - def load - WithoutSource.new(query) - end - - def to_s - "" - end - end - end -end
true
Other
Homebrew
brew
d1995dad4bf76b447d9c97f1c2db99c6b3854b51.json
Use a `Formulary`-like approach to load Casks.
Library/Homebrew/cask/lib/hbc/source/path_base.rb
@@ -1,29 +0,0 @@ -require "rubygems" -require "hbc/cask_loader" - -module Hbc - module Source - class PathBase - # derived classes must define method self.me? - - def self.path_for_query(query) - Pathname.new(query).sub(/(\.rb)?$/, ".rb") - end - - attr_reader :path - - def initialize(path) - @path = Pathname.new(path).expand_path - end - - def load - CaskLoader.load_from_file(@path) - end - - def to_s - # stringify to fully-resolved location - @path.to_s - end - end - end -end
true
Other
Homebrew
brew
d1995dad4bf76b447d9c97f1c2db99c6b3854b51.json
Use a `Formulary`-like approach to load Casks.
Library/Homebrew/cask/lib/hbc/source/path_slash_optional.rb
@@ -1,12 +0,0 @@ -require "hbc/source/path_base" - -module Hbc - module Source - class PathSlashOptional < PathBase - def self.me?(query) - path = path_for_query(query) - path.exist? - end - end - end -end
true
Other
Homebrew
brew
d1995dad4bf76b447d9c97f1c2db99c6b3854b51.json
Use a `Formulary`-like approach to load Casks.
Library/Homebrew/cask/lib/hbc/source/path_slash_required.rb
@@ -1,12 +0,0 @@ -require "hbc/source/path_base" - -module Hbc - module Source - class PathSlashRequired < PathBase - def self.me?(query) - path = path_for_query(query) - path.to_s.include?("/") && path.exist? - end - end - end -end
true
Other
Homebrew
brew
d1995dad4bf76b447d9c97f1c2db99c6b3854b51.json
Use a `Formulary`-like approach to load Casks.
Library/Homebrew/cask/lib/hbc/source/tapped.rb
@@ -1,24 +0,0 @@ -module Hbc - module Source - class Tapped - def self.me?(query) - Hbc.path(query).exist? - end - - attr_reader :token - - def initialize(token) - @token = token - end - - def load - PathSlashOptional.new(Hbc.path(token)).load - end - - def to_s - # stringify to fully-resolved location - Hbc.path(token).expand_path.to_s - end - end - end -end
true
Other
Homebrew
brew
d1995dad4bf76b447d9c97f1c2db99c6b3854b51.json
Use a `Formulary`-like approach to load Casks.
Library/Homebrew/cask/lib/hbc/source/tapped_qualified.rb
@@ -1,21 +0,0 @@ -require "hbc/source/tapped" - -module Hbc - module Source - class TappedQualified < Tapped - def self.me?(query) - return if (tap = tap_for_query(query)).nil? - - tap.installed? && Hbc.path(query).exist? - end - - def self.tap_for_query(query) - qualified_token = QualifiedToken.parse(query) - return if qualified_token.nil? - - user, repo = qualified_token[0..1] - Tap.fetch(user, repo) - end - end - end -end
true
Other
Homebrew
brew
d1995dad4bf76b447d9c97f1c2db99c6b3854b51.json
Use a `Formulary`-like approach to load Casks.
Library/Homebrew/cask/lib/hbc/source/untapped_qualified.rb
@@ -1,14 +0,0 @@ -require "hbc/source/tapped_qualified" - -module Hbc - module Source - class UntappedQualified < TappedQualified - def self.me?(query) - return if (tap = tap_for_query(query)).nil? - - tap.install - tap.installed? && Hbc.path(query).exist? - end - end - end -end
true
Other
Homebrew
brew
d1995dad4bf76b447d9c97f1c2db99c6b3854b51.json
Use a `Formulary`-like approach to load Casks.
Library/Homebrew/cask/lib/hbc/source/uri.rb
@@ -1,32 +0,0 @@ -module Hbc - module Source - class URI - def self.me?(query) - !(query.to_s =~ ::URI.regexp).nil? - end - - attr_reader :uri - - def initialize(uri) - @uri = uri - end - - def load - Hbc.cache.mkpath - path = Hbc.cache.join(File.basename(uri)) - ohai "Downloading #{uri}" - odebug "Download target -> #{path}" - begin - curl(uri, "-o", path.to_s) - rescue ErrorDuringExecution - raise CaskUnavailableError, uri - end - PathSlashOptional.new(path).load - end - - def to_s - uri.to_s - end - end - end -end
true
Other
Homebrew
brew
d1995dad4bf76b447d9c97f1c2db99c6b3854b51.json
Use a `Formulary`-like approach to load Casks.
Library/Homebrew/cask/lib/hbc/without_source.rb
@@ -1,17 +0,0 @@ -module Hbc - class WithoutSource < Cask - # Override from `Hbc::DSL` because we don't have a cask source file to work - # with, so we don't know the cask's `version`. - def staged_path - (caskroom_path.children - [metadata_master_container_path]).first - end - - def to_s - "#{token} (!)" - end - - def installed? - caskroom_path.exist? - end - end -end
true
Other
Homebrew
brew
d1995dad4bf76b447d9c97f1c2db99c6b3854b51.json
Use a `Formulary`-like approach to load Casks.
Library/Homebrew/cmd/irb.rb
@@ -19,6 +19,11 @@ def f(*args) end end +def cask + $LOAD_PATH.unshift("#{HOMEBREW_LIBRARY_PATH}/cask/lib") + require "hbc" +end + module Homebrew module_function
true
Other
Homebrew
brew
d1995dad4bf76b447d9c97f1c2db99c6b3854b51.json
Use a `Formulary`-like approach to load Casks.
Library/Homebrew/compat/hbc/cask_loader.rb
@@ -12,7 +12,11 @@ def cask(header_token, &block) end module Hbc - class CaskLoader - prepend CaskLoaderCompatibilityLayer + module CaskLoader + class FromContentLoader; end + + class FromPathLoader < FromContentLoader + prepend CaskLoaderCompatibilityLayer + end end end
true
Other
Homebrew
brew
d1995dad4bf76b447d9c97f1c2db99c6b3854b51.json
Use a `Formulary`-like approach to load Casks.
Library/Homebrew/tap.rb
@@ -285,7 +285,7 @@ def custom_remote? # path to the directory of all {Formula} files for this {Tap}. def formula_dir - @formula_dir ||= potential_formula_dirs.detect(&:directory?) + @formula_dir ||= potential_formula_dirs.detect(&:directory?) || path/"Formula" end def potential_formula_dirs @@ -294,12 +294,12 @@ def potential_formula_dirs # path to the directory of all {Cask} files for this {Tap}. def cask_dir - @cask_dir ||= [path/"Casks"].detect(&:directory?) + @cask_dir ||= path/"Casks" end # an array of all {Formula} files of this {Tap}. def formula_files - @formula_files ||= if formula_dir + @formula_files ||= if formula_dir.directory? formula_dir.children.select(&method(:formula_file?)) else [] @@ -308,7 +308,7 @@ def formula_files # an array of all {Cask} files of this {Tap}. def cask_files - @cask_files ||= if cask_dir + @cask_files ||= if cask_dir.directory? cask_dir.children.select(&method(:cask_file?)) else []
true
Other
Homebrew
brew
d1995dad4bf76b447d9c97f1c2db99c6b3854b51.json
Use a `Formulary`-like approach to load Casks.
Library/Homebrew/test/cask/cli/list_spec.rb
@@ -40,23 +40,6 @@ end end - describe "when Casks have been renamed" do - let(:caskroom_path) { Hbc.caskroom.join("ive-been-renamed") } - let(:staged_path) { caskroom_path.join("latest") } - - before do - staged_path.mkpath - end - - it "lists installed Casks without backing ruby files (due to renames or otherwise)" do - expect { - Hbc::CLI::List.run - }.to output(<<-EOS.undent).to_stdout - ive-been-renamed (!) - EOS - end - end - describe "given a set of installed Casks" do let(:caffeine) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") } let(:transmission) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") }
true
Other
Homebrew
brew
2c8544832eb75d2ce7a76ac178d1018c166d653a.json
Add test for command help strings.
Library/Homebrew/cask/lib/hbc/cli/base.rb
@@ -14,7 +14,7 @@ def self.cask_tokens_from(args) end def self.help - "No help available for the #{command_name} command" + nil end def self.needs_init?
true
Other
Homebrew
brew
2c8544832eb75d2ce7a76ac178d1018c166d653a.json
Add test for command help strings.
Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb
@@ -23,6 +23,10 @@ def self.posargs(args) args.reject { |a| a.empty? || a.chars.first == "-" } end + def self.help + "audit all modified Casks in a given commit range" + end + def self.usage <<-EOS.undent Usage: brew cask _audit_modified_casks [options...] <commit range>
true
Other
Homebrew
brew
2c8544832eb75d2ce7a76ac178d1018c166d653a.json
Add test for command help strings.
Library/Homebrew/test/cask/cli_spec.rb
@@ -63,4 +63,10 @@ described_class.process("noop") end end + + it "provides a help message for all commands" do + described_class.command_classes.each do |command_class| + expect(command_class.help).to match(/\w+/), command_class.name + end + end end
true
Other
Homebrew
brew
ca303f6195bbe0a8cc47e87a6fa530a35d3b6b5e.json
gpg2_requirement: set default_formula to gnupg (2.1.x)
Library/Homebrew/requirements/gpg2_requirement.rb
@@ -3,7 +3,7 @@ class GPG2Requirement < Requirement fatal true - default_formula "gnupg2" + default_formula "gnupg" # MacGPG2/GPGTools installs GnuPG 2.0.x as a vanilla `gpg` symlink # pointing to `gpg2`, as do we. Ensure we're actually using a 2.0 `gpg`.
false
Other
Homebrew
brew
7058c089a6c38681d1d84cfec9f40f499a3cf885.json
gpg: add the 2.1.x series as a recognized GnuPG version
Library/Homebrew/gpg.rb
@@ -5,7 +5,9 @@ def self.find_gpg(executable) which_all(executable).detect do |gpg| gpg_short_version = Utils.popen_read(gpg, "--version")[/\d\.\d/, 0] next unless gpg_short_version - Version.create(gpg_short_version.to_s) == Version.create("2.0") + gpg_version = Version.create(gpg_short_version.to_s) + gpg_version == Version.create("2.0") || + gpg_version == Version.create("2.1") end end
false
Other
Homebrew
brew
e1670a9210d461184708217285975a0023afc20b.json
Remove `sort` from `each_artifact`.
Library/Homebrew/cask/lib/hbc/artifact/relocated.rb
@@ -43,8 +43,7 @@ def add_altname_metadata(file, altname) end def each_artifact - # the sort is for predictability between Ruby versions - @cask.artifacts[self.class.artifact_dsl_key].sort.each do |artifact| + @cask.artifacts[self.class.artifact_dsl_key].each do |artifact| load_specification(artifact) yield end
false
Other
Homebrew
brew
cc8f029f222a618eb30b585ccb22efcce1e5cf91.json
secure urls + remove -k from in-doc curl command
Library/Homebrew/cask/lib/hbc/cli/home.rb
@@ -4,7 +4,7 @@ class Home < Base def self.run(*cask_tokens) if cask_tokens.empty? odebug "Opening project homepage" - system "/usr/bin/open", "--", "http://caskroom.github.io/" + system "/usr/bin/open", "--", "https://caskroom.github.io/" else cask_tokens.each do |cask_token| odebug "Opening homepage for Cask #{cask_token}"
true
Other
Homebrew
brew
cc8f029f222a618eb30b585ccb22efcce1e5cf91.json
secure urls + remove -k from in-doc curl command
Library/Homebrew/cask/lib/hbc/url.rb
@@ -2,7 +2,7 @@ module Hbc class URL - FAKE_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10) http://caskroom.github.io".freeze + FAKE_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10) https://caskroom.github.io".freeze attr_reader :using, :revision, :trust_cert, :uri, :cookies, :referer, :data
true
Other
Homebrew
brew
cc8f029f222a618eb30b585ccb22efcce1e5cf91.json
secure urls + remove -k from in-doc curl command
Library/Homebrew/dev-cmd/aspell-dictionaries.rb
@@ -10,7 +10,7 @@ module Homebrew module_function def aspell_dictionaries - dict_url = "http://ftpmirror.gnu.org/aspell/dict" + dict_url = "https://ftpmirror.gnu.org/aspell/dict" dict_mirror = "https://ftp.gnu.org/gnu/aspell/dict" languages = {}
true
Other
Homebrew
brew
cc8f029f222a618eb30b585ccb22efcce1e5cf91.json
secure urls + remove -k from in-doc curl command
Library/Homebrew/dev-cmd/pull.rb
@@ -13,7 +13,7 @@ #: #: ~ The URL of a commit on GitHub #: -#: ~ A "http://bot.brew.sh/job/..." string specifying a testing job ID +#: ~ A "https://bot.brew.sh/job/..." string specifying a testing job ID #: #: If `--bottle` is passed, handle bottles, pulling the bottle-update #: commit and publishing files on Bintray.
true
Other
Homebrew
brew
cc8f029f222a618eb30b585ccb22efcce1e5cf91.json
secure urls + remove -k from in-doc curl command
Library/Homebrew/diagnostic.rb
@@ -647,7 +647,7 @@ def check_dyld_vars Setting DYLD_INSERT_LIBRARIES can cause Go builds to fail. Having this set is common if you use this software: - #{Formatter.url("http://asepsis.binaryage.com/")} + #{Formatter.url("https://asepsis.binaryage.com/")} EOS end
true
Other
Homebrew
brew
cc8f029f222a618eb30b585ccb22efcce1e5cf91.json
secure urls + remove -k from in-doc curl command
Library/Homebrew/extend/os/mac/hardware/cpu.rb
@@ -102,7 +102,7 @@ def universal_archs # Amazingly, this order (64, then 32) matters. It shouldn't, but it # does. GCC (some versions? some systems?) can blow up if the other # order is used. - # http://superuser.com/questions/740563/gcc-4-8-on-macos-fails-depending-on-arch-order + # https://superuser.com/questions/740563/gcc-4-8-on-macos-fails-depending-on-arch-order [arch_64_bit, arch_32_bit].extend ArchitectureListExtension end end
true
Other
Homebrew
brew
cc8f029f222a618eb30b585ccb22efcce1e5cf91.json
secure urls + remove -k from in-doc curl command
Library/Homebrew/keg_relocate.rb
@@ -119,7 +119,7 @@ def text_files # file has known issues with reading files on other locales. Has # been fixed upstream for some time, but a sufficiently new enough # file with that fix is only available in macOS Sierra. - # http://bugs.gw.com/view.php?id=292 + # https://bugs.gw.com/view.php?id=292 with_custom_locale("C") do files = Set.new path.find.reject { |pn| next true if pn.symlink?
true
Other
Homebrew
brew
cc8f029f222a618eb30b585ccb22efcce1e5cf91.json
secure urls + remove -k from in-doc curl command
Library/Homebrew/manpages/brew-cask.1.md
@@ -64,7 +64,7 @@ names, and other aspects of this manual are still subject to change. * `home` or `homepage` [ <token> ... ]: Display the homepage associated with a given Cask in a browser. - With no arguments, display the project page <http://caskroom.github.io>. + With no arguments, display the project page <https://caskroom.github.io/>. * `info` or `abv` <token> [ <token> ... ]: Display information about the given Cask. @@ -248,7 +248,7 @@ Environment variables specific to Homebrew-Cask: ## SEE ALSO -The Homebrew-Cask home page: <http://caskroom.github.io> +The Homebrew-Cask home page: <https://caskroom.github.io/> The Homebrew-Cask GitHub page: <https://github.com/caskroom/homebrew-cask>
true
Other
Homebrew
brew
cc8f029f222a618eb30b585ccb22efcce1e5cf91.json
secure urls + remove -k from in-doc curl command
Library/Homebrew/test/cask/cli/home_spec.rb
@@ -40,7 +40,7 @@ def self.system_commands it "opens the project page when no Cask is specified" do Hbc::CLI::Home.run expect(Hbc::CLI::Home.system_commands).to eq [ - ["/usr/bin/open", "--", "http://caskroom.github.io/"], + ["/usr/bin/open", "--", "https://caskroom.github.io/"], ] end end
true
Other
Homebrew
brew
cc8f029f222a618eb30b585ccb22efcce1e5cf91.json
secure urls + remove -k from in-doc curl command
Library/Homebrew/test/cask/download_strategy_spec.rb
@@ -60,7 +60,7 @@ downloader.fetch end - expect(curl_args.each_cons(2)).to include(["-A", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10) http://caskroom.github.io"]) + expect(curl_args.each_cons(2)).to include(["-A", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10) https://caskroom.github.io"]) end end
true