worked more on set

git-svn-id: file:///home/svn/incoming/trunk@2609 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
Spoon M 2005-06-09 17:44:43 +00:00
parent bd8971130d
commit 0cfad842e6
1 changed files with 18 additions and 0 deletions

View File

@ -53,25 +53,43 @@ module X86
return opcodes[rand(opcodes.length)].chr + encode_modrm(reg, reg)
end
# B004 mov al,0x4
def self.mov_byte(reg, val)
_check_reg(reg)
# chr will raise RangeError if val not between 0 .. 255
return (0xb0 | reg).chr + val.chr
end
# 66B80400 mov ax,0x4
def self.mov_word(reg, val)
_check_reg(reg)
if val < 0 || val > 0xffff
raise RangeError, "Can only take unsigned word values!", caller()
end
return "\x66" + (0xb8 | reg).chr + [ val ].pack('v')
end
def self.set(dst, val, badchars = '')
_check_reg(dst)
# try push BYTE val; pop dst
begin
return _check_badchars(push_byte(val) + pop_dword(dst), badchars)
rescue RuntimeError, RangeError
end
# try clear dst, mov BYTE dst
begin
return _check_badchars(clear(dst, badchars) + mov_byte(dst, val), badchars)
rescue RuntimeError, RangeError
end
# try clear dst, mov WORD dst
begin
return _check_badchars(clear(dst, badchars) + mov_word(dst, val), badchars)
rescue RuntimeError, RangeError
end
raise RuntimeError, "No valid set instruction could be created!", caller()
end