[docs]classPatchManager(KnowledgeBasePlugin):""" A placeholder-style implementation for a binary patch manager. This class should be significantly changed in the future when all data about loaded binary objects are loaded into angr knowledge base from CLE. As of now, it only stores byte-level replacements. Patches should not overlap, but it's user's responsibility to check for and avoid overlapping patches. """
[docs]defget_patch(self,addr):""" Get patch at the given address. :param int addr: The address of the patch. :return: The patch if there is one starting at the address, or None if there isn't any. :rtype: Patch or None """returnself._patches.get(addr,None)
[docs]defget_all_patches(self,addr,size):""" Retrieve all patches that cover a region specified by [addr, addr+size). :param int addr: The address of the beginning of the region. :param int size: Size of the region. :return: A list of patches. :rtype: list """patches=[]forpatch_addrinself._patches.irange(maximum=addr+size-1,reverse=True):p=self._patches[patch_addr]ifself.overlap(p.addr,p.addr+len(p),addr,addr+size):patches.append(p)else:breakreturnpatches[::-1]