<commit_before>"""
This is the Manticore's CLI `manticore` script.
"""
import argparse
import logging
import sys

from .utils import config, log
from .core.manticore import ManticoreBase

consts = config.get_group('main')
consts.add('recursionlimit', default=10000,
           description="Value to set for Python recursion limit")
consts.add('timeout', default=0,
           description='Timeout, in seconds, for Manticore invocation')


# XXX(yan): This would normally be __name__, but then logger output will be pre-
# pended by 'm.__main__: ', which is not very pleasing. hard-coding to 'main'
logger = logging.getLogger('manticore.main')


def main():
    """
    Dispatches execution into one of Manticore's engines: evm or native.
    """
    args = parse_arguments()

    if args.no_colors:
        log.disable_colors()

    sys.setrecursionlimit(consts.recursionlimit)

    ManticoreBase.verbosity(args.v)

    if args.argv[0].endswith('.sol'):
        from manticore.ethereum.cli import ethereum_main
        ethereum_main(args, logger)
    else:
        from manticore.native.cli import native_main
        native_main(args, logger)


def parse_arguments():
    def positive(value):
        ivalue = int(value)
        if ivalue <= 0:
            raise argparse.ArgumentTypeError("Argument must be positive")
        return ivalue

    parser = argparse.ArgumentParser(description='Symbolic execution tool', prog='manticore',
                                     formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--context', type=str, default=None,
                        help=argparse.SUPPRESS)
    parser.add_argument('--coverage', type=str, default=None,
                        help='Where to write the coverage data')
    parser.add_argument('--names', type=str, default=None,
                        help=argparse.SUPPRESS)
    parser.add_argument('--no-colors', action='store_true',
                        help='Disable ANSI color escape sequences in output')
    parser.add_argument('--offset', type=int, default=16,
                        help=argparse.SUPPRESS)
    # FIXME (theo) Add some documentation on the different search policy options
    parser.add_argument('--policy', type=str, default='random',
                        help=("Search policy. random|adhoc|uncovered|dicount"
                              "|icount|syscount|depth. (use + (max) or - (min)"
                              " to specify order. e.g. +random)"))
    parser.add_argument('--profile', action='store_true',
                        help='Enable profiling mode.')
    parser.add_argument('--procs', type=int, default=1,
                        help='Number of parallel processes to spawn')
    parser.add_argument('argv', type=str, nargs='*', default=[],
                        help="Path to program, and arguments ('+' in arguments indicates symbolic byte).")
    parser.add_argument('--timeout', type=int, default=consts.timeout,
                        help='Timeout. Abort exploration after TIMEOUT seconds')
    parser.add_argument('-v', action='count', default=1,
                        help='Specify verbosity level from -v to -vvvv')
    parser.add_argument('--workspace', type=str, default=None,
                        help=("A folder name for temporaries and results."
                              "(default mcore_?????)"))
    parser.add_argument('--version', action='version', version='Manticore 0.2.3',
                        help='Show program version information')
    parser.add_argument('--config', type=str,
                        help='Manticore config file (.yml) to use. (default config file pattern is: ./[.]m[anti]core.yml)')
    parser.add_argument('--stdin_size', type=int, default=consts.stdin_size,
                        help='Control the maximum symbolic stdin size')

    bin_flags = parser.add_argument_group('Binary flags')
    bin_flags.add_argument('--entrysymbol', type=str, default=None,
                           help='Symbol as entry point')
    bin_flags.add_argument('--assertions', type=str, default=None,
                           help=argparse.SUPPRESS)
    bin_flags.add_argument('--buffer', type=str,
                           help=argparse.SUPPRESS)
    bin_flags.add_argument('--data', type=str, default='',
                           help='Initial concrete concrete_data for the input symbolic buffer')
    bin_flags.add_argument('--file', type=str, default=[], action='append', dest='files',
                           help='Specify symbolic input file, \'+\' marks symbolic bytes')
    bin_flags.add_argument('--env', type=str, nargs=1, default=[], action='append',
                           help='Add an environment variable. Use "+" for symbolic bytes. (VARNAME=++++)')
    bin_flags.add_argument('--pure-symbolic', action='store_true',
                           help='Treat all writable memory as symbolic')<commit_msg>__main__.py: fetch manticore version from installed module (#1310)<commit_after>"""
This is the Manticore's CLI `manticore` script.
"""
import argparse
import logging
import sys

import pkg_resources

from .core.manticore import ManticoreBase
from .utils import config, log

consts = config.get_group('main')
consts.add('recursionlimit', default=10000,
           description="Value to set for Python recursion limit")
consts.add('timeout', default=0,
           description='Timeout, in seconds, for Manticore invocation')


# XXX(yan): This would normally be __name__, but then logger output will be pre-
# pended by 'm.__main__: ', which is not very pleasing. hard-coding to 'main'
logger = logging.getLogger('manticore.main')


def main():
    """
    Dispatches execution into one of Manticore's engines: evm or native.
    """
    args = parse_arguments()

    if args.no_colors:
        log.disable_colors()

    sys.setrecursionlimit(consts.recursionlimit)

    ManticoreBase.verbosity(args.v)

    if args.argv[0].endswith('.sol'):
        from manticore.ethereum.cli import ethereum_main
        ethereum_main(args, logger)
    else:
        from manticore.native.cli import native_main
        native_main(args, logger)


def parse_arguments():
    def positive(value):
        ivalue = int(value)
        if ivalue <= 0:
            raise argparse.ArgumentTypeError("Argument must be positive")
        return ivalue

    parser = argparse.ArgumentParser(description='Symbolic execution tool', prog='manticore',
                                     formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--context', type=str, default=None,
                        help=argparse.SUPPRESS)
    parser.add_argument('--coverage', type=str, default=None,
                        help='Where to write the coverage data')
    parser.add_argument('--names', type=str, default=None,
                        help=argparse.SUPPRESS)
    parser.add_argument('--no-colors', action='store_true',
                        help='Disable ANSI color escape sequences in output')
    parser.add_argument('--offset', type=int, default=16,
                        help=argparse.SUPPRESS)
    # FIXME (theo) Add some documentation on the different search policy options
    parser.add_argument('--policy', type=str, default='random',
                        help=("Search policy. random|adhoc|uncovered|dicount"
                              "|icount|syscount|depth. (use + (max) or - (min)"
                              " to specify order. e.g. +random)"))
    parser.add_argument('--profile', action='store_true',
                        help='Enable profiling mode.')
    parser.add_argument('--procs', type=int, default=1,
                        help='Number of parallel processes to spawn')
    parser.add_argument('argv', type=str, nargs='*', default=[],
                        help="Path to program, and arguments ('+' in arguments indicates symbolic byte).")
    parser.add_argument('--timeout', type=int, default=consts.timeout,
                        help='Timeout. Abort exploration after TIMEOUT seconds')
    parser.add_argument('-v', action='count', default=1,
                        help='Specify verbosity level from -v to -vvvv')
    parser.add_argument('--workspace', type=str, default=None,
                        help=("A folder name for temporaries and results."
                              "(default mcore_?????)"))

    current_version = pkg_resources.get_distribution("manticore").version
    parser.add_argument('--version', action='version', version=f'Manticore {current_version}',
                        help='Show program version information')
    parser.add_argument('--config', type=str,
                        help='Manticore config file (.yml) to use. (default config file pattern is: ./[.]m[anti]core.yml)')
    parser.add_argument('--stdin_size', type=int, default=consts.stdin_size,
                        help='Control the maximum symbolic stdin size')

    bin_flags = parser.add_argument_group('Binary flags')
    bin_flags.add_argument('--entrysymbol', type=str, default=None,
                           help='Symbol as entry point')
    bin_flags.add_argument('--assertions', type=str, default=None,
                           help=argparse.SUPPRESS)
    bin_flags.add_argument('--buffer', type=str,
                           help=argparse.SUPPRESS)
    bin_flags.add_argument('--data', type=str, default='',
                           help='Initial concrete concrete_data for the input symbolic buffer')
    bin_flags.add_argument('--file', type=str, default=[], action='append', dest='files',
                           help='Specify symbolic input file, \'+\' marks symbolic bytes')
    bin_flags.add_argument('--env', type=str, nargs=1, default=[], action='append',
                           help='Add an environment variable. Use "+" for symbolic bytes. (VARNAME=++++)')
    bin_flags.add_argument('--pure-symbolic', action='store_true',
                           help='Treat all writable memory as symbolic')
{'fraction_non_alphanumeric': 0.12116365090472858, 'fraction_numerical': 0.0032990102969109266, 'mean_word_length': 2.5299929428369796, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4514699', 'n_tokens_mistral': 2771, 'n_tokens_neox': 2660, 'n_words': 676}