def main(): from core import clap from core import keyfile from datetime import datetime as dt try: p = clap.Parser() except Exception as e: print("%s: error: %s" % (os.path.basename(sys.argv[0]), e)) sys.exit(1) p.set_description("Split a key file into seperate parts and merge " \ "multiple key file parts to a single key file.") p.set_epilog("Further information and usage examples can be found " \ "inside the documentation file for this script.") # Define required arguments p.add_predef("-a", "--action", "action to perform", "action", ["merge", "split"], True) p.add_avalue("-k", "--key-file", "key file path", "key_file", None, True) # Define optional arguments p.add_avalue("-b", "--buffer-size", "buffer size in bytes", "buffer_size", 4096, False) p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_switch(None, "--overwrite", "overwrite existing file", "overwrite", True, False) p.add_avalue("-p", "--parts", "split key into separate parts", "parts", 1, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print(keyfile.get_version()) sys.exit(0) args = p.parse_args() if args.action == "merge" and args.parts > 1: p.error("The parts argument does not make any sense when merging " \ "files.") try: timestamp = dt.now() if args.action == "split": keyfile.split_key(args.key_file, args.parts, args.buffer_size, args.overwrite) else: keyfile.merge_key(args.key_file, args.buffer_size, args.overwrite) print("Elapsed time: %s" % (dt.now() - timestamp)) except Exception as e: p.error(e)
def main(): from core import clap from core import common from core import main try: p = clap.Parser() except Exception as e: print("%s: error: %s" % (os.path.basename(sys.argv[0]), e)) sys.exit(1) p.set_description("Compare two files and replace different bytes.") p.set_epilog("Further information and usage examples can be found " "inside the documentation file for this script.") # Required arguments p.add_avalue("-i", "--input-file", "source file where to read the data " "from", "input_file", None, True) p.add_avalue("-o", "--output-file", "destination file where to write " "data into", "output_file", None, True) # Optional arguments p.add_avalue("-b", "--buffer-size", "buffer size in bytes", "buffer_size", 4096, False) p.add_switch(None, "--no-hashes", "do not use file hash comparison", "no_hash", True, False) p.add_switch(None, "--no-progress", "do not display the process " "percentage", "no_progress", True, False) p.add_switch("-q", "--quiet", "disable output", "quiet", True, False) p.add_switch("-s", "--simulate", "do not change the output file", "simulate", True, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print(common.get_version()) sys.exit(0) args = p.parse_args() try: hashes = not args.no_hash progress = not args.no_progress verbose = not args.quiet byteweiser = main.ByteWeiser() byteweiser.compare_and_replace(args.input_file, args.output_file, args.buffer_size, args.simulate, verbose, progress, hashes) except Exception as e: p.error(e)
def main(): from core import clap from core import replace as r try: p = clap.Parser() except Exception as e: print("%s: error: %s" % (os.path.basename(sys.argv[0]), e)) sys.exit(1) p.set_description("Replace characters in a string with a random one " "from a user-defined character list.") p.set_epilog("Further information and usage examples can be found " "inside the documentation file for this script.") # Define required arguments p.add_avalue("-c", "--config-file", "config file path", "config_file", None, True) p.add_avalue("-s", "--string", "input string to modify", "string", None, True) # Define optional arguments p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_switch("-l", "--length", "sort output strings by their length", "length", True, False) p.add_avalue("-n", "--number", "number of strings to return", "number", 1, False) p.add_switch("-m", "--remove-chars", "remove certain user-defined " "characters from input string", "remove_chars", True, False) p.add_switch("-r", "--remove-spaces", "remove all spaces from input " "string", "remove_spaces", True, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print(r.get_version()) sys.exit(0) args = p.parse_args() try: output = r.replace_chars(args.config_file, args.string, args.remove_spaces, args.remove_chars, args.number, args.length) for string in output: print(string) except Exception as e: p.error(e)
def main(): from core import clap from core import sotp try: p = clap.Parser() except Exception as e: print("%s: error: %s" % (os.path.basename(sys.argv[0]), e)) sys.exit(1) p.set_description("Parse a config file and return the value of a " \ "requested option.") p.set_epilog("Further information and usage examples can be found " \ "inside the documentation file for this script.") # Required arguments p.add_avalue("-c", "--config-file", "config file to parse", "config_file", None, True) p.add_avalue("-o", "--option", "option to read out", "option", None, True) p.add_avalue("-s", "--section", "section that contains the option", "section", None, True) # Optional arguments p.add_avalue("-f", "--fallback", "value to return in case the given " \ "section or option does not exist", "fallback", None, False) p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print(sotp.get_version()) sys.exit(0) args = p.parse_args() try: value = sotp.read_option(args.config_file, args.section, args.option, args.fallback) print(value) except Exception as e: p.error(e)
def main(): from core import clap from core import monitor try: p = clap.Parser() except Exception as e: print "%s: error: %s" % (os.path.basename(sys.argv[0]), e) sys.exit(1) p.set_description("Return or monitor the current status of an Erfr " \ "encryption, decryption, key generation or file " \ "obfuscation process.") p.set_epilog("Further information and usage examples can be found " \ "inside the documentation file for this script.") # Define required arguments p.add_avalue("-t", "--task-id", "Erfr task ID", "task_id", None, True) # Define optional arguments p.add_avalue("-d", "--delay", "auto-refresh delay in seconds", "delay", 0, False) p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print monitor.get_version() sys.exit(0) args = p.parse_args() try: monitor.get_status(args.task_id, args.delay) except Exception as e: p.error(e)
def main(): from core import clap from core import common try: p = clap.Parser() except Exception as e: print("%s: error: %s" % (os.path.basename(sys.argv[0]), e)) sys.exit(1) p.set_description("Delete remaining temporary files of the Erfr " \ "components.") p.set_epilog("Further information and usage examples can be found " \ "inside the documentation file for this script.") # Define optional arguments p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print(common.get_version()) sys.exit(0) try: print("Started cleaning up temporary files.") max_tasks = int(common.get_max_tasks()) for task in range(1, max_tasks + 1): common.delete_temp_files(task) print("Finished cleaning up temporary files.") except Exception as e: print("cancelled cleaning up temporary files.") p.error(e)
def main(): from core import clap from core import common from core import fileren try: p = clap.Parser() except Exception as e: print("%s: error: %s" % (os.path.basename(sys.argv[0]), e)) sys.exit(1) p.set_description("Modify a directory name by removing leading, " "trailing and duplicate spaces or by inserting and " "removing spaces next to punctuation characters.") p.set_epilog("Further information and usage examples can be found " "inside the documentation file for this script.") # Required arguments p.add_avalue("-d", "--directory", "directory that contains the files " "to process", "directory", None, True) # Optional arguments p.add_switch("-b", "--brackets", "insert and remove spaces next to " "brackets", "brackets", True, False) p.add_avalue( None, "--exclude", "pattern to exclude certain files " "(case-insensitive, multiple patterns separated via " "semicolon)", "exclude_pattern", None, False) p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_switch(None, "--hyphens", "insert spaces next to hyphens", "hyphens", True, False) p.add_switch(None, "--ignore-symlinks", "ignore symbolic links", "ignore_symlinks", True, False) p.add_switch("-l", "--remove-leading", "remove leading spaces", "remove_leading", True, False) p.add_switch("-r", "--recursive", "process the given directory " "recursively", "recursive", True, False) p.add_switch("-p", "--punctuation", "insert and remove spaces next to " "punctuation characters", "punctuation", True, False) p.add_switch("-s", "--remove-duplicate", "remove duplicate spaces", "remove_duplicate", True, False) p.add_switch("-t", "--remove-trailing", "remove trailing spaces", "remove_trailing", True, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print(fileren.get_version()) sys.exit(0) try: args = p.parse_args() if not args.punctuation and not args.remove_duplicate and \ not args.remove_leading and not args.remove_trailing: p.error("Nothing to do (no optional arguments were given).") common.dir_space_modifier(args.directory, args.remove_duplicate, args.remove_leading, args.remove_trailing, args.brackets, args.hyphens, args.punctuation, args.ignore_symlinks, args.recursive, args.exclude_pattern) except Exception as e: p.error(e)
def main(): from core import clap from core import common from core import fileren try: p = clap.Parser() except Exception as e: print "%s: error: %s" % (os.path.basename(sys.argv[0]), e) sys.exit(1) p.set_description("Modify the base name of files by adding, removing " \ "or replacing a user-defined string.") p.set_epilog("Further information and usage examples can be found " \ "inside the documentation file for this script.") # Required arguments p.add_predef("-a", "--action", "action to perform", "action", ["add", "remove", "replace"], True) p.add_avalue("-d", "--directory", "directory that contains the files " \ "to process", "directory", None, True) p.add_predef("-p", "--position", "position where to perform the action", "position", ["any", "prefix", "suffix"], True) p.add_avalue("-s", "--string", "input string to perform the action " \ "with (case-sensitive)", "input_string", None, True) # Optional arguments p.add_switch("-c", "--case-sensitive", "do not ignore the case of the " \ "given exclude or explicit pattern", "case", False, False) p.add_switch(None, "--confirm", "skip the confirmation prompt and " \ "instantly rename files", "confirm", True, False) p.add_avalue(None, "--exclude", "pattern to exclude certain files " \ "(case-insensitive, multiple patterns separated via " \ "semicolon)", "exclude_pattern", None, False) p.add_avalue(None, "--explicit", "explicit pattern to only process " \ "certain files (case-insensitive, multiple patterns " \ "separated via semicolon)", "explicit_pattern", None, False) p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_switch(None, "--ignore-symlinks", "ignore symbolic links", "ignore_symlinks", True, False) p.add_switch("-r", "--recursive", "process the given directory " \ "recursively", "recursive", True, False) p.add_switch(None, "--regex", "use regex syntax for the exclude or " \ "explicit pattern instead of just asterisk wildcards and " \ "semicolon separators (for details see the section " \ "'Regular expression operations' inside the official " \ "Python documentation)", "regex_syntax", True, False) p.add_avalue(None, "--replace-string", "string to replace the input" \ "string with (when using the action 'replace')", "replace_string", None, False) p.add_avalue(None, "--simulate", "simulate the rename process and " \ "write the details into a report file", "report_file", None, False) p.add_avalue(None, "--strip", "remove certain leading and trailing " \ "characters from the base name", "strip_chars", None, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print fileren.get_version() sys.exit(0) args = p.parse_args() if args.confirm and not args.report_file == None: p.error("The confirm and the simulate argument cannot be given at " \ "the same time.") if args.exclude_pattern and args.explicit_pattern: p.error("The exclude and the explicit pattern argument cannot be " \ "given at the same time.") try: if not args.confirm and args.report_file == None: if not common.confirm_notice(): sys.exit(0) if args.exclude_pattern: pattern = args.exclude_pattern exclude = True elif args.explicit_pattern: exclude = False pattern = args.explicit_pattern else: exclude = None pattern = None fileren.modify_names(args.directory, args.action, args.position, args.input_string, args.replace_string, args.recursive, exclude, pattern, args.case, args.regex_syntax, args.report_file, args.ignore_symlinks, args.strip_chars) except Exception as e: p.error(e)
def main(): from core import clap from core import common from datetime import datetime as dt try: p = clap.Parser() except Exception as e: print("%s: error: %s" % (os.path.basename(sys.argv[0]), e)) sys.exit(1) p.set_description("Extract a user-defined byte range from an existing " \ "into a new file.") p.set_epilog("Further information and usage examples can be found " \ "inside the documentation file for this script.") # Define required arguments p.add_avalue("-i", "--input-file", "input file path", "input_file", None, True) p.add_avalue("-l", "--length", "number of bytes to read", "length", None, True) p.add_avalue("-o", "--output-file", "output file path", "output_file", None, True) p.add_avalue("-s", "--offset", "position where to start reading", "offset", None, True) # Define optional arguments p.add_avalue("-b", "--buffer-size", "buffer size in bytes", "buffer_size", 4096, False) p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_switch(None, "--overwrite", "overwrite existing file", "overwrite", True, False) p.add_switch("-r", "--remove", "remove the extracted data from the " \ "input file", "remove_bytes", True, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print(common.get_version()) sys.exit(0) args = p.parse_args() remove_bytes = None force_remove = \ bool(int(common.global_config(["Extractor"], ["force_remove"], "0"))) if force_remove: remove_bytes = True else: remove_bytes = args.remove_bytes try: timestamp = dt.now() common.extract_bytes(args.input_file, args.output_file, args.offset, args.length, args.buffer_size, args.overwrite, remove_bytes) print("Elapsed time: %s" % (dt.now() - timestamp)) except Exception as e: p.error(e)
def main(): from core import clap from core import sotp try: p = clap.Parser() except Exception as e: print "%s: error: %s" % (os.path.basename(sys.argv[0]), e) sys.exit(1) p.set_description("Modify an existing or create new config file.") p.set_epilog("Further information and usage examples can be found " \ "inside the documentation file for this script.") # Required arguments p.add_predef("-a", "--action", "action to perform", "action", ["remove", "write", "force-write"], True) p.add_avalue("-c", "--config-file", "config file to modify", "config_file", None, True) p.add_avalue("-s", "--section", "section for the option", "section", None, True) # Optional arguments p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_switch(None, "--new-file", "create a new config file", "new_file", True, False) p.add_switch(None, "--new-section", "create a new section", "new_section", True, False) p.add_avalue("-o", "--option", "option to write", "option", None, False) p.add_avalue("-v", "--value", "value to set for the option", "value", None, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print sotp.get_version() sys.exit(0) args = p.parse_args() try: if "write" in args.action: if args.option == None: raise Exception("An option is required.") force = False if args.action == "force-write": force = True sotp.write_option(args.config_file, args.section, args.option, args.value, args.new_section, args.new_file, force) else: if args.new_file: raise Exception("The '--new-file' argument does not make " \ "sense when deleting contents.") elif args.new_section: raise Exception("The '--new-section' argument does not " \ "make sense when deleting contents.") if args.option == None: sotp.remove_section(args.config_file, args.section) else: sotp.remove_option(args.config_file, args.section, args.option) except Exception as e: p.error(e)
def main(): from core import clap from core import common from core import main as core from datetime import datetime as dt try: p = clap.Parser() except Exception as e: print("%s: error: %s" % (os.path.basename(sys.argv[0]), e)) sys.exit(1) p.set_description("Process a parameter file generated by the main Erfr " \ "script containing encryption related information.") p.set_epilog("Further information and usage examples can be found " \ "inside the documentation file for this script.") # Define required arguments p.add_predef("-a", "--action", "action to perform", "action", ["encrypt", "decrypt"], True) p.add_avalue("-f", "--file", "parameter file to process", "file", None, True) # Define optional arguments (general) p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_avalue("-s", "--suffix", "add additional suffix to the decrypted " \ "file", "suffix", None, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print(core.get_version()) sys.exit(0) args = p.parse_args() if args.action == None: p.error("The action argument is missing.") elif args.action.lower() == "encrypt": encrypt = True elif args.action.lower() == "decrypt": encrypt = False else: p.error("An unsupported action was given.") try: params = common.process_params(args.file) buffer_size = params.get("buffer_size") dev_random = params.get("dev_random") fortuna = params.get("fortuna") input_file = params.get("input_file") key_file = params.get("key_file") obfuscate_enc = params.get("obfuscate_enc") obfuscate_key = params.get("obfuscate_key") output_file = params.get("output_file") overwrite = params.get("overwrite") rotate_max = params.get("rotate_max") rotate_min = params.get("rotate_min") rotate_mod = params.get("rotate_mod") rotate_step = params.get("rotate_step") reverse_bytes = params.get("reverse_bytes") sbox = params.get("sbox") task_id = params.get("task_id") use_existing_key = params.get("use_existing_key") timestamp = dt.now() erfr = core.ErfrCrypt() if task_id == 0: task_id = None if encrypt: if not args.suffix == None: p.error("The argument for an additional suffix can only be " \ "used when decrypting a file.") common.status(task_id, "encryption", "start") erfr.encrypt_file(task_id, input_file, key_file, output_file, buffer_size, use_existing_key, overwrite, obfuscate_enc, obfuscate_key, fortuna, dev_random, rotate_min, rotate_max, rotate_step, rotate_mod, reverse_bytes, sbox) common.status(task_id, "encryption", "finish") else: if not args.suffix == None: input_file += ".%s" % args.suffix common.status(task_id, "decryption", "start") erfr.decrypt_file(task_id, output_file, key_file, input_file, buffer_size, overwrite, obfuscate_enc, obfuscate_key, rotate_min, rotate_max, rotate_step, rotate_mod, reverse_bytes, sbox) common.status(task_id, "decryption", "finish") print("Elapsed time: %s" % (dt.now() - timestamp)) except Exception as e: if encrypt: common.status(task_id, "encryption", "cancel") else: common.status(task_id, "decryption", "cancel") p.error(e) finally: try: common.delete_temp_files(task_id) except: pass
def main(): from core import clap from core import common from core import fileren try: p = clap.Parser() except Exception as e: print("%s: error: %s" % (os.path.basename(sys.argv[0]), e)) sys.exit(1) p.set_description("Convert the case of the base name of all files " "inside a directory and (if requested) in all of its " "sub-directories.") p.set_epilog("Further information and usage examples can be found " "inside the documentation file for this script.") # Required arguments p.add_predef("-c", "--case", "target case of the base name", "case", ["lower", "title", "upper", "config"], True) p.add_avalue("-d", "--directory", "directory that contains the files " "to process", "directory", None, True) p.add_predef("-m", "--conflict-mode", "conflict mode (in case of " "duplicate file names)", "conflict_mode", ["rename", "skip"], True) # Optional arguments p.add_avalue( None, "--cfg-lower", "path to the config file for strings " "which should always be lowercase inside the file " "name", "cfg_lower", None, False) p.add_avalue( None, "--cfg-mixed", "path to the config file for strings " "which should always be mixed case inside the " "file name", "cfg_mixed", None, False) p.add_avalue( None, "--cfg-title", "path to the config file for strings " "which should always be title case inside the " "file name", "cfg_title", None, False) p.add_avalue( None, "--cfg-upper", "path to the config file for strings " "which should always be uppercase inside the file " "name", "cfg_upper", None, False) p.add_switch(None, "--confirm", "skip the confirmation prompt and " "instantly rename files", "confirm", True, False) p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_switch(None, "--ignore-symlinks", "ignore symbolic links", "ignore_symlinks", True, False) p.add_switch("-r", "--recursive", "process the given directory " "recursively", "recursive", True, False) p.add_avalue( None, "--simulate", "simulate the rename process and " "write the details into a report file", "report_file", None, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print(fileren.get_version()) sys.exit(0) args = p.parse_args() if args.confirm and args.report_file is not None: p.error("The confirm and the simulate argument cannot be given at " "the same time.") try: if not args.confirm and args.report_file is None: if not common.confirm_notice(): sys.exit(0) fileren.convert_case(args.directory, args.case, args.conflict_mode, args.recursive, args.cfg_lower, args.cfg_mixed, args.cfg_title, args.cfg_upper, args.report_file, args.ignore_symlinks) except Exception as e: p.error(e)
def main(): from core import clap from core import paval try: p = clap.Parser() except Exception as e: print "%s: error: %s" % (os.path.basename(sys.argv[0]), e) sys.exit(1) p.set_description("Check for exposed passwords offline on the local " + "system via password hash list.") # p.set_epilog() # Required arguments p.add_avalue("-l", "--pwned-list", "path to the text file containing " + "all the password hashes", "pwned_list", None, True) # Optional arguments p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_avalue("-i", "--input-file", "check passwords using a plain text" + "file containing your passwords", "input_file", None, False) p.add_switch("-p", "--prompt", "manually check your passwords via prompt", None, True, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() print print "Usage examples:" print " ./pwned-py2.py -l pwned-passwords.txt -i my-passwords.txt" print " ./pwned-py2.py -l pwned-passwords.txt -p" sys.exit(0) elif "--version" in sys.argv: print __version__ sys.exit(0) args = p.parse_args() try: paval.path(args.pwned_list, "password hash file", True, True) except: p.error("The given password hash list file does not exist.") if not args.input_file and not args.prompt: p.error("Another argument is required, see '--help' for usage " + "examples.") elif args.input_file and args.prompt: p.error("The arguments '--input-file' and '--prompt' cannot be " + "used together.") elif args.prompt: check_prompt(args.pwned_list) else: try: paval.path(args.input_file, "input file", True, True) except: p.error("The given plain text input file does not exist.") check_file(args.pwned_list, args.input_file)
def main(): from core import clap from core import keyfile from datetime import datetime as dt try: p = clap.Parser() except Exception as e: print "%s: error: %s" % (os.path.basename(sys.argv[0]), e) sys.exit(1) p.set_description("Find the corresponding key for an encrypted file " \ "and vice versa.") p.set_epilog("Further information and usage examples can be found " \ "inside the documentation file for this script.") # Define required arguments p.add_avalue("-d", "--directory", "directory to check for the " \ "corresponding files", "directory", None, True) p.add_avalue("-f", "--file", "file to compare (either the key or the " \ "encrypted file)", "input_file", None, True) # Define optional arguments p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_switch("-i", "--ignore-read-errors", "ignore read errors inside "\ "given directory", "ignore_read_errors", True, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) p.add_avalue("-e", "--obfuscate-enc", "number of bytes used to " \ "obfuscate the encrypted file", "obfuscate_enc", 0, False) p.add_avalue("-k", "--obfuscate-key", "number of bytes used to " \ "obfuscate the key file", "obfuscate_key", 0, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print keyfile.get_version() sys.exit(0) args = p.parse_args() if args.ignore_read_errors == None: args.ignore_read_errors = False try: timestamp = dt.now() list_matches = keyfile.compare_files(args.input_file, args.directory, args.ignore_read_errors, args.obfuscate_enc, args.obfuscate_key) if len(list_matches) == 0: print "\nNo matches found for \"%s\"." % args.input_file else: if len(list_matches) == 1: print "\nFound one possible match for \"%s\":\n" \ % args.input_file else: print "\nFound %s possible matches for \"%s\":\n" \ % (str(len(list_matches)), args.input_file) print "-" * 78 for match in list_matches: print "%s" % match print "-" * 78 print "\nElapsed time: %s" % (dt.now() - timestamp) except Exception as e: p.error(e)
def main(): from core import clap from core import common from core import keyfile from datetime import datetime as dt try: p = clap.Parser() except Exception as e: print "%s: error: %s" % (os.path.basename(sys.argv[0]), e) sys.exit(1) p.set_description("Generate key files which can either be used for " \ "encryption or obfuscation purposes (as fake key " \ "files).") p.set_epilog("Further information and usage examples can be found " \ "inside the documentation file for this script.") # Define required arguments p.add_avalue("-s", "--key-size", "key size in bytes", "key_size", None, True) # Define optional arguments p.add_switch(None, "--base64", "generate Base64 key string", "base64", True, False) p.add_avalue("-b", "--buffer-size", "buffer size in bytes", "buffer_size", 4096, False) p.add_switch(None, "--dev-random", "use \"/dev/random\" as random " \ "number generator (Unix-like systems only)", "dev_random", True, False) p.add_switch(None, "--fortuna", "use Fortuna as random number generator", "fortuna", True, False) p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_avalue("-k", "--key-file", "key file path", "key_file", None, False) p.add_switch(None, "--overwrite", "overwrite existing file", "overwrite", True, False) p.add_avalue("-p", "--parts", "split key into separate parts", "parts", 1, False) p.add_avalue("-t", "--task-id", "user-defined task ID", "task_id", None, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print keyfile.get_version() sys.exit(0) args = p.parse_args() if not args.base64 and args.key_file == None: p.error("The argument to either generate a key file or a Base64 " \ "encoded key string is missing.") elif args.base64 and not args.key_file == None: p.error("The arguments to generate a key file and a Base64 key " \ "string cannot be given at the same time.") elif args.base64 and args.overwrite: p.error("The overwrite argument does not make any sense when " \ "generating a Base64 string.") elif args.base64 and args.parts > 1: p.error("The parts argument does not make any sense when " \ "generating a Base64 string.") if args.base64: if not args.task_id == None: p.error("No task ID can be given when creating a Base64 key " \ "string.") try: print keyfile.generate_key_string(args.key_size, args.dev_random, args.fortuna) except Exception as e: p.error(e) else: try: task_id = common.get_task_id(args.task_id) except Exception as e: task_id = args.task_id p.error(e) try: timestamp = dt.now() common.status(task_id, "key generation", "start") keyfile.generate_key_file(task_id, args.key_file, args.key_size, args.buffer_size, 0, False, args.dev_random, args.fortuna, args.overwrite, args.parts) common.status(task_id, "key generation", "finish") print "Elapsed time: %s" % (dt.now() - timestamp) except Exception as e: common.status(task_id, "key generation", "cancel") p.error(e) finally: common.delete_temp_files(task_id)
def main(): from core import clap from core import common from core import indent as i try: p = clap.Parser() except Exception as e: print "%s: error: %s" % (os.path.basename(sys.argv[0]), e) sys.exit(1) p.set_description("Consistently indent messed up files (especially " \ "config files) using a user-defined amount of spaces.") p.set_epilog("Further information and usage examples can be found inside " "the documentation file for this script.") # Required arguments p.add_avalue("-d", "--directory", "directory that contains the files " \ "to process", "directory", None, True) p.add_avalue("-f", "--file-extension", "file extension of the files to " \ "process", "file_ext", None, True) p.add_avalue("-p", "--padding", "padding (in spaces) used to indent " \ "each item inside a line", "padding", None, True) p.add_avalue("-s", "--spaces", "amount of leading spaces for each " \ "indented line", "spaces", None, True) # Optional arguments p.add_switch(None, "--confirm", "skip the confirmation prompt and " \ "instantly process the data (in case the '--overwrite' " \ "argument was given)", "confirm", True, False) p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_switch("-l", "--left-justify", "left-justify the line if it only " \ "consists of a single character", "left_justify", True, False) p.add_switch(None, "--overwrite", "overwrite the input file with the " \ "processed data (instead of creating an output file with " \ "the same name and the additional suffix '.tasp')", "overwrite", True, False) p.add_switch("-r", "--recursive", "process the given directory " \ "recursively", "recursive", True, False) p.add_switch(None, "--verbose", "use verbose mode (print details while " \ "processing data)", "verbose", True, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print i.get_version() sys.exit(0) args = p.parse_args() try: if args.overwrite: if not args.confirm: if not common.confirm_notice(): sys.exit(0) else: if args.confirm: p.error("The '--confirm' argument only makes sense in " \ "combination with the '--overwrite' argument.") i.indent(args.directory, args.file_ext, args.spaces, args.padding, args.left_justify, args.recursive, args.overwrite, args.verbose) except Exception as e: p.error(e)
def main(): from core import clap from core import common from core import extren try: p = clap.Parser() except Exception as e: print "%s: error: %s" % (os.path.basename(sys.argv[0]), e) sys.exit(1) p.set_description("Rename (and adjust) differently spelled file " \ "extensions of the same file type file within a " \ "directory and (if requested) in all of its sub-" \ "directories.") p.set_epilog("Further information and usage examples can be found " \ "inside the documentation file for this script.") # Required arguments p.add_avalue("-d", "--directory", "directory that contains the files " \ "to process", "directory", None, True) p.add_avalue("-e", "--extension", "extension to rename (case-" \ "sensitive, multiple extensions separated via semicolon)", "extension", None, True) p.add_predef("-m", "--conflict-mode", "conflict mode (in case of " \ "duplicate file names)", "conflict_mode", ["rename", "skip"], True) p.add_avalue("-t", "--target-extension", "target extension (case-" \ "sensitive)", "extension_target", None, True) # Optional arguments p.add_switch("-c", "--case-sensitive", "do not ignore the case of the " \ "given extension list", "case", False, False) p.add_switch(None, "--confirm", "skip the confirmation prompt and " \ "instantly rename files", "confirm", True, False) p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_switch(None, "--ignore-symlinks", "ignore symbolic links", "ignore_symlinks", True, False) p.add_switch("-r", "--recursive", "process the given directory " \ "recursively", "recursive", True, False) p.add_avalue(None, "--simulate", "simulate the rename process and " \ "write the details into a report file", "report_file", None, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print extren.get_version() sys.exit(0) args = p.parse_args() if args.confirm and not args.report_file == None: p.error("The confirm and the simulate argument cannot be given at " \ "the same time.") try: if not args.confirm and args.report_file == None: if not common.confirm_notice(): sys.exit(0) extren.rename_extensions(args.directory, args.conflict_mode, args.extension, args.extension_target, args.recursive, args.case, args.report_file, args.ignore_symlinks) except Exception as e: p.error(e)
def main(): from core import clap from core import common from core import fileren try: p = clap.Parser() except Exception as e: print "%s: error: %s" % (os.path.basename(sys.argv[0]), e) sys.exit(1) p.set_description("Rename the base name of files within a directory " \ "and (if requested) in all of its sub-directories " \ "based on the name of the directory where the files " \ "are stored in and add a unique numeric ID.") p.set_epilog("Further information and usage examples can be found " \ "inside the documentation file for this script.") # Required arguments p.add_avalue("-d", "--directory", "directory that contains the files " \ "to process", "directory", None, True) p.add_predef("-m", "--rename-mode", "rename mode to use", "rename_mode", ["fill-gaps", "keep-order", "rename-new"], True) # Optional arguments p.add_switch("-c", "--case-sensitive", "do not ignore the case of the " \ "given exclude or explicit pattern", "case", False, False) p.add_switch(None, "--confirm", "skip the confirmation prompt and " \ "instantly rename files", "confirm", True, False) p.add_avalue(None, "--custom-name", "custom file name (instead of the " \ "directory name where the files are stored in)", "custom_name", None, False) p.add_avalue(None, "--exclude", "pattern to exclude certain files " \ "(case-insensitive, multiple patterns separated via " \ "semicolon)", "exclude_pattern", None, False) p.add_avalue(None, "--explicit", "explicit pattern to only process " \ "certain files (case-insensitive, multiple patterns " \ "separated via semicolon)", "explicit_pattern", None, False) p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_switch(None, "--ignore-file-ext", "ignore file extensions when " \ "numerating files", "ignore_file_ext", True, False) p.add_switch(None, "--ignore-symlinks", "ignore symbolic links", "ignore_symlinks", True, False) p.add_predef("-o", "--order-by", "order files by last accessed, " \ "created or modified date", "order_by", ["accessed", "created", "modified"], False) p.add_avalue("-p", "--padding", "set a user-defined numeric padding " \ "(if no user-defined padding value is given, it will be " \ "set automatically based on the amount of files per " \ "directory)", "padding", 0, False) p.add_switch("-r", "--recursive", "process the given directory " \ "recursively", "recursive", True, False) p.add_switch(None, "--regex", "use regex syntax for the exclude or " \ "explicit pattern instead of just asterisk wildcards and " \ "semicolon separators (for details see the section " \ "'Regular expression operations' inside the official " \ "Python documentation)", "regex_syntax", True, False) p.add_avalue("-s", "--separator", "use a user-defined character or " \ "string as a separator between the directory name and the " \ "unique numeric ID", "separator", " ", False) p.add_avalue(None, "--simulate", "simulate the rename process and " \ "write the details into a report file", "report_file", None, False) p.add_avalue(None, "--step", "steps between each numeric ID", "step", 1, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print fileren.get_version() sys.exit(0) args = p.parse_args() if args.confirm and not args.report_file == None: p.error("The confirm and the simulate argument cannot be given at " \ "the same time.") if args.exclude_pattern and args.explicit_pattern: p.error("The exclude and the explicit pattern argument cannot be " \ "given at the same time.") try: if not args.confirm and args.report_file == None: if not common.confirm_notice(): sys.exit(0) if args.exclude_pattern: pattern = args.exclude_pattern exclude = True elif args.explicit_pattern: exclude = False pattern = args.explicit_pattern else: exclude = None pattern = None fileren.rename_files(args.directory, args.rename_mode, args.separator, args.recursive, args.padding, exclude, pattern, args.case, args.regex_syntax, args.report_file, args.ignore_symlinks, args.ignore_file_ext, args.custom_name, args.step, args.order_by) except Exception as e: p.error(e)
def main(): from core import clap from core import common from core import replace as r try: p = clap.Parser() except Exception as e: print("%s: error: %s" % (os.path.basename(sys.argv[0]), e)) sys.exit(1) p.set_description("Replace tabs inside of files with a user-defined " "amount of spaces and vice versa.") p.set_epilog("Further information and usage examples can be found inside " "the documentation file for this script.") # Required arguments p.add_avalue("-d", "--directory", "directory that contains the files " \ "to process", "directory", None, True) p.add_avalue("-f", "--file-extension", "file extension of the files to " \ "process", "file_ext", None, True) p.add_predef("-m", "--indentation-mode", "indentation method to use", "mode", ["spaces", "tabs"], True) p.add_avalue("-s", "--spaces", "amount of spaces used to replace a tab " \ "or to get replaced by a tab (depending on the " "indentation mode)", "spaces", None, True) # Optional arguments p.add_switch(None, "--confirm", "skip the confirmation prompt and " \ "instantly process the data (in case the '--overwrite' " \ "argument was given)", "confirm", True, False) p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_switch(None, "--overwrite", "overwrite the input file with the " \ "processed data (instead of creating an output file with " \ "the same name and the additional suffix '.tasp')", "overwrite", True, False) p.add_switch("-r", "--recursive", "process the given directory " \ "recursively", "recursive", True, False) p.add_switch(None, "--verbose", "use verbose mode (print details while " \ "processing data)", "verbose", True, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print(r.get_version()) sys.exit(0) args = p.parse_args() try: if args.overwrite: if not args.confirm: if not common.confirm_notice(): sys.exit(0) else: if args.confirm: p.error("The '--confirm' argument only makes sense in " \ "combination with the '--overwrite' argument.") r.replace(args.directory, args.file_ext, args.mode, args.spaces, args.recursive, args.overwrite, args.verbose) except Exception as e: p.error(e)
def main(): from core import builder from core import clap from core import common try: p = clap.Parser() except Exception as e: print("%s: error: %s" % (os.path.basename(sys.argv[0]), e)) sys.exit(1) p.set_description("Create a content file from a directory or media.") p.set_epilog("Further information and usage examples can be found " \ "inside the documentation file for this script.") # Define required arguments p.add_avalue("-d", "--destination-directory", "destination directory " \ "(where to create the content file in)", "dir_destination", None, True) p.add_avalue("-f", "--content-file", "name of the content file to create", "content_file", None, True) p.add_avalue("-s", "--source-directory", "source directory (from which " \ "to gather the contents)", "dir_source", None, True) # Define optional arguments p.add_switch("-c", "--case-sensitive", "do not ignore the case of the " \ "given exclude pattern", "case", False, False) p.add_avalue("-e", "--exclude", "pattern to exclude certain files or " \ "directories from the content file (case-insensitive, " \ "multiple patterns separated via semicolon)", "pattern_exclude", None, False) p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_switch("-i", "--ignore-read-errors", "ignore read errors while " \ "gathering content", "ignore_read_errors", True, False) p.add_avalue(None, "--include-ace", "include the content from ACE " \ "archive files (requires 'unace' binary)", "bin_unace", None, False) p.add_avalue(None, "--include-rar", "include the content from RAR " \ "archive files (requires 'unrar' binary)", "bin_unrar", None, False) p.add_switch(None, "--include-tar", "include the content from TAR " \ "archive files (also supports Bzip2 and Gzip compressed " \ "TAR archives)", "include_tar", True, False) p.add_switch(None, "--include-zip", "include the content from ZIP " \ "archive files", "include_zip", True, False) p.add_switch(None, "--regex", "use regex syntax for the search term " \ "instead of just asterisk wildcards and semicolon " \ "separators (for details see the section \"Regular " \ "expression operations\" inside the Python documentation)", "regex", True, False) p.add_avalue("-r", "--replace-source-directory", "replace the source " \ "directory path with a user-defined string inside the " \ "content file", "replace_string", None, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print(builder.get_version()) sys.exit(0) args = p.parse_args() try: if args.ignore_read_errors == None: args.ignore_read_errors = False print() print("Building the content file. Please wait.") stats = builder.build_content_file( args.dir_destination, args.content_file, args.dir_source, args.ignore_read_errors, args.pattern_exclude, args.case, args.regex, args.bin_unace, args.bin_unrar, args.include_tar, args.include_zip, args.replace_string) just = common.get_max_digits([ str(stats["lines_archive"]), str(stats["lines_excluded"]), str(stats["lines_ignored"]), str(stats["lines_total"]), str(stats["lines_written"]) ]) print("Build process completed.") print() print("Total gathered lines of content: %s" % \ str(stats["lines_total"]).rjust(just, " ")) print("Total lines read from archives: %s" % \ str(stats["lines_archive"]).rjust(just, " ")) print("Total lines excluded from file: %s" % \ str(stats["lines_excluded"]).rjust(just, " ")) print("Total amount of read errors: %s" % \ str(stats["lines_ignored"]).rjust(just, " ")) print() print("Total lines written into file: %s" % \ str(stats["lines_written"]).rjust(just, " ")) print() except Exception as e: p.error(e)
def main(): from core import clap from core import common from core import finder try: p = clap.Parser() except Exception as e: print("%s: error: %s" % (os.path.basename(sys.argv[0]), e)) sys.exit(1) p.set_description("Search content files for a given search term.") p.set_epilog("Further information and usage examples can be found " \ "inside the documentation file for this script.") # Define required arguments p.add_avalue("-s", "--search-term", "term to search for", "search_term", None, True) p.add_avalue("-d", "--directory", "directory containing the content " \ "files", "directory", None, True) # Define optional arguments p.add_switch("-c", "--case-sensitive", "do not ignore the case of the " \ "given search term", "case", False, False) p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_switch(None, "--regex", "use regex syntax for the search term " \ "instead of just asterisk wildcards and semicolon " \ "separators (for details see the section \"Regular " \ "expression operations\" inside the Python documentation)", "regex", True, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print(finder.get_version()) sys.exit(0) args = p.parse_args() try: print() print("Searching for the given term. Please wait.") match_count = 0 match_files = 0 content_files = finder.get_files(args.directory) for content_file in content_files: list_matches = finder.find_term(content_file, args.search_term, args.case, args.regex) if len(list_matches) > 0: match_count += len(list_matches) match_files += 1 print() print(" [%s]" % content_file.replace(args.directory, "")) for match in list_matches: print(" - %s" % match) print() total_files = len(content_files) just = common.get_max_digits([total_files, match_files, match_count]) print("Search process completed.") print() print("Total files processed: %s" % \ str(total_files).rjust(just, " ")) print() if match_count == 0: print("No matches found.") else: print("Total files matched: %s" % \ str(match_files).rjust(just, " ")) print("Total matches found: %s" % \ str(match_count).rjust(just, " ")) print() except Exception as e: p.error(e)
def main(): from core import clap from core import common from core import obfuscator from datetime import datetime as dt try: p = clap.Parser() except Exception as e: print("%s: error: %s" % (os.path.basename(sys.argv[0]), e)) sys.exit(1) p.set_description("Obfuscate existing encrypted and key files by " \ "adding random bytes.") p.set_epilog("Further information and usage examples can be found " \ "inside the documentation file for this script.") # Define required arguments p.add_avalue("-f", "--file", "target file path", "file", None, True) p.add_avalue("-r", "--random-bytes", "amount of random bytes to add to " \ "the given file", "random_bytes", 0, True) # Define optional arguments p.add_avalue("-b", "--buffer-size", "buffer size in bytes", "buffer_size", 4096, False) p.add_switch(None, "--dev-random", "use \"/dev/random\" as random " \ "number generator (Unix-like systems only)", "dev_random", True, False) p.add_switch(None, "--fortuna", "use Fortuna as random number generator", "fortuna", True, False) p.add_switch("-h", "--help", "print this help message and exit", None, True, False) p.add_avalue("-t", "--task-id", "user-defined task ID", "task_id", None, False) p.add_switch(None, "--version", "print the version number and exit", None, True, False) if len(sys.argv) == 1: p.error("At least one required argument is missing.") elif ("-h" in sys.argv) or ("--help" in sys.argv): p.print_help() sys.exit(0) elif "--version" in sys.argv: print(obfuscator.get_version()) sys.exit(0) args = p.parse_args() try: task_id = common.get_task_id(args.task_id) except Exception as e: task_id = args.task_id p.error(e) try: timestamp = dt.now() common.status(task_id, "file obfuscation", "start") obfuscator.obfuscate_file(task_id, args.file, args.buffer_size, args.random_bytes, args.dev_random, args.fortuna) common.status(task_id, "file obfuscation", "finish") print("Elapsed time: %s" % (dt.now() - timestamp)) except Exception as e: common.status(task_id, "file obfuscation", "cancel") p.error(e) finally: common.delete_temp_files(task_id)