'Generate various type of ROP payload using ret2plt
Usage:
MYNAME copybytes (generate function template for ret2strcpy style payload)
MYNAME copybytes dest1 data1 dest2 data2 ...'

def payload(self, *arg):

    (option,) = normalize_argv(arg, 1)
    if (option is None):
        self._missing_argument()
    if (option == 'copybytes'):
        result = peda.payload_copybytes(template=1)
        arg = arg[1:]
        while (len(arg) > 0):
            (target, data) = normalize_argv(arg, 2)
            if (data is None):
                break
            if (to_int(data) is None):
                if ((data[0] == '[') and (data[(-1)] == ']')):
                    data = eval(data)
                    data = list2hexstr(data, peda.intsize())
            else:
                data = ('0x%x' % data)
            result += peda.payload_copybytes(target, data)
            arg = arg[2:]
    if (not result):
        msg('Failed    to    construct    payload')
    else:
        text = ''
        indent = to_int(config.Option.get('indent'))
        for line in result.splitlines():
            text += ((('    ' * indent) + line) + '\n')
        msg(text)
        filename = peda.get_config_filename('payload')
        open(filename, 'w').write(text)
    return
