Class: Indis::MachO::Symbol

Inherits:
Symbol
  • Object
show all
Defined in:
lib/indis-macho/symbol.rb

Constant Summary

STAB_MASK =
0xe0
PEXT_MASK =
0x10
TYPE_MASK =
0x0e
EXT_MASK =
0x01
TYPE =
{
  0x0 => :UNDEF,
  0x2 => :ABS,
  0xe => :SECT,
  0xc => :PBUD,
  0xa => :INDR,
}
STAB =
{
  0x20 => :N_GSYM,    # global symbol
  0x22 => :N_FNAME,   # procedure name (f77 kludge)
  0x24 => :N_FUN,     # procedure name
  0x26 => :N_STSYM,   # static symbol
  0x28 => :N_LCSYM,   # .lcomm symbol
  0x2e => :N_BNSYM,   # begin nsect symbol
  0x3c => :N_OPT,     # emitted with gcc2_compiled and in gcc source
  0x40 => :N_RSYM,    # register symbol
  0x44 => :N_SLINE,   # src line
  0x4e => :N_ENSYM,   # end nsect symbol
  0x60 => :N_SSYM,    # structure elt
  0x64 => :N_SO,      # source file name
  0x66 => :N_OSO,     # object file name
  0x80 => :N_LSYM,    # local symbol
  0x82 => :N_BINCL,   # include file beginning
  0x84 => :N_SOL,     # #included file name
  0x86 => :N_PARAMS,  # compiler parameters
  0x88 => :N_VERSION, # compiler version
  0x8A => :N_OLEVEL,  # compiler -O level
  0xa0 => :N_PSYM,    # parameter
  0xa2 => :N_EINCL,   # include file end
  0xa4 => :N_ENTRY,   # alternate entry
  0xc0 => :N_LBRAC,   # left bracket
  0xc2 => :N_EXCL,    # deleted include file
  0xe0 => :N_RBRAC,   # right bracket
  0xe2 => :N_BCOMM,   # begin common
  0xe4 => :N_ECOMM,   # end common
  0xe8 => :N_ECOML,   # end common (local name)
  0xfe => :N_LENG,    # second stab entry with length information
}
REFERENCE_TYPE_MASK =

global symbol procedure name (f77 kludge) procedure name static symbol .lcomm symbol begin nsect symbol emitted with gcc2_compiled and in gcc source register symbol src line end nsect symbol structure elt source file name object file name local symbol include file beginning #included file name compiler parameters compiler version compiler -O level parameter include file end alternate entry left bracket deleted include file right bracket begin common end common end common (local name) second stab entry with length information

0xf
DESC_REFERENCE =
{
  0x0 => :REFERENCE_FLAG_UNDEFINED_NON_LAZY,
  0x1 => :REFERENCE_FLAG_UNDEFINED_LAZY,
  0x2 => :REFERENCE_FLAG_DEFINED,
  0x3 => :REFERENCE_FLAG_PRIVATE_DEFINED,
  0x4 => :REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY,
  0x5 => :REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY,
}
DESC_ADDITIONAL =
{
  0x08 => :N_ARM_THUMB_DEF,
  0x10 => :REFERENCED_DYNAMICALLY,
  0x20 => :N_DESC_DISCARDED_OR_N_NO_DEAD_STRIP, # TODO: resolve mach file type
  0x40 => :N_WEAK_REF,
  0x80 => :N_WEAK_DEF,
}
LIBRARY_ORDINAL =
{
  0x0  => :SELF_LIBRARY_ORDINAL,
  0xfe => :DYNAMIC_LOOKUP_ORDINAL,
  0xff => :EXECUTABLE_ORDINAL,
}

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Symbol) initialize(payload, strtab)

A new instance of Symbol



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/indis-macho/symbol.rb', line 92

def initialize(payload, strtab)
  name_idx, @type_val, @macho_section_index, @desc_val, @value = payload.read(12).unpack('VCCSV')
  
  @name = ''
  unless name_idx == 0
    strtab.pos = name_idx
    subn = strtab.read(256)
    idx = subn.index("\0")
    while idx == nil
      @name += subn
      subn = strtab.read(256)
      idx = subn.index("\0")
    end
    @name += subn[0...idx]
  end
  
  super(@name, nil, nil, @value)
end

Instance Attribute Details

- (Object) image=(value) (writeonly)

image will be set later on by macho parser



89
90
91
# File 'lib/indis-macho/symbol.rb', line 89

def image=(value)
  @image = value
end

- (Object) macho_section_index (readonly)

Returns the value of attribute macho_section_index



90
91
92
# File 'lib/indis-macho/symbol.rb', line 90

def macho_section_index
  @macho_section_index
end

- (Object) section=(value) (writeonly)

image will be set later on by macho parser



89
90
91
# File 'lib/indis-macho/symbol.rb', line 89

def section=(value)
  @section = value
end

- (Object) vmaddr=(value) (writeonly)

image will be set later on by macho parser



89
90
91
# File 'lib/indis-macho/symbol.rb', line 89

def vmaddr=(value)
  @vmaddr = value
end

Instance Method Details

- (Object) desc



139
140
141
142
143
144
145
# File 'lib/indis-macho/symbol.rb', line 139

def desc
  d = [DESC_REFERENCE[@desc_val & REFERENCE_TYPE_MASK]]
  DESC_ADDITIONAL.each_pair do |k, v|
    d << v if @desc_val & k == k
  end
  d
end

- (Boolean) extern?

Returns:

  • (Boolean)


135
136
137
# File 'lib/indis-macho/symbol.rb', line 135

def extern?
  @type_val & EXT_MASK == EXT_MASK
end

- (Boolean) private_extern?

Returns:

  • (Boolean)


131
132
133
# File 'lib/indis-macho/symbol.rb', line 131

def private_extern?
  @type_val & PEXT_MASK == PEXT_MASK
end

- (Object) stab



123
124
125
126
127
128
129
# File 'lib/indis-macho/symbol.rb', line 123

def stab
  if stab?
    STAB[@type_val]
  else
    nil
  end
end

- (Boolean) stab?

Returns:

  • (Boolean)


119
120
121
# File 'lib/indis-macho/symbol.rb', line 119

def stab?
  @type_val & STAB_MASK != 0
end

- (Object) twolevel_library_ordinal



147
148
149
150
# File 'lib/indis-macho/symbol.rb', line 147

def twolevel_library_ordinal
  lo = (@desc_val >> 8) & 0xff
  LIBRARY_ORDINAL[lo] || lo
end

- (Object) type



111
112
113
114
115
116
117
# File 'lib/indis-macho/symbol.rb', line 111

def type
  if stab?
    STAB[@type_val]
  else
    TYPE[@type_val & TYPE_MASK]
  end
end