MCPcopy Create free account
hub / github.com/CheckPointSW/Karta / rankConst

Function rankConst

src/config/utils.py:385–408  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

383 return measureBitsVariance(const) / (NUM_BITS_IN_CONST / 2)
384
385def 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 ##

Callers 4

rankConstsMethod · 0.85
rankConstsMethod · 0.85
isAnchorFunction · 0.85
isAgentFunction · 0.85

Calls 2

measureBitsEntropyFunction · 0.85
countSetBitsFunction · 0.85

Tested by

no test coverage detected