class LinkAgainstFinder::Objdump

Attributes

binary_path[RW]

Public Class Methods

new(binary_path) click to toggle source
# File lib/LinkAgainstFinder/objdump.rb, line 7
def initialize(binary_path)
    self.binary_path = Pathname.new(binary_path)
    raise "File not exist" unless self.binary_path.exist?
    checkObjdumpVersion
end

Public Instance Methods

checkObjdumpVersion() click to toggle source
# File lib/LinkAgainstFinder/objdump.rb, line 57
def checkObjdumpVersion
    return if @@checked
    output = `#{objdump_command} -version`
    if $?.exitstatus != 0
        raise "Need objdump in commandline!"
    end
    firstLine =output.split("\n")[0]
    if !firstLine.include?('11.0')
        raise "Need objdump v11.0!"
    end
    @@checked = true
end
getSymbolTable() click to toggle source
# File lib/LinkAgainstFinder/objdump.rb, line 15
def getSymbolTable
    output = `#{objdump_command} -arch=arm64 -syms #{binary_path}`
    lines = output.split("\n")
    lines.reject{ |l| l.strip.empty? }

    parts = []
    current = []
    on = false
    (0...lines.length).each do |index|
        line = lines[index]
        if line == 'SYMBOL TABLE:'
            # finish last
            current = current[0...-1]
            parts << current unless current.empty?

            # set new
            on = true
            current = []
            next
        end
        if on
            current << lines[index]
        end
    end
    parts << current unless current.empty?
    all_symbol_lines = parts.flatten

    externals = all_symbol_lines.select{|l|l.include?('*UND*')}
    internals = all_symbol_lines.select{|l| !l.include?('*UND*')}

    table = SymbolTable.new
    table.internalSymbols = Set.new(internals.map do |l|
        l.split("\t")[-1]
    end)
    table.externalSymbols = Set.new(externals.map do |l|
        l.split("\t")[-1]
    end).reject { |s| table.internalSymbols.include?(s) }
    table.externalSymbols = Set.new(table.externalSymbols)

    table
end
objdump_command() click to toggle source
# File lib/LinkAgainstFinder/objdump.rb, line 72
def objdump_command
    "#{$LinkAgainstFinder_develop_dir_env} objdump"
end