Skip to content

Commit

Permalink
Fix logic and formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Chan <[email protected]>
  • Loading branch information
arthurscchan committed Jan 20, 2025
1 parent 53ea21c commit ebaa63d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
19 changes: 17 additions & 2 deletions src/fuzz_introspector/analyses/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Copyright 2025 Fuzz Introspector Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from fuzz_introspector import analysis
from fuzz_introspector.analyses import bug_digestor
from fuzz_introspector.analyses import driver_synthesizer
from fuzz_introspector.analyses import engine_input
Expand All @@ -12,7 +27,7 @@

# All optional analyses.
# Ordering here is important as top analysis will be shown first in the report
all_analyses = [
all_analyses: list[type[analysis.AnalysisInterface]] = [
optimal_targets.OptimalTargets,
engine_input.EngineInput,
runtime_coverage_analysis.RuntimeCoverageAnalysis,
Expand All @@ -27,6 +42,6 @@

# This is the list of analyses that are meant to run
# directly from CLI without the need to generate HTML reports
standalone_analyses = [
standalone_analyses: list[type[analysis.AnalysisInterface]] = [
source_code_line_analyser.SourceCodeLineAnalyser,
]
6 changes: 3 additions & 3 deletions src/fuzz_introspector/analyses/source_code_line_analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def analysis_func(self,

if not target_func_list:
logger.error('Failed to locate the target source file '
f'{target_source} from the project.')
f'{self.source_file} from the project.')

result_list = []
for func in target_func_list:
Expand All @@ -115,13 +115,13 @@ def analysis_func(self,
if start <= self.source_line <= end:
logger.info(f'Found function {func.function_name} from line '
f'{self.source_line} in {self.source_file}')
result_list.append(func)
result_list.append(func.to_dict())

if result_list:
self.json_results['functions'] = result_list
result_json_path = os.path.join(out_dir, 'functions.json')
logger.info(f'Dumping result to {result_json_path}')
with open(result_json_path, w) as f:
with open(result_json_path, 'w') as f:
json.dump(self.json_results, f)
else:
logger.info(f'No functions found from line {self.source_line}'
Expand Down
2 changes: 1 addition & 1 deletion src/fuzz_introspector/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def get_cmdline_parser() -> argparse.ArgumentParser:
type=str,
help='Target file path or name for SourceCodeLineAnalyser')
source_code_line_analyser_parser.add_argument(
'--line',
'--source-line',
default=-1,
type=int,
help='Target line for SourceCodeLineAnalyser')
Expand Down
1 change: 1 addition & 0 deletions src/fuzz_introspector/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from fuzz_introspector import analysis
from fuzz_introspector import constants
from fuzz_introspector import diff_report
from fuzz_introspector import html_helpers
from fuzz_introspector import html_report
from fuzz_introspector import utils

Expand Down
39 changes: 39 additions & 0 deletions src/fuzz_introspector/datatypes/function_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,45 @@ def __init__(self, elem: Dict[Any, Any]) -> None:
self.new_unreached_complexity: int = 0
self.total_cyclomatic_complexity: int = 0

def to_dict(self) -> Dict[str, Any]:
return {
"function_name": self.function_name,
"raw_function_name": self.raw_function_name,
"function_source_file": self.function_source_file,
"linkage_type": self.linkage_type,
"function_linenumber": self.function_linenumber,
"function_line_number_end": self.function_line_number_end,
"return_type": self.return_type,
"arg_count": self.arg_count,
"arg_types": self.arg_types,
"arg_names": self.arg_names,
"bb_count": self.bb_count,
"i_count": self.i_count,
"edge_count": self.edge_count,
"cyclomatic_complexity": self.cyclomatic_complexity,
"functions_reached": self.functions_reached,
"function_uses": self.function_uses,
"function_depth": self.function_depth,
"constants_touched": self.constants_touched,
"branch_profiles":
{k: str(v)
for k, v in self.branch_profiles.items()},
"signature": self.signature,
"functions_called": self.functions_called,
"is_accessible": self.is_accessible,
"is_jvm_library": self.is_jvm_library,
"is_enum": self.is_enum,
"is_static": self.is_static,
"exceptions": self.exceptions,
"need_close": self.need_close,
"callsite": self.callsite,
"hitcount": self.hitcount,
"reached_by_fuzzers": self.reached_by_fuzzers,
"incoming_references": self.incoming_references,
"new_unreached_complexity": self.new_unreached_complexity,
"total_cyclomatic_complexity": self.total_cyclomatic_complexity
}

@property
def has_source_file(self) -> bool:
return len(self.function_source_file.strip()) > 0
Expand Down

0 comments on commit ebaa63d

Please sign in to comment.