1#!/usr/bin/ruby 2 3# CONST REG_EX. DO NOT CHANGE 4delete_pattern = /add_deleted_comment\(\"(.*)\"\);/ 5diff_pattern = /add_diff_option_comment\(\"(.*)\",\s?\"(.*)\"\)/ 6template_diff = /<\s*&(.*),\s*&(.*),\s*&(.*?)(?:, true)?>/ 7config_delete_template = /deleted_ctor<&(.*)>/ 8paths_diff = /paths_ctor<\s*&(.*)\s*>/ # check kws_paths.cc 9normalizers_diff = /norm_sans_options_ctor<\s?&(.*)>/ # check pps_normalizers 10unified2_diff = /unified2_ctor<\s?&(.*)>/ # checkout out_unified2.cc 11star_reg = /\*/ 12 13if ARGV.empty?() || ARGV.length() > 1 14 abort("Usage: ruby get_differences.rb <path_to_search>") 15end 16 17dir = ARGV[0]; 18 19if !File.directory?(dir) 20 abort("Cannot find directory #{dir}") 21end 22 23 24arr = Array.new() 25 26Dir.glob("#{dir}/**/*cc").each do |file| 27 file_name = File.basename(file, ".cc") 28 underscore_index = file_name.index("_") 29 snort_opt = nil 30 31 if (underscore_index != nil) 32 snort_opt = file_name.slice(underscore_index + 1, file_name.length()) 33 else 34 snort_opt = file_name 35 end 36 37 38 File.open(file) do |f| 39 f.each_line do |line| 40 # gets rid of all lines which dereference pointers 41 if line =~ star_reg 42 next 43 end 44 45 if line =~ delete_pattern 46 arr << "deleted -> #{snort_opt.strip}: '#{$1.strip}'" 47 end 48 49 if line =~ diff_pattern 50 arr << "change -> #{snort_opt.strip}: '#{$1.strip}' ==> '#{$2.strip}'" 51 end 52 53 if line =~ template_diff 54 arr << "change -> config '#{$1.strip}' ==> '#{$2.strip}.#{$3.strip}'" 55 end 56 57 if line =~ config_delete_template 58 arr << "deleted -> config '#{$1.strip}'" 59 end 60 61 # Files with special templates 62 63 if line =~ paths_diff 64 arr << "change -> #{$1.strip} ==> 'snort.--plugin_path=<path>'" 65 end 66 67 if line =~ normalizers_diff 68 arr << "change -> preprocessor 'normalize_#{$1.strip}' ==> 'normalize.#{$1.strip}'" 69 end 70 71 if line =~ unified2_diff 72 arr << "change -> unified2: '#{$1.strip}' ==> 'unified2'" 73 end 74 75 end 76 end 77end 78 79arr.uniq! 80arr.sort! 81 82arr.each do |elem| 83 puts "#{elem}" 84end 85