How hikaruegashira/vulnhuntrs works
Main Components
• CLI & Entry Point: Start with src/main.rs and the build scripts (Cargo.toml, build.rs) that boot the tool.
• Analyzer Engine: Emphasize src/analyzer.rs which is likely the core logic for vulnerability detection.
• Language Parsing Module: Include src/parser.rs along with the tree-sitter grammar directories (tree-sitter-go, tree-sitter-java, etc.). These components provide language-specific parsing capabilities.
• Prompt Management & LLM Interaction: Represent the prompts subdirectory (src/prompts) that contains files like analysis.rs and evaluator.rs. This module likely builds requests to and processes responses from the LLM.
• Repository and Response Handling: Add components like src/repo.rs and src/response.rs which handle retrieval of code repositories and formatting of vulnerability reports.
• Security Patterns: Include src/security_patterns.rs that might define or match known vulnerability signatures.
• Documentation & Configuration: Although not part of runtime, include a section for docs (stack graphs, testing documents) and configuration files (e.g., .devcontainer, .gitignore) that influence how the system is developed and deployed.
Relationships and Interactions
• The CLI (src/main.rs) accepts a target project path (with -r option) and delegates analysis to the Analyzer Engine.
• The Analyzer calls the Parser to generate abstract representations of the code, leveraging tree-sitter modules for multiple programming languages.
• As part of the analysis, the tool uses defined security patterns and static analysis strategies (src/security_patterns.rs) to identify vulnerabilities.
• For vulnerability evaluation, the Analyzer interacts with the Prompt Management module which assembles prompts and communicates with external LLM services (such as gpt-4o-0806 and gpt-4o-mini, as noted in the README).
• The Response Module formats the output reports which are then printed or stored.
• The Repository Module (src/repo.rs) abstracts file system operations and potentially handles cloning or reading from the target project repository.
Architectural Patterns/Design Principles
• Separation of Concerns: The codebase is modularized into components (CLI, Analyzer, Parser, Prompts, etc.) to ensure clear boundaries between data collection, processing, and reporting.
• Extensibility: With directories for different tree-sitter languages and prompt configurations, the design allows for adding new language support or tweaking the LLM integration.
• Testability: The snapshots directory showing serialized responses indicates that snapshot tests enforce that changes in vulnerability detection are caught.
• Inversion of Control: By abstracting language-specific parsing and LLM interactions, components can be swapped or extended with minimal changes to core logic.