ass attempt at x86 stuff

git-svn-id: file:///home/svn/incoming/trunk@2595 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Spoon M 2005-06-09 04:24:45 +00:00
parent 83574ab2c1
commit a73185a141
2 changed files with 94 additions and 0 deletions

52
lib/rex/arch/x86.rb Normal file
View File

@ -0,0 +1,52 @@
#!/usr/bin/ruby
module Rex
module Arch
module X86
#
# Register number constants
#
EAX = AL = AX = ES = 0
ECX = CL = CX = CS = 1
EDX = DL = DX = SS = 2
EBX = BL = BX = DS = 3
ESP = AH = SP = FS = 4
EBP = CH = BP = GS = 5
ESI = DH = SI = 6
EDI = BH = DI = 7
def self.reg_number(str)
return self.const_get(str.upcase)
end
def self.push_byte(byte)
# push byte will sign extend...
if byte < 128 && byte >= -128
return "\x6a" + (byte & 0xff).chr
end
raise ::ArgumentError, "Can only take signed byte values!", caller()
end
def self.check_reg(reg)
if reg > 7 || reg < 0
raise ArgumentError, "Invalid register #{reg}", caller()
end
end
def self.pop_dword(dst)
check_reg(dst)
return (0x58 | dst).chr
end
def self.set(dst, val, badchars)
# I'm a lazy bum fix this!"
data = push_byte(val) + pop_dword(dst)
return data
# !!! check bad chars!
end
end
end end

42
lib/rex/arch/x86.rb.ut.rb Normal file
View File

@ -0,0 +1,42 @@
#!/usr/bin/ruby
$:.unshift(File.join('..', '..', File.dirname(__FILE__)))
require 'test/unit'
require 'Rex/Arch/X86'
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
end