[docs]classBlob(Backend):""" Representation of a binary blob, i.e. an executable in an unknown file format. """is_default=True# Tell CLE to automatically consider using the Blob backend
[docs]def__init__(self,*args,offset=None,segments=None,**kwargs):""" :param arch: (required) an :class:`archinfo.Arch` for the binary blob. :param offset: Skip this many bytes from the beginning of the file. :param segments: List of tuples describing how to map data into memory. Tuples are of ``(file_offset, mem_addr, size)``. You can't specify both ``offset`` and ``segments``. """if"custom_offset"inkwargs:offset=kwargs.pop("custom_offset")log.critical("Deprecation warning: the custom_offset parameter has been renamed to offset")super().__init__(*args,**kwargs)ifself._archisNone:raiseCLEError("Must specify arch when loading blob!")ifself._custom_entry_pointisNone:log.warning("No entry_point was specified for blob %s, assuming 0",self.binary_basename)self._entry=0self._max_addr=0self._min_addr=2**64try:self.linked_base=kwargs["base_addr"]exceptKeyError:log.warning("No base_addr was specified for blob %s, assuming 0",self.binary_basename)self.mapped_base=self.linked_baseself.os="unknown"ifoffsetisnotNone:ifsegmentsisnotNone:log.error("You can't specify both offset and segments. Taking only the segments data")else:self._binary_stream.seek(0,2)segments=[(offset,self.linked_base,self._binary_stream.tell()-offset)]else:ifsegmentsisnotNone:passelse:self._binary_stream.seek(0,2)segments=[(0,self.linked_base,self._binary_stream.tell())]forfile_offset,mem_addr,sizeinsegments:self._load(file_offset,mem_addr,size)
[docs]@staticmethoddefis_compatible(stream):returnstream==0# I hate pylint
@propertydefmin_addr(self):returnself._min_addr@propertydefmax_addr(self):returnself._max_addrdef_load(self,file_offset,mem_addr,size):""" Load a segment into memory. """self._binary_stream.seek(file_offset)string=self._binary_stream.read(size)ifstring:self.memory.add_backer(mem_addr-self.linked_base,string)seg=Segment(file_offset,mem_addr,size,size)self.segments.append(seg)self._max_addr=max(len(string)+mem_addr-1,self._max_addr)self._min_addr=min(mem_addr,self._min_addr)
[docs]deffunction_name(self,addr):# pylint: disable=unused-argument,no-self-use""" Blobs don't support function names. """returnNone