ronin-rb/ronin-support

View on GitHub
lib/ronin/support/binary/ctypes/arch/mips64.rb

Summary

Maintainability
A
1 hr
Test Coverage
# frozen_string_literal: true
#
# Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
#
# ronin-support is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ronin-support is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with ronin-support.  If not, see <https://www.gnu.org/licenses/>.
#

require 'ronin/support/binary/ctypes/big_endian'

module Ronin
  module Support
    module Binary
      module CTypes
        module Arch
          #
          # Represents the C types for the MIPS64 architecture.
          #
          module MIPS64
            include BigEndian

            # The size of a pointer in bytes on MIPS64.
            ADDRESS_SIZE = 8

            # The `long` type.
            LONG = BigEndian::INT64

            # The `unsigned long` type.
            ULONG = BigEndian::UINT64

            # The "machine word" type.
            MACHINE_WORD = BigEndian::UINT64

            # The `void *` type.
            POINTER = MACHINE_WORD

            # The MIPS64 types.
            TYPES = BigEndian::TYPES.merge(
              long:  self::LONG,
              ulong: self::ULONG,

              machine_word: self::MACHINE_WORD,
              pointer:      self::POINTER
            )

            #
            # 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.
            #
            def self.[](name)
              self::TYPES.fetch(name) do
                raise(ArgumentError,"unknown MIPS64 type: #{name.inspect}")
              end
            end
          end
        end
      end
    end
  end
end