2005-06-09 04:24:45 +00:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
2005-06-09 06:18:27 +00:00
|
|
|
$:.unshift(File.join(File.dirname(__FILE__), '..', '..'))
|
2005-06-09 04:24:45 +00:00
|
|
|
|
|
|
|
require 'test/unit'
|
2005-07-10 20:49:13 +00:00
|
|
|
require 'rex/string_utils'
|
2005-07-09 21:18:49 +00:00
|
|
|
require 'rex/arch/x86'
|
2005-06-09 04:24:45 +00:00
|
|
|
|
|
|
|
class Rex::Arch::X86::UnitTest < ::Test::Unit::TestCase
|
|
|
|
|
|
|
|
Klass = Rex::Arch::X86
|
|
|
|
|
|
|
|
def test_reg_number
|
|
|
|
assert_equal(Klass.reg_number('eax'), Klass::EAX)
|
|
|
|
assert_equal(Klass.reg_number('EsP'), Klass::ESP)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_push_byte
|
|
|
|
assert_raise(::ArgumentError) { Klass.push_byte(-129) }
|
|
|
|
assert_raise(::ArgumentError) { Klass.push_byte(8732) }
|
|
|
|
assert_equal("\x6a\x10", Klass.push_byte(16))
|
|
|
|
assert_equal("\x6a\xff", Klass.push_byte(-1))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_check_reg
|
|
|
|
assert_raise(::ArgumentError) { Klass.check_reg(8) }
|
|
|
|
assert_raise(::ArgumentError) { Klass.check_reg(-1) }
|
|
|
|
|
|
|
|
0.upto(7) { |reg|
|
|
|
|
assert_nothing_raised { Klass.check_reg(reg) }
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_pop_dword
|
|
|
|
assert_raise(::ArgumentError) { Klass.pop_dword(8) }
|
|
|
|
assert_raise(::ArgumentError) { Klass.pop_dword(-1) }
|
|
|
|
|
|
|
|
assert_equal("\x58", Klass.pop_dword(Klass::EAX))
|
|
|
|
assert_equal("\x5a", Klass.pop_dword(Klass::EDX))
|
|
|
|
assert_equal("\x5c", Klass.pop_dword(Klass::ESP))
|
|
|
|
end
|
|
|
|
|
2005-07-10 20:49:13 +00:00
|
|
|
def test_sub
|
|
|
|
assert_equal("\x83\xe8\x04", Klass.sub(4, Klass::EAX)[2, 3])
|
|
|
|
assert_equal("\x66\x81\xe8\x80\xff", Klass.sub(-128, Klass::EAX)[2, 5])
|
|
|
|
assert_equal("\x81\xe8\x00\x00\x01\x00", Klass.sub(65536, Klass::EAX)[2, 6])
|
|
|
|
end
|
|
|
|
|
2005-06-09 04:24:45 +00:00
|
|
|
end
|