Static Analyzer for Solidity
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
slither/utils/slither_format/format_constable_states.py

26 lines
1.1 KiB

import re
class FormatConstableStates:
@staticmethod
def format(slither, patches, elements):
for element in elements:
FormatConstableStates.create_patch(slither, patches, element['source_mapping']['filename'], element['name'], "constant " + element['name'], element['source_mapping']['start'], element['source_mapping']['start'] + element['source_mapping']['length'])
@staticmethod
def create_patch(slither, patches, in_file, match_text, replace_text, modify_loc_start, modify_loc_end):
in_file_str = slither.source_code[in_file]
old_str_of_interest = in_file_str[modify_loc_start:modify_loc_end]
(new_str_of_interest, num_repl) = re.subn(match_text, replace_text, old_str_of_interest, 1)
if num_repl != 0:
patches[in_file].append({
"detector" : "constable-states",
"start" : modify_loc_start,
"end" : modify_loc_end,
"old_string" : old_str_of_interest,
"new_string" : new_str_of_interest
})
else:
print("Error: State variable not found?!")
sys.exit(-1)