Class: Rex::MachParsey::MachBase::MachHeader

Inherits:
GenericHeader show all
Defined in:
lib/rex/machparsey/machbase.rb

Instance Attribute Summary collapse

Attributes inherited from GenericStruct

#struct

Instance Method Summary collapse

Methods inherited from GenericStruct

#[], #keys, #method_missing, #v

Constructor Details

#initialize(rawdata) ⇒ MachHeader

Returns a new instance of MachHeader.



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/rex/machparsey/machbase.rb', line 132

def initialize(rawdata)
  mach_header = MACH_HEADER_LSB.make_struct
  if !mach_header.from_s(rawdata)
    raise MachHeaderError, "Could't access Mach-O Magic", caller
  end

  if mach_header.v['magic'] == MH_MAGIC
    endian = ENDIAN_LSB
    bits = BITS_32
    mach_header = MACH_HEADER_LSB.make_struct
  elsif mach_header.v['magic'] == MH_CIGAM
    bits = BITS_32
    endian = ENDIAN_MSB
    mach_header = MACH_HEADER_MSB.make_struct
  elsif mach_header.v['magic'] == MH_MAGIC_64
    endian = ENDIAN_LSB
    bits = BITS_64
    mach_header = MACH_HEADER_LSB.make_struct
  elsif mach_header.v['magic'] == MH_CIGAM_64
    endian = ENDIAN_MSB
    bits = BITS_64
    mach_header = MACH_HEADER_MSB.make_struct
  else
    raise MachHeaderError, "Couldn't find Mach Magic", caller
  end

  if !mach_header.from_s(rawdata)
    raise MachHeaderError, "Could't process Mach-O Header", caller
  end

  self.struct = mach_header
  self.endian = endian
  self.bits = bits
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rex::MachParsey::GenericStruct

Instance Attribute Details

#bitsObject

Returns the value of attribute bits.



130
131
132
# File 'lib/rex/machparsey/machbase.rb', line 130

def bits
  @bits
end

#endianObject

Returns the value of attribute endian.



130
131
132
# File 'lib/rex/machparsey/machbase.rb', line 130

def endian
  @endian
end