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
-
Scalar Types:
-
Character Types:
-
{CharType char} (ex: ‘’c’‘)
-
{StringType string} (ex: ‘“abc”`)
-
-
Signed
Integer
Types:-
{CTypes::Int8Type int8} (‘-127` - `127`)
-
{CTypes::Int16Type int16} (‘-32768` to `32767`)
-
{CTypes::Int32Type int32} (‘-2147483648` - `2147483648`)
-
{CTypes::Int64Type int64} (‘-9223372036854775808` - `9223372036854775808`)
-
-
Unsigned
Integer
Types:-
{CTypes::UInt8Type uint8} (‘0x00` - `0xff`)
-
{CTypes::UInt16Type uint16} (‘0x0000` - `0xffff`)
-
{CTypes::UInt32Type uint32} (‘0x00000000` - `0xffffffff`)
-
{CTypes::UInt64Type uint64} (‘0x0000000000000000` - `0xffffffffffffffff`)
-
-
Floating Point Types:
-
{CTypes::Float32Type float} (‘-3.40282347E+38F` - `3.40282347E+38F`)
-
{CTypes::Float64Type double} (‘-1.79769313486231570E+308` - `1.79769313486231570E+308`)
-
-
-
Aggregate Types:
-
{CTypes::ArrayType Array} (ex: ‘{1,2,3}`)
-
{CTypes::UnboundedArrayType unbounded Array} (ex: ‘char c[] = {…}`)
-
{CTypes::StructType struct} (ex: ‘struct s = {1, ’c’, …}‘)
-
{CTypes::UnionType union} (ex: ‘union u = {1234}`)
-
-
Object Types:
-
{CTypes::ArrayObjectType array} objects (see: {Binary::Array}).
-
{CTypes::StructObjectType struct} objects (see: {Binary::Struct}).
-
{CTypes::UnionObjectType union} objects (see: {Binary::Union}).
-
## Supported Endian-ness
-
{CTypes::LittleEndian little-endian} byte-order
-
{CTypes::BigEndian big-endian} byte-order
-
{CTypes::Network network} byte-order
## Supported Architectures
-
{CTypes::Arch::ARM arm}
-
{CTypes::Arch::ARM::BigEndian armbe (big-endian)}
-
{CTypes::Arch::ARM64 arm64}
-
{CTypes::Arch::ARM64::BigEndian arm64be (big-endian)}
-
{CTypes::Arch::MIPS mips}
-
{CTypes::Arch::MIPS::LittleEndian mipsle (little-endian)}
-
{CTypes::Arch::MIPS64 mips64}
-
{CTypes::Arch::MIPS64::LittleEndian mips64le (little-endian)}
-
{CTypes::Arch::PPC ppc}
-
{CTypes::Arch::PPC64 ppc64}
-
{CTypes::Arch::X86 x86}
-
{CTypes::Arch::X86_64 x86-64}
## Supported Operating Systems (OS
)
-
{CTypes::OS::UNIX UNIX}
-
{CTypes::OS::BSD BSD}
-
{CTypes::OS::FreeBSD FreeBSD}
-
{CTypes::OS::OpenBSD OpenBSD}
-
{CTypes::OS::NetBSD NetBSD}
-
-
{CTypes::OS::Linux Linux}
-
{CTypes::OS::MacOS macOS}
-
{CTypes::OS::Windows Windows}
-
{CTypes::OS::Android Android}
-
{CTypes::OS::AppleIOS Apple iOS}
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
Source
# File lib/ronin/support/binary/ctypes.rb, line 343 def self.[](name) TYPES.fetch(name) do raise(ArgumentError,"unknown type: #{name.inspect}") end end
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.
Source
# 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
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.