class Ronin::Support::Binary::CTypes::OS

Represents additional typedefs defined by an Operating System (OS).

@api private

@since 1.0.0

Attributes

typedefs[R]

The defined typedefs for the OS.

@return [Hash{Symbol => Type}]

types[R]

The base types that the OS inherits.

@return [Native, LittleEndian, BigEndian, Network,

Arch::ARM, Arch::ARM::BigEndian,
Arch::ARM64, Arch::ARM64::BigEndian,
Arch::MIPS, Arch::MIPS::LittleEndian,
Arch::MIPS64, Arch::MIPS64::LittleEndian,
Arch::PPC64, Arch::PPC, Arch::X86_64, Arch::X86,
OS::FreeBSD,
OS::NetBSD,
OS::OpenBSD,
OS::Linux,
OS::MacOS,
OS::Windows,
OS::Android,
OS::AppleIOS]

Public Class Methods

new(types) click to toggle source

Initializes the OS with the given base types.

@param [Native, LittleEndian, BigEndian, Network,

       Arch::ARM, Arch::ARM::BigEndian,
       Arch::ARM64, Arch::ARM64::BigEndian,
       Arch::MIPS, Arch::MIPS::LittleEndian,
       Arch::MIPS64, Arch::MIPS64::LittleEndian,
       Arch::PPC64, Arch::PPC, Arch::X86_64, Arch::X86,
       OS::FreeBSD,
       OS::NetBSD,
       OS::OpenBSD,
       OS::Linux,
       OS::MacOS,
       OS::Windows,
       OS::Android] types
The base types that the OS builds upon.
# File lib/ronin/support/binary/ctypes/os.rb, line 73
def initialize(types)
  @types    = types
  @typedefs = {}
end

Public Instance Methods

[](name) click to toggle source

Retrieves the type with the given name.

@param [Symbol] name

@return [Type]

@api public

# File lib/ronin/support/binary/ctypes/os.rb, line 87
def [](name)
  @typedefs.fetch(name) { @types[name] }
end
typedef(type,new_name) click to toggle source

Defines a typedef within the type system.

@param [Symbol, Type] type

The original type to point to.

@param [Symbol] new_name

The new type name.

@raise [ArgumentError]

The given type was not a Symbol or a {Type}.

@example

os.typedef :uint, :foo_t
# File lib/ronin/support/binary/ctypes/os.rb, line 106
def typedef(type,new_name)
  case type
  when Type   then @typedefs[new_name] = type
  when Symbol then @typedefs[new_name] = self[type]
  else
    raise(ArgumentError,"type must be either a Symbol or a #{Type}: #{type.inspect}")
  end
end