-
-
Notifications
You must be signed in to change notification settings - Fork 1
Evaluator: implement indirect offset resolution #37
Copy link
Copy link
Labels
compatibilitylibmagic compatibility and migrationlibmagic compatibility and migrationenhancementNew feature or requestNew feature or requestevaluatorRule evaluation engine and logicRule evaluation engine and logicpriority:highImportant, significant compatibility or architecture impactImportant, significant compatibility or architecture impact
Milestone
Description
Summary
Implement evaluation of indirect offsets. The AST representation (OffsetSpec::Indirect) already exists, but the evaluator returns a "not yet implemented" error at src/evaluator/offset.rs:159.
Context
Indirect offsets are a core feature of magic files that allow pointer-chasing through binary structures. The syntax (offset.type) reads a value at the given offset, interprets it as a pointer of the specified type, and uses the result as the actual offset for matching.
Examples:
(0x3c.l)- Read a 32-bit long at offset 0x3c, use that value as the offset (PE executable header pointer)(4.s)- Read a 16-bit short at offset 4, use as offset
Current state: AST variant defined, evaluation stubbed with TODO.
Acceptance Criteria
-
resolve_offset()handlesOffsetSpec::Indirectby reading the pointer value from the buffer - Supports all numeric types as the indirect type (byte, short, long, quad)
- Handles endianness correctly for indirect reads
- Supports optional adjustment arithmetic:
(offset.type)+adjustment - Bounds checking on both the pointer read and the resulting offset
- Unit tests for indirect offset resolution
- Integration tests with PE header detection (classic indirect offset use case)
Impact
HIGH - Indirect offsets are critical for complex binary format detection (PE executables, compound documents, archive formats with headers pointing to content).
Files to Modify
src/evaluator/offset.rs- Implement indirect resolution (line ~159)src/evaluator/types.rs- May need to expose read functions for indirect use
References
- GNU file magic(5) man page: "indirect offsets"
- PE format detection uses
(0x3c.l)extensively - Epic Epic: libmagic-rs Phase 1 MVP #24
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
compatibilitylibmagic compatibility and migrationlibmagic compatibility and migrationenhancementNew feature or requestNew feature or requestevaluatorRule evaluation engine and logicRule evaluation engine and logicpriority:highImportant, significant compatibility or architecture impactImportant, significant compatibility or architecture impact