def__repr__(self):return"<CFGManager with %d CFGs>"%len(self.cfgs)def__contains__(self,ident):returnidentinself.cfgsdef__getitem__(self,ident)->CFGModel:ifidentnotinself.cfgs:ifself._kbisnotNoneandself._kb._projectisnotNone:is_arm=is_arm_arch(self._kb._project.arch)else:is_arm=Falseself.cfgs[ident]=CFGModel(ident,cfg_manager=self,is_arm=is_arm)returnself.cfgs[ident]def__setitem__(self,ident,model):self.cfgs[ident]=model
[docs]defnew_model(self,prefix):ifprefixnotinself.cfgs:returnself[prefix]# find a unique identi=0whileTrue:ident=prefix+"_%d"%iifidentnotinself.cfgs:breaki+=1returnself[ident]
[docs]defget_most_accurate(self)->Optional[CFGModel]:""" :return: The most accurate CFG present in the CFGManager, or None if it does not hold any. """less_accurate_to_most_accurate=["CFGFast","CFGEmulated"]# Try to get the most accurate first, then default to the next, ... all the way down to `None`.# Equivalent to `self.cfgs.get(<LAST>, self.cfgs.get(<SECOND LAST>, ... self.cfgs.get(<FIRST>, None)))`.returnreduce(lambdaacc,cfg:self.cfgs.get(cfg,acc),less_accurate_to_most_accurate,None)