Commit a9099f7
authored
feat: Add evaluation engine with offset resolution and CI/CD automation (#5)
* chore: Update implementation tasks in tasks.md for clarity and organization
- Renumbered and reorganized tasks in `tasks.md` to improve clarity and maintain a consistent structure.
- Added sub-tasks for offset resolution, type reading, operator creation, rule evaluation, and output formatting to enhance task tracking.
- Updated task descriptions to reflect current implementation requirements and ensure alignment with project goals.
These changes streamline the development process and provide clearer guidance for contributors on upcoming tasks and their dependencies.
Signed-off-by: UncleSp1d3r <[email protected]>
* feat: Enhance project metadata and CI configuration
- Added `homepage` and `documentation` fields to `Cargo.toml` for improved project visibility and resource access.
- Introduced `dist-workspace.toml` to configure workspace settings and CI parameters for building and releasing artifacts across multiple platforms.
- Created a comprehensive GitHub Actions workflow in `release.yml` to automate the release process, including artifact building, uploading, and GitHub release creation.
- Implemented offset resolution logic in `offset.rs`, including error handling and comprehensive unit tests to ensure robustness.
These changes improve project organization, enhance automation capabilities, and ensure better handling of file offsets during evaluation.
Signed-off-by: UncleSp1d3r <[email protected]>
* feat(evaluator): Implement basic byte reading functionality
- Added `read_byte` function in `src/evaluator/types.rs` for safely reading a single byte from a buffer with bounds checking.
- Introduced `TypeReadError` enum to handle buffer overrun errors during byte reading operations.
- Updated `mod.rs` to include the new `types` module.
- Marked task 6.1 as complete in `tasks.md`, reflecting the implementation of basic type reading for byte values.
These changes enhance the evaluator's capability to interpret byte data safely, improving overall robustness and error handling in the file type detection process.
Signed-off-by: UncleSp1d3r <[email protected]>
* feat(evaluator): Implement multi-byte type reading and interpretation
- Completed tasks for reading multi-byte types, including `read_short` and `read_long` functions in `src/evaluator/types.rs`, supporting both signed and unsigned interpretations with endianness handling.
- Introduced `read_typed_value` function to interpret bytes according to the specified `TypeKind`, allowing for flexible type reading.
- Enhanced error handling with the addition of `UnsupportedType` variant in `TypeReadError` for unsupported types.
- Updated `tasks.md` to reflect the completion of tasks related to multi-byte type reading and interpretation.
These changes significantly improve the evaluator's capability to handle various data types, enhancing the robustness and flexibility of the file type detection process.
Signed-off-by: UncleSp1d3r <[email protected]>
* feat(evaluator): Implement basic equality operator for value comparison
- Completed the implementation of the basic equality operator in `src/evaluator/operators.rs` with the `apply_equal` function, allowing for type-safe comparisons between different `Value` variants.
- Updated `mod.rs` to include the new `operators` module.
- Marked task 7.1 as complete in `tasks.md`, reflecting the addition of value-to-value comparison functionality.
These changes enhance the evaluator's capability to accurately compare values, improving the robustness of the file type detection process.
Signed-off-by: UncleSp1d3r <[email protected]>
* feat(evaluator): Implement inequality and bitwise AND operators for value comparison
- Completed the implementation of the inequality operator with the `apply_not_equal` function, allowing for type-safe comparisons between different `Value` variants.
- Added the bitwise AND operator with the `apply_bitwise_and` function, enabling pattern matching for integer values.
- Introduced the `apply_operator` function to dispatch operations based on the `Operator` enum, supporting equality, inequality, and bitwise AND operations.
- Updated `tasks.md` to reflect the completion of tasks related to operator creation and application.
These enhancements improve the evaluator's capability to perform complex comparisons and operations, further strengthening the file type detection process.
Signed-off-by: UncleSp1d3r <[email protected]>
* feat(evaluator): Implement single rule evaluation logic
- Added the `evaluate_single_rule` function in `src/evaluator/mod.rs` to evaluate a single magic rule against a file buffer.
- The function resolves the rule's offset, reads the corresponding bytes, and applies the specified operator for comparison.
- Comprehensive unit tests have been included to validate the functionality of the evaluation logic, covering various scenarios including equality, inequality, and bitwise operations.
- Updated `tasks.md` to reflect the completion of the task for basic rule evaluation.
These enhancements significantly improve the evaluator's capability to process and validate magic rules, enhancing the overall file type detection process.
Signed-off-by: UncleSp1d3r <[email protected]>
* chore(hooks): Remove outdated automation hooks for code analysis
- Deleted the `llms-txt-updater.kiro.hook`, `rust-code-analyzer.kiro.hook`, `rust-perf-analyzer.kiro.hook`, `rust-quality-monitor.kiro.hook`, and `rust-security-hardening.kiro.hook` files as they are no longer needed.
- These hooks were previously used for automated analysis and updates but have been replaced with more efficient user-triggered mechanisms to enhance control and accuracy in code quality and performance assessments.
This cleanup improves the project's automation infrastructure and reduces potential confusion regarding obsolete hooks.
Signed-off-by: UncleSp1d3r <[email protected]>
* feat(evaluator): Introduce EvaluationContext for managing evaluation state
- Added the `EvaluationContext` struct in `src/evaluator/mod.rs` to maintain the state during rule evaluation, including current offset, recursion depth, and configuration settings.
- Implemented methods for managing the offset and recursion depth, including incrementing and decrementing the recursion depth with error handling for exceeding limits.
- Updated `lib.rs` to re-export `EvaluationContext` for convenience.
- Marked task 8.2 as complete in `tasks.md`, reflecting the addition of the evaluation context structure.
These enhancements improve the evaluator's ability to manage state during complex rule evaluations, contributing to a more robust file type detection process.
Signed-off-by: UncleSp1d3r <[email protected]>
* feat(evaluator): Enhance evaluation configuration and hierarchical rule processing
- Completed the implementation of the `EvaluationConfig` struct in `src/lib.rs`, allowing for customizable evaluation options such as recursion limits, string length limits, and timeout settings.
- Introduced the `MatchResult` struct to encapsulate results from rule evaluations, including matched messages and offsets.
- Implemented the `evaluate_rules` function in `src/evaluator/mod.rs` to support hierarchical rule evaluation, enabling parent-child relationships in rules and refined matching.
- Updated `tasks.md` to reflect the completion of tasks related to evaluation configuration and hierarchical processing.
These enhancements improve the evaluator's flexibility and robustness, allowing for more complex and efficient file type detection processes.
Signed-off-by: UncleSp1d3r <[email protected]>
* refactor(evaluation): Enhance EvaluationConfig and EvaluationContext with const functions
- Updated `EvaluationConfig` in `src/lib.rs` to derive `Eq` for improved comparison capabilities.
- Refactored methods in `EvaluationContext` within `src/evaluator/mod.rs` to be `const fn`, allowing for compile-time evaluation and optimizations.
- Adjusted method signatures for `new`, `current_offset`, `set_current_offset`, `recursion_depth`, `config`, `should_stop_at_first_match`, `max_string_length`, `enable_mime_types`, `timeout_ms`, and `reset` to reflect the new const nature.
- Updated error handling in `src/io/mod.rs` to simplify path handling in error types.
These changes improve the efficiency and usability of the evaluation configuration and context, enhancing the overall robustness of the file type detection process.
Signed-off-by: UncleSp1d3r <[email protected]>
* chore(hooks): Update Rust code analysis and performance optimization hooks
- Modified the `rust-code-analyzer.kiro.hook` to analyze only the changed files in the current branch, enhancing its accuracy in identifying code quality issues.
- Updated the `rust-perf-optimizer.kiro.hook` to reflect the same change, ensuring performance analysis is based on the current diff.
- These updates improve the hooks' functionality and maintainability, aligning them with the project's focus on code quality and performance.
Signed-off-by: UncleSp1d3r <[email protected]>
* chore(output): Refactor MatchResult and EvaluationResult structures for enhanced clarity and functionality
- Updated the `MatchResult` struct in `src/output/mod.rs` to include additional fields such as `length`, `rule_path`, `confidence`, and `mime_type`, providing more comprehensive match information.
- Introduced the `EvaluationResult` struct to encapsulate the results of file evaluations, including metadata about the evaluation process and a vector of successful matches.
- Enhanced documentation with examples for both structs, improving usability and understanding of the evaluation results.
- Adjusted the `Cargo.toml` to modify lint settings, changing specific lints from "allow" to "warn" for better code quality enforcement.
These changes improve the output formatting module's capability to represent evaluation results, contributing to a more robust file type detection process.
Signed-off-by: UncleSp1d3r <[email protected]>
* feat(output): Implement text output formatting for evaluation results
- Created a new module `text.rs` in the `src/output` directory to handle text formatting of match results, providing a human-readable output style compatible with the GNU `file` command.
- Implemented functions for formatting single and multiple match results, as well as complete evaluation results, ensuring clear and structured output.
- Updated `tasks.md` to reflect the completion of tasks related to text output formatting, including unit tests for various scenarios.
These enhancements improve the output capabilities of the library, facilitating better user interaction and understanding of file type detection results.
Signed-off-by: UncleSp1d3r <[email protected]>
* refactor(evaluator): Update function signatures and enhance error handling
- Changed `set_current_offset` and `reset` methods in `src/evaluator/mod.rs` from `const fn` to regular functions to allow for mutable state changes.
- Improved error handling in `evaluate_rules` to provide more context for rule evaluation failures, including rule message and offset in error messages.
- Enhanced `read_byte` function in `src/evaluator/types.rs` to use `.copied()` for better clarity and safety.
- Added TODOs across various modules for comprehensive error handling, validation, and performance monitoring improvements, including file metadata validation and match result checks.
These changes enhance the robustness and clarity of the evaluation logic, paving the way for improved error management and validation in the file type detection process.
Signed-off-by: UncleSp1d3r <[email protected]>
* docs(lib): Enhance documentation for MagicDatabase methods
- Added detailed documentation for `load_from_file` and `evaluate_file` methods in `src/lib.rs`, including arguments, error handling, and usage examples to improve clarity and usability.
- Introduced a constant `SMALL_FILE_THRESHOLD` in `src/io/mod.rs` to indicate the threshold for small file handling, enhancing code readability and maintainability.
These updates improve the overall documentation quality, making it easier for users to understand and utilize the library's functionality effectively.
Signed-off-by: UncleSp1d3r <[email protected]>
* chore(dependencies): Update development dependencies and GitHub Actions
- Added `nix` crate as a development dependency in `Cargo.toml` for enhanced file type handling capabilities.
- Updated GitHub Actions in `dist-workspace.toml` to use newer versions for `attest-build-provenance` and `upload-artifact`, ensuring compatibility and improved functionality.
- Refactored the `release.yml` workflow to utilize the updated action version for build provenance.
These changes enhance the development environment and CI/CD pipeline, contributing to a more robust and maintainable project structure.
Signed-off-by: UncleSp1d3r <[email protected]>
* chore(markdown): Simplify allowed_elements formatting in markdownlint configuration
- Reformatted the `allowed_elements` array in `.markdownlint.json` to a single line for improved readability and consistency.
- This change enhances the clarity of the configuration file without altering its functionality.
Signed-off-by: UncleSp1d3r <[email protected]>
* feat(security): Enhance security features and validation in evaluation configuration
- Added comprehensive security documentation in `src/lib.rs`, outlining memory safety, bounds checking, resource limits, input validation, error handling, and timeout protection.
- Improved the `validate` method in `EvaluationConfig` to include checks for stack overflow, memory exhaustion, denial of service, and integer overflow vulnerabilities.
- Introduced tests for potential integer overflow vulnerabilities in offset calculations in `src/evaluator/offset.rs`.
- Enhanced the `read_byte` function in `src/evaluator/types.rs` with strict bounds checking to prevent buffer overruns and ensure secure byte reading.
- Updated `create_memory_mapping` in `src/io/mod.rs` to include security considerations for memory mapping.
These changes significantly bolster the security posture of the library, ensuring safer file type detection and evaluation processes.
Signed-off-by: UncleSp1d3r <[email protected]>
* chore(dependencies): Update nix crate to include fs feature
- Modified the `nix` dependency in `Cargo.toml` to enable the `fs` feature, enhancing file system capabilities for the project.
- Added an ignore attribute to the FIFO rejection test in `src/io/mod.rs` to prevent hanging issues in CI environments.
- Updated the text output formatting test in `src/output/text.rs` to clarify handling of Windows paths on Unix systems.
These changes improve the development environment and ensure more robust testing practices, contributing to a more reliable file type detection process.
Signed-off-by: UncleSp1d3r <[email protected]>
* fix(output): Improve cross-platform filename extraction in text formatting
- Update filename extraction logic in `format_evaluation_result` function
- Add platform-specific handling for Windows and Unix paths
- Modify test case to support different path extraction behaviors
- Ensure consistent filename display across different operating systems
- Add Windows-specific assertion for filename extraction
Signed-off-by: UncleSp1d3r <[email protected]>
* feat(output): Improve cross-platform filename extraction in text formatting
- Add cfg-if dependency to Cargo.toml for conditional compilation
- Update text output formatting test to handle different path extraction on Windows and Unix
- Implement cfg_if! macro to conditionally assert filename extraction based on platform
- Enhance test coverage for filename extraction in evaluation result formatting
Signed-off-by: UncleSp1d3r <[email protected]>
* ci(workflow): Update GitHub Actions matrix for Linux platform support
- Modify Linux platform matrix to use ubuntu-22.04 instead of generic 'arm'
- Ensure consistent and reliable Linux platform testing configuration
- Improve cross-platform compatibility for CI/CD pipeline
Signed-off-by: UncleSp1d3r <[email protected]>
---------
Signed-off-by: UncleSp1d3r <[email protected]>1 parent 0b0815c commit a9099f7
File tree
22 files changed
+8031
-179
lines changed- .github/workflows
- .kiro
- hooks
- specs/rust-libmagic-implementation
- src
- evaluator
- io
- output
- parser
22 files changed
+8031
-179
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
| 102 | + | |
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
This file was deleted.
0 commit comments