예제 #1
0
파일: black_box.py 프로젝트: Honggou/kpro9
def create_protocols(headers, yml, args=None, cleanup=True):
    """Create protocols for black-box-testing."""
    # Store default options to be able to restore them later
    config.Options.platforms = set()
    o = config.Options
    defaults = (o.verbose, o.debug, o.strict, o.use_cpp,
                o.output_dir, o.output_file, o.platforms, o.delegator)

    # Parse command line arguments
    if args is None:
        args = []
    cli_args = ['-f'] + headers + ['-c', yml] + args
    headers, configs = csjark.parse_args(cli_args)

    # Parse config files
    for filename in configs:
        config.parse_file(filename)
    config.Options.prepare_for_parsing()

    # Create protocols
    csjark.parse_headers(headers)

    # Sort the protocols on name
    structs = {}
    for key, proto in cparser.StructVisitor.all_protocols.items():
        structs[proto.name] = proto.generate()

    if cleanup:
        perform_cleanup(defaults)
        return structs
    else:
        return structs, defaults
예제 #2
0
def parse_headers(cli):
    """Test the parse header function in csjark module."""
    headers = [os.path.join(os.path.dirname(__file__), i)
                for i in ('sprint2.h', 'sprint3.h', 'cpp.h')]
    tmp, configs = csjark.parse_args([headers[0], '-v', '-d'])
    failed = csjark.parse_headers(headers)
    assert failed == 0
    # Cleanup
    cparser.StructVisitor.all_protocols = {}
    dissector.Protocol.protocols = {}
예제 #3
0
def parse_headers(cli):
    """Test the parse header function in csjark module."""
    headers = [
        os.path.join(os.path.dirname(__file__), i)
        for i in ('sprint2.h', 'sprint3.h', 'cpp.h')
    ]
    tmp, configs = csjark.parse_args([headers[0], '-v', '-d'])
    failed = csjark.parse_headers(headers)
    assert failed == 0
    # Cleanup
    cparser.StructVisitor.all_protocols = {}
    dissector.Protocol.protocols = {}