Module: ELFTools::Constants::Naming

Included in:
DT, SHN, STB, STT, STV
Defined in:
lib/elftools/constants.rb

Overview

Names a value after the constants that define it, for the modules where several of them may define one value.

A machine defines names of its own, and a name may mark where a range of values begins or ends, or how many of them are defined, rather than name one of them.

Constant Summary collapse

ARCHITECTURES =

Architectures a constant can be named after, the longest first so that a name is read as the architecture it spells out in full.

(R.constants - [:MACHINES]).sort_by { |name| -name.length }.freeze

Instance Method Summary collapse

Instance Method Details

#mapping(machine, value) ⇒ String

Return the name of value.

Names of a machine other than machine are passed over, as are the ones that mark a range or a count instead of naming a value.

Examples:

Constants::STT.mapping(Constants::EM_ARM, 13)
#=> 'STT_ARM_TFUNC'
Constants::STT.mapping(Constants::EM_X86_64, 13)
#=> '<unknown>: 0xd'

Parameters:

  • machine (Integer?)

    Value of e_machine.

  • value (Integer)

    The value to name.

Returns:

  • (String)

    The name.



37
38
39
40
41
42
43
# File 'lib/elftools/constants.rb', line 37

def mapping(machine, value)
  architecture = R::MACHINES[machine]
  name = names_by_value.fetch(value, []).find do |constant|
    !marker?(constant) && [nil, architecture].include?(architecture_of(constant))
  end
  name ? name.to_s : format('<unknown>: 0x%x', value)
end