angr.analyses.decompiler.x87_fsw

Evaluation of integer expressions derived from an x87 CmpF result or an fxam classification.

CmpF yields one of four codes (GT 0x00, LT 0x01, EQ 0x40, unordered 0x45). fnstsw ax places them in AH together with the (unknown) top-of-stack pointer; test ah, imm / sahf / and ah, 0x45; cmp ah, 0x40 then test individual bits. Instead of matching every such shape structurally, we evaluate the expression in a known-bits domain once per outcome; the ftop contribution and the preserved OF bit of sahf drop out as unknown bits that the final mask discards. The resulting outcome -> value table is then turned into an IEEE comparison.

__fxam(x) is handled the same way over its outcomes: the C3/C2/C0 class bits (Intel SDM, FXAM) times the C1 sign. x87_fprem[1]_c3210(a, b) has every C3/C2/C1/C0 combination as an outcome (C2: the remainder is partial). A boolean placed at the C2 position (cond * 0x400, how fsin/fcos/fptan report an out-of-range operand) has two outcomes.

class angr.analyses.decompiler.x87_fsw.FswTable

Bases: object

Values of one or more integer expressions for each outcome of the single CmpF or __fxam they are built from.

values[outcome] holds one integer per evaluated expression.

__init__(source, operands, values)
Parameters:
source
operands
values
true_set(pred)
Return type:

frozenset[int]

Parameters:

pred (Callable[[tuple[int, ...]], bool])

angr.analyses.decompiler.x87_fsw.evaluate_over_fsw(exprs, vvar_defs=None, load_resolver=None, tmp_defs=None, fp_compare_leaves=False)

Evaluate integer expressions that depend on a single CmpF(a, b), __fxam(x), x87_fprem[1]_c3210(a, b) or C2 boolean for each of its outcomes.

Parameters:
Return type:

FswTable | None

Returns:

The table of values, or None if no source is found or any expression has unknown bits for some outcome.

angr.analyses.decompiler.x87_fsw.fsw_predicate(table, true_set, idx, ail_manager, bits, tags)

Convert true_set to a corresponding AIL expression. Returns None if no such expression exists.

Return type:

Expression | None

Parameters:
angr.analyses.decompiler.x87_fsw.fxam_predicate(true_set, x, idx, ail_manager, bits, tags)

Build the classification test of x that is exactly true for the fxam outcomes in true_set. This includes isnan, isinf, isfinite, isnormal, x == 0, signbit, and the negation of each one of them.

Return type:

Expression | None

Parameters:
angr.analyses.decompiler.x87_fsw.fp_predicate_from_outcomes(true_set, operands, idx, ail_manager, bits, tags)

Build the comparison for the CmpF outcomes in true_set.

Printed FP comparisons are ordered source-level predicates, as IDA prints them: the unordered outcome is folded into the comparison ({LT, UN} is a < b, {GT, EQ, UN} is a >= b) since it only reflects the parity check the compiler emits next to the comparison. {UN} and its complement are NaN tests and stay exact.

Return type:

Expression

Parameters:
angr.analyses.decompiler.x87_fsw.fold_fp_logic(expr, ail_manager, vvar_defs=None, tmp_defs=None)

Rebuild a boolean combination of comparisons and NaN tests of one operand pair, e.g. a != b ? 1 : isunordered(a, b), a == b && !isunordered(a, b) or !(a < b || isunordered(a, b)), as the single ordered comparison (see fp_predicate_from_outcomes).

Return type:

Expression | None

Returns:

The comparison, or None if expr is not such a combination or is a NaN test by itself.

Parameters:
angr.analyses.decompiler.x87_fsw.lower_cmpf_value(expr, ail_manager)

Exact C for an integer expression of one CmpF(a, b) and constants: isunordered(a, b) ? v_un : a == b ? v_eq : a < b ? v_lt : v_gt. A constant OR-ed on top (e.g., the ftop bits of a status word) is kept. A test whose value equals the fall-through value is dropped: later tests are false for the outcomes tested before them.

Return type:

Expression | None

Returns:

The replacement, or None if expr is not such an expression.

Parameters:
angr.analyses.decompiler.x87_fsw.fp_operands_match(a, b)

Whether two float comparison operands are the same value, ignoring exact FP widening (float -> double).

Return type:

bool

Parameters:
angr.analyses.decompiler.x87_fsw.const_is_nan(const)
Return type:

bool

Parameters:

const (Const)

angr.analyses.decompiler.x87_fsw.store_forwarder(statements, stmt_idx, has_call_memo=None)

Resolve a Load in statement stmt_idx to the data of an earlier Store in the same block that fully covers it, e.g. fnstsw word [ebp-0xa0]; test byte [ebp-0x9f], 0x41. The search stops at any statement that may write memory the Load could read.

Return type:

Callable[[Load], Expression | None]

Parameters: