samples/metasm-shell.rb in metasm-1.0.3 vs samples/metasm-shell.rb in metasm-1.0.4

- old
+ new

@@ -2,11 +2,11 @@ # 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 -# modifies the standard ruby class String to add #decode and #encode methods +# modifies the standard ruby class String to add #asm_decode and #asm_encode methods # they will respectively disassemble binary data / assemble asm source # the default CPU is x86 32bits, change it using eg String.cpu = Metasm::MIPS.new(:big) (mips bigendian) # # it also defines the toplevel 'asm' method, that will start an interactive # assembler shell (type in assembly statements, they are shown assembled in binary escaped form) @@ -29,37 +29,37 @@ @@cpu=c end end # encodes the current string as a Shellcode, returns the resulting EncodedData - def encode_edata + def asm_encode_edata Metasm::Shellcode.assemble(@@cpu, self).encode.encoded end # encodes the current string as a Shellcode, returns the resulting binary String # outputs warnings on unresolved relocations - def encode - ed = encode_edata + def asm_encode + ed = asm_encode_edata if not ed.reloc.empty? puts 'W: encoded string has unresolved relocations: ' + ed.reloc.map { |o, r| r.target.inspect }.join(', ') end ed.fill ed.data end # decodes the current string as a Shellcode, with specified base address # returns the resulting Disassembler - def decode_blocks(base_addr=0, eip=base_addr) + def asm_decode_blocks(base_addr=0, eip=base_addr) sc = Metasm::Shellcode.decode(self, @@cpu) sc.base_addr = base_addr sc.disassemble(eip) end # decodes the current string as a Shellcode, with specified base address # returns the asm source equivallent - def decode(base_addr=0, eip=base_addr) - decode_blocks(base_addr, eip).to_s + def asm_decode(base_addr=0, eip=base_addr) + asm_decode_blocks(base_addr, eip).to_s end end # get in interactive assembler mode def asm @@ -84,10 +84,10 @@ break else begin data = line.gsub(';', "\n") next if data.strip.empty? - e_data = data.encode + e_data = data.asm_encode puts '"' + e_data.unpack('C*').map { |c| '\\x%02x' % c }.join + '"' rescue Metasm::Exception => e puts "Error: #{e.class} #{e.message}" end end