feat: wire offsetscan yara subcommand (schema-parity with Invoke-OffsetYaraScan); refactor PE assembly; fix strict-path overlay - #13
Conversation
…etYaraScan); refactor PE assembly; fix strict-path overlay
Reviewer's GuideWires up a feature-gated Sequence diagram for the new offsetscan yara subcommandsequenceDiagram
actor User
participant CLI as offsetscan_main
participant FS as FileSystem
participant Yara as yara_scan
User->>CLI: Commands::Yara(path,rules,recurse,timeout,ndjson)
CLI->>FS: expand_paths(path,recurse)
FS-->>CLI: files
loop per file
CLI->>Yara: scan_with_rules(file,rules,timeout)
Yara-->>CLI: Vec<YaraHit>
end
alt ndjson
CLI->>CLI: serde_json::to_string(hit)
else pretty JSON
CLI->>CLI: serde_json::to_string_pretty(all_hits)
end
opt had_error && all_hits.is_empty()
CLI->>CLI: std::process::exit(1)
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/main.rs" line_range="81-83" />
<code_context>
+ rules: Vec<String>,
+ #[arg(long)]
+ recurse: bool,
+ /// Per-file scan timeout in seconds.
+ #[arg(long, default_value_t = 60)]
+ timeout: i32,
+ },
}
</code_context>
<issue_to_address>
**issue (bug_risk):** Validate or constrain `timeout` to avoid negative values being passed into YARA.
The CLI’s `i32` timeout is passed straight through to `Rules::scan_file`, so clap will accept negative values and forward them to YARA. Please either switch to an unsigned type or explicitly reject/normalize negative timeouts before calling the scan to avoid undefined behavior in the YARA API.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| /// Per-file scan timeout in seconds. | ||
| #[arg(long, default_value_t = 60)] | ||
| timeout: i32, |
There was a problem hiding this comment.
issue (bug_risk): Validate or constrain timeout to avoid negative values being passed into YARA.
The CLI’s i32 timeout is passed straight through to Rules::scan_file, so clap will accept negative values and forward them to YARA. Please either switch to an unsigned type or explicitly reject/normalize negative timeouts before calling the scan to avoid undefined behavior in the YARA API.
Summary by Sourcery
Add a feature-gated YARA scanning subcommand and unify PE assembly/overlay handling while fixing a strict-path overlay inconsistency.
New Features:
offsetscan yaraCLI subcommand that scans files against one or more YARA rule files and emits OffsetInspect-compatible match records.Bug Fixes:
Enhancements:
assemble_pe_infobuilder between strict and lenient paths, removing duplicated struct assembly and overlay logic.Build:
yaracrate to 0.32 and enable itsvendoredfeature so YARA support builds reliably without a system-wide libyara install.Documentation:
Tests:
YaraHitJSON field names match OffsetInspect’s expected schema, even when the YARA feature is disabled.