Class: MachO::MachOStructure Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/macho/structure.rb

Overview

This class is abstract.

A general purpose pseudo-structure. Described in detail in docs/machostructure-dsl.md.

Defined Under Namespace

Modules: Fields

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ MachOStructure

Returns a new instance of MachOStructure.

Parameters:

  • args (Array[Value])

    list of field parameters

Raises:

  • (ArgumentError)


75
76
77
78
79
# File 'lib/macho/structure.rb', line 75

def initialize(*args)
  raise ArgumentError, "Invalid number of arguments" if args.size < self.class.min_args

  @values = args
end

Class Attribute Details

.min_argsObject (readonly)

Returns the value of attribute min_args.



92
93
94
# File 'lib/macho/structure.rb', line 92

def min_args
  @min_args
end

Class Method Details

.bytesizeObject



108
109
110
# File 'lib/macho/structure.rb', line 108

def bytesize
  @bytesize ||= @size_list.sum
end

.formatObject



104
105
106
# File 'lib/macho/structure.rb', line 104

def format
  @format ||= @fmt_list.join
end

.new_from_bin(endianness, bin) ⇒ MachO::MachOStructure

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the resulting structure.

Parameters:

  • endianness (Symbol)

    either :big or :little

  • bin (String)

    the string to be unpacked into the new structure

Returns:



98
99
100
101
102
# File 'lib/macho/structure.rb', line 98

def new_from_bin(endianness, bin)
  format = Utils.specialize_format(self.format, endianness)

  new(*bin.unpack(format))
end

Instance Method Details

#to_hHash

Returns a hash representation of this MachO::MachOStructure.

Returns:



82
83
84
85
86
87
88
89
# File 'lib/macho/structure.rb', line 82

def to_h
  {
    "structure" => {
      "format" => self.class.format,
      "bytesize" => self.class.bytesize,
    },
  }
end