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

Class SourceContext

src/function_context.py:404–736  ·  view source on GitHub ↗

A context that describes the canonical representation of a source file function, with it's full logic. Attributes ---------- unknown_funcs (set): temporary set of (source) function names from outside of our compilation file unknown_fptrs (set): temporary set of (source) func

Source from the content-addressed store, hash-verified

402 return len(self.calls) + len(self.xrefs) > 0
403
404class SourceContext(SrcFileFunction, FunctionContext):
405 """A context that describes the canonical representation of a source file function, with it's full logic.
406
407 Attributes
408 ----------
409 unknown_funcs (set): temporary set of (source) function names from outside of our compilation file
410 unknown_fptrs (set): temporary set of (source) function (pointer) names from outside of our compilation file
411 hash (str): hex digest of the function's hash (calculated on the raw binary)
412 call_order (dict): a mapping of: call invocation => set of call invocations that can reach it
413 followers (set): set of binary functions that use us as a potential match hint
414 exists (bool): validity flag marking our existence in the source (according to info from the binary match)
415 file_hint (str): source file name string if exists inside function, None otherwise
416 collision_candidates (list) list of src candidates with a possibility for merging (same name + linker optimizations)
417 """
418
419 def __init__(self, name, index):
420 """Create a source function instance.
421
422 Args:
423 name (str): source function name
424 index (int): index of the function in the global array of all source functions
425 """
426 SrcFileFunction.__init__(self, name, index)
427 FunctionContext.__init__(self)
428 # temporary field
429 self.unknown_funcs = set()
430 self.unknown_fptrs = set()
431 # artifacts
432 self.hash = None
433 # matching hints
434 self.followers = set()
435 # validity flag
436 self.exists = True
437 # File (source) hint
438 self.file_hint = None
439 # Compilation clues
440 self.is_static = False
441 # Linker optimizations
442 self.collision_candidates = []
443
444 # Overridden base function
445 def declareMatch(self, match):
446 """Declare a match between a source and a bin context.
447
448 Args:
449 match (BinaryCodeContext): the matching binary context
450 """
451 self.match = match
452 # notify our followers that we are now out of the game
453 for follower in self.followers:
454 follower.removeHint(self, clear=False)
455 self.followers = set()
456
457 # Overridden base function
458 def isPartial(self):
459 """Tell us that the current instance is a full function.
460
461 Return Value:

Callers 1

deserializeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected