2010-09-09 18:19:35 +00:00
|
|
|
# This file is part of Metasm, the Ruby assembly manipulation suite
|
|
|
|
# Copyright (C) 2006-2009 Yoann GUILLOT
|
|
|
|
#
|
|
|
|
# Licence is LGPL, see LICENCE in the top-level directory
|
|
|
|
|
|
|
|
require 'test/unit'
|
|
|
|
require 'metasm'
|
|
|
|
|
|
|
|
class TestDynldr < Test::Unit::TestCase
|
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
def test_dynldr
|
|
|
|
str = "1234"
|
|
|
|
d = Metasm::DynLdr
|
|
|
|
d.new_api_c('int memcpy(char*, char*, int)')
|
|
|
|
d.memcpy(str, "9999", 2)
|
|
|
|
assert_equal('9934', str)
|
2010-10-08 16:01:37 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
c_src = <<EOS
|
2010-10-08 16:01:37 +00:00
|
|
|
int sprintf(char*, char*, ...);
|
|
|
|
void fufu(int i, char* ptr)
|
|
|
|
{
|
2013-08-30 21:28:33 +00:00
|
|
|
sprintf(ptr, "lolzor %i\\n", i);
|
2010-10-08 16:01:37 +00:00
|
|
|
}
|
|
|
|
EOS
|
2013-08-30 21:28:33 +00:00
|
|
|
buf = 'aaaaaaaaaaaaaaaaaa'
|
|
|
|
d.new_func_c(c_src) { d.fufu(42, buf) }
|
|
|
|
assert_equal("lolzor 42\n\000aaaaaaa", buf)
|
2011-04-06 17:40:01 +00:00
|
|
|
|
2013-08-30 21:28:33 +00:00
|
|
|
if d.host_cpu.shortname == 'ia32'
|
|
|
|
ret = d.new_func_asm('int __fastcall bla(int)', "lea eax, [ecx+1]\nret") { d.bla(42) }
|
|
|
|
assert_equal(43, ret)
|
|
|
|
assert_equal(false, d.respond_to?(:bla))
|
|
|
|
end
|
|
|
|
end
|
2010-09-09 18:19:35 +00:00
|
|
|
end
|