[docs]classBackedCGC(CGC):""" This is a backend for CGC executables that allows user provide a memory backer and a register backer as the initial state of the running binary. """is_default=True# Tell CLE to automatically consider using the BackedCGC backend
[docs]def__init__(self,*args,memory_backer=None,register_backer=None,writes_backer=None,permissions_map=None,current_allocation_base=None,**kwargs,):""" :param path: File path to CGC executable. :param memory_backer: A dict of memory content, with beginning address of each segment as key and actual memory content as data. :param register_backer: A dict of all register contents. EIP will be used as the entry point of this executable. :param permissions_map: A dict of memory region to permission flags :param current_allocation_base: An integer representing the current address of the top of the CGC heap. """super().__init__(*args,**kwargs)self.memory_backer=memory_backerself.register_backer=register_backerself.writes_backer=writes_backerself.permissions_map=permissions_mapself.current_allocation_base=current_allocation_baseforseginself.segments:ifseg.is_executable:exec_seg_addr=seg.vaddrbreakelse:raiseValueError("Couldn't find executable segment?")forstart,_inself.memory._backers:ifstart!=exec_seg_addr:self.memory.remove_backer(start)forstart,datainsorted(self.memory_backer.items()):existing_seg=self.find_segment_containing(start)ifexisting_segisNone:# this is the text or data segmentnew_seg=FakeSegment(start,len(data))self.segments.append(new_seg)ifstart==exec_seg_addr:continueifstartinself.memory:raiseValueError("IF THIS GETS THROWN I'M GONNA JUMP OUT THE WINDOW")self.memory.add_backer(start,data)ifself.register_backerisnotNoneand"eip"inself.register_backer:self._entry=self.register_backer["eip"]
[docs]@staticmethoddefis_compatible(stream):returnFalse# Don't use this for anything unless it's manual