'Get common rop gadgets in binary: ret, popret, pop2ret, pop3ret, add [mem] reg, add reg [mem]
Returns:
- dictionary of (gadget(String), address(Int))'

def common_rop_gadget(self, mapname=None):

    def _valid_register_opcode(bytes_):
        if (not bytes_):
            return False
        for c in bytes_iterator(bytes_):
            if (ord(c) not in list(range(88, 96))):
                return False
        return True
    result = {}
    if (mapname is None):
        mapname = 'binary'
    maps = self.get_vmmap(mapname)
    if (maps is None):
        return result
    for (start, end, _, _) in maps:
        if (not self.is_executable(start, maps)):
            continue
        mem = self.dumpmem(start, end)
        found = self.searchmem(start, end, '....\xc3', mem)
        for (a, v) in found:
            v = codecs.decode(v, 'hex')
            if ('ret' not in result):
                result['ret'] = (a + 4)
            if ('leaveret' not in result):
                if (v[(-2)] == '\xc9'):
                    result['leaveret'] = (a + 3)
            if ('popret' not in result):
                if _valid_register_opcode(v[(-2):(-1)]):
                    result['popret'] = (a + 3)
            if ('pop2ret' not in result):
                if _valid_register_opcode(v[(-3):(-1)]):
                    result['pop2ret'] = (a + 2)
            if ('pop3ret' not in result):
                if _valid_register_opcode(v[(-4):(-1)]):
                    result['pop3ret'] = (a + 1)
            if ('pop4ret' not in result):
                if _valid_register_opcode(v[(-5):(-1)]):
                    result['pop4ret'] = a
        found = self.searchmem(start, end, '\x83\xc4([^\xc3]){0,24}\xc3', mem)
        found += self.searchmem(start, end, '\x81\xc4([^\xc3]){0,24}\xc3', mem)
        for (a, v) in found:
            if v.startswith('81'):
                offset = to_int(('0x' + codecs.encode(codecs.decode(v, 'hex')[2:5][::(-1)], 'hex').decode('utf-8')))
            elif v.startswith('83'):
                offset = to_int(('0x' + v[4:6].decode('utf-8')))
            gg = self._verify_rop_gadget(a, ((a + (len(v) // 2)) - 1))
            for (_, c) in gg:
                if ('pop' in c):
                    offset += 4
            gadget = ('addesp_%d' % offset)
            if (gadget not in result):
                result[gadget] = a
    return result
