metasploit-framework/lib/rex/arch.rb

110 lines
2.1 KiB
Ruby
Raw Normal View History

# -*- coding: binary -*-
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
2013-08-30 21:28:33 +00:00
#
# Architecture classes
#
require 'rex/arch/x86'
require 'rex/arch/sparc'
require 'rex/arch/zarch'
2013-08-30 21:28:33 +00:00
#
# This routine adjusts the stack pointer for a given architecture.
#
def self.adjust_stack_pointer(arch, adjustment)
2013-08-30 21:28:33 +00:00
if ( arch.is_a?(::Array))
arch = arch[0]
end
2013-08-30 21:28:33 +00:00
case arch
when /x86/
Rex::Arch::X86.adjust_reg(Rex::Arch::X86::ESP, adjustment)
else
nil
end
end
2013-08-30 21:28:33 +00:00
#
# This route provides address packing for the specified arch
#
def self.pack_addr(arch, addr)
2013-08-30 21:28:33 +00:00
if ( arch.is_a?(::Array))
arch = arch[0]
end
2013-08-30 21:28:33 +00:00
case arch
when ARCH_X86
[addr].pack('V')
when ARCH_X86_64, ARCH_X64
[addr].pack('Q<')
2013-08-30 21:28:33 +00:00
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')
when ARCH_ZARCH
[addr].pack('Q>')
2013-08-30 21:28:33 +00:00
end
end
2013-08-30 21:28:33 +00:00
#
# This routine reports the endianess of a given architecture
#
def self.endian(arch)
2013-08-30 21:28:33 +00:00
if ( arch.is_a?(::Array))
arch = arch[0]
end
2013-08-30 21:28:33 +00:00
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
when ARCH_ZARCH
return ENDIAN_BIG
2013-08-30 21:28:33 +00:00
end
2013-08-30 21:28:33 +00:00
return ENDIAN_LITTLE
end
end
end