Sha256: 4a1f22297591cdd254785036d32034ebcc795d4df5d0a1ed884a1887af906e4f

Contents?: true

Size: 1.78 KB

Versions: 42

Compression:

Stored size: 1.78 KB

Contents

require 'rex/constants'

module Rex


###
#
# This module provides generalized methods for performing operations that are
# architecture specific.  Furthermore, the modules contained within this
# module provide features that are specific to a given architecture.
#
###
module Arch

	#
	# Architecture classes
	#
	require 'rex/arch/x86'
	require 'rex/arch/sparc'

	#
	# This routine adjusts the stack pointer for a given architecture.
	#
	def self.adjust_stack_pointer(arch, adjustment)

		if ( arch.is_a?(::Array))
			arch = arch[0]
		end

		case arch
			when /x86/
				Rex::Arch::X86.adjust_reg(Rex::Arch::X86::ESP, adjustment)
			else
				nil
		end
	end

	#
	# This route provides address packing for the specified arch
	#
	def self.pack_addr(arch, addr)

		if ( arch.is_a?(::Array))
			arch = arch[0]
		end

		case arch
			when ARCH_X86
				[addr].pack('V')
			when ARCH_X86_64
				[addr].pack('Q')
			when ARCH_MIPS # ambiguous
				[addr].pack('N')
			when ARCH_MIPSBE
				[addr].pack('N')
			when ARCH_MIPSLE
				[addr].pack('V')
			when ARCH_PPC  # ambiguous
				[addr].pack('N')
			when ARCH_SPARC
				[addr].pack('N')
			when ARCH_ARMLE
				[addr].pack('V')
			when ARCH_ARMBE
				[addr].pack('N')
		end
	end

	#
	# This routine reports the endianess of a given architecture
	#
	def self.endian(arch)

		if ( arch.is_a?(::Array))
			arch = arch[0]
		end

		case arch
			when ARCH_X86
				return ENDIAN_LITTLE
			when ARCH_X86_64
				return ENDIAN_LITTLE
			when ARCH_MIPS # ambiguous
				return ENDIAN_BIG
			when ARCH_MIPSLE
				return ENDIAN_LITTLE
			when ARCH_MIPSBE
				return ENDIAN_BIG
			when ARCH_PPC  # ambiguous
				return ENDIAN_BIG
			when ARCH_SPARC
				return ENDIAN_BIG
			when ARCH_ARMLE
				return ENDIAN_LITTLE
			when ARCH_ARMBE
				return ENDIAN_BIG
		end

		return ENDIAN_LITTLE
	end

end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
librex-0.0.65 lib/rex/arch.rb
librex-0.0.63 lib/rex/arch.rb
librex-0.0.54 lib/rex/arch.rb
librex-0.0.53 lib/rex/arch.rb
librex-0.0.52 lib/rex/arch.rb
librex-0.0.51 lib/rex/arch.rb
librex-0.0.50 lib/rex/arch.rb
librex-0.0.49 lib/rex/arch.rb
librex-0.0.48 lib/rex/arch.rb
librex-0.0.47 lib/rex/arch.rb
librex-0.0.46 lib/rex/arch.rb
librex-0.0.44 lib/rex/arch.rb
librex-0.0.43 lib/rex/arch.rb
librex-0.0.42 lib/rex/arch.rb
librex-0.0.41 lib/rex/arch.rb
librex-0.0.40 lib/rex/arch.rb
librex-0.0.39 lib/rex/arch.rb
librex-0.0.38 lib/rex/arch.rb
librex-0.0.37 lib/rex/arch.rb
librex-0.0.36 lib/rex/arch.rb