tests/mips.rb in metasm-1.0.1 vs tests/mips.rb in metasm-1.0.2
- old
+ new
@@ -103,14 +103,21 @@
# ruby19 string.encoding. What a wonderful feature!
# if we use a "\x<80 or more>", the encoding is 8bits
# '' << "\x80" => 8bits
# '' << 0x80 => ascii
# Edata.data is ascii for now, so this is needed to make the test work.
- str = ''
- "\x24\x0e\xff\xfb\x01\xc0\x70\x27\x24\x0b\xff\xb7\x05\x10\xff\xff\x28\x08\x82\x82\x01\x60\x58\x27\x03\xeb\xc8\x21\x28\x17\x82\x82\x8f\x31\xff\xfc\x24\x0d\xff\xfb\x01\xa0\x68\x27\x21\xaf\xff\xfd\x8f\x28\xff\xfc\x02\xef\xb8\x21\x01\x11\x18\x26\x02\xee\xf0\x2b\xaf\x23\xff\xfc\x21\xa6\xff\xff\x17\xc0\xff\xf9\x03\x2d\xc8\x21\x24\x02\x10\x33\x01\x4a\x54\x0c\0\0\0\0".each_byte { |b| str << b }
+ str = bin("\x24\x0e\xff\xfb\x01\xc0\x70\x27\x24\x0b\xff\xb7\x05\x10\xff\xff\x28\x08\x82\x82\x01\x60\x58\x27\x03\xeb\xc8\x21\x28\x17\x82\x82\x8f\x31\xff\xfc\x24\x0d\xff\xfb\x01\xa0\x68\x27\x21\xaf\xff\xfd\x8f\x28\xff\xfc\x02\xef\xb8\x21\x01\x11\x18\x26\x02\xee\xf0\x2b\xaf\x23\xff\xfc\x21\xa6\xff\xff\x17\xc0\xff\xf9\x03\x2d\xc8\x21\x24\x02\x10\x33\x01\x4a\x54\x0c\0\0\0\0")
assert_equal(str, sc.encoded.data)
dasm_src = Metasm::Shellcode.disassemble(Metasm::MIPS.new(:big), sc.encoded.data).to_s
lines = dasm_src.respond_to?(:lines) ? dasm_src.lines : dasm_src.to_a
assert_equal(28, lines.grep(/\S/).length)
+ end
+
+ def bin(s)
+ if s.respond_to?(:force_encoding)
+ s.force_encoding('BINARY')
+ else
+ s
+ end
end
end