class String

Public Class Methods

cpu() click to toggle source
# File samples/metasm-shell.rb, line 25
def cpu()   @@cpu   end
cpu=(c) click to toggle source
# File samples/metasm-shell.rb, line 26
def cpu=(c)
        c = Metasm.const_get(c).new if c.kind_of? String
        @@cpu=c
end

Public Instance Methods

decode(base_addr=0, eip=base_addr) click to toggle source

decodes the current string as a Shellcode, with specified base address returns the asm source equivallent

# File samples/metasm-shell.rb, line 58
def decode(base_addr=0, eip=base_addr)
        decode_blocks(base_addr, eip).to_s
end
decode_blocks(base_addr=0, eip=base_addr) click to toggle source

decodes the current string as a Shellcode, with specified base address returns the resulting Disassembler

# File samples/metasm-shell.rb, line 50
def decode_blocks(base_addr=0, eip=base_addr)
        sc = Metasm::Shellcode.decode(self, @@cpu)
        sc.base_addr = base_addr
        sc.disassemble(eip)
end
encode() click to toggle source

encodes the current string as a Shellcode, returns the resulting binary String outputs warnings on unresolved relocations

# File samples/metasm-shell.rb, line 39
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
encode_edata() click to toggle source

encodes the current string as a Shellcode, returns the resulting EncodedData

# File samples/metasm-shell.rb, line 33
def encode_edata
        Metasm::Shellcode.assemble(@@cpu, self).encode.encoded
end
hexdump(ctx={}) click to toggle source
# 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]}}/m) { |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("\0-\x1f\x7f-\xff", '.') 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