module Ronin::Support::Binary::CTypes

Provides a complete virtual C type system, implemented purely in Ruby. The type objects are then used by {Binary::Template}, {Binary::Buffer}, {Binary::Stream}, {Binary::Array}, {Binary::Struct}, and {Binary::Union} to encode and decoded any C binary data.

## Supported Types

## Supported Endian-ness

## Supported Architectures

## Supported Operating Systems (OS)

Constants

ARCHES

The supported architectures.

DOUBLE_BE
DOUBLE_LE
DOUBLE_NE
DOUBLE_NET
DWORD_BE
DWORD_LE
DWORD_NE
DWORD_NET
ENDIAN

Represents the different endian type systems.

FLOAT32_BE
FLOAT32_LE
FLOAT32_NE
FLOAT32_NET
FLOAT64_BE
FLOAT64_LE
FLOAT64_NE
FLOAT64_NET
FLOAT_BE
FLOAT_LE
FLOAT_NE
FLOAT_NET
INT16_BE

big-endian types

INT16_LE

little-endian types

INT16_NE

network byte-order types

INT16_NET
INT32_BE
INT32_LE
INT32_NE
INT32_NET
INT64_BE
INT64_LE
INT64_NE
INT64_NET
MACHINE_WORD_BE
MACHINE_WORD_LE
MACHINE_WORD_NE
MACHINE_WORD_NET
Network

Represents the C types, but in big-endian byte-order.

OSES

The supported Operating Systems.

POINTER_BE
POINTER_LE
POINTER_NE
POINTER_NET
QWORD_BE
QWORD_LE
QWORD_NE
QWORD_NET
TYPES

All types (native, little-endian, big-endian, and network byte-order).

UINT16_BE
UINT16_LE
UINT16_NE
UINT16_NET
UINT32_BE
UINT32_LE
UINT32_NE
UINT32_NET
UINT64_BE
UINT64_LE
UINT64_NE
UINT64_NET
WORD_BE
WORD_LE
WORD_NE
WORD_NET

Public Class Methods

[](name) click to toggle source

Fetches the type from {TYPES}.

@param [Symbol] name

The type name to lookup.

@return [Type]

The type object from {TYPES}.

@raise [ArgumentError]

The type name was unknown.
# File lib/ronin/support/binary/ctypes.rb, line 343
def self.[](name)
  TYPES.fetch(name) do
    raise(ArgumentError,"unknown type: #{name.inspect}")
  end
end
platform(arch: nil, endian: nil, os: nil) click to toggle source

Returns the types module/object for the given endianness, architecture, and/or Operating System (OS).

@param [:little, :big, :net, nil] endian

The endianness.

@param [:x86, :x86_64,

      :ppc, :ppc64,
      :mips, :mips_le, :mips_be,
      :mips64, :mips64_le, :mips64_be,
      :arm, :arm_le, :arm_be,
      :arm64, :arm64_le, :arm64_be] arch
The architecture name to lookup.

@param [:linux, :macos, :windows,

      :android, :apple_ios, :bsd,
      :freebsd, :openbsd, :netbsd] os
The Operating System name to lookup.

@return [CTypes,

       CTypes::LittleEndian,
       CTypes::BigEndian,
       CTypes::Network,
       CTypes::Arch::ARM,
       CTypes::Arch::ARM::BigEndian,
       CTypes::Arch::ARM64,
       CTypes::Arch::ARM64::BigEndian,
       CTypes::Arch::MIPS,
       CTypes::Arch::MIPS::LittleEndian,
       CTypes::Arch::MIPS64,
       CTypes::Arch::MIPS64::LittleEndian,
       CTypes::Arch::PPC,
       CTypes::Arch::PPC64,
       CTypes::Arch::X86,
       CTypes::Arch::X86_64,
       CTypes::OS]
The types module.

@raise [ArgumentError]

The endian was unknown, the architecture name was unknown,
or the os name was unknown.
# File lib/ronin/support/binary/ctypes.rb, line 446
def self.platform(arch: nil, endian: nil, os: nil)
  types = if arch
            ARCHES.fetch(arch) do
              raise(ArgumentError,"unknown architecture: #{arch.inspect}")
            end
          else
            ENDIAN.fetch(endian) do
              raise(ArgumentError,"unknown endian: #{endian.inspect}")
            end
          end

  if os
    types = OSES.fetch(os) {
      raise(ArgumentError,"unknown OS: #{os.inspect}")
    }.new(types)
  end

  return types
end