diff --git a/plugins/xrefer/core/analyzer.py b/plugins/xrefer/core/analyzer.py index 8c03a34..919b258 100644 --- a/plugins/xrefer/core/analyzer.py +++ b/plugins/xrefer/core/analyzer.py @@ -947,6 +947,18 @@ def _group_interesting_artifacts(self, interesting_indices: Set[int]) -> Tuple[D return func_artifacts, orphan_func_artifacts, orphan_artifacts + def _is_function_excluded(self, func_name: str) -> bool: + """ + Check if a function name should be excluded from analysis. + + Args: + func_name (str): Name of the function to check (e.g., "sub_401000", "unknown_lib"). + + Returns: + bool: True if the function should be excluded, False otherwise. + """ + return func_name.startswith('unknown_') + def populate_entity_xrefs(self, entity_idx: int) -> None: """Quickly populate xrefs for a specific entity.""" entity = self.entities[entity_idx] @@ -2493,6 +2505,19 @@ def run_full_analysis(self) -> None: for ref in self.mapped_refs: orig_name = idc.get_func_name(ref[0]) func_ea = idc.get_name_ea(0, orig_name) + + # If the user has requested to skip library functions + if self.settings["exclude_non_language_libs"]: + func_flags = idc.get_func_flags(func_ea) + + # Check if the function is a library function, then skip it + if (func_flags & idc.FUNC_LIB) == 0: + continue + + # Check if the function is excluded based on custom criteria + if self._is_function_excluded(orig_name): + continue + self.leaf_funcs.add(func_ea) entity_index = ref[1] diff --git a/plugins/xrefer/core/settings.py b/plugins/xrefer/core/settings.py index ee05246..25acb3d 100644 --- a/plugins/xrefer/core/settings.py +++ b/plugins/xrefer/core/settings.py @@ -69,6 +69,7 @@ def get_default_settings(self) -> Dict[str, Any]: "llm_model": "gemini-1.5-pro", "api_key": "", "enable_exclusions": True, + "exclude_non_language_libs": False, "display_options": { "auto_size_graphs": True, "hide_llm_disclaimer": False, @@ -896,6 +897,12 @@ def setup_exclusion_tab(self, tab) -> None: path_layout.addWidget(self.exclusion_browse_btn, 0, 3) layout.addLayout(path_layout) + + self.exclude_non_language_libs_checkbox = QCheckBox("Exclude non-language specific library functions from analysis") + self.exclude_non_language_libs_checkbox.setChecked(self.settings["exclude_non_language_libs"]) + self.exclude_non_language_libs_checkbox.setToolTip("Exclude non-language specific library functions from analysis") + layout.addWidget(self.exclude_non_language_libs_checkbox) + # Lists lists_layout = QGridLayout() self.exclusion_lists = {} @@ -997,6 +1004,7 @@ def save_settings(self) -> None: "llm_model": self.llm_model_combo.currentText(), "api_key": self.api_key_edit.text(), "enable_exclusions": self.enable_exclusion_checkbox.isChecked(), + "exclude_non_language_libs" : self.exclude_non_language_libs_checkbox.isChecked(), # Add display options "display_options": { "auto_size_graphs": self.auto_size_graphs.isChecked(), @@ -1272,4 +1280,4 @@ def __exit__(self, exc_type, exc_val, exc_tb): os.unlink(self.lockfile) except OSError: pass - \ No newline at end of file +