mirror of https://github.com/crytic/slither
parent
9db7167817
commit
6ad193abd9
@ -0,0 +1,32 @@ |
||||
from typing import Dict |
||||
from slither.core.cfg.node import NodeType |
||||
from slither.tools.mutator.utils.patch import create_patch_with_line |
||||
from slither.tools.mutator.mutators.abstract_mutator import AbstractMutator, FaultNature |
||||
|
||||
|
||||
class CR(AbstractMutator): # pylint: disable=too-few-public-methods |
||||
NAME = "CR" |
||||
HELP = 'Comment Replacement' |
||||
FAULTNATURE = FaultNature.Missing |
||||
|
||||
def _mutate(self) -> Dict: |
||||
result: Dict = {} |
||||
|
||||
for function in self.contract.functions_and_modifiers_declared: |
||||
for node in function.nodes: |
||||
if node.type != NodeType.ENTRYPOINT and NodeType.ENDIF != node.type and NodeType.ENDLOOP != node.type: |
||||
# Get the string |
||||
start = node.source_mapping.start |
||||
stop = start + node.source_mapping.length |
||||
old_str = self.in_file_str[start:stop] |
||||
line_no = node.source_mapping.lines |
||||
new_str = "//" + old_str |
||||
create_patch_with_line(result, self.in_file, start, stop, old_str, new_str, line_no[0]) |
||||
|
||||
return result |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,22 @@ |
||||
from typing import Dict, Union |
||||
from collections import defaultdict |
||||
|
||||
# pylint: disable=too-many-arguments |
||||
def create_patch_with_line( |
||||
result: Dict, |
||||
file: str, |
||||
start: int, |
||||
end: int, |
||||
old_str: Union[str, bytes], |
||||
new_str: Union[str, bytes], |
||||
line_no: int |
||||
) -> None: |
||||
if isinstance(old_str, bytes): |
||||
old_str = old_str.decode("utf8") |
||||
if isinstance(new_str, bytes): |
||||
new_str = new_str.decode("utf8") |
||||
p = {"start": start, "end": end, "old_string": old_str, "new_string": new_str, "line_number": line_no} |
||||
if "patches" not in result: |
||||
result["patches"] = defaultdict(list) |
||||
if p not in result["patches"][file]: |
||||
result["patches"][file].append(p) |
Loading…
Reference in new issue