Expand description
Strength calculation for magic rules
This module implements the strength calculation algorithm based on libmagic’s
apprentice_magic_strength function. Strength is used to order rules during
evaluation, giving priority to more specific rules.
§Algorithm Overview
The default strength of a rule is calculated based on several factors:
- Type specificity: String types have higher strength than numeric types
- Operator specificity: Equality operators are more specific than bitwise
- Offset type: Absolute offsets are more reliable than indirect/relative
- Value length: Longer strings are more specific matches
The calculated strength can be modified using !:strength directives in magic
files, which apply arithmetic operations to the default strength.
Constants§
- MAX_
STRENGTH - Maximum strength value (clamped to prevent overflow)
- MIN_
STRENGTH - Minimum strength value (clamped to prevent negative strength)
Functions§
- apply_
strength_ modifier - Apply a strength modifier to a base strength value.
- calculate_
default_ strength - Calculate the default strength of a magic rule based on its specificity.
- calculate_
rule_ strength - Calculate the final strength of a magic rule, including any modifiers.
- into_
sorted_ by_ strength - Sort magic rules by strength and return the sorted vec (consuming the input).
- sort_
rules_ by_ strength - Sort magic rules by their calculated strength in descending order.