'Generate or download common shellcodes.
Usage:
MYNAME generate [arch/]platform type [port] [host]
MYNAME search keyword (use % for any character wildcard)
MYNAME display shellcodeId (shellcodeId as appears in search results)
MYNAME zsc [generate customize shellcode]
For generate option:
default port for bindport shellcode: 16706 (0x4142)
default host/port for connect back shellcode: 127.127.127.127/16706
supported arch: x86'

def shellcode(self, *arg):

    def list_shellcode():
        '\n                                                List    available    shellcodes\n                                                '
        text = 'Available    shellcodes:\n'
        for arch in SHELLCODES:
            for platform in SHELLCODES[arch]:
                for sctype in SHELLCODES[arch][platform]:
                    text += ('                %s/%s    %s\n' % (arch, platform, sctype))
        msg(text)
    '    Multiple    variable    name    for    different    modes    '
    (mode, platform, sctype, port, host) = normalize_argv(arg, 5)
    (mode, keyword) = normalize_argv(arg, 2)
    (mode, shellcodeId) = normalize_argv(arg, 2)
    if (mode == 'generate'):
        arch = 'x86'
        if (platform and ('/' in platform)):
            (arch, platform) = platform.split('/')
        if ((platform not in SHELLCODES[arch]) or (not sctype)):
            list_shellcode()
            return
        try:
            sc = Shellcode(arch, platform).shellcode(sctype, port, host)
        except Exception as e:
            self._missing_argument()
        if (not sc):
            msg('Unknown    shellcode')
            return
        hexstr = to_hexstr(sc)
        linelen = 16
        i = 0
        text = ('#    %s/%s/%s:    %d    bytes\n' % (arch, platform, sctype, len(sc)))
        if (sctype in ['bindport', 'connect']):
            text += ('#    port=%s,    host=%s\n' % ((port if port else '16706'), (host if host else '127.127.127.127')))
        text += 'shellcode    =    (\n'
        while hexstr:
            text += ('                "%s"\n' % hexstr[:(linelen * 4)])
            hexstr = hexstr[(linelen * 4):]
            i += 1
        text += ')'
        msg(text)
    elif (mode == 'search'):
        if (keyword is None):
            self._missing_argument()
        res_dl = Shellcode().search(keyword)
        if (not res_dl):
            msg('Shellcode    not    found    or    cannot    retrieve    the    result')
            return
        msg(('Found    %d    shellcodes' % len(res_dl)))
        msg(('%s DCTB %s' % (blue('ScId'), blue('Title'))))
        text = ''
        for data_d in res_dl:
            text += ('[%s] DCTB %s    -    %s\n' % (yellow(data_d['ScId']), data_d['ScArch'], data_d['ScTitle']))
        pager(text)
    elif (mode == 'display'):
        if (to_int(shellcodeId) is None):
            self._missing_argument()
        res = Shellcode().display(shellcodeId)
        if (not res):
            msg('Shellcode    id    not    found    or    cannot    retrieve    the    result')
            return
        msg(res)
    elif (mode == 'zsc'):
        'os    lists'
        oslist = ['linux_x86', 'linux_x64', 'linux_arm', 'linux_mips', 'freebsd_x86', 'freebsd_x64', 'windows_x86', 'windows_x64', 'osx', 'solaris_x64', 'solaris_x86']
        'functions'
        joblist = ["exec('/path/file')", "chmod('/path/file','permission    number')", "write('/path/file','text    to    write')", "file_create('/path/file','text    to    write')", "dir_create('/path/folder')", "download('url','filename')", "download_execute('url','filename','command    to    execute')", "system('command    to    execute')"]
        'encode    types'
        encodelist = ['none', 'xor_random', 'xor_yourvalue', 'add_random', 'add_yourvalue', 'sub_random', 'sub_yourvalue', 'inc', 'inc_timeyouwant', 'dec', 'dec_timeyouwant', 'mix_all']
        try:
            while True:
                for os in oslist:
                    msg(('%s    %s' % (yellow('[+]'), green(os))))
                if (pyversion is 2):
                    os = input(('%s' % blue('os:')))
                if (pyversion is 3):
                    os = input(('%s' % blue('os:')))
                if (os in oslist):
                    break
                else:
                    warning_msg('Wrong    input!    Try    Again.')
            while True:
                for job in joblist:
                    msg(('%s    %s' % (yellow('[+]'), green(job))))
                if (pyversion is 2):
                    job = raw_input(('%s' % blue('job:')))
                if (pyversion is 3):
                    job = input(('%s' % blue('job:')))
                if (job != ''):
                    break
                else:
                    warning_msg('Please    enter    a    function.')
            while True:
                for encode in encodelist:
                    msg(('%s    %s' % (yellow('[+]'), green(encode))))
                if (pyversion is 2):
                    encode = raw_input(('%s' % blue('encode:')))
                if (pyversion is 3):
                    encode = input(('%s' % blue('encode:')))
                if (encode != ''):
                    break
                else:
                    warning_msg('Please    enter    a    encode    type.')
        except (KeyboardInterrupt, SystemExit):
            warning_msg('Aborted    by    user')
        result = Shellcode().zsc(os, job, encode)
        if (result is not None):
            msg(result)
        else:
            pass
        return
    else:
        self._missing_argument()
    return
