github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/tools/syz-headerparser/headerparser.py (about) 1 # Copyright 2017 syzkaller project authors. All rights reserved. 2 # Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 ''' 5 This scripts takes as input a list of header files and generates metadata 6 files to make syzkaller device descriptions. 7 ''' 8 9 import argparse 10 import logging 11 import sys 12 import traceback 13 14 from headerlib.header_preprocessor import HeaderFilePreprocessorException 15 from headerlib.container import GlobalHierarchy 16 17 18 def main(): 19 """ 20 python parser.py --filename=A.h,B.h 21 """ 22 23 parser = argparse.ArgumentParser(description='Parse header files to output fuzzer' 24 'struct metadata.') 25 parser.add_argument('--filenames', 26 help='comma-separated header filenames', 27 dest='filenames', 28 required=True) 29 parser.add_argument('--debug', 30 help='print debug-information at every level of parsing', 31 action='store_true') 32 parser.add_argument('--include', 33 help='include the specified file as the first line of the processed header files', 34 required=False, 35 const='', 36 nargs='?') 37 38 args = parser.parse_args() 39 40 loglvl = logging.INFO 41 42 if args.debug: 43 loglvl = logging.DEBUG 44 45 include_lines = '' 46 if args.include: 47 include_lines = open(args.include, 'r').read() 48 49 try: 50 gh = GlobalHierarchy(filenames=args.filenames.split(','), 51 loglvl=loglvl, include_lines=include_lines) 52 except HeaderFilePreprocessorException as e: 53 excdata = traceback.format_exc().splitlines() 54 logging.error(excdata[-1]) 55 sys.exit(-1) 56 57 58 print(gh.get_metadata_structs()) 59 60 if __name__ == '__main__': 61 main()