Score a given constant, in the context of its function. Args: const (int): numeric constant to rank context (FunctionContext): function context or None (for islands) Return Value: Overall score of the given numeric constant
(const, context)
| 383 | return measureBitsVariance(const) / (NUM_BITS_IN_CONST / 2) |
| 384 | |
| 385 | def rankConst(const, context): |
| 386 | """Score a given constant, in the context of its function. |
| 387 | |
| 388 | Args: |
| 389 | const (int): numeric constant to rank |
| 390 | context (FunctionContext): function context or None (for islands) |
| 391 | |
| 392 | Return Value: |
| 393 | Overall score of the given numeric constant |
| 394 | """ |
| 395 | # 0. Ignore stack variable offsets |
| 396 | if context is not None and const < context.frame + FRAME_SAFETY_GAP: |
| 397 | return 0 |
| 398 | # 1. Measure the entropy |
| 399 | score = measureBitsEntropy(const) |
| 400 | # 2. Scale it: use a wider range, and spread the values |
| 401 | score = score * score |
| 402 | # 3. Boost special values |
| 403 | if const in CONST_SPECIAL_VALUES: |
| 404 | score += CONST_BOOST_SPECIAL |
| 405 | # 4. Boost bit flags that are bigger than the frame size |
| 406 | if context is not None and countSetBits(const) == 1 and const > context.frame: |
| 407 | score += CONST_BOOST_BIT_FLAG |
| 408 | return score |
| 409 | |
| 410 | ################## |
| 411 | ## Global State ## |
no test coverage detected