'Search for ROP gadgets in memory
Note: only for simple gadgets, for full ROP search try: http://ropshell.com
Usage:
MYNAME "gadget" start end
MYNAME "gadget" pagename'

def ropsearch(self, *arg):

    (asmcode, start, end) = normalize_argv(arg, 3)
    if (asmcode is None):
        self._missing_argument()
    if (not self._is_running()):
        return
    asmcode = arg[0]
    result = []
    if (end is None):
        if (start is None):
            mapname = 'binary'
        else:
            mapname = start
        maps = peda.get_vmmap(mapname)
        msg(('Searching    for    ROP    gadget:    %s    in:    %s    ranges' % (repr(asmcode), mapname)))
        for (start, end, _, _) in maps:
            if (not peda.is_executable(start, maps)):
                continue
            result += peda.search_asm(start, end, asmcode, rop=1)
    else:
        msg(('Searching    for    ROP    gadget:    %s    in    range:    0x%x    -    0x%x' % (repr(asmcode), start, end)))
        result = peda.search_asm(start, end, asmcode, rop=1)
    result = sorted(result, key=(lambda x: len(x[1][0])))
    text = 'Not    found'
    if result:
        text = ''
        for (addr, (byte, code)) in result:
            text += ('%s    :    (%s) DCTB %s\n' % (to_address(addr), byte, code))
    pager(text)
    return
