2005-12-05 15:22:17 +00:00
|
|
|
require 'rex/constants'
|
|
|
|
|
2005-10-01 05:55:15 +00:00
|
|
|
module Rex
|
2005-11-02 23:03:02 +00:00
|
|
|
|
2011-05-12 20:03:55 +00:00
|
|
|
|
2005-11-02 23:03:02 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
###
|
2005-10-01 05:55:15 +00:00
|
|
|
module Arch
|
|
|
|
|
2005-11-26 00:04:26 +00:00
|
|
|
#
|
|
|
|
# Architecture classes
|
|
|
|
#
|
2011-05-12 20:03:55 +00:00
|
|
|
require 'rex/arch/x86'
|
|
|
|
require 'rex/arch/sparc'
|
2005-10-01 05:55:15 +00:00
|
|
|
|
|
|
|
#
|
2005-11-15 05:22:13 +00:00
|
|
|
# This routine adjusts the stack pointer for a given architecture.
|
2005-10-01 05:55:15 +00:00
|
|
|
#
|
|
|
|
def self.adjust_stack_pointer(arch, adjustment)
|
2010-02-11 07:42:26 +00:00
|
|
|
|
|
|
|
if ( arch.is_a?(::Array))
|
|
|
|
arch = arch[0]
|
|
|
|
end
|
|
|
|
|
2005-10-01 05:55:15 +00:00
|
|
|
case arch
|
|
|
|
when /x86/
|
2005-11-11 01:22:03 +00:00
|
|
|
Rex::Arch::X86.adjust_reg(Rex::Arch::X86::ESP, adjustment)
|
2005-10-01 05:55:15 +00:00
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-11-17 19:41:54 +00:00
|
|
|
#
|
|
|
|
# This route provides address packing for the specified arch
|
|
|
|
#
|
|
|
|
def self.pack_addr(arch, addr)
|
2010-02-11 07:42:26 +00:00
|
|
|
|
|
|
|
if ( arch.is_a?(::Array))
|
|
|
|
arch = arch[0]
|
|
|
|
end
|
|
|
|
|
2005-11-17 19:41:54 +00:00
|
|
|
case arch
|
|
|
|
when ARCH_X86
|
|
|
|
[addr].pack('V')
|
2009-08-23 23:47:33 +00:00
|
|
|
when ARCH_X86_64
|
|
|
|
[addr].pack('Q')
|
2005-11-17 19:41:54 +00:00
|
|
|
when ARCH_MIPS # ambiguous
|
|
|
|
[addr].pack('N')
|
2008-09-15 18:50:34 +00:00
|
|
|
when ARCH_MIPSBE
|
|
|
|
[addr].pack('N')
|
|
|
|
when ARCH_MIPSLE
|
|
|
|
[addr].pack('V')
|
2005-11-17 19:41:54 +00:00
|
|
|
when ARCH_PPC # ambiguous
|
2010-02-11 07:48:56 +00:00
|
|
|
[addr].pack('N')
|
2005-11-17 19:41:54 +00:00
|
|
|
when ARCH_SPARC
|
2007-09-24 03:16:50 +00:00
|
|
|
[addr].pack('N')
|
|
|
|
when ARCH_ARMLE
|
|
|
|
[addr].pack('V')
|
|
|
|
when ARCH_ARMBE
|
2010-02-11 07:48:56 +00:00
|
|
|
[addr].pack('N')
|
2005-11-17 19:41:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-03-09 17:28:37 +00:00
|
|
|
#
|
|
|
|
# This routine reports the endianess of a given architecture
|
|
|
|
#
|
2006-07-31 02:50:41 +00:00
|
|
|
def self.endian(arch)
|
2010-02-11 07:48:56 +00:00
|
|
|
|
2007-07-16 01:23:17 +00:00
|
|
|
if ( arch.is_a?(::Array))
|
|
|
|
arch = arch[0]
|
|
|
|
end
|
2010-02-11 07:48:56 +00:00
|
|
|
|
2006-03-09 17:28:37 +00:00
|
|
|
case arch
|
|
|
|
when ARCH_X86
|
|
|
|
return ENDIAN_LITTLE
|
2009-08-23 23:47:33 +00:00
|
|
|
when ARCH_X86_64
|
|
|
|
return ENDIAN_LITTLE
|
2006-03-09 17:28:37 +00:00
|
|
|
when ARCH_MIPS # ambiguous
|
|
|
|
return ENDIAN_BIG
|
2008-09-15 18:50:34 +00:00
|
|
|
when ARCH_MIPSLE
|
|
|
|
return ENDIAN_LITTLE
|
|
|
|
when ARCH_MIPSBE
|
|
|
|
return ENDIAN_BIG
|
2006-03-09 17:28:37 +00:00
|
|
|
when ARCH_PPC # ambiguous
|
|
|
|
return ENDIAN_BIG
|
|
|
|
when ARCH_SPARC
|
|
|
|
return ENDIAN_BIG
|
2007-09-24 03:16:50 +00:00
|
|
|
when ARCH_ARMLE
|
|
|
|
return ENDIAN_LITTLE
|
|
|
|
when ARCH_ARMBE
|
|
|
|
return ENDIAN_BIG
|
2006-03-09 17:28:37 +00:00
|
|
|
end
|
2010-02-11 07:48:56 +00:00
|
|
|
|
2006-03-09 17:28:37 +00:00
|
|
|
return ENDIAN_LITTLE
|
|
|
|
end
|
|
|
|
|
2005-10-01 05:55:15 +00:00
|
|
|
end
|
2010-02-11 07:48:56 +00:00
|
|
|
end
|