Esempio n. 1
0
def obfuscate_proj(platform='default',
                   do_rebuild=True,
                   is_verbose=True,
                   do_import=False):
    """Obfuscate a project.

    Parameters
    ----------
    do_import : bool
        Run import_project fabfile if True.
    do_rebuild : bool
        Rebuild the Reserved and Identifier tables if True.
    is_verbose: bool
        Print verbose messages.
    platform : str
        Destination platform.

    Returns
    -------
    True if successfully completed.
    """
    print('***OBFUSCATE tasks started at {}'.format(ctime(time())))

    if do_import:
        if not import_proj():
            print('### Import called but failed. Export canceled. ###')
            return

    obfuscate(platform=platform, do_rebuild=do_rebuild, is_verbose=is_verbose)

    print('***OBFUSCATE tasks ended at {}'.format(ctime(time())))
    return True
Esempio n. 2
0
def main():
    """Obfuscate a python project.

    Create a project in the OBFUSCATED directory for the destination platform.
    This project directory will have three subdirectories:

        1. obfuscated. This has files and packages specified in the
            common/settings.py obfuscated_packages and obfuscated_root_files
            lists.
        2. unobfuscated. This has a complete copy of the project in the
            IMPORTED directory.
        3. db. This contains a copy of the Reserved and Identifier tables.

    System arguments
    ----------------
    platform: The destination platform.

    norebuild: Don't rebuild the dictionary. That is, keep all the previously
        assigned variable names, but check for new names and changes in
        reserved names. The default is to rebuild the dictionary.

    notverbose: Do not print verbose messages.
    doimport: Import source.
    """
    # Set command line parameters
    parser = argparse.ArgumentParser(description='Obfuscate source files.')
    parser.add_argument(
        '--platform',
        dest='platform',
        help='destination platform',
        required=False)
    parser.add_argument(
        '--norebuild',
        action='store_true',
        help='add/refresh identifier names',
        required=False)
    parser.add_argument(
        '--notverbose',
        action='store_true',
        help='print verbose messages',
        required=False)
    parser.add_argument(
        '--doimport',
        action='store_true',
        help='import source',
        required=False)

    # Parse the command line
    args = parser.parse_args()

    # Obfuscate project
    obfuscate(platform=args.platform if args.platform else 'default',
              do_rebuild=not args.norebuild,
              is_verbose=not args.notverbose)
Esempio n. 3
0
def main():
    """Obfuscate a python project.

    Create a project in the OBFUSCATED directory for the destination platform.
    This project directory will have three subdirectories:

        1. obfuscated. This has files and packages specified in the
            common/settings.py obfuscated_packages and obfuscated_root_files
            lists.
        2. unobfuscated. This has a complete copy of the project in the
            IMPORTED directory.
        3. db. This contains a copy of the Reserved and Identifier tables.

    System arguments
    ----------------
    platform: The destination platform.

    norebuild: Don't rebuild the dictionary. That is, keep all the previously
        assigned variable names, but check for new names and changes in
        reserved names. The default is to rebuild the dictionary.

    notverbose: Do not print verbose messages.
    doimport: Import source.
    """
    # Set command line parameters
    parser = argparse.ArgumentParser(description='Obfuscate source files.')
    parser.add_argument('--platform',
                        dest='platform',
                        help='destination platform',
                        required=False)
    parser.add_argument('--norebuild',
                        action='store_true',
                        help='add/refresh identifier names',
                        required=False)
    parser.add_argument('--notverbose',
                        action='store_true',
                        help='print verbose messages',
                        required=False)
    parser.add_argument('--doimport',
                        action='store_true',
                        help='import source',
                        required=False)

    # Parse the command line
    args = parser.parse_args()

    # Obfuscate project
    obfuscate(platform=args.platform if args.platform else 'default',
              do_rebuild=not args.norebuild,
              is_verbose=not args.notverbose)
Esempio n. 4
0
def pyminify(options, _file):

    module = os.path.split(_file)[1]
    module = ".".join(module.split('.')[:-1])
    filesize = os.path.getsize(_file)
    source = open(_file, 'rb').read()
    tokens = token_utils.listified_tokenizer(source)

     # Perform obfuscation if any of the related options were set
    if options['obfuscate']:
        identifier_length = int(options['replacement_length'])
        name_generator = obfuscate.obfuscation_machine(identifier_length=identifier_length)
        obfuscate.obfuscate(module, tokens, options)

    result = token_utils.untokenize(tokens).strip()
    #result = filter(lambda x: x != '\r' and x != '\n', ' '.join(result.split()))
    print result
Esempio n. 5
0
 def test_ciphers(self):
     for i in range(10000):
         str = "".join(list([choice(list(map(chr, range(0,255)))) for _ in range(randint(0,3000))]))
         try:
             if str != deobfuscate(obfuscate(str)):
                 print "FAILED: %s\n\n\n" % str
         except:
             print "EXCEPTION: %s" % str
Esempio n. 6
0
import hashdeep
import obfuscate
import package

hashdeep_out_file = "file_hashes.out"

hashdeep.hashdeep(hashdeep_out_file)
obfuscate.obfuscate(hashdeep_out_file)
package.package()

Esempio n. 7
0
    os.system( 'java -jar compiler/compiler.jar --language_in=ECMASCRIPT5 --js ' + sourcePath + ' --js_output_file ' + buildPath )

    buildFile = open( buildPath, 'r' )
    contents = buildFile.read();
    buildFile.close()

    licenseFile = open( licensePath, 'r' )
    license_contents = licenseFile.read();
    licenseFile.close()

    buildFile = open( buildPath, 'w' )
    buildFile.write( license_contents + contents )
    buildFile.close()

## here comes
obfuscate()

#build anaglyph js
source = 'middle.js'
build = '../build/video.anaglyph.js'
license = '../src/LICENSE'

buildit(source, build, license)

## build video js
source2 = 'middle2.js'
build = '../build/video.patched.js'
license = '../src/LICENSE-VideoJS'

buildit(source2, build, license)
Esempio n. 8
0
import sys
import obfuscate
import token_utils
import minification

if __name__ == '__main__':
    if len(sys.argv) != 3:
        print("Usage: %s <emoji_length> <filename.py>" % sys.argv[0])
        sys.exit(1)

    source = open(sys.argv[2]).read()
    replacement_length = int(sys.argv[1])

    tokens = token_utils.listified_tokenizer(source)
    source = minification.minify(tokens)

    tokens = token_utils.listified_tokenizer(source)
    obfuscate.obfuscate(source, tokens, replacement_length)

    result = '# -*- coding: emoji -*-\n'
    result += token_utils.untokenize(tokens)

    with open('out/out.py', 'w') as f:
        f.write(result)
    with open('out/run.py', 'w') as f:
        f.write('import out\n')

    print('Export successful ./out/out.py')
    print('Run the program with python3 ./out/run.py')
    # print(result)
Esempio n. 9
0
def main():
    try:
        params = parsed_arguments()
        common = Common(params)
        clauses = common.load_input_file()
        if params["restore"]:
            import shutil

            shutil.copyfile(os.path.join(params["script_directory"], "pristine_sandbox.mcd"), "sandbox.mcd")
            return open("params.json", "w").write("{}")
        if params["print_params"]:
            import json

            for added_key in params["added_keys"][:]:
                del params[added_key]
            params["print_params"] = False
            params_contents = json.dumps(params, ensure_ascii=False, indent=2, sort_keys=True)
            return safe_print_for_PHP(params_contents)
        if params["obfuscate"]:
            from obfuscate import obfuscate

            return safe_print_for_PHP(obfuscate(clauses, params))
        mcd = Mcd(clauses, params)
        if params["flip"]:
            return safe_print_for_PHP(
                {
                    "v": mcd.get_clauses_vertical_mirror,
                    "h": mcd.get_clauses_horizontal_mirror,
                    "d": mcd.get_clauses_diagonal_mirror,
                }[params["flip"]]()
            )
        if params["arrange"]:
            params.update(mcd.get_layout_data())
            if params["arrange"] == "ga":
                from arrange_ga import arrange
            elif params["arrange"] == "bb":
                from arrange_bb import arrange
            result = arrange(**params)
            if result:
                return safe_print_for_PHP(mcd.get_clauses_from_layout(**result))
            raise RuntimeError(("Mocodo Err.9 - " + _("Failed to calculate a planar layout.")).encode("utf8"))
        relations = Relations(mcd, params)
        common.dump_mld_files(relations)
        if params["image_format"] == "svg":
            from mcd_to_svg import main
            import runpy

            main(mcd, common)
            runpy.run_path(u"%(output_name)s_svg.py" % params)
            return
        if params["image_format"] == "nodebox":
            from mcd_to_nodebox import main

            main(mcd, common)
            return os.system(u"""open -a NodeBox "%(output_name)s_nodebox.py" """ % params)
        raise RuntimeError(("Mocodo Err.13 - " + _("Should never happen.")).encode("utf8"))
    except RuntimeError, err:
        msg = str(err)
        if msg.startswith("Mocodo Err."):
            print >> sys.stderr, msg
        else:
            raise