Skip to content

Commit

Permalink
First Pass of changes
Browse files Browse the repository at this point in the history
- removes the -g flag
- default behavior is to validate the rule as it is without generating id, fingerprint, version, first_imported, or last_modified if not already present.
- id, fingerprint, version, first_imported, or last_modified are auto generated, if not already present, when the -i or -c flags are used
- changed the help message
  • Loading branch information
cccs-gm committed Jul 14, 2020
1 parent 044412d commit 5c78926
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
3 changes: 2 additions & 1 deletion yara-validator/yara_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ def validation(self, rule_to_validate, rule_to_validate_string, generate_values=
if value.optional == MetadataOpt.REQ_PROVIDED:
valid.update_validity(False, key, 'Missing required metadata')
elif value.optional == MetadataOpt.REQ_OPTIONAL:
valid.update_validity(False, key, 'Missing metadata that could have been generated')
valid.update_validity(False, key, '⚙️ Missing metadata that could have been generated with the -i'
' or -c flag for the cli')
else:
if self.required_fields_index[value.position].count > value.max_count and value.max_count != -1:
valid.update_validity(False, key, 'Too many instances of metadata value.')
Expand Down
24 changes: 12 additions & 12 deletions yara_validator_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
# Defining the parser and arguments to parse so it be used both when called by the command line and with the git_ci
# function.
parser = argparse.ArgumentParser(description='CCCS YARA script to run the CCCS YARA validator, '
'if the -i or -c flags are not provided no changes '
'will be made to the files. '
'The default behavior without either of the -i or -c flags is to return '
'the validity of the file or files if the -i or -c flag had been used. '
'Use the -g flag to check the current validity of the file or files.')
'use the -i or -c flags to generate the id, fingerprint, version, '
'first_imported, or last_modified (if not already present) and add them'
'to the file.')
parser.add_argument('paths', nargs='+', type=str, default=[],
help='A list of files or folders to be analyzed.')
parser.add_argument('-r', '--recursive', action='store_true', default=False, dest='recursive',
Expand All @@ -46,9 +44,6 @@
help='This mode will ignore warnings and proceed with other behaviors if the rule is valid.')
parser.add_argument('-s', '--standard', action='store_true', default=False, dest='standard',
help='This prints the YARA standard to the screen.')
parser.add_argument('-g', '--generate-values', action='store_false', default=True, dest='generatevalues',
help='Generate-values, this is true by default use this flag to prevent values from being'
' generated.')

parser_group = parser.add_mutually_exclusive_group()
parser_group.add_argument('-i', '--in-place', action='store_true', default=False, dest='inplace',
Expand Down Expand Up @@ -182,17 +177,22 @@ def __call_validator(options):
y_file=yara_rule_path,
))

yara_file_processor = run_yara_validator(yara_rule_path, options.generatevalues)
what_will_be_done = 'make no changes'
yara_file_output = None

# handle if we want to overwrite or create new files
if options.createfile:
generate_values = True
yara_file_output = get_yara_file_new_path(yara_rule_path)
what_will_be_done = 'create a new file with the {} preface.'.format(YARA_VALID_PREFIX)
elif options.inplace:
generate_values = True
yara_file_output = yara_rule_path
what_will_be_done = 'modify the file in place.'
else:
generate_values = False
what_will_be_done = 'make no changes'
yara_file_output = None

yara_file_processor = run_yara_validator(yara_rule_path, generate_values)


# Prints the output of the validator.
file_message = '{message:39}{y_file}'
Expand Down

0 comments on commit 5c78926

Please sign in to comment.