Class: DsymUuidExtractor::MachOBinaryReader

Inherits:
MachOReader
  • Object
show all
Defined in:
lib/dsym_uuid_extractor/macho_reader.rb

Defined Under Namespace

Classes: FatArch, FatHeader

Constant Summary collapse

FAT_MAGIC =

Magic Numbers

0xcafebabe
FAT_CIGAM =
0xbebafeca

Constants inherited from MachOReader

DsymUuidExtractor::MachOReader::CPU_ARCH_ABI64, DsymUuidExtractor::MachOReader::CPU_SUBTYPE_ARM_V7, DsymUuidExtractor::MachOReader::CPU_SUBTYPE_ARM_V7S, DsymUuidExtractor::MachOReader::CPU_TYPE_ARM, DsymUuidExtractor::MachOReader::CPU_TYPE_ARM64, DsymUuidExtractor::MachOReader::CPU_TYPE_I386, DsymUuidExtractor::MachOReader::CPU_TYPE_X86_64

Instance Attribute Summary

Attributes inherited from MachOReader

#file

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MachOReader

#initialize

Constructor Details

This class inherits a constructor from DsymUuidExtractor::MachOReader

Class Method Details

.is_binary_file?(file_path) ⇒ Boolean

Methods

Returns:

  • (Boolean)


64
65
66
67
68
69
70
71
72
# File 'lib/dsym_uuid_extractor/macho_reader.rb', line 64

def self.is_binary_file?(file_path)
  fail EmptySymbolicationFile if File.zero?(file_path)

  File.read(file_path, 4).unpack('L>')[0] == FAT_MAGIC ||
    File.read(file_path, 4).unpack('L<')[0] == FAT_CIGAM
  rescue EmptySymbolicationFile
    # To be logged in CloudWatch...
    false
end

Instance Method Details

#each_fileObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/dsym_uuid_extractor/macho_reader.rb', line 74

def each_file
  arch_count = fat_header[:nfat_arch]

  seek_to_fat_arch
  arch_offsets = arch_count.times.map do
    fat_arch = read_struct(FatArch)

    fat_arch[:offset]
  end

  arch_offsets.each do |arch_offset|
    yield MachOFileReader.new(file_path: File.absolute_path(file.path), seek_to_pos: arch_offset)
  end
end

#read_struct(struct_class, opts = {}) ⇒ Object



89
90
91
# File 'lib/dsym_uuid_extractor/macho_reader.rb', line 89

def read_struct(struct_class, opts = {})
  super(struct_class, opts.merge(byte_order: :big))
end