Class: Ronin::Support::Binary::CTypes::TypeResolver Private

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/support/binary/ctypes/type_resolver.rb

Overview

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

Adds a type system that can be used by Memory objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(types) ⇒ TypeResolver

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.

Initializes the type resolver.

The types module or object that provides a #[] method for looking up type names.



70
71
72
# File 'lib/ronin/support/binary/ctypes/type_resolver.rb', line 70

def initialize(types)
  @types = types
end

Instance Attribute Details

#typesNative, ... (readonly)

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.

The Ronin::Support::Binary::CTypes module or object to lookup type names in.



50
51
52
# File 'lib/ronin/support/binary/ctypes/type_resolver.rb', line 50

def types
  @types
end

Instance Method Details

#resolve(type_signature) ⇒ Type

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.

Resolves C type short-hand syntax into a Ronin::Support::Binary::CTypes::Type object.

The C type value. The value can be one of the following:

  • Symbol - represents a single type (ex: :int32)
  • (type, Integer) - represents an Array type with the given element type and length (ex: [:int32, 10])
  • Range(type) - represents an unbounded Array type with the given element type. (ex: :int32..)
  • Struct.class - a subclass of Struct.
  • Union.class - a subclass of Union.

Parameters:

Returns:

  • (Type)

    The translated type.

Raises:



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/ronin/support/binary/ctypes/type_resolver.rb', line 98

def resolve(type_signature)
  case type_signature
  when ::Array then resolve_array(type_signature)
  when Range   then resolve_range(type_signature)
  when Symbol  then resolve_symbol(type_signature)
  when Type    then type_signature
  when Class
    if type_signature < Binary::Union
      resolve_union(type_signature)
    elsif type_signature < Binary::Struct
      resolve_struct(type_signature)
    else
      raise(ArgumentError,"class must be either a #{Binary::Struct} or a #{Binary::Union} class")
    end
  else
    raise(ArgumentError,"type type_signature must be a Symbol, Array, Range, #{Binary::Struct}, #{Binary::Union}, or a #{CTypes::Type} object: #{type_signature.inspect}")
  end
end