lib/ronin/arch.rb in ronin-0.3.0 vs lib/ronin/arch.rb in ronin-1.0.0.pre1
- old
+ new
@@ -1,9 +1,9 @@
#
# Ronin - A Ruby platform for exploit development and security research.
#
-# Copyright (c) 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
+# Copyright (c) 2006-2010 Hal Brodigan (postmodern.mod3 at gmail.com)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
@@ -16,54 +16,59 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
-require 'ronin/extensions/meta'
-require 'ronin/extensions/string'
require 'ronin/model'
+require 'ronin/model/has_unique_name'
-require 'dm-predefined'
+require 'dm-is-predefined'
module Ronin
+ #
+ # Represents a Computer Architecture and pre-defines many other common
+ # architectures ({i386}, {i486}, {i686}, {i986}, {x86_64}, {ia64}, {ppc},
+ # {ppc64}, {sparc}, {sparc64}, {mips_le}, {mips_be}, {arm_le}
+ # and {arm_be}).
+ #
class Arch
include Model
- include DataMapper::Predefined
+ include Model::HasUniqueName
+ is :predefined
+
# Primary key
property :id, Serial
- # Name of the architecture
- property :name, String
-
# Endianness of the architecture
- property :endian, String
+ property :endian, String, :set => ['little', 'big'], :required => true
# Address length of the architecture
- property :address_length, Integer
+ property :address_length, Integer, :required => true
- # Validates
- validates_present :name, :endian, :address_length
- validates_is_unique :name
- validates_format :endian, :with => lambda { |endian|
- endian == 'big' || endian == 'little'
- }
- validates_is_number :address_length
-
#
- # Converts the architecture to a String.
+ # Splats the architecture into multiple variables.
#
- # @return [String]
- # The name of the architecture.
+ # @return [Array]
+ # The {#endian} and {#address_length} of the architecture.
#
- def to_s
- self.name.to_s
+ # @example
+ # endian, address_length = Arch.i386
+ #
+ # endian
+ # # => 'little'
+ # address_length
+ # # => 4
+ #
+ # @since 1.0.0
+ #
+ def to_ary
+ [self.endian, self.address_length]
end
#
- # Defines a new builtin Arch with the specified _name_ and the given
- # _options_.
+ # Defines a new builtin Arch.
#
# @param [Symbol, String] name
# The name of the architecture.
#
# @param [Hash] options