2005-12-17 06:46:23 +00:00
|
|
|
#!/usr/bin/env ruby
|
2005-06-09 04:24:45 +00:00
|
|
|
|
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-11-09 04:18:08 +00:00
|
|
|
require 'rex/text'
|
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
|
2005-10-01 05:55:15 +00:00
|
|
|
assert_raise(::ArgumentError) { Klass._check_reg(8) }
|
|
|
|
assert_raise(::ArgumentError) { Klass._check_reg(-1) }
|
2005-06-09 04:24:45 +00:00
|
|
|
|
|
|
|
0.upto(7) { |reg|
|
2005-10-01 05:55:15 +00:00
|
|
|
assert_nothing_raised { Klass._check_reg(reg) }
|
2005-06-09 04:24:45 +00:00
|
|
|
}
|
|
|
|
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-10-01 05:55:15 +00:00
|
|
|
def test_add
|
|
|
|
assert_equal("\x83\xc4\x47", Klass.add(0x47, Klass::ESP)[2,6])
|
|
|
|
assert_equal("\x83\xc4\x47", Klass.add(0x47, Klass::ESP, '', true))
|
|
|
|
assert_equal("\x81\xc4\x11\x11\x01\x00", Klass.add(0x11111, Klass::ESP, '', true))
|
|
|
|
end
|
2005-11-25 20:02:21 +00:00
|
|
|
|
|
|
|
def test_searcher
|
|
|
|
s = "\xbe"+ # mov esi, Tag - 1
|
2005-12-02 14:12:24 +00:00
|
|
|
"\x03\x03\x02\x01"+
|
2005-11-25 20:02:21 +00:00
|
|
|
"\x46"+ # inc esi
|
|
|
|
"\x47"+ # inc edi (end_search:)
|
|
|
|
"\x39\x37"+ # cmp [edi],esi
|
|
|
|
"\x75\xfb"+ # jnz 0xa (end_search)
|
|
|
|
"\x46"+ # inc esi
|
|
|
|
"\x4f"+ # dec edi (start_search:)
|
|
|
|
"\x39\x77\xfc"+ # cmp [edi-0x4],esi
|
|
|
|
"\x75\xfa"+ # jnz 0x10 (start_search)
|
|
|
|
"\xff\xe7" # jmp edi
|
|
|
|
|
|
|
|
assert_equal(s, Klass.searcher("\x04\x03\x02\x01"))
|
|
|
|
end
|
2005-10-01 05:55:15 +00:00
|
|
|
|
2005-06-09 04:24:45 +00:00
|
|
|
end
|