mirror of https://github.com/crytic/slither
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.
35 lines
1.5 KiB
35 lines
1.5 KiB
6 years ago
|
import re
|
||
|
from slither.exceptions import SlitherException
|
||
|
from ..utils.patches import create_patch
|
||
6 years ago
|
|
||
|
class FormatConstableStates:
|
||
|
|
||
|
@staticmethod
|
||
|
def format(slither, patches, elements):
|
||
|
for element in elements:
|
||
6 years ago
|
FormatConstableStates.create_patch(slither, patches, element['source_mapping']['filename_absolute'], \
|
||
|
element['source_mapping']['filename_relative'], element['name'], \
|
||
|
"constant " + element['name'], element['source_mapping']['start'], \
|
||
|
element['source_mapping']['start'] + element['source_mapping']['length'])
|
||
6 years ago
|
|
||
|
@staticmethod
|
||
6 years ago
|
def create_patch(slither, patches, in_file, in_file_relative, match_text, replace_text, modify_loc_start, modify_loc_end):
|
||
6 years ago
|
in_file_str = slither.source_code[in_file].encode('utf-8')
|
||
6 years ago
|
old_str_of_interest = in_file_str[modify_loc_start:modify_loc_end]
|
||
6 years ago
|
(new_str_of_interest, num_repl) = re.subn(match_text, replace_text, old_str_of_interest.decode('utf-8'), 1)
|
||
6 years ago
|
if num_repl != 0:
|
||
6 years ago
|
create_patch(
|
||
|
patches,
|
||
|
"constable-states",
|
||
|
in_file_relative,
|
||
|
in_file,
|
||
|
modify_loc_start,
|
||
|
modify_loc_end,
|
||
|
old_str_of_interest.decode('utf-8'),
|
||
|
new_str_of_interest
|
||
|
)
|
||
|
|
||
6 years ago
|
else:
|
||
6 years ago
|
raise SlitherException("State variable not found?!")
|
||
|
|