pub fn apply_value_transform(
value: &Value,
transform: ValueTransform,
) -> Result<Value, EvaluationError>Expand description
Apply a magic-file pre-comparison ValueTransform to a numeric value
read from the file. The result is what the rule’s comparison operator
sees, and what printf-style format specifiers (%d, %x, …) render
into the message.
Magic file usage examples:
lelong+1 x volume %d– read a long, add 1, format as%dulequad/1073741824 x size %lluGB– read a quad, divide by 1 GiB
§Numeric promotion
Both Value::Uint and Value::Int operands are supported. The
transform is computed in the value’s existing type:
Uintopi64-> thei64operand is reinterpreted bitwise asu64forMul/Or/Xorand asi64for the others (matching libmagic’sapprentice.c::mconvert, which treats the operand as a raw machine word for bitwise ops and a signed integer for arithmetic).Subon aUintis rejected if it would underflow;Addclamps a negative operand to subtraction.Intuses signed arithmetic throughout.
Float, String, and Bytes values are left unchanged because
magic-file arithmetic transforms are only meaningful on integer
reads. Returning the value unchanged keeps the comparison flow
well-defined while preserving the GOTCHAS S2.3 catch-all discipline
for unknown Value variants.
§Errors
Returns EvaluationError::InvalidValueTransform when:
DivorModis applied with a zero operand;- any arithmetic op overflows the natural integer range.