# 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/exe_format/shellcode' class TestEncodedData < Test::Unit::TestCase def compile(src) p = Metasm::Shellcode.assemble(Metasm::UnknownCPU.new(32, :little), src) p.encoded end def test_basic e = compile < 42) assert_raise(Metasm::EncodeError) { e.fixup('tata' => 192349129) } e.fixup('tata' => -12) assert_equal(30.chr[0], e.data[1]) assert_equal(1, e.reloc.length) assert_equal(2, e.offset_of_reloc('tutu')) assert_equal(2, e.offset_of_reloc(Metasm::Expression[:+, 'tutu'])) e.fixup('tutu' => 1024) assert_equal("\1\x1e\0\4\0\0", e.data) ee = Metasm::Expression[:+, 'bla'].encode(:u16, :big) ee.fixup('bla' => 1024) assert_equal("\4\0", ee.data) eee = compile <