Skip to main content

resolve_offset

Function resolve_offset 

Source
pub fn resolve_offset(
    spec: &OffsetSpec,
    buffer: &[u8],
) -> Result<usize, LibmagicError>
Expand description

Resolve any offset specification to an absolute position

This is a higher-level function that handles all types of offset specifications. Currently only supports absolute offsets, but will be extended to handle indirect, relative, and from-end offsets in future tasks.

§Arguments

  • spec - The offset specification to resolve
  • buffer - The file buffer to resolve against

§Returns

Returns the resolved absolute offset as a usize, or a LibmagicError if resolution fails.

§Examples

use libmagic_rs::evaluator::offset::resolve_offset;
use libmagic_rs::parser::ast::OffsetSpec;

let buffer = b"Test data";
let spec = OffsetSpec::Absolute(4);

let offset = resolve_offset(&spec, buffer).unwrap();
assert_eq!(offset, 4);

§Errors

  • LibmagicError::EvaluationError - If offset resolution fails