-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement user defined function call analyzer
- Loading branch information
1 parent
910e5ae
commit 6593c99
Showing
3 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
from sierra.analyzer.functions.functions_analyzer import FunctionsAnalyzer | ||
from sierra.analyzer.security.dead_code_analyzer import DeadCodeAnalyzer | ||
from sierra.analyzer.security.delegate_call_analyzer import DelegateCallAnalyzer | ||
from sierra.analyzer.security.user_defined_function_call_analyzer import ( | ||
UserDefinedFunctionCallAnalyzer, | ||
) | ||
from sierra.analyzer.security.usused_arguments_analyzer import UnusedArgumentsAnalyzer | ||
from sierra.analyzer.statistics.statistics_analyzer import StatisticsAnalyzer | ||
from sierra.analyzer.strings.strings_analyzer import StringsAnalyzer | ||
|
||
|
||
all_analyzers = [ | ||
# Security | ||
UserDefinedFunctionCallAnalyzer, | ||
DeadCodeAnalyzer, | ||
DelegateCallAnalyzer, | ||
UnusedArgumentsAnalyzer, | ||
# Informational | ||
FunctionsAnalyzer, | ||
StringsAnalyzer, | ||
StatisticsAnalyzer, | ||
StringsAnalyzer, | ||
] |
49 changes: 49 additions & 0 deletions
49
sierra/analyzer/security/user_defined_function_call_analyzer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from sierra.analyzer.abstract_analyzer import ( | ||
AbstractAnalyzer, | ||
CategoryClassification, | ||
ImpactClassification, | ||
PrecisionClassification, | ||
) | ||
from sierra.objects.objects import SierraConditionalBranch, SierraVariableAssignation | ||
|
||
|
||
class UserDefinedFunctionCallAnalyzer(AbstractAnalyzer): | ||
""" | ||
Detect user defined function call | ||
""" | ||
|
||
NAME = "user defined function call" | ||
ARGUMENT = "user_defined" | ||
HELP = "Find user defined function calls" | ||
IMPACT: ImpactClassification = ImpactClassification.MEDIUM | ||
PRECISION: PrecisionClassification = PrecisionClassification.MEDIUM | ||
CATEGORY: CategoryClassification = CategoryClassification.OPTIMIZATION | ||
|
||
def _detect(self) -> bool: | ||
for f in self.program.functions: | ||
statements = f.statements | ||
|
||
for statement in statements: | ||
if isinstance(statement, SierraVariableAssignation): | ||
libfunc_call = statement.function.id | ||
elif isinstance(statement, SierraConditionalBranch): | ||
libfunc_call = statement.function | ||
else: | ||
continue | ||
|
||
# user defined function | ||
if libfunc_call.startswith("function_call<user@") and libfunc_call.endswith(">"): | ||
# Core functions | ||
if libfunc_call.startswith("function_call<user@core"): | ||
continue | ||
|
||
# Remove function_call<> wrapper | ||
function_name = libfunc_call[19:-1] | ||
|
||
self.detected = True | ||
self.result.append( | ||
"User defined function %s called in %s" | ||
% (function_name.split("::")[-1], f.id.split("::")[-1]) | ||
) | ||
|
||
return self.detected |