<commit_before>#!/usr/bin/env ruby

$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))

require 'macho'

file = MachO::MachOFile.new(ARGV.shift)

puts "FILE INFORMATION:"
puts "  Header type: #{file.header.class}"
puts "  Magic: #{file.magic_string}"
puts "  Filetype: #{file.filetype}"
puts "  CPU type: #{file.cputype}"
puts "  CPU subtype: #{file.cpusubtype}"
puts "  No. load commands: #{file.ncmds}"
puts "  Size of load commands: #{file.sizeofcmds}"
puts "  Flags: #{file.flags}"

puts "\nLOAD COMMANDS:"
file.load_commands.each do |lc|
  puts "  #{lc} (#{lc.class}) (offset: #{lc.offset}, size: #{lc.cmdsize})"
end

puts "\nDYLIB ID: #{file.dylib_id}" if file.dylib?

puts "\nDYNAMIC LIBRARIES:"<commit_msg>bin/info.rb: Add basic support for fat binaries<commit_after>#!/usr/bin/env ruby

$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))

require 'macho'

# Usage: bin/info.rb [--fat|--macho] <file>
arg1 = ARGV.shift
case arg1
when "--fat"
  file = MachO::FatFile.new(ARGV.shift) # Force fat binary.
when "--macho"
  file = MachO::MachOFile.new(ARGV.shift) # Force Mach-O binary.
else
  file = MachO.open(arg1) # Auto-detect fat/Mach-O binary.
end

if file.is_a?(MachO::FatFile)
  puts "NOTE: File is a fat binary with #{file.machos.size} architectures."
  puts "NOTE: Only showing information for the first architecture."
  puts
  file = file.machos.first
end

puts "FILE INFORMATION:"
puts "  Header type: #{file.header.class}"
puts "  Magic: #{file.magic_string}"
puts "  Filetype: #{file.filetype}"
puts "  CPU type: #{file.cputype}"
puts "  CPU subtype: #{file.cpusubtype}"
puts "  No. load commands: #{file.ncmds}"
puts "  Size of load commands: #{file.sizeofcmds}"
puts "  Flags: #{file.flags}"

puts "\nLOAD COMMANDS:"
file.load_commands.each do |lc|
  puts "  #{lc} (#{lc.class}) (offset: #{lc.offset}, size: #{lc.cmdsize})"
end

puts "\nDYLIB ID: #{file.dylib_id}" if file.dylib?

puts "\nDYNAMIC LIBRARIES:"
{'fraction_non_alphanumeric': 0.17934224049331962, 'fraction_numerical': 0.001541623843782117, 'mean_word_length': 4.3489010989010985, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2296652', 'n_tokens_mistral': 794, 'n_tokens_neox': 769, 'n_words': 189}