# File samples/metasm-shell.rb, line 26 def cpu() @@cpu end
# File samples/metasm-shell.rb, line 27 def cpu=(c) c = Metasm.const_get(c).new if c.kind_of? String @@cpu=c end
decodes the current string as a Shellcode, with specified base address returns the asm source equivallent
# File samples/metasm-shell.rb, line 59 def decode(base_addr=0, eip=base_addr) decode_blocks(base_addr, eip).to_s end
decodes the current string as a Shellcode, with specified base address returns the resulting Disassembler
# File samples/metasm-shell.rb, line 51 def decode_blocks(base_addr=0, eip=base_addr) sc = Metasm::Shellcode.decode(self, @@cpu) sc.base_addr = base_addr sc.disassemble(eip) end
encodes the current string as a Shellcode, returns the resulting binary String outputs warnings on unresolved relocations
# File samples/metasm-shell.rb, line 40 def encode ed = 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
encodes the current string as a Shellcode, returns the resulting EncodedData
# File samples/metasm-shell.rb, line 34 def encode_edata Metasm::Shellcode.assemble(@@cpu, self).encode.encoded end
# File misc/hexdump.rb, line 21 def hexdump(ctx={}) fmt = ctx[:fmt] ||= ['c', 'd', 'a'] ctx[:pos] ||= 0 ctx[:linelen] ||= 16 scan(/.{1,#{ctx[:linelen]}}/) { |s| if s != ctx[:lastline] ctx[:lastdup] = false print '%04x ' % ctx[:pos] print s.unpack('C*').map { |b| '%02x' % b }.join(' ').ljust(3*16-1) + ' ' if fmt.include? 'c' print s.unpack('v*').map { |b| '%04x' % b }.join(' ').ljust(5*8-1) + ' ' if fmt.include? 'w' print s.unpack('L*').map { |b| '%08x' % b }.join(' ').ljust(9*4-1) + ' ' if fmt.include? 'd' print s.tr("\00--\x1f\x7f-\xff".force_encoding('BINARY'), '.') if fmt.include? 'a' puts elsif not ctx[:lastdup] ctx[:lastdup] = true puts '*' end ctx[:lastline] = s ctx[:pos] += s.length } puts '%04x' % ctx[:pos] if not ctx[:noend] rescue Errno::EPIPE exit end