Пример #1
0
def obfuscate():
    args = parse_args()
    #import logging
    #logging.basicConfig(level=logging.DEBUG)

    config = json.load(
        open(os.path.join(os.path.dirname(__file__), "client.config.json"),
             "rt"))
    ak = config["connection"]["access_key"].decode("hex")
    sk = config["connection"]["secret_key"].decode("hex")
    jscrambler.API_HOSTNAME = config["connection"]["server"]
    api_port = int(config["connection"]["port"])
    if api_port != 443:
        jscrambler.API_URL = "http://{0}:{1}/v3".format(
            jscrambler.API_HOSTNAME, api_port)
    maximum_poll_retries = 10
    poll_pause = 5  # seconds
    delete_project_at_the_end = True

    source_file = os.path.abspath(args.filepath)

    print "pyjscrambler 1.0"
    print "Using address {}:{}".format(jscrambler.API_HOSTNAME, api_port)
    print "Trying to send project containing:", ", ".join(
        config["files"].values())
    try:
        print jscrambler.post(ak, sk, {source_file}, **config["parameters"])
    except requests.exceptions.ConnectionError:
        print "Couldnt connect to JScrambler server."
        sys.exit()

    for dummy in range(1, maximum_poll_retries):
        time.sleep(poll_pause)
        statuses = "getstatus:", jscrambler.get_status(ak, sk, limit=1)
        print statuses
        if statuses[1][0]['finished_at'] is not None:
            for status in statuses[1]:
                project_id = status['id']
                print "Fetching project", status['id']
                projstat = jscrambler.get_project_status(ak, sk, project_id)
                source_ids = [s['id'] for s in projstat['sources']]
                #jscrambler.get_project_zip(ak, sk, project_id, project_id+".zip")
                for source_id in source_ids:
                    extension = jscrambler.get_project_source_info(
                        ak, sk, project_id, source_id)['extension']
                    obfuscated_contents = jscrambler.get_project_source(
                        ak, sk, project_id, source_id, extension)
                    file_path, file_extension = os.path.splitext(source_file)
                    open(file_path + '.obfuscated' + file_extension,
                         'wt').write(obfuscated_contents)

                if delete_project_at_the_end:
                    print "Deleting project from JScrambler server..."
                    jscrambler.delete_project(ak, sk, project_id)
                    print "Finished."
                    return
        else:
            print "Project not finished. Retrying..."
Пример #2
0
def obfuscate():
    args = parse_args()
    #import logging
    #logging.basicConfig(level=logging.DEBUG)

    config = json.load(open(os.path.join(os.path.dirname(__file__), "client.config.json"), "rt"))
    ak = config["connection"]["access_key"].decode("hex")
    sk = config["connection"]["secret_key"].decode("hex")
    jscrambler.API_HOSTNAME = config["connection"]["server"]
    api_port = int(config["connection"]["port"])
    if api_port != 443:
        jscrambler.API_URL = "http://{0}:{1}/v3".format(jscrambler.API_HOSTNAME, api_port)
    maximum_poll_retries = 10
    poll_pause = 5 # seconds
    delete_project_at_the_end = True

    source_file = os.path.abspath(args.filepath)

    print "pyjscrambler 1.0"
    print "Using address {}:{}".format(jscrambler.API_HOSTNAME, api_port)
    print "Trying to send project containing:", ", ".join(config["files"].values())
    try:
        print jscrambler.post(ak, sk, {source_file}, **config["parameters"])
    except requests.exceptions.ConnectionError:
        print "Couldnt connect to JScrambler server."
        sys.exit() 

    for dummy in range(1, maximum_poll_retries):
        time.sleep(poll_pause)
        statuses = "getstatus:", jscrambler.get_status(ak, sk, limit=1)
        print statuses
        if statuses[1][0]['finished_at'] is not None:
            for status in statuses[1]:
                project_id = status['id']
                print "Fetching project", status['id']
                projstat = jscrambler.get_project_status(ak, sk, project_id)
                source_ids = [s['id'] for s in projstat['sources']]
                #jscrambler.get_project_zip(ak, sk, project_id, project_id+".zip")
                for source_id in source_ids:
                    extension = jscrambler.get_project_source_info(ak, sk, project_id, source_id)['extension']
                    obfuscated_contents = jscrambler.get_project_source(ak, sk, project_id, source_id, extension)
                    file_path, file_extension = os.path.splitext(source_file)
                    open(file_path + '.obfuscated' + file_extension, 'wt').write(obfuscated_contents)

                if delete_project_at_the_end:
                    print "Deleting project from JScrambler server..."
                    jscrambler.delete_project(ak, sk, project_id)
                    print "Finished."
                    return
        else:
            print "Project not finished. Retrying..."
def test():
    #import logging
    #logging.basicConfig(level=logging.DEBUG)
    version = 3
    api_port = 443
    config = json.load(open("config.json", "rt"))
    ak = config["connection"]["access_key"].decode("hex")
    sk = config["connection"]["secret_key"].decode("hex")
    if 'version' in config["connection"]:
        version = config["connection"]["version"];
    if 'server' in config["connection"]:
        jscrambler.API_HOSTNAME = config["connection"]["server"]
    if 'port' in config["connection"]:
        api_port = int(config["connection"]["port"])
    if version != 3:
        jscrambler.API_URL = "https://{0}/v{1}".format(jscrambler.API_HOSTNAME, version)
    if api_port != 443:
        jscrambler.API_URL = "http://{0}:{1}/v{2}".format(jscrambler.API_HOSTNAME, api_port, version)
    maximum_poll_retries = 10
    poll_pause = 5 # seconds
    delete_project_at_the_end = True

    print "pyjscrambler 1.0"
    print "Using address {}:{} (v{})".format(jscrambler.API_HOSTNAME, api_port, version)
    print "Trying to send project containing:", ", ".join(config["files"].values())
    try:
        r = jscrambler.post(ak, sk, config["files"].values(), **config["parameters"])
        error_helper(r)
    except requests.exceptions.ConnectionError:
        print "Couldnt connect to JScrambler server."
        sys.exit()

    for dummy in range(1, maximum_poll_retries):
        time.sleep(poll_pause)
        statuses = "getstatus:", jscrambler.get_status(ak, sk, limit=1)
        if statuses[1][0]['finished_at'] is not None:
            for status in statuses[1]:
                project_id = status['id']
                print "Fetching project", status['id']
                projstat = jscrambler.get_project_status(ak, sk, project_id)
                error_helper(projstat)
                source_ids = [s['id'] for s in projstat['sources']]
                jscrambler.get_project_zip(ak, sk, project_id, project_id+".zip")
                for source_id in source_ids:
                    extension = jscrambler.get_project_source_info(ak, sk, project_id, source_id)['extension']
                    jscrambler.get_project_source(ak, sk, project_id, source_id, extension)
                if delete_project_at_the_end:
                    print "Deleting project from JScrambler server..."
                    jscrambler.delete_project(ak, sk, project_id)
                    print "Finished."
                    return
        else:
            print "Project not finished. Retrying..."