1#!/usr/bin/env python 2 3from __future__ import absolute_import 4import sys 5 6 7def type_map(x): 8 return "TYPE_" + x.upper() 9 10 11def print_preamble(): 12 print(r'struct blacklist_entry blacklist[] = {') 13 14 15def print_entry(kext, func, type): 16 strkext = '"' + kext + '"' if kext != "" else "NULL" 17 strfunc = '"' + func + '"' if func != "" else "NULL" 18 19 strtype = "0" 20 if type: 21 strtype = type_map(type) if type != "" else "normal" 22 23 print(""" {{ 24 .kext_name = {}, 25 .func_name = {}, 26 .type_mask = {}, 27 }},""".format(strkext, strfunc, strtype)) 28 29 30def print_postamble(nentries, extra_entries): 31 print('') # add space for new entries added at runtime 32 print(r' /* Unused entries that can be populated at runtime */') 33 34 for _ in range(extra_entries): 35 print_entry("", "", None) 36 37 print("};\n") 38 39 print('static size_t blacklist_entries = {};'.format(nentries)) 40 print('static const size_t blacklist_max_entries = {};'.format( 41 nentries + extra_entries)) 42 43 44def extract_symbol(line): 45 fields = line.split(":") 46 if len(fields) == 3: 47 return [field.strip() for field in fields] 48 raise Exception("Invalid exclusion rule: {}".format(line)) 49 50 51with open(sys.argv[1]) as fd: 52 nentries = 0 53 extra_entries = 5 54 55 print_preamble() 56 57 for line in fd.readlines(): 58 line = line.strip() 59 if line and not line.startswith("#"): 60 kext, func, ty = extract_symbol(line) 61 print_entry(kext, func, ty) 62 nentries += 1 63 64 print_postamble(nentries, extra_entries) 65